FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
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/route_domain.hpp"
17 #include "vom/cmd.hpp"
20 
21 namespace VOM {
22 
23 route_domain::event_handler route_domain::m_evh;
24 
25 /**
26  * A DB of al the interfaces, key on the name
27  */
28 singular_db<route::table_id_t, route_domain> route_domain::m_db;
29 
30 /**
31  * Construct a new object matching the desried state
32  */
34  : m_hw_v4(true)
35  , m_hw_v6(true)
36  , m_table_id(id)
37 {
38 }
39 
41  : m_hw_v4(o.m_hw_v4)
42  , m_hw_v6(o.m_hw_v6)
43  , m_table_id(o.m_table_id)
44 {
45 }
46 
47 bool
49 {
50  return (m_table_id == r.m_table_id);
51 }
52 
55 {
56  return (m_table_id);
57 }
58 
61 {
62  return (table_id());
63 }
64 
67 {
68  return m_db.begin();
69 }
70 
73 {
74  return m_db.end();
75 }
76 
77 void
78 route_domain::sweep()
79 {
80  if (m_hw_v4) {
82  new route_domain_cmds::delete_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
83  }
84  if (m_hw_v6) {
86  new route_domain_cmds::delete_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
87  }
88  HW::write();
89 }
90 
91 void
93 {
94  if (m_hw_v4) {
96  new route_domain_cmds::create_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
97  }
98  if (m_hw_v6) {
100  new route_domain_cmds::create_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
101  }
102 }
103 
105 {
106  sweep();
107 
108  // not in the DB anymore.
109  m_db.release(m_table_id, this);
110 }
111 
112 std::string
114 {
115  std::ostringstream s;
116  s << "route-domain:["
117  << "table-id:" << m_table_id << " v4:" << m_hw_v4.to_string()
118  << " v6:" << m_hw_v6.to_string() << "]";
119 
120  return (s.str());
121 }
122 
123 std::shared_ptr<route_domain>
125 {
126  return (m_db.find(k));
127 }
128 
129 void
130 route_domain::update(const route_domain& desired)
131 {
132  /*
133  * create the table if it is not yet created
134  */
135  if (rc_t::OK != m_hw_v4.rc()) {
136  HW::enqueue(
137  new route_domain_cmds::create_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
138  }
139  if (rc_t::OK != m_hw_v6.rc()) {
140  HW::enqueue(
141  new route_domain_cmds::create_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
142  }
143 }
144 
145 std::shared_ptr<route_domain>
147 {
149 
150  return (find_or_add(rd));
151 }
152 
153 std::shared_ptr<route_domain>
154 route_domain::find_or_add(const route_domain& temp)
155 {
156  return (m_db.find_or_add(temp.m_table_id, temp));
157 }
158 
159 std::shared_ptr<route_domain>
161 {
162  return find_or_add(*this);
163 }
164 
165 void
166 route_domain::dump(std::ostream& os)
167 {
168  db_dump(m_db, os);
169 }
170 
171 void
172 route_domain::event_handler::handle_populate(const client_db::key_t& key)
173 {
174  std::shared_ptr<route_domain_cmds::dump_cmd> cmd =
175  std::make_shared<route_domain_cmds::dump_cmd>();
176 
177  HW::enqueue(cmd);
178  HW::write();
179 
180  for (auto& record : *cmd) {
181  auto& payload = record.get_payload();
182 
183  route_domain rd(payload.table.table_id);
184 
185  VOM_LOG(log_level_t::DEBUG) << "ip-table-dump: " << rd.to_string();
186 
187  /*
188  * Write each of the discovered interfaces into the OM,
189  * but disable the HW Command q whilst we do, so that no
190  * commands are sent to VPP
191  */
192  OM::commit(key, rd);
193  }
194 }
195 
197 {
198  OM::register_listener(this);
199  inspect::register_handler({ "rd", "route-domain" }, "Route Domains", this);
200 }
201 
202 void
203 route_domain::event_handler::handle_replay()
204 {
205  m_db.replay();
206 }
207 
209 route_domain::event_handler::order() const
210 {
211  return (dependency_t::TABLE);
212 }
213 
214 void
215 route_domain::event_handler::show(std::ostream& os)
216 {
217  db_dump(m_db, os);
218 }
219 
220 }; // namespace VOPM
221 
222 /*
223  * fd.io coding-style-patch-verification: ON
224  *
225  * Local Variables:
226  * eval: (c-set-style "mozilla")
227  * End:
228  */
bool operator==(const route_domain &r) const
comparison operator - for UT
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:121
static std::shared_ptr< route_domain > find(const key_t &temp)
Find the instnace of the route domain in the OM.
#define VOM_LOG(lvl)
Definition: logger.hpp:181
route::table_id_t table_id() const
Get the table ID.
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
std::string to_string() const
Debug print function.
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 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
A route-domain is a VRF.
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
key_t key() const
Get the route-domain&#39;s key.
static const l3_proto_t IPV4
Definition: prefix.hpp:55
static const l3_proto_t IPV6
Definition: prefix.hpp:56
static const table_id_t DEFAULT_TABLE
The table-id for the default table.
Definition: prefix.hpp:126
singular_db< const key_t, route_domain >::const_iterator const_iterator_t
The iterator type.
static std::shared_ptr< route_domain > get_default()
Return the sigular instance for the default table.
void replay(void)
replay the object to create it in hardware
A command class that creates the IP table.
Tables in which entries are added, e.g bridge/route-domains.
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
A cmd class that Deletes the IP Table.
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
route_domain(route::table_id_t id)
Construct a new object matching the desried state.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
std::shared_ptr< route_domain > singular() const
Return the matching &#39;singular instance&#39;.
A representation of a method call to VPP.
Definition: cmd.hpp:32
static const_iterator_t cbegin()
~route_domain()
Destructor.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
static const_iterator_t cend()
static void dump(std::ostream &os)
Dump all route-doamin into the stream provided.
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
route::table_id_t key_t
The Key for a route-domain.