blob: f1a27b3d1c64aa8437c8f6657f06009abf0a89f9 [file] [log] [blame]
Mohsin Kazmied76ee22018-03-02 12:31:37 +01001/*
2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "vom/bond_member.hpp"
17
18namespace VOM {
19/**
20 * Construct a new object matching the desried state
21 */
22bond_member::bond_member(const interface& itf, mode_t mode, rate_t rate)
23 : m_itf(itf.singular())
24 , m_mode(mode)
25 , m_rate(rate)
26{
27}
28
29bond_member::~bond_member()
30{
31}
32
33bond_member::bond_member(const bond_member& o)
34 : m_itf(o.m_itf)
35 , m_mode(o.m_mode)
36 , m_rate(o.m_rate)
37{
38}
39
40void
41bond_member::to_vpp(vapi_payload_bond_enslave& bond_enslave) const
42{
43 bond_enslave.sw_if_index = m_itf->handle().value();
44 bond_enslave.is_passive = (m_mode == mode_t::PASSIVE) ? 1 : 0;
45 bond_enslave.is_long_timeout = (m_rate == rate_t::SLOW) ? 1 : 0;
46}
47
48std::string
49bond_member::to_string() const
50{
51 std::ostringstream s;
52
53 s << m_itf->to_string() << " mode:" << m_mode.to_string()
54 << " rate:" << m_rate.to_string();
55
56 return (s.str());
57}
58
59bool
60bond_member::operator<(const bond_member& itf) const
61{
62 return (m_itf->handle() < itf.m_itf->handle());
63}
64
65void
66bond_member::set(mode_t mode)
67{
68 m_mode = mode;
69}
70
71void
72bond_member::set(rate_t rate)
73{
74 m_rate = rate;
75}
76
77const handle_t
78bond_member::hdl(void) const
79{
80 return m_itf->handle();
81}
82
83bool
84bond_member::operator==(const bond_member& b) const
85{
86 return ((m_itf == b.m_itf) && (m_mode == b.m_mode) && (m_rate == b.m_rate));
87}
88
89const bond_member::mode_t bond_member::mode_t::ACTIVE(0, "active");
90const bond_member::mode_t bond_member::mode_t::PASSIVE(1, "passive");
91
92const bond_member::mode_t
93bond_member::mode_t::from_numeric_val(uint8_t numeric)
94{
95 if (0 == numeric)
96 return (bond_member::mode_t::ACTIVE);
97
98 return (bond_member::mode_t::PASSIVE);
99}
100
101bond_member::mode_t::mode_t(int v, const std::string& s)
102 : enum_base<bond_member::mode_t>(v, s)
103{
104}
105
106const bond_member::rate_t bond_member::rate_t::FAST(0, "fast");
107const bond_member::rate_t bond_member::rate_t::SLOW(1, "slow");
108
109const bond_member::rate_t
110bond_member::rate_t::from_numeric_val(uint8_t numeric)
111{
112 if (0 == numeric)
113 return (bond_member::rate_t::FAST);
114
115 return (bond_member::rate_t::SLOW);
116}
117
118bond_member::rate_t::rate_t(int v, const std::string& s)
119 : enum_base<bond_member::rate_t>(v, s)
120{
121}
122}; // namespace VOM
123
124/*
125 * fd.io coding-style-patch-verification: ON
126 *
127 * Local Variables:
128 * eval: (c-set-style "mozilla")
129 * End:
130 */