FD.io VPP  v21.10.1-2-g0a485f517
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 
27 const gbp_endpoint::flags_t gbp_endpoint::flags_t::NONE(0, "none");
28 const gbp_endpoint::flags_t gbp_endpoint::flags_t::BOUNCE(1, "bounce");
29 const gbp_endpoint::flags_t gbp_endpoint::flags_t::LEARNT(2, "learnt");
30 const gbp_endpoint::flags_t gbp_endpoint::flags_t::REMOTE(4, "remote");
31 const gbp_endpoint::flags_t gbp_endpoint::flags_t::EXTERNAL(8, "external");
32 
33 gbp_endpoint::flags_t::flags_t(int v, const std::string& s)
34  : enum_base<gbp_endpoint::flags_t>(v, s)
35 {
36 }
37 
39  const interface& itf,
40  const std::vector<boost::asio::ip::address>& ip_addrs,
41  const mac_address_t& mac,
42  const gbp_endpoint_group& epg,
43  const flags_t& flags)
44  : m_hdl(handle_t::INVALID)
45  , m_itf(itf.singular())
46  , m_ips(ip_addrs)
47  , m_mac(mac)
48  , m_epg(epg.singular())
49  , m_flags(flags)
50 {
51 }
52 
54  : m_hdl(gbpe.m_hdl)
55  , m_itf(gbpe.m_itf)
56  , m_ips(gbpe.m_ips)
57  , m_mac(gbpe.m_mac)
58  , m_epg(gbpe.m_epg)
59  , m_flags(gbpe.m_flags)
60 {
61 }
62 
64 {
65  sweep();
66  m_db.release(key(), this);
67 }
68 
71 {
72  return (std::make_pair(m_itf->key(), m_mac));
73 }
74 
75 bool
77 {
78  return ((key() == gbpe.key()) && (m_epg == gbpe.m_epg) &&
79  (m_flags == gbpe.m_flags));
80 }
81 
82 void
83 gbp_endpoint::sweep()
84 {
85  if (m_hdl) {
87  }
88  HW::write();
89 }
90 
91 void
93 {
94  if (m_hdl) {
96  m_hdl, m_itf->handle(), m_ips, m_mac, m_epg->sclass(), m_flags));
97  }
98 }
99 
102 {
103  std::ostringstream s;
104  s << "gbp-endpoint:[" << m_itf->to_string() << ", ips:[";
105 
106  for (auto ip : m_ips)
107  s << ip.to_string();
108 
109  s << "], " << m_mac.to_string() << ", epg:" << m_epg->to_string() << "]";
110 
111  return (s.str());
112 }
113 
114 void
115 gbp_endpoint::update(const gbp_endpoint& r)
116 {
117  if (rc_t::OK != m_hdl.rc()) {
119  m_hdl, m_itf->handle(), m_ips, m_mac, m_epg->sclass(), m_flags));
120  }
121 }
122 
123 std::shared_ptr<gbp_endpoint>
124 gbp_endpoint::find_or_add(const gbp_endpoint& temp)
125 {
126  return (m_db.find_or_add(temp.key(), temp));
127 }
128 
129 std::shared_ptr<gbp_endpoint>
131 {
132  return (m_db.find(k));
133 }
134 
135 std::shared_ptr<gbp_endpoint>
137 {
138  return find_or_add(*this);
139 }
140 
141 void
142 gbp_endpoint::dump(std::ostream& os)
143 {
144  db_dump(m_db, os);
145 }
146 
148 {
149  OM::register_listener(this);
150  inspect::register_handler({ "gbp-endpoint" }, "GBP Endpoints", this);
151 }
152 
153 void
154 gbp_endpoint::event_handler::handle_replay()
155 {
156  m_db.replay();
157 }
158 
159 void
160 gbp_endpoint::event_handler::handle_populate(const client_db::key_t& key)
161 {
162  std::shared_ptr<gbp_endpoint_cmds::dump_cmd> cmd =
163  std::make_shared<gbp_endpoint_cmds::dump_cmd>();
164 
165  HW::enqueue(cmd);
166  HW::write();
167 
168  for (auto& record : *cmd) {
169  auto& payload = record.get_payload();
170 
171  std::vector<boost::asio::ip::address> addresses;
172 
173  for (uint8_t n = 0; n < payload.endpoint.n_ips; n++)
174  addresses.push_back(from_api(payload.endpoint.ips[n]));
175  std::shared_ptr<interface> itf =
176  interface::find(payload.endpoint.sw_if_index);
177  std::shared_ptr<gbp_endpoint_group> epg =
178  gbp_endpoint_group::find(payload.endpoint.sclass);
179  mac_address_t mac = from_api(payload.endpoint.mac);
180 
181  VOM_LOG(log_level_t::DEBUG) << "data: " << payload.endpoint.sw_if_index;
182 
183  if (itf && epg) {
184  gbp_endpoint gbpe(*itf, addresses, mac, *epg);
185  OM::commit(key, gbpe);
186 
187  VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
188  } else {
190  << "no interface:" << payload.endpoint.sw_if_index
191  << "or sclass:" << payload.endpoint.sclass;
192  }
193  }
194 }
195 
197 gbp_endpoint::event_handler::order() const
198 {
199  return (dependency_t::ENTRY);
200 }
201 
202 void
203 gbp_endpoint::event_handler::show(std::ostream& os)
204 {
205  db_dump(m_db, os);
206 }
207 
208 std::ostream&
209 operator<<(std::ostream& os, const gbp_endpoint::key_t& key)
210 {
211  os << key.first << "," << key.second;
212 
213  return os;
214 }
215 
216 } // namespace VOM
217 
218 /*
219  * fd.io coding-style-patch-verification: OFF
220  *
221  * Local Variables:
222  * eval: (c-set-style "mozilla")
223  * End:
224  */
VOM::gbp_endpoint::flags_t::EXTERNAL
const static flags_t EXTERNAL
Definition: gbp_endpoint.hpp:42
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_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::gbp_endpoint::singular
std::shared_ptr< gbp_endpoint > singular() const
Return the matching 'singular instance'.
Definition: gbp_endpoint.cpp:136
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::gbp_endpoint_cmds::create_cmd
A command class that creates or updates the GBP endpoint.
Definition: gbp_endpoint_cmds.hpp:30
VOM::gbp_endpoint::~gbp_endpoint
~gbp_endpoint()
Destructor.
Definition: gbp_endpoint.cpp:63
VOM::gbp_endpoint::key_t
std::pair< interface::key_t, mac_address_t > key_t
The key for a GBP endpoint; interface and IP.
Definition: gbp_endpoint.hpp:54
VOM::dependency_t::ENTRY
@ ENTRY
Entries in Tables.
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
VOM::gbp_endpoint_cmds::delete_cmd
A cmd class that deletes a GBP endpoint.
Definition: gbp_endpoint_cmds.hpp:71
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::gbp_endpoint::gbp_endpoint
gbp_endpoint(const interface &itf, const std::vector< boost::asio::ip::address > &ip_addr, const mac_address_t &mac, const gbp_endpoint_group &epg, const flags_t &flags=flags_t::NONE)
Construct a GBP endpoint.
Definition: gbp_endpoint.cpp:38
VOM::gbp_endpoint::flags_t::BOUNCE
const static flags_t BOUNCE
Definition: gbp_endpoint.hpp:39
VOM::OM::register_listener
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
VOM::gbp_endpoint_group::find
static std::shared_ptr< gbp_endpoint_group > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
Definition: gbp_endpoint_group.cpp:188
VOM::gbp_endpoint::flags_t::LEARNT
const static flags_t LEARNT
Definition: gbp_endpoint.hpp:41
VOM::gbp_endpoint::flags_t
Endpoint flags.
Definition: gbp_endpoint.hpp:36
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::gbp_endpoint::dump
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: gbp_endpoint.cpp:142
VOM::gbp_endpoint::key
const key_t key() const
Return the object's key.
Definition: gbp_endpoint.cpp:70
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::HW::enqueue
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
VOM::gbp_endpoint::to_string
std::string to_string() const
Convert to string for debugging.
Definition: gbp_endpoint.cpp:101
VOM::gbp_endpoint::operator==
bool operator==(const gbp_endpoint &bdae) const
comparison operator
Definition: gbp_endpoint.cpp:76
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::gbp_endpoint::flags_t::REMOTE
const static flags_t REMOTE
Definition: gbp_endpoint.hpp:40
singular_db_funcs.hpp
VOM::HW::item::rc
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
VOM::gbp_endpoint::replay
void replay(void)
replay the object to create it in hardware
Definition: gbp_endpoint.cpp:92
VOM::gbp_endpoint
A GBP Enpoint (i.e.
Definition: gbp_endpoint.hpp:30
gbp_endpoint
typedef gbp_endpoint
Definition: gbp.api:129
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
mac_address_t_
Definition: mac_address.h:21
gbp_endpoint_cmds.hpp
ip
vl_api_address_t ip
Definition: l2.api:558
VOM::gbp_endpoint::flags_t::NONE
const static flags_t NONE
Definition: gbp_endpoint.hpp:38
VOM::gbp_endpoint::find
static std::shared_ptr< gbp_endpoint > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
Definition: gbp_endpoint.cpp:130
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::gbp_endpoint_group
A entry in the ARP termination table of a Bridge Domain.
Definition: gbp_endpoint_group.hpp:32
VOM::log_level_t::ERROR
const static log_level_t ERROR
Definition: logger.hpp:29
VOM::from_api
const neighbour::flags_t from_api(vapi_enum_ip_neighbor_flags f)
Definition: api_types.cpp:36
api_types.hpp
gbp_endpoint.hpp
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
string
const char *const string
Definition: cJSON.h:172
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105