FD.io VPP  v18.04-17-g3a0d853
Vector Packet Processing
bond_interface.hpp
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 #ifndef __VOM_BOND_INTERFACE_H__
17 #define __VOM_BOND_INTERFACE_H__
18 
19 #include "vom/interface.hpp"
20 
21 namespace VOM {
22 /**
23  * A bond-interface. e.g. a bond interface
24  */
25 class bond_interface : public interface
26 {
27 public:
28  /**
29  * A bond interface mode
30  */
31  struct mode_t : enum_base<mode_t>
32  {
33  /**
34  * Round-Robin bond interface mode
35  */
36  const static mode_t ROUND_ROBIN;
37  /**
38  * Active-backup bond interface mode
39  */
40  const static mode_t ACTIVE_BACKUP;
41  /**
42  * XOR bond interface mode
43  */
44  const static mode_t XOR;
45  /**
46  * Broadcast bond interface mode
47  */
48  const static mode_t BROADCAST;
49  /**
50  * LACP bond interface mode
51  */
52  const static mode_t LACP;
53  /**
54  * Unspecificed bond interface mode
55  */
56  const static mode_t UNSPECIFIED;
57 
58  /**
59  * Convert VPP's value of the bond to a mode
60  */
61  static const mode_t from_numeric_val(uint8_t v);
62 
63  private:
64  /**
65  * Private constructor taking the value and the string name
66  */
67  mode_t(int v, const std::string& s);
68  };
69 
70  /**
71  * A bond interface load balance
72  */
73  struct lb_t : enum_base<lb_t>
74  {
75  /**
76  * L2 bond interface lb
77  */
78  const static lb_t L2;
79  /**
80  * L34 bond interface lb
81  */
82  const static lb_t L34;
83  /**
84  * L23 bond interface lb
85  */
86  const static lb_t L23;
87  /**
88  * Unspecificed bond interface lb
89  */
90  const static lb_t UNSPECIFIED;
91 
92  /**
93  * Convert VPP's value of the bond to a lb
94  */
95  static const lb_t from_numeric_val(uint8_t v);
96 
97  private:
98  /**
99  * Private constructor taking the value and the string name
100  */
101  lb_t(int v, const std::string& s);
102  };
103 
104  bond_interface(const std::string& name,
106  mode_t mode,
107  lb_t lb = lb_t::UNSPECIFIED);
108 
109  bond_interface(const std::string& name,
111  const l2_address_t& l2_address,
112  mode_t mode,
113  lb_t lb = lb_t::UNSPECIFIED);
114 
115  ~bond_interface();
116  bond_interface(const bond_interface& o);
117 
118  /**
119  * The the singular instance of the bond interface in the DB by handle
120  */
121  static std::shared_ptr<bond_interface> find(const handle_t& hdl);
122 
123  /**
124  * Return the matching 'singular instance' of the BOND interface
125  */
126  std::shared_ptr<bond_interface> singular() const;
127 
128  /**
129  * set the mode
130  */
131  void set(mode_t mode);
132 
133  /**
134  * set the lb
135  */
136  void set(lb_t lb);
137 
138  /**
139  * convert to string
140  */
141  virtual std::string to_string() const;
142 
143 protected:
144  /**
145  * set the handle
146  */
147  void set(handle_t& handle);
148  friend class interface_factory;
149 
150 private:
151  /**
152  * l2 address on bond interface
153  */
154  l2_address_t m_l2_address;
155 
156  /**
157  * mode on bond interface
158  */
159  mode_t m_mode;
160 
161  /**
162  * lb mode on bond interface
163  */
164  lb_t m_lb;
165 
166  /**
167  * Return the matching 'instance' of the sub-interface
168  * over-ride from the base class
169  */
170  std::shared_ptr<interface> singular_i() const;
171 
172  /**
173  * Virtual functions to construct an interface create commands.
174  */
175  virtual std::queue<cmd*>& mk_create_cmd(std::queue<cmd*>& cmds);
176 
177  /**
178  * Virtual functions to construct an interface delete commands.
179  */
180  virtual std::queue<cmd*>& mk_delete_cmd(std::queue<cmd*>& cmds);
181 
182  /*
183  * It's the OM class that call singular()
184  */
185  friend class OM;
186 };
187 }
188 
189 /*
190  * fd.io coding-style-patch-verification: ON
191  *
192  * Local Variables:
193  * eval: (c-set-style "mozilla")
194  * End:
195  */
196 
197 #endif
static const mode_t BROADCAST
Broadcast bond interface mode.
A template base class for all enum types.
Definition: enum_base.hpp:30
static const mode_t XOR
XOR bond interface mode.
std::shared_ptr< bond_interface > singular() const
Return the matching &#39;singular instance&#39; of the BOND interface.
const handle_t & handle() const
Return VPP&#39;s handle to this object.
Definition: interface.cpp:132
A bond interface load balance.
Type def of a L2 address as read from VPP.
Definition: types.hpp:342
static const mode_t LACP
LACP bond interface mode.
const l2_address_t & l2_address() const
Return the L2 Address.
Definition: interface.cpp:144
#define v
Definition: acl.c:495
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.
static const mode_t ACTIVE_BACKUP
Active-backup bond interface mode.
A bond-interface.
The admin state of the interface.
Definition: interface.hpp:127
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:236
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:264
The interface to writing objects into VPP OM.
Definition: om.hpp:140
vhost_vring_state_t state
Definition: vhost-user.h:82
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.
static const lb_t L2
L2 bond interface lb.