FD.io VPP  v18.10-34-gcce845e
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 
65 void
66 route_domain::sweep()
67 {
68  if (m_hw_v4) {
70  new route_domain_cmds::delete_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
71  }
72  if (m_hw_v6) {
74  new route_domain_cmds::delete_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
75  }
76  HW::write();
77 }
78 
79 void
81 {
82  if (m_hw_v4) {
84  new route_domain_cmds::create_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
85  }
86  if (m_hw_v6) {
88  new route_domain_cmds::create_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
89  }
90 }
91 
93 {
94  sweep();
95 
96  // not in the DB anymore.
97  m_db.release(m_table_id, this);
98 }
99 
100 std::string
102 {
103  std::ostringstream s;
104  s << "route-domain:["
105  << "table-id:" << m_table_id << " v4:" << m_hw_v4.to_string()
106  << " v6:" << m_hw_v6.to_string() << "]";
107 
108  return (s.str());
109 }
110 
111 std::shared_ptr<route_domain>
113 {
114  return (m_db.find(k));
115 }
116 
117 void
118 route_domain::update(const route_domain& desired)
119 {
120  /*
121  * create the table if it is not yet created
122  */
123  if (rc_t::OK != m_hw_v4.rc()) {
124  HW::enqueue(
125  new route_domain_cmds::create_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
126  }
127  if (rc_t::OK != m_hw_v6.rc()) {
128  HW::enqueue(
129  new route_domain_cmds::create_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
130  }
131 }
132 
133 std::shared_ptr<route_domain>
135 {
137 
138  return (find_or_add(rd));
139 }
140 
141 std::shared_ptr<route_domain>
142 route_domain::find_or_add(const route_domain& temp)
143 {
144  return (m_db.find_or_add(temp.m_table_id, temp));
145 }
146 
147 std::shared_ptr<route_domain>
149 {
150  return find_or_add(*this);
151 }
152 
153 void
154 route_domain::dump(std::ostream& os)
155 {
156  db_dump(m_db, os);
157 }
158 
159 void
160 route_domain::event_handler::handle_populate(const client_db::key_t& key)
161 {
162 }
163 
165 {
166  OM::register_listener(this);
167  inspect::register_handler({ "rd", "route-domain" }, "Route Domains", this);
168 }
169 
170 void
171 route_domain::event_handler::handle_replay()
172 {
173  m_db.replay();
174 }
175 
177 route_domain::event_handler::order() const
178 {
179  return (dependency_t::TABLE);
180 }
181 
182 void
183 route_domain::event_handler::show(std::ostream& os)
184 {
185  db_dump(m_db, os);
186 }
187 
188 }; // namespace VOPM
189 
190 /*
191  * fd.io coding-style-patch-verification: ON
192  *
193  * Local Variables:
194  * eval: (c-set-style "mozilla")
195  * End:
196  */
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:82
static std::shared_ptr< route_domain > find(const key_t &temp)
Find the instnace of the route domain in the OM.
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
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:236
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:160
A route-domain is a VRF.
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:118
static const l3_proto_t IPV4
Definition: prefix.hpp:55
route::table_id_t table_id() const
Get the table ID.
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:87
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.
std::shared_ptr< route_domain > singular() const
Return the matching &#39;singular instance&#39;.
Tables in which entries are added, e.g bridge/route-domains.
void event_handler(void *tls_async)
Definition: tls_async.c:339
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:104
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:194
bool operator==(const route_domain &r) const
comparison operator - for UT
std::string to_string() const
Debug print function.
route_domain(route::table_id_t id)
Construct a new object matching the desried state.
key_t key() const
Get the route-domain&#39;s key.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
~route_domain()
Destructor.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
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.