FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
gbp_bridge_domain.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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 
18 #include "vom/interface.hpp"
19 #include "vom/l2_binding.hpp"
21 
22 namespace VOM {
23 
24 /**
25  * A DB of al the interfaces, key on the name
26  */
27 singular_db<uint32_t, gbp_bridge_domain> gbp_bridge_domain::m_db;
28 
29 gbp_bridge_domain::event_handler gbp_bridge_domain::m_evh;
30 
31 /**
32  * Construct a new object matching the desried state
33  */
35  const interface& bvi)
36  : m_id(bd.id())
37  , m_bd(bd.singular())
38  , m_bvi(bvi.singular())
39 {
40 }
41 
43  const interface& bvi,
44  const interface& uu_fwd)
45  : m_id(bd.id())
46  , m_bd(bd.singular())
47  , m_bvi(bvi.singular())
48  , m_uu_fwd(uu_fwd.singular())
49 {
50 }
51 
53  const std::shared_ptr<interface> bvi,
54  const std::shared_ptr<interface> uu_fwd)
55  : m_id(bd.id())
56  , m_bd(bd.singular())
57  , m_bvi(bvi->singular())
58  , m_uu_fwd(uu_fwd->singular())
59 {
60 }
61 
63  const interface& bvi,
64  const std::shared_ptr<interface> uu_fwd)
65  : m_id(bd.id())
66  , m_bd(bd.singular())
67  , m_bvi(bvi.singular())
68  , m_uu_fwd(uu_fwd->singular())
69 {
70 }
71 
73  : m_id(bd.id())
74  , m_bd(bd.m_bd)
75  , m_bvi(bd.m_bvi)
76  , m_uu_fwd(bd.m_uu_fwd)
77 {
78 }
79 
82 {
83  return (m_bd->key());
84 }
85 
86 uint32_t
88 {
89  return (m_bd->id());
90 }
91 
92 const std::shared_ptr<bridge_domain>
94 {
95  return m_bd;
96 }
97 
98 const std::shared_ptr<interface>
100 {
101  return m_bvi;
102 }
103 
104 bool
106 {
107  bool equal = true;
108 
109  if (m_bvi && b.m_bvi)
110  equal &= (m_bvi->key() == b.m_bvi->key());
111  else if (!m_bvi && !b.m_bvi)
112  ;
113  else
114  equal = false;
115 
116  if (m_uu_fwd && b.m_uu_fwd)
117  equal &= (m_uu_fwd->key() == b.m_uu_fwd->key());
118  else if (!m_uu_fwd && !b.m_uu_fwd)
119  ;
120  else
121  equal = false;
122 
123  return ((m_bd->key() == b.m_bd->key()) && equal);
124 }
125 
126 void
127 gbp_bridge_domain::sweep()
128 {
129  if (rc_t::OK == m_id.rc()) {
131  }
132  HW::write();
133 }
134 
135 void
137 {
138  if (rc_t::OK == m_id.rc()) {
140  m_id, (m_bvi ? m_bvi->handle() : handle_t::INVALID),
141  (m_uu_fwd ? m_uu_fwd->handle() : handle_t::INVALID)));
142  }
143 }
144 
146 {
147  sweep();
148 
149  // not in the DB anymore.
150  m_db.release(m_id.data(), this);
151 }
152 
153 std::string
155 {
156  std::ostringstream s;
157  s << "gbp-bridge-domain:[" << m_bd->to_string();
158 
159  if (m_bvi)
160  s << " bvi:" << m_bvi->to_string();
161  if (m_uu_fwd)
162  s << " uu-fwd:" << m_uu_fwd->to_string();
163 
164  s << "]";
165 
166  return (s.str());
167 }
168 
169 std::shared_ptr<gbp_bridge_domain>
171 {
172  return (m_db.find(key));
173 }
174 
175 void
176 gbp_bridge_domain::update(const gbp_bridge_domain& desired)
177 {
178  /*
179  * the desired state is always that the interface should be created
180  */
181  if (rc_t::OK != m_id.rc()) {
183  m_id, (m_bvi ? m_bvi->handle() : handle_t::INVALID),
184  (m_uu_fwd ? m_uu_fwd->handle() : handle_t::INVALID)));
185  }
186 }
187 
188 std::shared_ptr<gbp_bridge_domain>
189 gbp_bridge_domain::find_or_add(const gbp_bridge_domain& temp)
190 {
191  return (m_db.find_or_add(temp.m_id.data(), temp));
192 }
193 
194 std::shared_ptr<gbp_bridge_domain>
196 {
197  return find_or_add(*this);
198 }
199 
200 void
201 gbp_bridge_domain::dump(std::ostream& os)
202 {
203  db_dump(m_db, os);
204 }
205 
206 void
207 gbp_bridge_domain::event_handler::handle_populate(const client_db::key_t& key)
208 {
209  /*
210  * dump GBP Bridge domains
211  */
212  std::shared_ptr<gbp_bridge_domain_cmds::dump_cmd> cmd =
213  std::make_shared<gbp_bridge_domain_cmds::dump_cmd>();
214 
215  HW::enqueue(cmd);
216  HW::write();
217 
218  for (auto& record : *cmd) {
219  auto& payload = record.get_payload();
220 
221  std::shared_ptr<interface> uu_fwd =
222  interface::find(payload.bd.uu_fwd_sw_if_index);
223  std::shared_ptr<interface> bvi =
224  interface::find(payload.bd.bvi_sw_if_index);
225 
226  if (uu_fwd && bvi) {
227  gbp_bridge_domain bd(payload.bd.bd_id, bvi, uu_fwd);
228  OM::commit(key, bd);
229  VOM_LOG(log_level_t::DEBUG) << "dump: " << bd.to_string();
230  } else if (bvi) {
231  gbp_bridge_domain bd(payload.bd.bd_id, *bvi);
232  OM::commit(key, bd);
233  VOM_LOG(log_level_t::DEBUG) << "dump: " << bd.to_string();
234  } else {
236  << "no BVI:" << payload.bd.bvi_sw_if_index
237  << " nor uu-fwd:" << payload.bd.uu_fwd_sw_if_index;
238  }
239  }
240 }
241 
243 {
244  OM::register_listener(this);
245  inspect::register_handler({ "gbd", "gbridge" }, "GBP Bridge Domains", this);
246 }
247 
248 void
249 gbp_bridge_domain::event_handler::handle_replay()
250 {
251  m_db.replay();
252 }
253 
255 gbp_bridge_domain::event_handler::order() const
256 {
258 }
259 
260 void
262 {
263  db_dump(m_db, os);
264 }
265 }
266 
267 /*
268  * fd.io coding-style-patch-verification: ON
269  *
270  * Local Variables:
271  * eval: (c-set-style "mozilla")
272  * End:
273  */
#define VOM_LOG(lvl)
Definition: logger.hpp:181
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
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:527
A cmd class that Delete an Bridge-Domain.
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
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
const std::shared_ptr< interface > get_bvi()
static const log_level_t DEBUG
Definition: logger.hpp:32
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
static const handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
virtual tables - tables with a dependency on another table
T & data()
Return the data read/written.
Definition: hw.hpp:109
std::shared_ptr< gbp_bridge_domain > singular() const
Return the matching &#39;singular instance&#39;.
void replay(void)
replay the object to create it in hardware
static std::shared_ptr< gbp_bridge_domain > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
bool operator==(const gbp_bridge_domain &bdae) const
comparison operator
A command class that creates an Bridge-Domain.
A entry in the ARP termination table of a Bridge Domain.
gbp_bridge_domain(const bridge_domain &bd, const interface &bvi)
Construct a GBP bridge_domain.
bridge_domain::key_t key_t
The key for a bridge_domain is the pari of EPG-IDs.
A representation of an interface in VPP.
Definition: interface.hpp:41
A base class for all object_base in the VPP object_base-Model.
static rc_t commit(const client_db::key_t &key, const OBJ &obj)
Make the State in VPP reflect the expressed desired state.
Definition: om.hpp:202
void event_handler(void *tls_async)
Definition: tls_async.c:340
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 const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
static const log_level_t ERROR
Definition: logger.hpp:29
std::string to_string() const
Convert to string for debugging.
const std::shared_ptr< bridge_domain > get_bridge_domain()
const key_t key() const
Return the object&#39;s key.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
u32 id
Definition: udp.api:45
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
uint32_t id() const
Return the bridge domain&#39;s VPP ID.