FD.io VPP  v18.01-8-g0eacf49
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"
19 
20 namespace VOM {
21 
22 route_domain::event_handler route_domain::m_evh;
23 
24 /**
25  * A DB of al the interfaces, key on the name
26  */
27 singular_db<route::table_id_t, route_domain> route_domain::m_db;
28 
29 /**
30  * Construct a new object matching the desried state
31  */
33  : m_hw_v4(true)
34  , m_hw_v6(true)
35  , m_table_id(id)
36 {
37 }
38 
40  : m_hw_v4(o.m_hw_v4)
41  , m_hw_v6(o.m_hw_v6)
42  , m_table_id(o.m_table_id)
43 {
44 }
45 
46 bool
48 {
49  return (m_table_id == r.m_table_id);
50 }
51 
54 {
55  return (m_table_id);
56 }
57 
60 {
61  return (table_id());
62 }
63 
64 void
65 route_domain::sweep()
66 {
67  if (m_hw_v4) {
69  new route_domain_cmds::delete_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
70  }
71  if (m_hw_v6) {
73  new route_domain_cmds::delete_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
74  }
75  HW::write();
76 }
77 
78 void
80 {
81  if (m_hw_v4) {
83  new route_domain_cmds::create_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
84  }
85  if (m_hw_v6) {
87  new route_domain_cmds::create_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
88  }
89 }
90 
92 {
93  sweep();
94 
95  // not in the DB anymore.
96  m_db.release(m_table_id, this);
97 }
98 
99 std::string
101 {
102  std::ostringstream s;
103  s << "route-domain:["
104  << "table-id:" << m_table_id << " v4:" << m_hw_v4.to_string()
105  << " v6:" << m_hw_v6.to_string() << "]";
106 
107  return (s.str());
108 }
109 
110 std::shared_ptr<route_domain>
112 {
113  std::shared_ptr<route_domain> rd;
114 
115  auto it = m_db.cbegin();
116 
117  while (it != m_db.cend()) {
118  /*
119  * The key in the DB is a pair of the interface's name and prefix.
120  * If the keys match, save the L3-config
121  */
122  auto key = it->first;
123 
124  if (temp.table_id() == key) {
125  rd = it->second.lock();
126  break;
127  }
128 
129  ++it;
130  }
131 
132  return (rd);
133 }
134 
135 void
136 route_domain::update(const route_domain& desired)
137 {
138  /*
139  * create the table if it is not yet created
140  */
141  if (rc_t::OK != m_hw_v4.rc()) {
142  HW::enqueue(
143  new route_domain_cmds::create_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
144  }
145  if (rc_t::OK != m_hw_v6.rc()) {
146  HW::enqueue(
147  new route_domain_cmds::create_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
148  }
149 }
150 
151 std::shared_ptr<route_domain>
153 {
155 
156  return (find_or_add(rd));
157 }
158 
159 std::shared_ptr<route_domain>
160 route_domain::find_or_add(const route_domain& temp)
161 {
162  return (m_db.find_or_add(temp.m_table_id, temp));
163 }
164 
165 std::shared_ptr<route_domain>
167 {
168  return find_or_add(*this);
169 }
170 
171 void
172 route_domain::dump(std::ostream& os)
173 {
174  m_db.dump(os);
175 }
176 
177 void
178 route_domain::event_handler::handle_populate(const client_db::key_t& key)
179 {
180 }
181 
182 route_domain::event_handler::event_handler()
183 {
184  OM::register_listener(this);
185  inspect::register_handler({ "rd", "route-domain" }, "Route Domains", this);
186 }
187 
188 void
189 route_domain::event_handler::handle_replay()
190 {
191  m_db.replay();
192 }
193 
195 route_domain::event_handler::order() const
196 {
197  return (dependency_t::TABLE);
198 }
199 
200 void
201 route_domain::event_handler::show(std::ostream& os)
202 {
203  m_db.dump(os);
204 }
205 
206 }; // namespace VOPM
207 
208 /*
209  * fd.io coding-style-patch-verification: ON
210  *
211  * Local Variables:
212  * eval: (c-set-style "mozilla")
213  * End:
214  */
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:81
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:225
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:160
static std::shared_ptr< route_domain > find(const route_domain &temp)
Find the instnace of the route domain in the OM.
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:35
route::table_id_t table_id() const
Get the table ID.
static const l3_proto_t IPV6
Definition: prefix.hpp:36
static const table_id_t DEFAULT_TABLE
The table-id for the default table.
Definition: prefix.hpp:86
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.
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:106
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:189
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:124
route::table_id_t key_t
The Key for a route-domain.