FD.io VPP  v21.01.1
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  */
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
const 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
virtual interfaces - those that depend on some real interface
const char *const string
Definition: cJSON.h:172
const key_t key() const
get the key to this object
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
A cmd class that detach slave from a bond interface.
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
std::shared_ptr< bond_group_binding > singular() const
Return the &#39;singular&#39; of the bond interface binding that matches this object.
A representation of bond interface binding.
#define false
Definition: cJSON.c:70
bond_group_binding(const bond_interface &itf, const enslaved_itf_t &mem)
Construct a new object matching the desried state.
static void dump(std::ostream &os)
Dump all bond interface bindings into the stream provided.
A bond-interface.
std::set< bond_member > enslaved_itf_t
The container type for enslaved itfs.
void event_handler(void *tls_async)
Definition: tls_async.c:334
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
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
std::string to_string() const
convert to string format for debug purposes
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
save_rewrite_length must be aligned so that reass doesn t overwrite it
Definition: buffer.h:401
std::string key_t
The KEY can be used to uniquely identify the Bond Binding.
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
A command class that binds the slave interface to the bond interface.