vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / vom / vom / bond_member.cpp
1 /*
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
18 namespace VOM {
19 /**
20  * Construct a new object matching the desried state
21  */
22 bond_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
29 bond_member::~bond_member()
30 {
31 }
32
33 bond_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
40 void
41 bond_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
48 std::string
49 bond_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
59 bool
60 bond_member::operator<(const bond_member& itf) const
61 {
62   return (m_itf->handle() < itf.m_itf->handle());
63 }
64
65 void
66 bond_member::set(mode_t mode)
67 {
68   m_mode = mode;
69 }
70
71 void
72 bond_member::set(rate_t rate)
73 {
74   m_rate = rate;
75 }
76
77 const handle_t
78 bond_member::hdl(void) const
79 {
80   return m_itf->handle();
81 }
82
83 bool
84 bond_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
89 const bond_member::mode_t bond_member::mode_t::ACTIVE(0, "active");
90 const bond_member::mode_t bond_member::mode_t::PASSIVE(1, "passive");
91
92 const bond_member::mode_t
93 bond_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
101 bond_member::mode_t::mode_t(int v, const std::string& s)
102   : enum_base<bond_member::mode_t>(v, s)
103 {
104 }
105
106 const bond_member::rate_t bond_member::rate_t::FAST(0, "fast");
107 const bond_member::rate_t bond_member::rate_t::SLOW(1, "slow");
108
109 const bond_member::rate_t
110 bond_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
118 bond_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  */