FD.io VPP  v19.04-6-g6f05f72
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 
19 
20 namespace VOM {
21 
22 singular_db<bridge_domain_arp_entry::key_t, bridge_domain_arp_entry>
23  bridge_domain_arp_entry::m_db;
24 
25 bridge_domain_arp_entry::event_handler bridge_domain_arp_entry::m_evh;
26 
28  const bridge_domain& bd,
29  const boost::asio::ip::address& ip_addr,
30  const mac_address_t& mac)
31  : m_hw(false)
32  , m_bd(bd.singular())
33  , m_ip_addr(ip_addr)
34  , m_mac(mac)
35 {
36 }
37 
39  const boost::asio::ip::address& ip_addr,
40  const mac_address_t& mac)
41  : m_hw(false)
42  , m_bd(nullptr)
43  , m_ip_addr(ip_addr)
44  , m_mac(mac)
45 {
46  /*
47  * the route goes in the default table
48  */
50 
51  m_bd = bd.singular();
52 }
53 
55  const bridge_domain_arp_entry& bde)
56  : m_hw(bde.m_hw)
57  , m_bd(bde.m_bd)
58  , m_ip_addr(bde.m_ip_addr)
59  , m_mac(bde.m_mac)
60 {
61 }
62 
64 {
65  sweep();
66 
67  // not in the DB anymore.
68  m_db.release(key(), this);
69 }
70 
73 {
74  return (std::make_pair(m_bd->key(), m_ip_addr));
75 }
76 
77 bool
79 {
80  return ((key() == bdae.key()) && (m_mac == bdae.m_mac));
81 }
82 
83 void
84 bridge_domain_arp_entry::sweep()
85 {
86  if (m_hw) {
88  m_mac, m_ip_addr));
89  }
90  HW::write();
91 }
92 
93 void
95 {
96  if (m_hw) {
98  m_mac, m_ip_addr));
99  }
100 }
101 
102 std::string
104 {
105  std::ostringstream s;
106  s << "bridge-domain-arp-entry:[" << m_bd->to_string() << ", "
107  << m_mac.to_string() << ", " << m_ip_addr.to_string() << "]";
108 
109  return (s.str());
110 }
111 
112 void
113 bridge_domain_arp_entry::update(const bridge_domain_arp_entry& r)
114 {
115  /*
116  * create the table if it is not yet created
117  */
118  if (rc_t::OK != m_hw.rc()) {
120  m_mac, m_ip_addr));
121  }
122 }
123 
124 std::shared_ptr<bridge_domain_arp_entry>
125 bridge_domain_arp_entry::find_or_add(const bridge_domain_arp_entry& temp)
126 {
127  return (m_db.find_or_add(temp.key(), temp));
128 }
129 
130 std::shared_ptr<bridge_domain_arp_entry>
132 {
133  return (m_db.find(k));
134 }
135 
136 std::shared_ptr<bridge_domain_arp_entry>
138 {
139  return find_or_add(*this);
140 }
141 
142 void
144 {
145  db_dump(m_db, os);
146 }
147 
149 {
150  OM::register_listener(this);
151  inspect::register_handler({ "bd-arp" },
152  "bridge domain ARP termination entries", this);
153 }
154 
155 void
156 bridge_domain_arp_entry::event_handler::handle_replay()
157 {
158  m_db.replay();
159 }
160 
161 void
162 bridge_domain_arp_entry::event_handler::handle_populate(
163  const client_db::key_t& key)
164 {
165  /*
166  * dump VPP Bridge domains
167  */
168  std::shared_ptr<bridge_domain_arp_entry_cmds::dump_cmd> cmd =
169  std::make_shared<bridge_domain_arp_entry_cmds::dump_cmd>(~0);
170 
171  HW::enqueue(cmd);
172  HW::write();
173 
174  for (auto& record : *cmd) {
175  auto& payload = record.get_payload();
176 
177  std::shared_ptr<bridge_domain> bd = bridge_domain::find(payload.bd_id);
179  *bd, from_bytes(payload.is_ipv6, payload.ip_address),
180  mac_address_t(payload.mac_address));
181 
182  VOM_LOG(log_level_t::DEBUG) << "dump: " << bd_ae.to_string();
183 
184  /*
185  * Write each of the discovered bridge-domain arp entry into the OM,
186  * but disable the HW Command q whilst we do, so that no
187  * commands are sent to VPP
188  */
189  OM::commit(key, bd_ae);
190  }
191 }
192 
194 bridge_domain_arp_entry::event_handler::order() const
195 {
196  return (dependency_t::ENTRY);
197 }
198 
199 void
201 {
202  db_dump(m_db, os);
203 }
204 
205 std::ostream&
206 operator<<(std::ostream& os, const bridge_domain_arp_entry::key_t& key)
207 {
208  os << "[" << key.first << ", " << key.second << "]";
209 
210  return (os);
211 }
212 }
213 /*
214  * fd.io coding-style-patch-verification: ON
215  *
216  * Local Variables:
217  * eval: (c-set-style "mozilla")
218  * End:
219  */
std::shared_ptr< bridge_domain_arp_entry > singular() const
Return the matching &#39;singular instance&#39;.
typedef address
Definition: ip_types.api:30
#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 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:148
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
static const log_level_t DEBUG
Definition: logger.hpp:32
static std::shared_ptr< bridge_domain > find(const key_t &key)
Static function to find the bridge_domain in the model.
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.
void replay(void)
replay the object to create it in hardware
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
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.
A base class for all object_base in the VPP object_base-Model.
A cmd class that deletes a bridge domain ARP entry.
const key_t key() const
Return the object&#39;s key.
~bridge_domain_arp_entry()
Destructor.
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
boost::asio::ip::address from_bytes(uint8_t is_ip6, const uint8_t *bytes)
Convert a VPP byte stinrg into a boost addresss.
Definition: prefix.cpp:193
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)
bool operator==(const bridge_domain_arp_entry &bdae) const
comparison operator
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
Entries in Tables.
std::string to_string() const
Convert to string for debugging.
Type def of a Ethernet address.
Definition: types.hpp:295
A command class that creates or updates the bridge domain ARP Entry.
static std::shared_ptr< bridge_domain_arp_entry > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
vl_api_mac_address_t mac
Definition: gbp.api:120
static const uint32_t DEFAULT_TABLE
The value of the defaultbridge domain.
A entry in the ARP termination table of a Bridge Domain.