FD.io VPP  v19.04.2-12-g66b1689
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_ip4_uu_fwd(rd.m_ip4_uu_fwd)
38  , m_ip6_uu_fwd(rd.m_ip6_uu_fwd)
39 {
40 }
41 
43  const interface& ip4_uu_fwd,
44  const interface& ip6_uu_fwd)
45  : m_id(rd.table_id())
46  , m_rd(rd.singular())
47  , m_ip4_uu_fwd(ip4_uu_fwd.singular())
48  , m_ip6_uu_fwd(ip6_uu_fwd.singular())
49 {
50 }
51 
53  const std::shared_ptr<interface> ip4_uu_fwd,
54  const std::shared_ptr<interface> ip6_uu_fwd)
55  : m_id(rd.table_id())
56  , m_rd(rd.singular())
57  , m_ip4_uu_fwd(ip4_uu_fwd)
58  , m_ip6_uu_fwd(ip6_uu_fwd)
59 {
60  if (m_ip4_uu_fwd)
61  m_ip4_uu_fwd = m_ip4_uu_fwd->singular();
62  if (m_ip6_uu_fwd)
63  m_ip6_uu_fwd = m_ip6_uu_fwd->singular();
64 }
65 
67  : m_id(rd.table_id())
68  , m_rd(rd.singular())
69  , m_ip4_uu_fwd()
70  , m_ip6_uu_fwd()
71 {
72 }
73 
76 {
77  return (m_rd->key());
78 }
79 
82 {
83  return (m_rd->table_id());
84 }
85 
86 const std::shared_ptr<route_domain>
88 {
89  return m_rd;
90 }
91 
92 const std::shared_ptr<interface>
94 {
95  return m_ip4_uu_fwd;
96 }
97 
98 const std::shared_ptr<interface>
100 {
101  return m_ip6_uu_fwd;
102 }
103 
104 bool
106 {
107  bool equal = true;
108 
109  if (m_ip4_uu_fwd && b.m_ip4_uu_fwd)
110  equal &= (m_ip4_uu_fwd->key() == b.m_ip4_uu_fwd->key());
111  else if (!m_ip4_uu_fwd && !b.m_ip4_uu_fwd)
112  ;
113  else
114  equal = false;
115 
116  if (m_ip6_uu_fwd && b.m_ip6_uu_fwd)
117  equal &= (m_ip6_uu_fwd->key() == b.m_ip6_uu_fwd->key());
118  else if (!m_ip6_uu_fwd && !b.m_ip6_uu_fwd)
119  ;
120  else
121  equal = false;
122 
123  return ((m_rd->key() == b.m_rd->key()) && equal);
124 }
125 
126 void
127 gbp_route_domain::sweep()
128 {
129  if (rc_t::OK == m_id.rc()) {
131  }
132  HW::write();
133 }
134 
135 void
137 {
138  if (rc_t::OK == m_id.rc()) {
139  if (m_ip4_uu_fwd && m_ip6_uu_fwd)
141  m_id, m_ip4_uu_fwd->handle(), m_ip6_uu_fwd->handle()));
142  else
145  }
146 }
147 
149 {
150  sweep();
151 
152  // not in the DB anymore.
153  m_db.release(m_id.data(), this);
154 }
155 
156 std::string
158 {
159  std::ostringstream s;
160  s << "gbp-route-domain:[" << m_rd->to_string();
161 
162  if (m_ip4_uu_fwd)
163  s << " v4-uu:[" << m_ip4_uu_fwd->to_string() << "]";
164  if (m_ip6_uu_fwd)
165  s << " v6-uu:[" << m_ip6_uu_fwd->to_string() << "]";
166 
167  s << "]";
168 
169  return (s.str());
170 }
171 
172 std::shared_ptr<gbp_route_domain>
174 {
175  return (m_db.find(key));
176 }
177 
178 void
179 gbp_route_domain::update(const gbp_route_domain& desired)
180 {
181  /*
182  * the desired state is always that the interface should be created
183  */
184  if (rc_t::OK != m_id.rc()) {
185  if (m_ip4_uu_fwd && m_ip6_uu_fwd)
187  m_id, m_ip4_uu_fwd->handle(), m_ip6_uu_fwd->handle()));
188  else
191  }
192 }
193 
194 std::shared_ptr<gbp_route_domain>
195 gbp_route_domain::find_or_add(const gbp_route_domain& temp)
196 {
197  return (m_db.find_or_add(temp.key(), temp));
198 }
199 
200 std::shared_ptr<gbp_route_domain>
202 {
203  return find_or_add(*this);
204 }
205 
206 void
207 gbp_route_domain::dump(std::ostream& os)
208 {
209  db_dump(m_db, os);
210 }
211 
212 void
213 gbp_route_domain::event_handler::handle_populate(const client_db::key_t& key)
214 {
215  /*
216  * dump VPP Route domains
217  */
218  std::shared_ptr<gbp_route_domain_cmds::dump_cmd> cmd =
219  std::make_shared<gbp_route_domain_cmds::dump_cmd>();
220 
221  HW::enqueue(cmd);
222  HW::write();
223 
224  for (auto& record : *cmd) {
225  auto& payload = record.get_payload();
226 
227  std::shared_ptr<interface> ip6_uu_fwd =
228  interface::find(payload.rd.ip6_uu_sw_if_index);
229  std::shared_ptr<interface> ip4_uu_fwd =
230  interface::find(payload.rd.ip4_uu_sw_if_index);
231 
232  if (ip6_uu_fwd && ip4_uu_fwd) {
233  gbp_route_domain rd(payload.rd.rd_id, *ip4_uu_fwd, *ip6_uu_fwd);
234  OM::commit(key, rd);
235  VOM_LOG(log_level_t::DEBUG) << "dump: " << rd.to_string();
236  } else {
237  gbp_route_domain rd(payload.rd.rd_id);
238  OM::commit(key, rd);
239  VOM_LOG(log_level_t::DEBUG) << "dump: " << rd.to_string();
240  }
241  }
242 }
243 
245 {
246  OM::register_listener(this);
247  inspect::register_handler({ "grd", "groute" }, "GBP Route Domains", this);
248 }
249 
250 void
251 gbp_route_domain::event_handler::handle_replay()
252 {
253  m_db.replay();
254 }
255 
257 gbp_route_domain::event_handler::order() const
258 {
260 }
261 
262 void
264 {
265  db_dump(m_db, os);
266 }
267 }
268 
269 /*
270  * fd.io coding-style-patch-verification: ON
271  *
272  * Local Variables:
273  * eval: (c-set-style "mozilla")
274  * End:
275  */
std::shared_ptr< gbp_route_domain > singular() const
Return the matching &#39;singular instance&#39;.
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:82
const std::shared_ptr< interface > get_ip6_uu_fwd() const
#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:531
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::string to_string() const
Convert to string for debugging.
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
static const log_level_t DEBUG
Definition: logger.hpp:32
gbp_route_domain(const route_domain &rd)
Construct a GBP route_domain.
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
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
bool operator==(const gbp_route_domain &rdae) const
comparison operator
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
const key_t key() const
Return the object&#39;s key.
A cmd class that Delete an Route-Domain.
A representation of an interface in VPP.
Definition: interface.hpp:41
A command class that creates an Route-Domain.
const std::shared_ptr< interface > get_ip4_uu_fwd() const
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:340
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.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
void replay(void)
replay the object to create it in hardware
u32 id
Definition: udp.api:45
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
const std::shared_ptr< route_domain > get_route_domain() const
Accessors for children.
route::table_id_t id() const
Return the route domain&#39;s VPP ID.