FD.io VPP  v18.07.1-19-g511ce25
Vector Packet Processing
gbp_endpoint.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 
16 #include "vom/gbp_endpoint.hpp"
19 
20 namespace VOM {
21 
22 singular_db<gbp_endpoint::key_t, gbp_endpoint> gbp_endpoint::m_db;
23 
24 gbp_endpoint::event_handler gbp_endpoint::m_evh;
25 
27  const boost::asio::ip::address& ip_addr,
28  const mac_address_t& mac,
29  const gbp_endpoint_group& epg)
30  : m_hw(false)
31  , m_itf(itf.singular())
32  , m_ip(ip_addr)
33  , m_mac(mac)
34  , m_epg(epg.singular())
35 {
36 }
37 
39  : m_hw(gbpe.m_hw)
40  , m_itf(gbpe.m_itf)
41  , m_ip(gbpe.m_ip)
42  , m_mac(gbpe.m_mac)
43  , m_epg(gbpe.m_epg)
44 {
45 }
46 
48 {
49  sweep();
50  m_db.release(key(), this);
51 }
52 
55 {
56  return (std::make_pair(m_itf->key(), m_ip));
57 }
58 
59 bool
61 {
62  return ((key() == gbpe.key()) && (m_epg == gbpe.m_epg));
63 }
64 
65 void
66 gbp_endpoint::sweep()
67 {
68  if (m_hw) {
69  HW::enqueue(new gbp_endpoint_cmds::delete_cmd(m_hw, m_itf->handle(), m_ip));
70  }
71  HW::write();
72 }
73 
74 void
76 {
77  if (m_hw) {
78  HW::enqueue(new gbp_endpoint_cmds::create_cmd(m_hw, m_itf->handle(), m_ip,
79  m_mac, m_epg->id()));
80  }
81 }
82 
83 std::string
85 {
86  std::ostringstream s;
87  s << "gbp-endpoint:[" << m_itf->to_string() << ", " << m_ip.to_string()
88  << ", " << m_mac.to_string() << ", epg:" << m_epg->to_string() << "]";
89 
90  return (s.str());
91 }
92 
93 void
94 gbp_endpoint::update(const gbp_endpoint& r)
95 {
96  if (rc_t::OK != m_hw.rc()) {
97  HW::enqueue(new gbp_endpoint_cmds::create_cmd(m_hw, m_itf->handle(), m_ip,
98  m_mac, m_epg->id()));
99  }
100 }
101 
102 std::shared_ptr<gbp_endpoint>
103 gbp_endpoint::find_or_add(const gbp_endpoint& temp)
104 {
105  return (m_db.find_or_add(temp.key(), temp));
106 }
107 
108 std::shared_ptr<gbp_endpoint>
110 {
111  return (m_db.find(k));
112 }
113 
114 std::shared_ptr<gbp_endpoint>
116 {
117  return find_or_add(*this);
118 }
119 
120 void
121 gbp_endpoint::dump(std::ostream& os)
122 {
123  db_dump(m_db, os);
124 }
125 
127 {
128  OM::register_listener(this);
129  inspect::register_handler({ "gbp-endpoint" }, "GBP Endpoints", this);
130 }
131 
132 void
133 gbp_endpoint::event_handler::handle_replay()
134 {
135  m_db.replay();
136 }
137 
138 void
139 gbp_endpoint::event_handler::handle_populate(const client_db::key_t& key)
140 {
141  std::shared_ptr<gbp_endpoint_cmds::dump_cmd> cmd =
142  std::make_shared<gbp_endpoint_cmds::dump_cmd>();
143 
144  HW::enqueue(cmd);
145  HW::write();
146 
147  for (auto& record : *cmd) {
148  auto& payload = record.get_payload();
149 
151  from_bytes(payload.endpoint.is_ip6, payload.endpoint.address);
152  std::shared_ptr<interface> itf =
153  interface::find(payload.endpoint.sw_if_index);
154  std::shared_ptr<gbp_endpoint_group> epg =
155  gbp_endpoint_group::find(payload.endpoint.epg_id);
156  mac_address_t mac(payload.endpoint.mac);
157 
158  VOM_LOG(log_level_t::DEBUG) << "data: " << payload.endpoint.sw_if_index;
159 
160  if (itf && epg) {
161  gbp_endpoint gbpe(*itf, address, mac, *epg);
162  OM::commit(key, gbpe);
163 
164  VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
165  }
166  }
167 }
168 
170 gbp_endpoint::event_handler::order() const
171 {
172  return (dependency_t::ENTRY);
173 }
174 
175 void
176 gbp_endpoint::event_handler::show(std::ostream& os)
177 {
178  db_dump(m_db, os);
179 }
180 } // namespace VOM
181 
182 /*
183  * fd.io coding-style-patch-verification: ON
184  *
185  * Local Variables:
186  * eval: (c-set-style "mozilla")
187  * End:
188  */
std::pair< interface::key_t, boost::asio::ip::address > key_t
The key for a GBP endpoint; interface and IP.
const key_t key() const
Return the object&#39;s key.
typedef address
Definition: ip_types.api:35
#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:461
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::shared_ptr< gbp_endpoint > singular() const
Return the matching &#39;singular instance&#39;.
std::string to_string() const
String conversion.
Definition: types.cpp:148
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:236
static const log_level_t DEBUG
Definition: logger.hpp:32
~gbp_endpoint()
Destructor.
A cmd class that deletes a GBP endpoint.
gbp_endpoint(const interface &itf, const boost::asio::ip::address &ip_addr, const mac_address_t &mac, const gbp_endpoint_group &epg)
Construct a GBP endpoint.
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:118
A GBP Enpoint (i.e.
A command class that creates or updates the GBP endpoint.
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
A representation of an interface in VPP.
Definition: interface.hpp:41
A entry in the ARP termination table of a Bridge Domain.
boost::asio::ip::address from_bytes(uint8_t is_ip6, uint8_t *bytes)
Convert a VPP byte stinrg into a boost addresss.
Definition: prefix.cpp:193
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:311
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:104
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:194
void replay(void)
replay the object to create it in hardware
std::string to_string() const
Convert to string for debugging.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
static std::shared_ptr< gbp_endpoint > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
Entries in Tables.
static std::shared_ptr< gbp_endpoint_group > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
bool operator==(const gbp_endpoint &bdae) const
comparison operator
Type def of a Ethernet address.
Definition: types.hpp:290
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127