FD.io VPP  v18.10-34-gcce845e
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"
17 #include "vom/api_types.hpp"
20 
21 namespace VOM {
22 
23 singular_db<gbp_endpoint::key_t, gbp_endpoint> gbp_endpoint::m_db;
24 
25 gbp_endpoint::event_handler gbp_endpoint::m_evh;
26 
28  const interface& itf,
29  const std::vector<boost::asio::ip::address>& ip_addrs,
30  const mac_address_t& mac,
31  const gbp_endpoint_group& epg)
32  : m_hdl(handle_t::INVALID)
33  , m_itf(itf.singular())
34  , m_ips(ip_addrs)
35  , m_mac(mac)
36  , m_epg(epg.singular())
37 {
38 }
39 
41  : m_hdl(gbpe.m_hdl)
42  , m_itf(gbpe.m_itf)
43  , m_ips(gbpe.m_ips)
44  , m_mac(gbpe.m_mac)
45  , m_epg(gbpe.m_epg)
46 {
47 }
48 
50 {
51  sweep();
52  m_db.release(key(), this);
53 }
54 
57 {
58  return (std::make_pair(m_itf->key(), m_mac));
59 }
60 
61 bool
63 {
64  return ((key() == gbpe.key()) && (m_epg == gbpe.m_epg));
65 }
66 
67 void
68 gbp_endpoint::sweep()
69 {
70  if (m_hdl) {
72  }
73  HW::write();
74 }
75 
76 void
78 {
79  if (m_hdl) {
80  HW::enqueue(new gbp_endpoint_cmds::create_cmd(m_hdl, m_itf->handle(), m_ips,
81  m_mac, m_epg->id()));
82  }
83 }
84 
85 std::string
87 {
88  std::ostringstream s;
89  s << "gbp-endpoint:[" << m_itf->to_string() << ", ips:[";
90 
91  for (auto ip : m_ips)
92  s << ip.to_string();
93 
94  s << "], " << m_mac.to_string() << ", epg:" << m_epg->to_string() << "]";
95 
96  return (s.str());
97 }
98 
99 void
100 gbp_endpoint::update(const gbp_endpoint& r)
101 {
102  if (rc_t::OK != m_hdl.rc()) {
103  HW::enqueue(new gbp_endpoint_cmds::create_cmd(m_hdl, m_itf->handle(), m_ips,
104  m_mac, m_epg->id()));
105  }
106 }
107 
108 std::shared_ptr<gbp_endpoint>
109 gbp_endpoint::find_or_add(const gbp_endpoint& temp)
110 {
111  return (m_db.find_or_add(temp.key(), temp));
112 }
113 
114 std::shared_ptr<gbp_endpoint>
116 {
117  return (m_db.find(k));
118 }
119 
120 std::shared_ptr<gbp_endpoint>
122 {
123  return find_or_add(*this);
124 }
125 
126 void
127 gbp_endpoint::dump(std::ostream& os)
128 {
129  db_dump(m_db, os);
130 }
131 
133 {
134  OM::register_listener(this);
135  inspect::register_handler({ "gbp-endpoint" }, "GBP Endpoints", this);
136 }
137 
138 void
139 gbp_endpoint::event_handler::handle_replay()
140 {
141  m_db.replay();
142 }
143 
144 void
145 gbp_endpoint::event_handler::handle_populate(const client_db::key_t& key)
146 {
147  std::shared_ptr<gbp_endpoint_cmds::dump_cmd> cmd =
148  std::make_shared<gbp_endpoint_cmds::dump_cmd>();
149 
150  HW::enqueue(cmd);
151  HW::write();
152 
153  for (auto& record : *cmd) {
154  auto& payload = record.get_payload();
155 
156  std::vector<boost::asio::ip::address> addresses;
157 
158  for (uint8_t n = 0; n < payload.endpoint.n_ips; n++)
159  addresses.push_back(from_api(payload.endpoint.ips[n]));
160  std::shared_ptr<interface> itf =
161  interface::find(payload.endpoint.sw_if_index);
162  std::shared_ptr<gbp_endpoint_group> epg =
163  gbp_endpoint_group::find(payload.endpoint.epg_id);
164  mac_address_t mac = from_api(payload.endpoint.mac);
165 
166  VOM_LOG(log_level_t::DEBUG) << "data: " << payload.endpoint.sw_if_index;
167 
168  if (itf && epg) {
169  gbp_endpoint gbpe(*itf, addresses, mac, *epg);
170  OM::commit(key, gbpe);
171 
172  VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
173  }
174  }
175 }
176 
178 gbp_endpoint::event_handler::order() const
179 {
180  return (dependency_t::ENTRY);
181 }
182 
183 void
184 gbp_endpoint::event_handler::show(std::ostream& os)
185 {
186  db_dump(m_db, os);
187 }
188 
189 std::ostream&
190 operator<<(std::ostream& os, const gbp_endpoint::key_t& key)
191 {
192  os << key.first << "," << key.second;
193 
194  return os;
195 }
196 
197 } // namespace VOM
198 
199 /*
200  * fd.io coding-style-patch-verification: ON
201  *
202  * Local Variables:
203  * eval: (c-set-style "mozilla")
204  * End:
205  */
const key_t key() const
Return the object&#39;s key.
#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
gbp_endpoint(const interface &itf, const std::vector< boost::asio::ip::address > &ip_addr, const mac_address_t &mac, const gbp_endpoint_group &epg)
Construct a GBP endpoint.
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:236
static const log_level_t DEBUG
Definition: logger.hpp:32
std::pair< interface::key_t, mac_address_t > key_t
The key for a GBP endpoint; interface and IP.
~gbp_endpoint()
Destructor.
ip_address_t from_api(const vapi_type_address &v)
Definition: api_types.cpp:65
A cmd class that deletes 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.
A type declaration of an interface handle in VPP.
Definition: types.hpp:228
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:339
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.
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 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
vl_api_mac_address_t mac
Definition: gbp.api:31