FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
bridge_domain_arp_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 
17 #include "vom/api_types.hpp"
20 
21 namespace VOM {
22 
23 singular_db<bridge_domain_arp_entry::key_t, bridge_domain_arp_entry>
24  bridge_domain_arp_entry::m_db;
25 
26 bridge_domain_arp_entry::event_handler bridge_domain_arp_entry::m_evh;
27 
29  const bridge_domain& bd,
30  const boost::asio::ip::address& ip_addr,
31  const mac_address_t& mac)
32  : m_hw(false)
33  , m_bd(bd.singular())
34  , m_ip_addr(ip_addr)
35  , m_mac(mac)
36 {
37 }
38 
40  const boost::asio::ip::address& ip_addr,
41  const mac_address_t& mac)
42  : m_hw(false)
43  , m_bd(nullptr)
44  , m_ip_addr(ip_addr)
45  , m_mac(mac)
46 {
47  /*
48  * the route goes in the default table
49  */
51 
52  m_bd = bd.singular();
53 }
54 
56  const bridge_domain_arp_entry& bde)
57  : m_hw(bde.m_hw)
58  , m_bd(bde.m_bd)
59  , m_ip_addr(bde.m_ip_addr)
60  , m_mac(bde.m_mac)
61 {
62 }
63 
65 {
66  sweep();
67 
68  // not in the DB anymore.
69  m_db.release(key(), this);
70 }
71 
74 {
75  return (std::make_pair(m_bd->key(), m_ip_addr));
76 }
77 
78 bool
80 {
81  return ((key() == bdae.key()) && (m_mac == bdae.m_mac));
82 }
83 
84 void
85 bridge_domain_arp_entry::sweep()
86 {
87  if (m_hw) {
89  m_mac, m_ip_addr));
90  }
91  HW::write();
92 }
93 
94 void
96 {
97  if (m_hw) {
99  m_mac, m_ip_addr));
100  }
101 }
102 
105 {
106  std::ostringstream s;
107  s << "bridge-domain-arp-entry:[" << m_bd->to_string() << ", "
108  << m_mac.to_string() << ", " << m_ip_addr.to_string() << "]";
109 
110  return (s.str());
111 }
112 
113 void
114 bridge_domain_arp_entry::update(const bridge_domain_arp_entry& r)
115 {
116  /*
117  * create the table if it is not yet created
118  */
119  if (rc_t::OK != m_hw.rc()) {
121  m_mac, m_ip_addr));
122  }
123 }
124 
125 std::shared_ptr<bridge_domain_arp_entry>
126 bridge_domain_arp_entry::find_or_add(const bridge_domain_arp_entry& temp)
127 {
128  return (m_db.find_or_add(temp.key(), temp));
129 }
130 
131 std::shared_ptr<bridge_domain_arp_entry>
133 {
134  return (m_db.find(k));
135 }
136 
137 std::shared_ptr<bridge_domain_arp_entry>
139 {
140  return find_or_add(*this);
141 }
142 
143 void
145 {
146  db_dump(m_db, os);
147 }
148 
150 {
151  OM::register_listener(this);
152  inspect::register_handler({ "bd-arp" },
153  "bridge domain ARP termination entries", this);
154 }
155 
156 void
157 bridge_domain_arp_entry::event_handler::handle_replay()
158 {
159  m_db.replay();
160 }
161 
162 void
163 bridge_domain_arp_entry::event_handler::handle_populate(
164  const client_db::key_t& key)
165 {
166  /*
167  * dump VPP Bridge domains
168  */
169  std::shared_ptr<bridge_domain_arp_entry_cmds::dump_cmd> cmd =
170  std::make_shared<bridge_domain_arp_entry_cmds::dump_cmd>(~0);
171 
172  HW::enqueue(cmd);
173  HW::write();
174 
175  for (auto& record : *cmd) {
176  auto& payload = record.get_payload();
177 
178  std::shared_ptr<bridge_domain> bd =
179  bridge_domain::find(payload.entry.bd_id);
180  bridge_domain_arp_entry bd_ae(*bd, from_api(payload.entry.ip),
181  from_api(payload.entry.mac));
182 
183  VOM_LOG(log_level_t::DEBUG) << "dump: " << bd_ae.to_string();
184 
185  /*
186  * Write each of the discovered bridge-domain arp entry into the OM,
187  * but disable the HW Command q whilst we do, so that no
188  * commands are sent to VPP
189  */
190  OM::commit(key, bd_ae);
191  }
192 }
193 
195 bridge_domain_arp_entry::event_handler::order() const
196 {
197  return (dependency_t::ENTRY);
198 }
199 
200 void
202 {
203  db_dump(m_db, os);
204 }
205 
206 std::ostream&
208 {
209  os << "[" << key.first << ", " << key.second << "]";
210 
211  return (os);
212 }
213 }
214 /*
215  * fd.io coding-style-patch-verification: OFF
216  *
217  * Local Variables:
218  * eval: (c-set-style "mozilla")
219  * End:
220  */
VOM::bridge_domain
A base class for all object_base in the VPP object_base-Model.
Definition: bridge_domain.hpp:31
VOM::bridge_domain_arp_entry::operator==
bool operator==(const bridge_domain_arp_entry &bdae) const
comparison operator
Definition: bridge_domain_arp_entry.cpp:79
bridge_domain_arp_entry.hpp
VOM::HW::write
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
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::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_arp_entry::to_string
std::string to_string() const
Convert to string for debugging.
Definition: bridge_domain_arp_entry.cpp:104
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.
VOM::bridge_domain_arp_entry_cmds::create_cmd
A command class that creates or updates the bridge domain ARP Entry.
Definition: bridge_domain_arp_entry_cmds.hpp:31
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
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::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::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
address
manual_print typedef address
Definition: ip_types.api:96
VOM::bridge_domain_arp_entry::singular
std::shared_ptr< bridge_domain_arp_entry > singular() const
Return the matching 'singular instance'.
Definition: bridge_domain_arp_entry.cpp:138
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
VOM::bridge_domain_arp_entry
A entry in the ARP termination table of a Bridge Domain.
Definition: bridge_domain_arp_entry.hpp:28
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_arp_entry::key_t
std::pair< bridge_domain::key_t, boost::asio::ip::address > key_t
The key for a bridge_domain ARP entry; the BD, IP address and MAC address.
Definition: bridge_domain_arp_entry.hpp:35
VOM::bridge_domain_arp_entry::~bridge_domain_arp_entry
~bridge_domain_arp_entry()
Destructor.
Definition: bridge_domain_arp_entry.cpp:64
VOM::bridge_domain_arp_entry::replay
void replay(void)
replay the object to create it in hardware
Definition: bridge_domain_arp_entry.cpp:95
VOM::mac_address_t::to_string
std::string to_string() const
String conversion.
Definition: types.cpp:148
VOM::mac_address_t
Type def of a Ethernet address.
Definition: types.hpp:295
VOM::bridge_domain_arp_entry::bridge_domain_arp_entry
bridge_domain_arp_entry(const bridge_domain &bd, const boost::asio::ip::address &ip_addr, const mac_address_t &mac)
Construct a bridge domain ARP Entry in the given bridge domain.
Definition: bridge_domain_arp_entry.cpp:28
VOM::bridge_domain_arp_entry_cmds::delete_cmd
A cmd class that deletes a bridge domain ARP entry.
Definition: bridge_domain_arp_entry_cmds.hpp:66
bridge_domain_arp_entry_cmds.hpp
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_arp_entry::key
const key_t key() const
Return the object's key.
Definition: bridge_domain_arp_entry.cpp:73
VOM::from_api
const neighbour::flags_t from_api(vapi_enum_ip_neighbor_flags f)
Definition: api_types.cpp:36
api_types.hpp
VOM::bridge_domain_arp_entry::find
static std::shared_ptr< bridge_domain_arp_entry > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
Definition: bridge_domain_arp_entry.cpp:132
VOM::bridge_domain_arp_entry::dump
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: bridge_domain_arp_entry.cpp:144
string
const char *const string
Definition: cJSON.h:172