FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
bridge_domain_entry.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 
19 namespace VOM {
20 singular_db<bridge_domain_entry::key_t, bridge_domain_entry>
21  bridge_domain_entry::m_db;
22 
23 bridge_domain_entry::event_handler bridge_domain_entry::m_evh;
24 
26  const mac_address_t& mac,
27  const interface& tx_itf)
28  : m_hw(false)
29  , m_mac(mac)
30  , m_bd(bd.singular())
31  , m_tx_itf(tx_itf.singular())
32 {
33 }
34 
36  const interface& tx_itf)
37  : m_hw(false)
38  , m_mac(mac)
39  , m_bd(nullptr)
40  , m_tx_itf(tx_itf.singular())
41 {
42  /*
43  * the entry goes in the default bridge-domain
44  */
46 
47  m_bd = bd.singular();
48 }
49 
51  : m_hw(bde.m_hw)
52  , m_mac(bde.m_mac)
53  , m_bd(bde.m_bd)
54  , m_tx_itf(bde.m_tx_itf)
55 {
56 }
57 
60 {
61  return (std::make_pair(m_bd->key(), m_mac));
62 }
63 
64 bool
66 {
67  return ((key() == bde.key()) && (m_tx_itf == bde.m_tx_itf));
68 }
69 
71 {
72  sweep();
73 
74  // not in the DB anymore.
75  m_db.release(key(), this);
76 }
77 
78 void
79 bridge_domain_entry::sweep()
80 {
81  if (m_hw) {
83  m_hw, m_mac, m_bd->id(), interface::type_t::BVI == m_tx_itf->type()));
84  }
85  HW::write();
86 }
87 
88 void
90 {
91  if (m_hw) {
93  m_hw, m_mac, m_bd->id(), m_tx_itf->handle(),
94  interface::type_t::BVI == m_tx_itf->type()));
95  }
96 }
97 std::string
99 {
100  std::ostringstream s;
101  s << "bridge-domain-entry:[" << m_bd->to_string() << ", " << m_mac.to_string()
102  << ", tx:" << m_tx_itf->name() << "]";
103 
104  return (s.str());
105 }
106 
107 void
108 bridge_domain_entry::update(const bridge_domain_entry& r)
109 {
110  /*
111  * create the table if it is not yet created
112  */
113  if (rc_t::OK != m_hw.rc()) {
115  m_hw, m_mac, m_bd->id(), m_tx_itf->handle(),
116  interface::type_t::BVI == m_tx_itf->type()));
117  }
118 }
119 
120 std::shared_ptr<bridge_domain_entry>
121 bridge_domain_entry::find_or_add(const bridge_domain_entry& temp)
122 {
123  return (m_db.find_or_add(temp.key(), temp));
124 }
125 
126 std::shared_ptr<bridge_domain_entry>
128 {
129  return (m_db.find(k));
130 }
131 
132 std::shared_ptr<bridge_domain_entry>
134 {
135  return find_or_add(*this);
136 }
137 
138 void
139 bridge_domain_entry::dump(std::ostream& os)
140 {
141  m_db.dump(os);
142 }
143 
144 bridge_domain_entry::event_handler::event_handler()
145 {
146  OM::register_listener(this);
147  inspect::register_handler({ "bd-entry" },
148  "bridge domain entry configurations", this);
149 }
150 
151 void
152 bridge_domain_entry::event_handler::handle_replay()
153 {
154  m_db.replay();
155 }
156 
157 void
158 bridge_domain_entry::event_handler::handle_populate(const client_db::key_t& key)
159 {
160  std::shared_ptr<bridge_domain_entry_cmds::dump_cmd> cmd =
161  std::make_shared<bridge_domain_entry_cmds::dump_cmd>();
162 
163  HW::enqueue(cmd);
164  HW::write();
165 
166  for (auto& record : *cmd) {
167  auto& payload = record.get_payload();
168 
169  std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
170  std::shared_ptr<bridge_domain> bd = bridge_domain::find(payload.bd_id);
171 
172  if (!bd || !itf) {
173  VOM_LOG(log_level_t::ERROR) << "bridge-domain-entry dump:"
174  << " itf:" << payload.sw_if_index
175  << " bd:" << payload.bd_id;
176  continue;
177  }
178 
179  mac_address_t mac(payload.mac);
180  bridge_domain_entry bd_e(*bd, mac, *itf);
181 
182  VOM_LOG(log_level_t::DEBUG) << "bridge-domain-entry dump:"
183  << " " << bd->to_string() << " "
184  << itf->to_string() << " mac:["
185  << mac.to_string() << "]";
186 
187  /*
188  * Write each of the discovered interfaces into the OM,
189  * but disable the HW Command q whilst we do, so that no
190  * commands are sent to VPP
191  */
192  OM::commit(key, bd_e);
193  }
194 }
195 
197 bridge_domain_entry::event_handler::order() const
198 {
199  return (dependency_t::ENTRY);
200 }
201 
202 void
204 {
205  m_db.dump(os);
206 }
207 
208 std::ostream&
209 operator<<(std::ostream& os, const bridge_domain_entry::key_t& key)
210 {
211  os << "[" << key.first << ", " << key.second.to_string() << "]";
212 
213  return (os);
214 }
215 }
216 
217 /*
218  * fd.io coding-style-patch-verification: ON
219  *
220  * Local Variables:
221  * eval: (c-set-style "mozilla")
222  * End:
223  */
#define VOM_LOG(lvl)
Definition: logger.hpp:181
~bridge_domain_entry()
Destructor.
A command class that creates or updates the bridge_domain.
void replay(void)
replay the object to create it in hardware
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:402
static std::shared_ptr< bridge_domain_entry > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
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
std::string to_string() const
String conversion.
Definition: types.cpp:141
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:225
static const log_level_t DEBUG
Definition: logger.hpp:32
A cmd class that deletes a bridge_domain.
static std::shared_ptr< bridge_domain > find(const key_t &key)
Static function to find the bridge_domain in the model.
const key_t key() const
Return the object&#39;s key.
bridge_domain_entry(const bridge_domain &bd, const mac_address_t &mac, const interface &tx_itf)
Construct a bridge_domain in the given bridge domain.
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:118
A MAC forwarding entry in the bridge-domain/L2-FIB.
A representation of an interface in VPP.
Definition: interface.hpp:41
A base class for all object_base in the VPP object_base-Model.
std::string to_string() const
Convert to string for debugging.
std::pair< bridge_domain::key_t, mac_address_t > key_t
The key for a bridge_domain.
bool operator==(const bridge_domain_entry &be) const
comparison operator
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
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:106
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:189
static const log_level_t ERROR
Definition: logger.hpp:29
std::shared_ptr< bridge_domain_entry > singular() const
Return the matching &#39;singular instance&#39;.
std::shared_ptr< bridge_domain > singular() const
Return the matchin &#39;singular&#39; instance of the bridge-domain.
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
static const type_t BVI
A brideged Virtual interface (aka SVI or IRB)
Definition: interface.hpp:67
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
Entries in Tables.
Type def of a Ethernet address.
Definition: types.hpp:221
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:124
static const uint32_t DEFAULT_TABLE
The value of the defaultbridge domain.