FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gbp_endpoint_group.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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<gbp_endpoint_group::key_t, gbp_endpoint_group>
23  gbp_endpoint_group::m_db;
24 
25 gbp_endpoint_group::event_handler gbp_endpoint_group::m_evh;
26 
28  : remote_ep_timeout(0xffffffff)
29 {
30 }
32  : remote_ep_timeout(remote_ep_timeout_)
33 {
34 }
35 
36 bool
38 {
39  return (remote_ep_timeout == o.remote_ep_timeout);
40 }
41 
44 {
45  return std::to_string(remote_ep_timeout);
46 }
47 
50  const interface& itf,
51  const gbp_route_domain& rd,
52  const gbp_bridge_domain& bd)
53  : m_hw(false)
54  , m_vnid(vnid)
55  , m_sclass(sclass)
56  , m_itf(itf.singular())
57  , m_rd(rd.singular())
58  , m_bd(bd.singular())
59  , m_retention()
60 {
61 }
62 
65  const gbp_route_domain& rd,
66  const gbp_bridge_domain& bd)
67  : m_hw(false)
68  , m_vnid(vnid)
69  , m_sclass(sclass)
70  , m_itf()
71  , m_rd(rd.singular())
72  , m_bd(bd.singular())
73  , m_retention()
74 {
75 }
76 
78  const gbp_route_domain& rd,
79  const gbp_bridge_domain& bd)
80  : m_hw(false)
81  , m_vnid(~0)
82  , m_sclass(sclass)
83  , m_itf()
84  , m_rd(rd.singular())
85  , m_bd(bd.singular())
86  , m_retention()
87 {
88 }
89 
91  : m_hw(epg.m_hw)
92  , m_vnid(epg.m_vnid)
93  , m_sclass(epg.m_sclass)
94  , m_itf(epg.m_itf)
95  , m_rd(epg.m_rd)
96  , m_bd(epg.m_bd)
97  , m_retention(epg.m_retention)
98 {
99 }
100 
102 {
103  sweep();
104  m_db.release(key(), this);
105 }
106 
109 {
110  return (m_sclass);
111 }
112 
113 vnid_t
115 {
116  return (m_vnid);
117 }
118 
119 void
121 {
122  m_retention = retention;
123 }
124 
125 sclass_t
127 {
128  return (m_sclass);
129 }
130 
131 bool
133 {
134  return (key() == gg.key() && (m_vnid == gg.m_vnid) &&
135  (m_retention == gg.m_retention) && (m_itf == gg.m_itf) &&
136  (m_rd == gg.m_rd) && (m_bd == gg.m_bd));
137 }
138 
139 void
140 gbp_endpoint_group::sweep()
141 {
142  if (m_hw) {
144  }
145  HW::write();
146 }
147 
148 void
150 {
151  if (m_hw) {
153  m_hw, m_vnid, m_sclass, m_bd->id(), m_rd->id(), m_retention,
154  (m_itf ? m_itf->handle() : handle_t::INVALID)));
155  }
156 }
157 
160 {
161  std::ostringstream s;
162  s << "gbp-endpoint-group:["
163  << "vnid:" << m_vnid << ", sclass:" << m_sclass << ", "
164  << "retention:[" << m_retention.to_string() << "], "
165  << (m_itf ? m_itf->to_string() : "NULL") << ", " << m_bd->to_string()
166  << ", " << m_rd->to_string() << "]";
167 
168  return (s.str());
169 }
170 
171 void
172 gbp_endpoint_group::update(const gbp_endpoint_group& r)
173 {
174  if (rc_t::OK != m_hw.rc()) {
176  m_hw, m_vnid, m_sclass, m_bd->id(), m_rd->id(), m_retention,
177  (m_itf ? m_itf->handle() : handle_t::INVALID)));
178  }
179 }
180 
181 std::shared_ptr<gbp_endpoint_group>
182 gbp_endpoint_group::find_or_add(const gbp_endpoint_group& temp)
183 {
184  return (m_db.find_or_add(temp.key(), temp));
185 }
186 
187 std::shared_ptr<gbp_endpoint_group>
189 {
190  return (m_db.find(k));
191 }
192 
193 std::shared_ptr<gbp_endpoint_group>
195 {
196  return find_or_add(*this);
197 }
198 
199 void
200 gbp_endpoint_group::dump(std::ostream& os)
201 {
202  db_dump(m_db, os);
203 }
204 
205 const std::shared_ptr<gbp_route_domain>
207 {
208  return m_rd;
209 }
210 
211 const std::shared_ptr<gbp_bridge_domain>
213 {
214  return m_bd;
215 }
216 
218 {
219  OM::register_listener(this);
220  inspect::register_handler({ "gbp-endpoint-group" }, "GBP Endpoint_Groups",
221  this);
222 }
223 
224 void
225 gbp_endpoint_group::event_handler::handle_replay()
226 {
227  m_db.replay();
228 }
229 
230 void
231 gbp_endpoint_group::event_handler::handle_populate(const client_db::key_t& key)
232 {
233  std::shared_ptr<gbp_endpoint_group_cmds::dump_cmd> cmd =
234  std::make_shared<gbp_endpoint_group_cmds::dump_cmd>();
235 
236  HW::enqueue(cmd);
237  HW::write();
238 
239  for (auto& record : *cmd) {
240  auto& payload = record.get_payload();
241 
242  std::shared_ptr<interface> itf =
243  interface::find(payload.epg.uplink_sw_if_index);
244  std::shared_ptr<gbp_route_domain> rd =
245  gbp_route_domain::find(payload.epg.rd_id);
246  std::shared_ptr<gbp_bridge_domain> bd =
247  gbp_bridge_domain::find(payload.epg.bd_id);
248 
249  VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.epg.uplink_sw_if_index
250  << ", " << payload.epg.rd_id << ", "
251  << payload.epg.bd_id << "]";
252 
253  if (itf && bd && rd) {
254  gbp_endpoint_group gbpe(payload.epg.vnid, payload.epg.sclass, *itf, *rd,
255  *bd);
256  OM::commit(key, gbpe);
257 
258  VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
259  } else if (bd && rd) {
260  gbp_endpoint_group gbpe(payload.epg.sclass, *rd, *bd);
261  OM::commit(key, gbpe);
262 
263  VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
264  } else {
265  VOM_LOG(log_level_t::ERROR) << "no itf:" << payload.epg.uplink_sw_if_index
266  << " or BD:" << payload.epg.bd_id
267  << " or RD:" << payload.epg.rd_id;
268  }
269  }
270 }
271 
273 gbp_endpoint_group::event_handler::order() const
274 {
275  return (dependency_t::ACL);
276 }
277 
278 void
280 {
281  db_dump(m_db, os);
282 }
283 } // namespace VOM
284 
285 /*
286  * fd.io coding-style-patch-verification: OFF
287  *
288  * Local Variables:
289  * eval: (c-set-style "mozilla")
290  * End:
291  */
VOM::gbp_endpoint_group::operator==
bool operator==(const gbp_endpoint_group &bdae) const
comparison operator
Definition: gbp_endpoint_group.cpp:132
VOM::HW::write
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
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::gbp_bridge_domain
A entry in the ARP termination table of a Bridge Domain.
Definition: gbp_bridge_domain.hpp:29
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::gbp_endpoint_group::retention_t::to_string
std::string to_string() const
Definition: gbp_endpoint_group.cpp:43
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::gbp_endpoint_group::retention_t::retention_t
retention_t()
Definition: gbp_endpoint_group.cpp:27
VOM::gbp_endpoint_group::get_route_domain
const std::shared_ptr< gbp_route_domain > get_route_domain() const
Definition: gbp_endpoint_group.cpp:206
VOM::gbp_endpoint_group::get_bridge_domain
const std::shared_ptr< gbp_bridge_domain > get_bridge_domain() const
Definition: gbp_endpoint_group.cpp:212
VOM::sclass_t
uint16_t sclass_t
Definition: gbp_types.hpp:27
gbp_endpoint_group.hpp
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
key
typedef key
Definition: ipsec_types.api:91
VOM::gbp_endpoint_group::retention_t::operator==
bool operator==(const retention_t &o) const
Definition: gbp_endpoint_group.cpp:37
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_group::to_string
std::string to_string() const
Convert to string for debugging.
Definition: gbp_endpoint_group.cpp:159
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_bridge_domain::find
static std::shared_ptr< gbp_bridge_domain > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
Definition: gbp_bridge_domain.cpp:235
VOM::gbp_endpoint_group::gbp_endpoint_group
gbp_endpoint_group(vnid_t vnid, sclass_t sclass, const interface &itf, const gbp_route_domain &rd, const gbp_bridge_domain &bd)
Construct a GBP endpoint_group.
Definition: gbp_endpoint_group.cpp:48
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
retention
vl_api_gbp_endpoint_retention_t retention
Definition: gbp.api:191
VOM::HW::enqueue
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
sclass
u16 sclass
Definition: gbp.api:131
VOM::gbp_endpoint_group::retention_t::remote_ep_timeout
uint32_t remote_ep_timeout
Remote Endpoint timeout/ageing.
Definition: gbp_endpoint_group.hpp:52
VOM::gbp_endpoint_group::key
const key_t key() const
Return the object's key.
Definition: gbp_endpoint_group.cpp:108
VOM::log_level_t::DEBUG
const static log_level_t DEBUG
Definition: logger.hpp:32
false
#define false
Definition: cJSON.c:70
singular_db_funcs.hpp
VOM::vnid_t
uint32_t vnid_t
EPG IDs are 32 bit integers.
Definition: gbp_types.hpp:26
VOM::HW::item::rc
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
VOM::gbp_endpoint_group::retention_t
Endpoint Retention Policy Settings.
Definition: gbp_endpoint_group.hpp:38
VOM::gbp_endpoint_group::replay
void replay(void)
replay the object to create it in hardware
Definition: gbp_endpoint_group.cpp:149
VOM::gbp_endpoint_group_cmds::create_cmd
A command class that creates or updates the GBP endpoint_group.
Definition: gbp_endpoint_group_cmds.hpp:30
gbp_endpoint_group_cmds.hpp
VOM::gbp_endpoint_group::singular
std::shared_ptr< gbp_endpoint_group > singular() const
Return the matching 'singular instance'.
Definition: gbp_endpoint_group.cpp:194
VOM::gbp_route_domain
A entry in the ARP termination table of a Route Domain.
Definition: gbp_route_domain.hpp:30
VOM::handle_t::INVALID
const static handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
VOM::gbp_endpoint_group::dump
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: gbp_endpoint_group.cpp:200
VOM::gbp_endpoint_group::key_t
sclass_t key_t
The key for a GBP endpoint group is its ID.
Definition: gbp_endpoint_group.hpp:58
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::~gbp_endpoint_group
~gbp_endpoint_group()
Destructor.
Definition: gbp_endpoint_group.cpp:101
VOM::gbp_endpoint_group
A entry in the ARP termination table of a Bridge Domain.
Definition: gbp_endpoint_group.hpp:32
VOM::gbp_endpoint_group::sclass
sclass_t sclass() const
Definition: gbp_endpoint_group.cpp:126
VOM::gbp_endpoint_group_cmds::delete_cmd
A cmd class that deletes a GBP endpoint_group.
Definition: gbp_endpoint_group_cmds.hpp:71
gbp_endpoint_group
typedef gbp_endpoint_group
Definition: gbp.api:185
VOM::log_level_t::ERROR
const static log_level_t ERROR
Definition: logger.hpp:29
VOM::gbp_endpoint_group::set
void set(const retention_t &retention)
Definition: gbp_endpoint_group.cpp:120
VOM::gbp_endpoint_group::vnid
vnid_t vnid() const
Get the ID of the EPG.
Definition: gbp_endpoint_group.cpp:114
VOM::dependency_t::ACL
@ ACL
ACLs.
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
VOM::gbp_route_domain::find
static std::shared_ptr< gbp_route_domain > find(const key_t &k)
Find the instnace of the route_domain domain in the OM.
Definition: gbp_route_domain.cpp:179
string
const char *const string
Definition: cJSON.h:172