FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
bond_group_binding.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 
19 
20 namespace VOM {
21 
22 /**
23  * A DB of all bond interface binding
24  */
25 singular_db<bond_group_binding::key_t, bond_group_binding>
26  bond_group_binding::m_db;
27 
28 bond_group_binding::event_handler bond_group_binding::m_evh;
29 
31  const enslaved_itf_t& itfs)
32  : m_itf(itf.singular())
33  , m_mem_itfs(itfs)
34  , m_binding(false)
35 {
36 }
37 
39  : m_itf(o.m_itf)
40  , m_mem_itfs(o.m_mem_itfs)
41  , m_binding(o.m_binding)
42 {
43 }
44 
46 {
47  sweep();
48 
49  // not in the DB anymore.
50  m_db.release(key(), this);
51 }
52 
55 {
56  return (m_itf->key() + "-binding");
57 }
58 
59 void
60 bond_group_binding::sweep()
61 {
62 
63  auto it = m_mem_itfs.cbegin();
64  while (it != m_mem_itfs.cend()) {
65  if (m_binding) {
67  new bond_group_binding_cmds::unbind_cmd(m_binding, it->hdl()));
68  }
69  HW::write();
70  ++it;
71  }
72 }
73 
74 void
75 bond_group_binding::dump(std::ostream& os)
76 {
77  db_dump(m_db, os);
78 }
79 
80 void
81 bond_group_binding::replay()
82 {
83  auto it = m_mem_itfs.cbegin();
84  while (it != m_mem_itfs.cend()) {
85  if (m_binding) {
87  new bond_group_binding_cmds::bind_cmd(m_binding, m_itf->handle(), *it));
88  }
89  HW::write();
90  ++it;
91  }
92 }
93 
96 {
97  auto it = m_mem_itfs.cbegin();
98  std::ostringstream s;
99  s << "bond-interface-binding: " << m_itf->to_string() << " slave-itfs: [";
100  while (it != m_mem_itfs.cend()) {
101  s << " " << it->to_string();
102  ++it;
103  }
104  s << "]";
105  return (s.str());
106 }
107 
108 void
109 bond_group_binding::update(const bond_group_binding& desired)
110 {
111  /*
112  * the desired state is always that the interface should be created
113  */
114  auto it = m_mem_itfs.cbegin();
115  while (it != m_mem_itfs.cend()) {
116  if (!m_binding) {
117  HW::enqueue(
118  new bond_group_binding_cmds::bind_cmd(m_binding, m_itf->handle(), *it));
119  }
120  ++it;
121  }
122 }
123 
124 std::shared_ptr<bond_group_binding>
125 bond_group_binding::find_or_add(const bond_group_binding& temp)
126 {
127  return (m_db.find_or_add(temp.key(), temp));
128 }
129 
130 std::shared_ptr<bond_group_binding>
132 {
133  return find_or_add(*this);
134 }
135 
137 {
138  OM::register_listener(this);
139  inspect::register_handler({ "bond-intf-binding" }, "Bond interface binding",
140  this);
141 }
142 
143 void
144 bond_group_binding::event_handler::handle_replay()
145 {
146  m_db.replay();
147 }
148 
149 void
150 bond_group_binding::event_handler::handle_populate(const client_db::key_t& key)
151 {
152  /*
153  * handle it in interface class
154  */
155 }
156 
158 bond_group_binding::event_handler::order() const
159 {
160  /*
161  * We want enslaved interfaces bind to bond after interface
162  * but before anything else.
163  */
165 }
166 
167 void
169 {
170  db_dump(m_db, os);
171 }
172 }
173 /*
174  * fd.io coding-style-patch-verification: OFF
175  *
176  * Local Variables:
177  * eval: (c-set-style "mozilla")
178  * End:
179  */
VOM::bond_interface
A bond-interface.
Definition: bond_interface.hpp:25
VOM::HW::write
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::inspect::register_handler
static void register_handler(const std::vector< std::string > &cmds, const std::string &help, command_handler *ch)
Register a command handler for inspection.
Definition: inspect.cpp:85
VOM::dependency_t
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
bond_group_binding.hpp
VOM::bond_group_binding_cmds::unbind_cmd
A cmd class that detach slave from a bond interface.
Definition: bond_group_binding_cmds.hpp:68
VOM::bond_group_binding::key
const key_t key() const
get the key to this object
Definition: bond_group_binding.cpp:54
key
typedef key
Definition: ipsec_types.api:91
VOM::db_dump
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
Definition: singular_db_funcs.hpp:35
VOM::bond_group_binding::key_t
std::string key_t
The KEY can be used to uniquely identify the Bond Binding.
Definition: bond_group_binding.hpp:42
VOM::OM::register_listener
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
VOM::client_db::key_t
const typedef std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
VOM::HW::enqueue
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
it
save_rewrite_length must be aligned so that reass doesn t overwrite it
Definition: buffer.h:425
VOM::bond_group_binding::~bond_group_binding
~bond_group_binding()
Destructor.
Definition: bond_group_binding.cpp:45
false
#define false
Definition: cJSON.c:70
singular_db_funcs.hpp
VOM::dependency_t::VIRTUAL_INTERFACE
@ VIRTUAL_INTERFACE
virtual interfaces - those that depend on some real interface
VOM::bond_group_binding
A representation of bond interface binding.
Definition: bond_group_binding.hpp:34
bond_group_binding_cmds.hpp
VOM::bond_group_binding::bond_group_binding
bond_group_binding(const bond_interface &itf, const enslaved_itf_t &mem)
Construct a new object matching the desried state.
Definition: bond_group_binding.cpp:30
VOM::bond_group_binding::singular
std::shared_ptr< bond_group_binding > singular() const
Return the 'singular' of the bond interface binding that matches this object.
Definition: bond_group_binding.cpp:131
VOM::bond_group_binding::dump
static void dump(std::ostream &os)
Dump all bond interface bindings into the stream provided.
Definition: bond_group_binding.cpp:75
VOM::bond_group_binding_cmds::bind_cmd
A command class that binds the slave interface to the bond interface.
Definition: bond_group_binding_cmds.hpp:29
show
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
event_handler
void event_handler(void *tls_async)
Definition: tls_async.c:334
VOM::bond_group_binding::enslaved_itf_t
std::set< bond_member > enslaved_itf_t
The container type for enslaved itfs.
Definition: bond_group_binding.hpp:47
VOM::bond_group_binding::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: bond_group_binding.cpp:95
string
const char *const string
Definition: cJSON.h:172