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