FD.io VPP  v21.01.1
Vector Packet Processing
gbp_route_domain.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_route_domain.hpp"
18 #include "vom/interface.hpp"
19 #include "vom/l2_binding.hpp"
21 
22 namespace VOM {
23 
24 /**
25  * A DB of al the interfaces, key on the name
26  */
27 singular_db<uint32_t, gbp_route_domain> gbp_route_domain::m_db;
28 
29 gbp_route_domain::event_handler gbp_route_domain::m_evh;
30 
31 /**
32  * Construct a new object matching the desried state
33  */
35  : m_id(rd.id())
36  , m_rd(rd.m_rd)
37  , m_scope(rd.m_scope)
38  , m_ip4_uu_fwd(rd.m_ip4_uu_fwd)
39  , m_ip6_uu_fwd(rd.m_ip6_uu_fwd)
40 {
41 }
42 
44  scope_t scope,
45  const interface& ip4_uu_fwd,
46  const interface& ip6_uu_fwd)
47  : m_id(rd.table_id())
48  , m_rd(rd.singular())
49  , m_scope(scope)
50  , m_ip4_uu_fwd(ip4_uu_fwd.singular())
51  , m_ip6_uu_fwd(ip6_uu_fwd.singular())
52 {
53 }
54 
56  scope_t scope,
57  const std::shared_ptr<interface> ip4_uu_fwd,
58  const std::shared_ptr<interface> ip6_uu_fwd)
59  : m_id(rd.table_id())
60  , m_rd(rd.singular())
61  , m_scope(scope)
62  , m_ip4_uu_fwd(ip4_uu_fwd)
63  , m_ip6_uu_fwd(ip6_uu_fwd)
64 {
65  if (m_ip4_uu_fwd)
66  m_ip4_uu_fwd = m_ip4_uu_fwd->singular();
67  if (m_ip6_uu_fwd)
68  m_ip6_uu_fwd = m_ip6_uu_fwd->singular();
69 }
70 
72  : m_id(rd.table_id())
73  , m_rd(rd.singular())
74  , m_scope(scope)
75  , m_ip4_uu_fwd()
76  , m_ip6_uu_fwd()
77 {
78 }
79 
82 {
83  return (m_rd->key());
84 }
85 
88 {
89  return (m_rd->table_id());
90 }
91 
92 const std::shared_ptr<route_domain>
94 {
95  return m_rd;
96 }
97 
98 const std::shared_ptr<interface>
100 {
101  return m_ip4_uu_fwd;
102 }
103 
104 const std::shared_ptr<interface>
106 {
107  return m_ip6_uu_fwd;
108 }
109 
110 bool
112 {
113  bool equal = true;
114 
115  if (m_ip4_uu_fwd && b.m_ip4_uu_fwd)
116  equal &= (m_ip4_uu_fwd->key() == b.m_ip4_uu_fwd->key());
117  else if (!m_ip4_uu_fwd && !b.m_ip4_uu_fwd)
118  ;
119  else
120  equal = false;
121 
122  if (m_ip6_uu_fwd && b.m_ip6_uu_fwd)
123  equal &= (m_ip6_uu_fwd->key() == b.m_ip6_uu_fwd->key());
124  else if (!m_ip6_uu_fwd && !b.m_ip6_uu_fwd)
125  ;
126  else
127  equal = false;
128 
129  return ((m_rd->key() == b.m_rd->key()) && m_scope == b.m_scope && equal);
130 }
131 
132 void
133 gbp_route_domain::sweep()
134 {
135  if (rc_t::OK == m_id.rc()) {
137  }
138  HW::write();
139 }
140 
141 void
143 {
144  if (rc_t::OK == m_id.rc()) {
145  if (m_ip4_uu_fwd && m_ip6_uu_fwd)
147  m_id, m_scope, m_ip4_uu_fwd->handle(), m_ip6_uu_fwd->handle()));
148  else
150  m_id, m_scope, handle_t::INVALID, handle_t::INVALID));
151  }
152 }
153 
155 {
156  sweep();
157 
158  // not in the DB anymore.
159  m_db.release(m_id.data(), this);
160 }
161 
164 {
165  std::ostringstream s;
166  s << "gbp-route-domain:[" << m_rd->to_string() << "scope:" << m_scope;
167 
168  if (m_ip4_uu_fwd)
169  s << " v4-uu:[" << m_ip4_uu_fwd->to_string() << "]";
170  if (m_ip6_uu_fwd)
171  s << " v6-uu:[" << m_ip6_uu_fwd->to_string() << "]";
172 
173  s << "]";
174 
175  return (s.str());
176 }
177 
178 std::shared_ptr<gbp_route_domain>
180 {
181  return (m_db.find(key));
182 }
183 
184 void
185 gbp_route_domain::update(const gbp_route_domain& desired)
186 {
187  if (rc_t::OK != m_id.rc()) {
188  if (m_ip4_uu_fwd && m_ip6_uu_fwd)
190  m_id, m_scope, m_ip4_uu_fwd->handle(), m_ip6_uu_fwd->handle()));
191  else
193  m_id, m_scope, handle_t::INVALID, handle_t::INVALID));
194  }
195 }
196 
197 std::shared_ptr<gbp_route_domain>
198 gbp_route_domain::find_or_add(const gbp_route_domain& temp)
199 {
200  return (m_db.find_or_add(temp.key(), temp));
201 }
202 
203 std::shared_ptr<gbp_route_domain>
205 {
206  return find_or_add(*this);
207 }
208 
209 void
210 gbp_route_domain::dump(std::ostream& os)
211 {
212  db_dump(m_db, os);
213 }
214 
215 void
216 gbp_route_domain::event_handler::handle_populate(const client_db::key_t& key)
217 {
218  /*
219  * dump VPP Route domains
220  */
221  std::shared_ptr<gbp_route_domain_cmds::dump_cmd> cmd =
222  std::make_shared<gbp_route_domain_cmds::dump_cmd>();
223 
224  HW::enqueue(cmd);
225  HW::write();
226 
227  for (auto& record : *cmd) {
228  auto& payload = record.get_payload();
229 
230  std::shared_ptr<interface> ip6_uu_fwd =
231  interface::find(payload.rd.ip6_uu_sw_if_index);
232  std::shared_ptr<interface> ip4_uu_fwd =
233  interface::find(payload.rd.ip4_uu_sw_if_index);
234 
235  if (ip6_uu_fwd && ip4_uu_fwd) {
236  gbp_route_domain rd(payload.rd.rd_id, payload.rd.scope, *ip4_uu_fwd,
237  *ip6_uu_fwd);
238  OM::commit(key, rd);
239  VOM_LOG(log_level_t::DEBUG) << "dump: " << rd.to_string();
240  } else {
241  gbp_route_domain rd(payload.rd.rd_id, payload.rd.scope);
242  OM::commit(key, rd);
243  VOM_LOG(log_level_t::DEBUG) << "dump: " << rd.to_string();
244  }
245  }
246 }
247 
249 {
250  OM::register_listener(this);
251  inspect::register_handler({ "grd", "groute" }, "GBP Route Domains", this);
252 }
253 
254 void
255 gbp_route_domain::event_handler::handle_replay()
256 {
257  m_db.replay();
258 }
259 
261 gbp_route_domain::event_handler::order() const
262 {
264 }
265 
266 void
268 {
269  db_dump(m_db, os);
270 }
271 }
272 
273 /*
274  * fd.io coding-style-patch-verification: OFF
275  *
276  * Local Variables:
277  * eval: (c-set-style "mozilla")
278  * End:
279  */
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:121
#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.
route_domain::key_t key_t
The key for a route_domain is the pair of EPG-IDs.
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:538
const char *const string
Definition: cJSON.h:172
std::string to_string() const
Convert to string for debugging.
bool operator==(const gbp_route_domain &rdae) const
comparison operator
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
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
static const log_level_t DEBUG
Definition: logger.hpp:32
std::shared_ptr< gbp_route_domain > singular() const
Return the matching &#39;singular instance&#39;.
static void dump(std::ostream &os)
Dump all route_domain-doamin into the stream provided.
static const handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
u8 id[64]
Definition: dhcp.api:160
virtual tables - tables with a dependency on another table
A route-domain is a VRF.
T & data()
Return the data read/written.
Definition: hw.hpp:109
const cJSON *const b
Definition: cJSON.h:255
const std::shared_ptr< interface > get_ip6_uu_fwd() const
A cmd class that Delete an Route-Domain.
const std::shared_ptr< interface > get_ip4_uu_fwd() const
const std::shared_ptr< route_domain > get_route_domain() const
Accessors for children.
A representation of an interface in VPP.
Definition: interface.hpp:41
A command class that creates an Route-Domain.
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:334
uint16_t scope_t
Definition: gbp_types.hpp:28
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
A entry in the ARP termination table of a Route Domain.
~gbp_route_domain()
Destructor.
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_route_domain > find(const key_t &k)
Find the instnace of the route_domain domain in the OM.
u32 table_id
Definition: wireguard.api:102
const key_t key() const
Return the object&#39;s key.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
gbp_route_domain(const route_domain &rd, scope_t scope)
Construct a GBP route_domain.
void replay(void)
replay the object to create it in hardware
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
vl_api_gbp_scope_t scope
Definition: gbp.api:78
route::table_id_t id() const
Return the route domain&#39;s VPP ID.