FD.io VPP  v19.01.2-3-gf61a1a8
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 }
52  const std::shared_ptr<interface> ip4_uu_fwd,
53  const std::shared_ptr<interface> ip6_uu_fwd)
54  : m_id(rd.table_id())
55  , m_rd(rd.singular())
56  , m_ip4_uu_fwd(ip4_uu_fwd->singular())
57  , m_ip6_uu_fwd(ip6_uu_fwd->singular())
58 {
59 }
60 
62  : m_id(rd.table_id())
63  , m_rd(rd.singular())
64 {
65 }
66 
69 {
70  return (m_rd->key());
71 }
72 
73 uint32_t
75 {
76  return (m_rd->table_id());
77 }
78 
79 const std::shared_ptr<route_domain>
81 {
82  return m_rd;
83 }
84 
85 bool
87 {
88  bool equal = true;
89 
90  if (m_ip4_uu_fwd && b.m_ip4_uu_fwd)
91  equal &= (m_ip4_uu_fwd->key() == b.m_ip4_uu_fwd->key());
92  else if (!m_ip4_uu_fwd && !b.m_ip4_uu_fwd)
93  ;
94  else
95  equal = false;
96 
97  if (m_ip6_uu_fwd && b.m_ip6_uu_fwd)
98  equal &= (m_ip6_uu_fwd->key() == b.m_ip6_uu_fwd->key());
99  else if (!m_ip6_uu_fwd && !b.m_ip6_uu_fwd)
100  ;
101  else
102  equal = false;
103 
104  return ((m_rd->key() == b.m_rd->key()) && equal);
105 }
106 
107 void
108 gbp_route_domain::sweep()
109 {
110  if (rc_t::OK == m_id.rc()) {
112  }
113  HW::write();
114 }
115 
116 void
118 {
119  if (rc_t::OK == m_id.rc()) {
120  if (m_ip4_uu_fwd && m_ip6_uu_fwd)
122  m_id, m_ip4_uu_fwd->handle(), m_ip6_uu_fwd->handle()));
123  else
126  }
127 }
128 
130 {
131  sweep();
132 
133  // not in the DB anymore.
134  m_db.release(m_id.data(), this);
135 }
136 
137 std::string
139 {
140  std::ostringstream s;
141  s << "gbp-route-domain:[" << m_rd->to_string();
142 
143  if (m_ip4_uu_fwd)
144  s << " v4-uu:[" << m_ip4_uu_fwd->to_string() << "]";
145  if (m_ip6_uu_fwd)
146  s << " v6-uu:[" << m_ip6_uu_fwd->to_string() << "]";
147 
148  s << "]";
149 
150  return (s.str());
151 }
152 
153 std::shared_ptr<gbp_route_domain>
155 {
156  return (m_db.find(key));
157 }
158 
159 void
160 gbp_route_domain::update(const gbp_route_domain& desired)
161 {
162  /*
163  * the desired state is always that the interface should be created
164  */
165  if (rc_t::OK != m_id.rc()) {
166  if (m_ip4_uu_fwd && m_ip6_uu_fwd)
168  m_id, m_ip4_uu_fwd->handle(), m_ip6_uu_fwd->handle()));
169  else
172  }
173 }
174 
175 std::shared_ptr<gbp_route_domain>
176 gbp_route_domain::find_or_add(const gbp_route_domain& temp)
177 {
178  return (m_db.find_or_add(temp.m_id.data(), temp));
179 }
180 
181 std::shared_ptr<gbp_route_domain>
183 {
184  return find_or_add(*this);
185 }
186 
187 void
188 gbp_route_domain::dump(std::ostream& os)
189 {
190  db_dump(m_db, os);
191 }
192 
193 void
194 gbp_route_domain::event_handler::handle_populate(const client_db::key_t& key)
195 {
196  /*
197  * dump VPP Route domains
198  */
199  std::shared_ptr<gbp_route_domain_cmds::dump_cmd> cmd =
200  std::make_shared<gbp_route_domain_cmds::dump_cmd>();
201 
202  HW::enqueue(cmd);
203  HW::write();
204 
205  for (auto& record : *cmd) {
206  auto& payload = record.get_payload();
207 
208  std::shared_ptr<interface> ip6_uu_fwd =
209  interface::find(payload.rd.ip6_uu_sw_if_index);
210  std::shared_ptr<interface> ip4_uu_fwd =
211  interface::find(payload.rd.ip4_uu_sw_if_index);
212 
213  if (ip6_uu_fwd && ip4_uu_fwd) {
214  gbp_route_domain rd(payload.rd.rd_id, *ip4_uu_fwd, *ip6_uu_fwd);
215  OM::commit(key, rd);
216  VOM_LOG(log_level_t::DEBUG) << "dump: " << rd.to_string();
217  } else {
218  gbp_route_domain rd(payload.rd.rd_id);
219  OM::commit(key, rd);
220  VOM_LOG(log_level_t::DEBUG) << "dump: " << rd.to_string();
221  }
222  }
223 }
224 
226 {
227  OM::register_listener(this);
228  inspect::register_handler({ "grd", "groute" }, "GBP Route Domains", this);
229 }
230 
231 void
232 gbp_route_domain::event_handler::handle_replay()
233 {
234  m_db.replay();
235 }
236 
238 gbp_route_domain::event_handler::order() const
239 {
241 }
242 
243 void
245 {
246  db_dump(m_db, os);
247 }
248 }
249 
250 /*
251  * fd.io coding-style-patch-verification: ON
252  *
253  * Local Variables:
254  * eval: (c-set-style "mozilla")
255  * End:
256  */
std::shared_ptr< gbp_route_domain > singular() const
Return the matching &#39;singular instance&#39;.
#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 pari 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:527
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
const std::shared_ptr< route_domain > get_route_domain()
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.
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.
uint32_t id() const
Return the route domain&#39;s VPP ID.
~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