FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
bond_member.cpp
Go to the documentation of this file.
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  */
23  : m_itf(itf.singular())
24  , m_mode(mode)
25  , m_rate(rate)
26 {
27 }
28 
30 {
31 }
32 
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 
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
61 {
62  return (m_itf->handle() < itf.m_itf->handle());
63 }
64 
65 void
67 {
68  m_mode = mode;
69 }
70 
71 void
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
85 {
86  return ((m_itf == b.m_itf) && (m_mode == b.m_mode) && (m_rate == b.m_rate));
87 }
88 
91 
94 {
95  if (0 == numeric)
97 
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 
108 
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: OFF
126  *
127  * Local Variables:
128  * eval: (c-set-style "mozilla")
129  * End:
130  */
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::bond_member::to_vpp
void to_vpp(vapi_payload_bond_enslave &bond_enslave) const
convert to VPP
Definition: bond_member.cpp:41
VOM::bond_member::to_string
std::string to_string(void) const
convert to string
Definition: bond_member.cpp:49
VOM::bond_member::mode_t::PASSIVE
const static mode_t PASSIVE
Passive member interface mode.
Definition: bond_member.hpp:41
VOM::bond_member::rate_t::from_numeric_val
static const rate_t from_numeric_val(uint8_t v)
Convert VPP's value of the bond to a mode.
Definition: bond_member.cpp:110
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
VOM::bond_member::operator==
bool operator==(const bond_member &i) const
equality operator
Definition: bond_member.cpp:84
VOM::bond_member::rate_t::SLOW
const static rate_t SLOW
SLOW member interface rate.
Definition: bond_member.hpp:67
VOM::bond_member::set
void set(mode_t mode)
set the mode
Definition: bond_member.cpp:66
VOM::bond_member::operator<
bool operator<(const bond_member &mem_itf) const
less-than operator
Definition: bond_member.cpp:60
VOM::bond_member::bond_member
bond_member(const interface &itf, mode_t mode, rate_t rate)
Construct a new object matching the desried state.
Definition: bond_member.cpp:22
VOM::enum_base
A template base class for all enum types.
Definition: enum_base.hpp:30
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
bond_member.hpp
VOM::bond_member::mode_t::ACTIVE
const static mode_t ACTIVE
Active member interface mode.
Definition: bond_member.hpp:37
VOM::bond_member::rate_t
A member interface rate.
Definition: bond_member.hpp:58
VOM::enum_base::to_string
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
VOM::bond_member::~bond_member
~bond_member()
Definition: bond_member.cpp:29
VOM::bond_member::mode_t::from_numeric_val
static const mode_t from_numeric_val(uint8_t v)
Convert VPP's value of the bond to a mode.
Definition: bond_member.cpp:93
VOM::bond_member
A bond-member.
Definition: bond_member.hpp:26
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
VOM::bond_member::rate_t::FAST
const static rate_t FAST
Fast member interface rate.
Definition: bond_member.hpp:63
string
const char *const string
Definition: cJSON.h:172
VOM::bond_member::mode_t
A member interface mode.
Definition: bond_member.hpp:32
VOM::bond_member::hdl
const handle_t hdl(void) const
Get the interface handle.
Definition: bond_member.cpp:78