FD.io VPP  v21.06-3-gbb25fbf28
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 
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: OFF
224  *
225  * Local Variables:
226  * eval: (c-set-style "mozilla")
227  * End:
228  */
VOM::route_domain::table_id
route::table_id_t table_id() const
Get the table ID.
Definition: route_domain.cpp:54
VOM::HW::write
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
VOM::route_domain::to_string
std::string to_string() const
Debug print function.
Definition: route_domain.cpp:113
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::route_domain::operator==
bool operator==(const route_domain &r) const
comparison operator - for UT
Definition: route_domain.cpp:48
route_domain_cmds.hpp
VOM_LOG
#define VOM_LOG(lvl)
Definition: logger.hpp:181
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
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::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::l3_proto_t::IPV4
const static l3_proto_t IPV4
Definition: prefix.hpp:55
VOM::route_domain::key
key_t key() const
Get the route-domain's key.
Definition: route_domain.cpp:60
cmd.hpp
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1071
key
typedef key
Definition: ipsec_types.api:88
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::route_domain::const_iterator_t
singular_db< const key_t, route_domain >::const_iterator const_iterator_t
The iterator type.
Definition: route_domain.hpp:43
VOM::OM::register_listener
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
VOM::route_domain::get_default
static std::shared_ptr< route_domain > get_default()
Return the sigular instance for the default table.
Definition: route_domain.cpp:146
VOM::route_domain::replay
void replay(void)
replay the object to create it in hardware
Definition: route_domain.cpp:92
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
VOM::HW::enqueue
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::log_level_t::DEBUG
const static log_level_t DEBUG
Definition: logger.hpp:32
VOM::dependency_t::TABLE
@ TABLE
Tables in which entries are added, e.g bridge/route-domains.
VOM::route_domain_cmds::create_cmd
A command class that creates the IP table.
Definition: route_domain_cmds.hpp:31
singular_db_funcs.hpp
id
u8 id[64]
Definition: dhcp.api:160
true
#define true
Definition: cJSON.c:65
VOM::HW::item::rc
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
VOM::route_domain_cmds::delete_cmd
A cmd class that Deletes the IP Table.
Definition: route_domain_cmds.hpp:69
VOM::route_domain::cbegin
static const_iterator_t cbegin()
Definition: route_domain.cpp:66
VOM::route_domain::~route_domain
~route_domain()
Destructor.
Definition: route_domain.cpp:104
VOM::route_domain
A route-domain is a VRF.
Definition: route_domain.hpp:31
VOM::route_domain::route_domain
route_domain(route::table_id_t id)
Construct a new object matching the desried state.
Definition: route_domain.cpp:33
VOM::route_domain::cend
static const_iterator_t cend()
Definition: route_domain.cpp:72
route_domain.hpp
VOM::route_domain::dump
static void dump(std::ostream &os)
Dump all route-doamin into the stream provided.
Definition: route_domain.cpp:166
VOM::route_domain::singular
std::shared_ptr< route_domain > singular() const
Return the matching 'singular instance'.
Definition: route_domain.cpp:160
VOM::route::table_id_t
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:121
show
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
VOM::route::DEFAULT_TABLE
const static table_id_t DEFAULT_TABLE
The table-id for the default table.
Definition: prefix.hpp:126
event_handler
void event_handler(void *tls_async)
Definition: tls_async.c:334
VOM::cmd
A representation of a method call to VPP.
Definition: cmd.hpp:32
VOM::route_domain::key_t
route::table_id_t key_t
The Key for a route-domain.
Definition: route_domain.hpp:37
VOM::l3_proto_t::IPV6
const static l3_proto_t IPV6
Definition: prefix.hpp:56
VOM::route_domain::find
static std::shared_ptr< route_domain > find(const key_t &temp)
Find the instnace of the route domain in the OM.
Definition: route_domain.cpp:124
string
const char *const string
Definition: cJSON.h:172