FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
bond_interface.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_interface.hpp"
20 
21 namespace VOM {
22 /**
23  * Construct a new object matching the desried state
24  */
27  mode_t mode,
28  lb_t lb)
29  : interface(name, type_t::BOND, state)
30  , m_l2_address(l2_address_t::ZERO)
31  , m_mode(mode)
32  , m_lb(lb)
33 {
34 }
35 
38  const l2_address_t& l2_address,
39  mode_t mode,
40  lb_t lb)
41  : interface(name, type_t::BOND, state)
42  , m_l2_address(l2_address)
43  , m_mode(mode)
44  , m_lb(lb)
45 {
46 }
47 
49 {
50  sweep();
51  release();
52 }
53 
55  : interface(o)
56  , m_l2_address(o.m_l2_address)
57  , m_mode(o.m_mode)
58  , m_lb(o.m_lb)
59 {
60 }
61 
62 std::shared_ptr<bond_interface>
64 {
65  return std::dynamic_pointer_cast<bond_interface>(interface::find(hdl));
66 }
67 
68 void
70 {
71  m_mode = mode;
72 }
73 
74 void
76 {
77  m_lb = lb;
78 }
79 
82 {
83  std::ostringstream s;
84 
85  s << this->interface::to_string() << " mode:" << m_mode.to_string()
86  << " lb:" << m_lb.to_string();
87 
88  return (s.str());
89 }
90 
91 std::queue<cmd*>&
92 bond_interface::mk_create_cmd(std::queue<cmd*>& q)
93 {
94  q.push(new bond_interface_cmds::create_cmd(m_hdl, name(), m_mode, m_lb,
95  m_l2_address));
96 
97  return (q);
98 }
99 
100 std::queue<cmd*>&
101 bond_interface::mk_delete_cmd(std::queue<cmd*>& q)
102 {
103  q.push(new bond_interface_cmds::delete_cmd(m_hdl));
104 
105  return (q);
106 }
107 
108 std::shared_ptr<bond_interface>
110 {
111  return std::dynamic_pointer_cast<bond_interface>(singular_i());
112 }
113 
114 std::shared_ptr<interface>
115 bond_interface::singular_i() const
116 {
117  return m_db.find_or_add(name(), *this);
118 }
119 
120 void
122 {
123  this->interface::set(handle);
124 }
125 
127  "round-robin");
129  2,
130  "active-backup");
135  "unspecified");
136 
139 {
140  if (1 == numeric) {
142  }
143  if (2 == numeric) {
145  }
146  if (3 == numeric) {
148  }
149  if (4 == numeric) {
151  }
152  if (5 == numeric) {
154  }
155 
157 }
158 
159 bond_interface::mode_t::mode_t(int v, const std::string& s)
161 {
162 }
163 
168 
171 {
172  if (0 == numeric) {
173  return (bond_interface::lb_t::L2);
174  }
175  if (1 == numeric) {
176  return (bond_interface::lb_t::L34);
177  }
178  if (2 == numeric) {
179  return (bond_interface::lb_t::L23);
180  }
181 
183 }
184 
185 bond_interface::lb_t::lb_t(int v, const std::string& s)
186  : enum_base<bond_interface::lb_t>(v, s)
187 {
188 }
189 }; // namespace VOM
190 
191 /*
192  * fd.io coding-style-patch-verification: OFF
193  *
194  * Local Variables:
195  * eval: (c-set-style "mozilla")
196  * End:
197  */
VOM::bond_interface
A bond-interface.
Definition: bond_interface.hpp:25
VOM::bond_interface::lb_t::L23
const static lb_t L23
L23 bond interface lb.
Definition: bond_interface.hpp:86
VOM::bond_interface::mode_t::BROADCAST
const static mode_t BROADCAST
Broadcast bond interface mode.
Definition: bond_interface.hpp:48
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
name
string name[64]
Definition: fib.api:25
VOM::bond_interface::to_string
virtual std::string to_string() const
convert to string
Definition: bond_interface.cpp:81
bond_group_binding.hpp
VOM::interface::m_db
static singular_db< key_t, interface > m_db
A map of all interfaces key against the interface's name.
Definition: interface.hpp:572
VOM::bond_interface::set
void set(mode_t mode)
set the mode
Definition: bond_interface.cpp:69
bond_interface_cmds.hpp
VOM::interface::m_hdl
HW::item< handle_t > m_hdl
The SW interface handle VPP has asigned to the interface.
Definition: interface.hpp:540
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
VOM::bond_interface::mode_t::LACP
const static mode_t LACP
LACP bond interface mode.
Definition: bond_interface.hpp:52
state
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
VOM::bond_interface::lb_t
A bond interface load balance.
Definition: bond_interface.hpp:73
VOM::interface::name
const std::string & name() const
Return the interface type.
Definition: interface.cpp:271
VOM::bond_interface::lb_t::L34
const static lb_t L34
L34 bond interface lb.
Definition: bond_interface.hpp:82
bond_interface.hpp
VOM::bond_interface::lb_t::from_numeric_val
static const lb_t from_numeric_val(uint8_t v)
Convert VPP's value of the bond to a lb.
Definition: bond_interface.cpp:170
VOM::interface::to_string
virtual std::string to_string(void) const
convert to string format for debug purposes
Definition: interface.cpp:247
VOM::bond_interface::~bond_interface
~bond_interface()
Definition: bond_interface.cpp:48
VOM::bond_interface::lb_t::UNSPECIFIED
const static lb_t UNSPECIFIED
Unspecified bond interface lb.
Definition: bond_interface.hpp:90
VOM::bond_interface::mode_t::XOR
const static mode_t XOR
XOR bond interface mode.
Definition: bond_interface.hpp:44
VOM::bond_interface_cmds::create_cmd
A functor class that creates an interface.
Definition: bond_interface_cmds.hpp:33
VOM::interface::sweep
virtual void sweep(void)
Sweep/reap the object if still stale.
Definition: interface.cpp:182
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::interface::set
void set(const admin_state_t &state)
Set the admin state of the interface.
Definition: interface.cpp:402
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::bond_interface::mode_t::ACTIVE_BACKUP
const static mode_t ACTIVE_BACKUP
Active-backup bond interface mode.
Definition: bond_interface.hpp:40
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_interface::lb_t::L2
const static lb_t L2
L2 bond interface lb.
Definition: bond_interface.hpp:78
VOM::l2_address_t
Type def of a L2 address as read from VPP.
Definition: types.hpp:339
VOM::interface::type_t
An interface type.
Definition: interface.hpp:67
VOM::bond_interface::mode_t
A bond interface mode.
Definition: bond_interface.hpp:31
VOM::interface::admin_state_t
The admin state of the interface.
Definition: interface.hpp:138
VOM::bond_interface::mode_t::UNSPECIFIED
const static mode_t UNSPECIFIED
Unspecified bond interface mode.
Definition: bond_interface.hpp:56
bond_group_binding_cmds.hpp
VOM::bond_interface::mode_t::ROUND_ROBIN
const static mode_t ROUND_ROBIN
Round-Robin bond interface mode.
Definition: bond_interface.hpp:36
VOM::bond_interface::find
static std::shared_ptr< bond_interface > find(const handle_t &hdl)
The the singular instance of the bond interface in the DB by handle.
Definition: bond_interface.cpp:63
VOM::bond_interface::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_interface.cpp:138
VOM::bond_interface::singular
std::shared_ptr< bond_interface > singular() const
Return the matching 'singular instance' of the BOND interface.
Definition: bond_interface.cpp:109
VOM::interface::release
void release()
release/remove an interface form the singular store
Definition: interface.cpp:240
VOM::bond_interface::bond_interface
bond_interface(const std::string &name, admin_state_t state, mode_t mode, lb_t lb=lb_t::UNSPECIFIED)
Construct a new object matching the desried state.
Definition: bond_interface.cpp:25
VOM::interface::find
static std::shared_ptr< interface > find(const handle_t &h)
The the singular instance of the interface in the DB by handle.
Definition: interface.cpp:538
string
const char *const string
Definition: cJSON.h:172