FD.io VPP  v18.07-34-g55fbdb9
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  */
25 bond_interface::bond_interface(const std::string& name,
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 
80 std::string
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 {
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) {
141  return (bond_interface::mode_t::ROUND_ROBIN);
142  }
143  if (2 == numeric) {
144  return (bond_interface::mode_t::ACTIVE_BACKUP);
145  }
146  if (3 == numeric) {
147  return (bond_interface::mode_t::XOR);
148  }
149  if (4 == numeric) {
150  return (bond_interface::mode_t::BROADCAST);
151  }
152  if (5 == numeric) {
153  return (bond_interface::mode_t::LACP);
154  }
155 
156  return (bond_interface::mode_t::UNSPECIFIED);
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 
182  return (bond_interface::lb_t::UNSPECIFIED);
183 }
184 
185 bond_interface::lb_t::lb_t(int v, const std::string& s)
187 {
188 }
189 }; // namespace VOM
190 
191 /*
192  * fd.io coding-style-patch-verification: ON
193  *
194  * Local Variables:
195  * eval: (c-set-style "mozilla")
196  * End:
197  */
static const mode_t BROADCAST
Broadcast bond interface mode.
void release()
release/remove an interface form the singular store
Definition: interface.cpp:234
A template base class for all enum types.
Definition: enum_base.hpp:30
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:461
HW::item< handle_t > m_hdl
The SW interface handle VPP has asigned to the interface.
Definition: interface.hpp:487
A functor class that deletes a Tap interface.
virtual void sweep(void)
Sweep/reap the object if still stale.
Definition: interface.cpp:163
static const mode_t XOR
XOR bond interface mode.
void set(const admin_state_t &state)
Set the admin state of the interface.
Definition: interface.cpp:390
std::shared_ptr< bond_interface > singular() const
Return the matching &#39;singular instance&#39; of the BOND interface.
static const lb_t from_numeric_val(uint8_t v)
Convert VPP&#39;s value of the bond to a lb.
const handle_t & handle() const
Return VPP&#39;s handle to this object.
Definition: interface.cpp:133
A bond interface load balance.
Type def of a L2 address as read from VPP.
Definition: types.hpp:334
void set(mode_t mode)
set the mode
static const mode_t LACP
LACP bond interface mode.
static singular_db< key_t, interface > m_db
A map of all interfaces key against the interface&#39;s name.
Definition: interface.hpp:519
vhost_vring_state_t state
Definition: vhost_user.h:115
virtual std::string to_string() const
convert to string
const l2_address_t & l2_address() const
Return the L2 Address.
Definition: interface.cpp:145
#define v
Definition: acl.c:491
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.
static const mode_t UNSPECIFIED
Unspecificed bond interface mode.
A functor class that creates an interface.
static const mode_t ACTIVE_BACKUP
Active-backup bond interface mode.
A bond-interface.
The admin state of the interface.
Definition: interface.hpp:142
A representation of an interface in VPP.
Definition: interface.hpp:41
static const lb_t L34
L34 bond interface lb.
A type declaration of an interface handle in VPP.
Definition: types.hpp:228
A bond interface mode.
static const lb_t UNSPECIFIED
Unspecificed bond interface lb.
const std::string & name() const
Return the interface type.
Definition: interface.cpp:265
An interface type.
Definition: interface.hpp:67
static const lb_t L23
L23 bond interface lb.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
static const mode_t ROUND_ROBIN
Round-Robin bond interface mode.
static std::shared_ptr< bond_interface > find(const handle_t &hdl)
The the singular instance of the bond interface in the DB by handle.
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
static const mode_t from_numeric_val(uint8_t v)
Convert VPP&#39;s value of the bond to a mode.
virtual std::string to_string(void) const
convert to string format for debug purposes
Definition: interface.cpp:241
static const lb_t L2
L2 bond interface lb.