FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
route.hpp
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 #ifndef __VOM_ROUTE_H__
17 #define __VOM_ROUTE_H__
18 
19 #include "vom/interface.hpp"
20 #include "vom/prefix.hpp"
21 #include "vom/route_domain.hpp"
22 #include "vom/singular_db.hpp"
23 
24 namespace VOM {
25 /**
26  * Types belonging to Routing
27  */
28 namespace route {
29 /**
30  * A path for IP or MPLS routes
31  */
32 class path
33 {
34 public:
35  /**
36  * Special path types
37  */
38  class special_t : public enum_base<special_t>
39  {
40  public:
41  /**
42  * A standard path type. this includes path types
43  * that use the next-hop and interface
44  */
45  const static special_t STANDARD;
46 
47  /**
48  * A local/for-us/recieve
49  */
50  const static special_t LOCAL;
51 
52  /**
53  * drop path
54  */
55  const static special_t DROP;
56 
57  /**
58  * a path will return ICMP unreachables
59  */
60  const static special_t UNREACH;
61 
62  /**
63  * a path will return ICMP prohibit
64  */
65  const static special_t PROHIBIT;
66 
67  private:
68  /**
69  * Private constructor taking the value and the string name
70  */
71  special_t(int v, const std::string& s);
72  };
73 
74  /**
75  * Path flags
76  */
77  class flags_t : public enum_base<flags_t>
78  {
79  public:
80  /**
81  * No flags
82  */
83  const static flags_t NONE;
84 
85  /**
86  * A path that resolves via a DVR next-hop
87  */
88  const static flags_t DVR;
89 
90  private:
91  /**
92  * Private constructor taking the value and the string name
93  */
94  flags_t(int v, const std::string& s);
95  };
96 
97  /**
98  * constructor for special paths
99  */
100  path(special_t special, const nh_proto_t& proto = nh_proto_t::IPV4);
101 
102  /**
103  * Constructor for standard non-recursive paths
104  */
106  const interface& interface,
107  uint8_t weight = 1,
108  uint8_t preference = 0);
109 
110  /**
111  * Constructor for standard recursive paths
112  */
113  path(const route_domain& rd,
115  uint8_t weight = 1,
116  uint8_t preference = 0);
117 
118  /**
119  * Constructor for DVR paths or attached paths.
120  */
121  path(const interface& interface,
122  const nh_proto_t& proto,
123  const flags_t& flags = flags_t::NONE,
124  uint8_t weight = 1,
125  uint8_t preference = 0);
126 
127  /**
128  * Copy Constructor
129  */
130  path(const path& p);
131 
132  /**
133  * Destructor
134  */
135  ~path();
136 
137  /**
138  * comparison operator
139  */
140  bool operator==(const path& p) const;
141 
142  /**
143  * Less than operator for set insertion
144  */
145  bool operator<(const path& p) const;
146 
147  /**
148  * convert to string format for debug purposes
149  */
150  std::string to_string() const;
151 
152  /**
153  * Getters
154  */
155  special_t type() const;
156  nh_proto_t nh_proto() const;
157  flags_t flags() const;
158  const boost::asio::ip::address& nh() const;
159  std::shared_ptr<route_domain> rd() const;
160  std::shared_ptr<interface> itf() const;
161  uint8_t weight() const;
162  uint8_t preference() const;
163 
164 private:
165  /**
166  * The special path tpye
167  */
168  special_t m_type;
169 
170  /**
171  * The next-hop protocol
172  */
173  nh_proto_t m_nh_proto;
174 
175  /**
176  * Flags for the path
177  */
178  flags_t m_flags;
179 
180  /**
181  * The next-hop
182  */
184 
185  /**
186  * For recursive routes, this is the table in which the
187  * the next-hop exists.
188  */
189  std::shared_ptr<route_domain> m_rd;
190 
191  /**
192  * The next-hop interface [if present].
193  */
194  std::shared_ptr<interface> m_interface;
195 
196  /**
197  * UCMP weight
198  */
199  uint8_t m_weight;
200 
201  /**
202  * Path preference
203  */
204  uint8_t m_preference;
205 };
206 
207 class itf_flags_t : public enum_base<itf_flags_t>
208 {
209 public:
210  const static itf_flags_t NONE;
211  /**
212  * Path is accepting multicast traffic
213  */
214  const static itf_flags_t ACCEPT;
215 
216  /**
217  * A local/for-us/recieve
218  */
219  const static itf_flags_t FORWARD;
220 
221 private:
222  /**
223  * Private constructor taking the value and the string name
224  */
225  itf_flags_t(int v, const std::string& s);
226 };
227 
228 /**
229  * A path-list is a set of paths
230  */
231 typedef std::set<path> path_list_t;
232 
233 /**
234  * A mpath-list is a set of paths and interface flags
235  */
236 typedef std::set<std::pair<path, itf_flags_t>> mpath_list_t;
237 
238 /**
239  * ostream output for iterator
240  */
241 std::ostream& operator<<(std::ostream& os, const path_list_t& path_list);
242 std::ostream& operator<<(std::ostream& os, const mpath_list_t& path_list);
243 
244 /**
245  * A IP route
246  */
247 class ip_route : public object_base
248 {
249 public:
250  /**
251  * The key for a route
252  */
253  typedef std::pair<route::table_id_t, prefix_t> key_t;
254 
255  /**
256  * Construct a route in the default table
257  */
258  ip_route(const prefix_t& prefix);
259 
260  /**
261  * Construct a route with a path
262  */
263  ip_route(const prefix_t& prefix, const path& p);
264 
265  /**
266  * Copy Construct
267  */
268  ip_route(const ip_route& r);
269 
270  /**
271  * Construct a route in the given route domain
272  */
273  ip_route(const route_domain& rd, const prefix_t& prefix);
274 
275  /**
276  * Construct a route in the given route domain with a path
277  */
278  ip_route(const route_domain& rd, const prefix_t& prefix, const path& p);
279 
280  /**
281  * Destructor
282  */
283  ~ip_route();
284 
285  /**
286  * Get the route's key
287  */
288  const key_t key() const;
289 
290  /**
291  * Comparison operator
292  */
293  bool operator==(const ip_route& i) const;
294 
295  /**
296  * Return the matching 'singular instance'
297  */
298  std::shared_ptr<ip_route> singular() const;
299 
300  /**
301  * Add a path.
302  */
303  void add(const path& path);
304 
305  /**
306  * remove a path.
307  */
308  void remove(const path& path);
309 
310  /**
311  * Find the instnace of the route domain in the OM
312  */
313  static std::shared_ptr<ip_route> find(const ip_route& temp);
314 
315  /**
316  * Dump all route-doamin into the stream provided
317  */
318  static void dump(std::ostream& os);
319 
320  /**
321  * replay the object to create it in hardware
322  */
323  void replay(void);
324 
325  /**
326  * Convert to string for debugging
327  */
328  std::string to_string() const;
329 
330  /**
331  * Return the matching 'singular instance'
332  */
333  static std::shared_ptr<ip_route> find(const key_t& k);
334 
335 private:
336  /**
337  * Class definition for listeners to OM events
338  */
340  {
341  public:
342  event_handler();
343  virtual ~event_handler() = default;
344 
345  /**
346  * Handle a populate event
347  */
348  void handle_populate(const client_db::key_t& key);
349 
350  /**
351  * Handle a replay event
352  */
353  void handle_replay();
354 
355  /**
356  * Show the object in the Singular DB
357  */
358  void show(std::ostream& os);
359 
360  /**
361  * Get the sortable Id of the listener
362  */
363  dependency_t order() const;
364  };
365 
366  /**
367  * event_handler to register with OM
368  */
369  static event_handler m_evh;
370 
371  /**
372  * Find or add the instnace of the route domain in the OM
373  */
374  static std::shared_ptr<ip_route> find_or_add(const ip_route& temp);
375 
376  /*
377  * It's the OM class that updates the objects in HW
378  */
379  friend class VOM::OM;
380 
381  /**
382  * It's the singular_db class that calls replay()
383  */
384  friend class singular_db<key_t, ip_route>;
385 
386  /**
387  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
388  */
389  void update(const ip_route& obj);
390 
391  /**
392  * Sweep/reap the object if still stale
393  */
394  void sweep(void);
395 
396  /**
397  * HW configuration for the result of creating the route
398  */
399  HW::item<handle_t> m_hw;
400 
401  /**
402  * The route domain the route is in.
403  */
404  std::shared_ptr<route_domain> m_rd;
405 
406  /**
407  * The prefix to match
408  */
409  prefix_t m_prefix;
410 
411  /**
412  * The set of paths
413  */
414  path_list_t m_paths;
415 
416  /**
417  * A map of all routes
418  */
419  static singular_db<key_t, ip_route> m_db;
420 };
421 
422 /**
423  * A IP multicast route
424  */
425 class ip_mroute : public object_base
426 {
427 public:
428  /**
429  * The key for a route
430  */
431  typedef std::pair<route::table_id_t, mprefix_t> key_t;
432 
433  /**
434  * Construct a route in the default table
435  */
436  ip_mroute(const mprefix_t& mprefix);
437 
438  /**
439  * Copy Construct
440  */
441  ip_mroute(const ip_mroute& r);
442 
443  /**
444  * Construct a route in the given route domain
445  */
446  ip_mroute(const route_domain& rd, const mprefix_t& mprefix);
447 
448  /**
449  * Destructor
450  */
451  ~ip_mroute();
452 
453  /**
454  * Get the route's key
455  */
456  const key_t key() const;
457 
458  /**
459  * Comparison operator
460  */
461  bool operator==(const ip_mroute& i) const;
462 
463  /**
464  * Return the matching 'singular instance'
465  */
466  std::shared_ptr<ip_mroute> singular() const;
467 
468  /**
469  * Find the instnace of the route domain in the OM
470  */
471  static std::shared_ptr<ip_mroute> find(const ip_mroute& temp);
472 
473  /**
474  * Dump all route-doamin into the stream provided
475  */
476  static void dump(std::ostream& os);
477 
478  /**
479  * replay the object to create it in hardware
480  */
481  void replay(void);
482 
483  /**
484  * Convert to string for debugging
485  */
486  std::string to_string() const;
487 
488  /**
489  * Return the matching 'singular instance'
490  */
491  static std::shared_ptr<ip_mroute> find(const key_t& k);
492 
493  void add(const path& path, const itf_flags_t& flag);
494 
495 private:
496  /**
497  * Class definition for listeners to OM events
498  */
500  {
501  public:
502  event_handler();
503  virtual ~event_handler() = default;
504 
505  /**
506  * Handle a populate event
507  */
508  void handle_populate(const client_db::key_t& key);
509 
510  /**
511  * Handle a replay event
512  */
513  void handle_replay();
514 
515  /**
516  * Show the object in the Singular DB
517  */
518  void show(std::ostream& os);
519 
520  /**
521  * Get the sortable Id of the listener
522  */
523  dependency_t order() const;
524  };
525 
526  /**
527  * event_handler to register with OM
528  */
529  static event_handler m_evh;
530 
531  /**
532  * Find or add the instnace of the route domain in the OM
533  */
534  static std::shared_ptr<ip_mroute> find_or_add(const ip_mroute& temp);
535 
536  /*
537  * It's the OM class that updates the objects in HW
538  */
539  friend class VOM::OM;
540 
541  /**
542  * It's the singular_db class that calls replay()
543  */
544  friend class singular_db<key_t, ip_mroute>;
545 
546  /**
547  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
548  */
549  void update(const ip_mroute& obj);
550 
551  /**
552  * Sweep/reap the object if still stale
553  */
554  void sweep(void);
555 
556  /**
557  * HW configuration for the result of creating the route
558  */
559  HW::item<bool> m_hw;
560 
561  /**
562  * The route domain the route is in.
563  */
564  std::shared_ptr<route_domain> m_rd;
565 
566  /**
567  * The mprefix to match
568  */
569  mprefix_t m_mprefix;
570 
571  /**
572  * The set of paths
573  */
574  mpath_list_t m_paths;
575 
576  /**
577  * A map of all routes
578  */
579  static singular_db<key_t, ip_mroute> m_db;
580 };
581 
582 std::ostream& operator<<(std::ostream& os, const ip_route::key_t& key);
583 std::ostream& operator<<(std::ostream& os, const ip_mroute::key_t& key);
584 }; // namespace route
585 }; // namesapce VPP
586 
587 /*
588  * fd.io coding-style-patch-verification: OFF
589  *
590  * Local Variables:
591  * eval: (c-set-style "mozilla")
592  * End:
593  */
594 
595 #endif
VOM::route::prefix_t
A prefix defintion.
Definition: prefix.hpp:131
VOM::route::ip_mroute::key
const key_t key() const
Get the route's key.
Definition: route.cpp:501
VOM::HW::item< handle_t >
VOM::route::ip_route::~ip_route
~ip_route()
Destructor.
Definition: route.cpp:297
VOM::route::ip_mroute
A IP multicast route.
Definition: route.hpp:425
VOM::route::path::special_t::PROHIBIT
const static special_t PROHIBIT
a path will return ICMP prohibit
Definition: route.hpp:65
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
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::OM
The interface to writing objects into VPP OM.
Definition: om.hpp:140
VOM::route::path_list_t
std::set< path > path_list_t
A path-list is a set of paths.
Definition: route.hpp:231
VOM::route::path::nh
const boost::asio::ip::address & nh() const
Definition: route.cpp:226
VOM::route::path::rd
std::shared_ptr< route_domain > rd() const
Definition: route.cpp:232
VOM::inspect::command_handler
inspect command handler Handler
Definition: inspect.hpp:54
VOM::route::itf_flags_t::FORWARD
const static itf_flags_t FORWARD
A local/for-us/recieve.
Definition: route.hpp:219
VOM::route::ip_route::find
static std::shared_ptr< ip_route > find(const ip_route &temp)
Find the instnace of the route domain in the OM.
VOM::OM::listener
Class definition for listeners to OM events.
Definition: om.hpp:284
VOM::route::path::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: route.cpp:188
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
VOM::route::ip_route::dump
static void dump(std::ostream &os)
Dump all route-doamin into the stream provided.
Definition: route.cpp:386
VOM::route::ip_route::operator==
bool operator==(const ip_route &i) const
Comparison operator.
Definition: route.cpp:313
VOM::route::mprefix_t
A prefix defintion.
Definition: prefix.hpp:252
mprefix
typedef mprefix
Definition: ip_types.api:118
key
typedef key
Definition: ipsec_types.api:91
VOM::route::itf_flags_t::NONE
const static itf_flags_t NONE
Definition: route.hpp:210
VOM::route::ip_mroute::~ip_mroute
~ip_mroute()
Destructor.
Definition: route.cpp:494
VOM::route::ip_route::replay
void replay(void)
replay the object to create it in hardware
Definition: route.cpp:341
VOM::route::path::special_t
Special path types.
Definition: route.hpp:38
VOM::route::ip_route::singular
std::shared_ptr< ip_route > singular() const
Return the matching 'singular instance'.
Definition: route.cpp:380
VOM::route::path::~path
~path()
Destructor.
Definition: route.cpp:163
VOM::route::path::operator==
bool operator==(const path &p) const
comparison operator
Definition: route.cpp:168
VOM::route::ip_mroute::operator==
bool operator==(const ip_mroute &i) const
Comparison operator.
Definition: route.cpp:507
VOM::route::ip_mroute::add
void add(const path &path, const itf_flags_t &flag)
Definition: route.cpp:489
VOM::route::path::preference
uint8_t preference() const
Definition: route.cpp:250
VOM::enum_base
A template base class for all enum types.
Definition: enum_base.hpp:30
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
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::route::path::type
special_t type() const
Getters.
Definition: route.cpp:208
VOM::route::path::operator<
bool operator<(const path &p) const
Less than operator for set insertion.
Definition: route.cpp:129
address
manual_print typedef address
Definition: ip_types.api:96
VOM::route::ip_route::key_t
std::pair< route::table_id_t, prefix_t > key_t
The key for a route.
Definition: route.hpp:253
VOM::route::ip_route::remove
void remove(const path &path)
remove a path.
Definition: route.cpp:325
VOM::route::operator<<
std::ostream & operator<<(std::ostream &os, const ip_route::key_t &key)
Definition: route.cpp:655
VOM::route::path::flags_t::DVR
const static flags_t DVR
A path that resolves via a DVR next-hop.
Definition: route.hpp:88
VOM::route::path::special_t::STANDARD
const static special_t STANDARD
A standard path type.
Definition: route.hpp:45
VOM::route::itf_flags_t::ACCEPT
const static itf_flags_t ACCEPT
Path is accepting multicast traffic.
Definition: route.hpp:214
VOM::route::mpath_list_t
std::set< std::pair< path, itf_flags_t > > mpath_list_t
A mpath-list is a set of paths and interface flags.
Definition: route.hpp:236
VOM::route::path::weight
uint8_t weight() const
Definition: route.cpp:244
VOM::route::path::special_t::LOCAL
const static special_t LOCAL
A local/for-us/recieve.
Definition: route.hpp:50
VOM::route::ip_mroute::find
static std::shared_ptr< ip_mroute > find(const ip_mroute &temp)
Find the instnace of the route domain in the OM.
VOM::route::ip_route::ip_route
ip_route(const prefix_t &prefix)
Construct a route in the default table.
Definition: route.cpp:263
VOM::route::path::special_t::DROP
const static special_t DROP
drop path
Definition: route.hpp:55
VOM::route::ip_mroute::to_string
std::string to_string() const
Convert to string for debugging.
Definition: route.cpp:533
VOM::route::ip_route::to_string
std::string to_string() const
Convert to string for debugging.
Definition: route.cpp:349
singular_db.hpp
prefix.hpp
VOM::nh_proto_t
Types belonging to Routing.
Definition: prefix.hpp:31
VOM::route::ip_mroute::ip_mroute
ip_mroute(const mprefix_t &mprefix)
Construct a route in the default table.
Definition: route.cpp:464
VOM::route::ip_route::add
void add(const path &path)
Add a path.
Definition: route.cpp:319
interface.hpp
VOM::route::itf_flags_t
Definition: route.hpp:207
VOM::route::path::special_t::UNREACH
const static special_t UNREACH
a path will return ICMP unreachables
Definition: route.hpp:60
VOM::route::path::nh_proto
nh_proto_t nh_proto() const
Definition: route.cpp:214
VOM::route_domain
A route-domain is a VRF.
Definition: route_domain.hpp:31
VOM::singular_db
A Database to store the unique 'singular' instances of a single object type.
Definition: singular_db.hpp:33
VOM::route::path::path
path(special_t special, const nh_proto_t &proto=nh_proto_t::IPV4)
constructor for special paths
Definition: route.cpp:58
VOM::route::path
A path for IP or MPLS routes.
Definition: route.hpp:32
route_domain.hpp
i
int i
Definition: flowhash_template.h:376
VOM::route::path::itf
std::shared_ptr< interface > itf() const
Definition: route.cpp:238
VOM::route::path::flags_t::NONE
const static flags_t NONE
No flags.
Definition: route.hpp:83
VOM::nh_proto_t::IPV4
const static nh_proto_t IPV4
Definition: prefix.hpp:34
VOM::route::path::flags
flags_t flags() const
Definition: route.cpp:220
show
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
event_handler
void event_handler(void *tls_async)
Definition: tls_async.c:334
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
VOM::route::ip_route::key
const key_t key() const
Get the route's key.
Definition: route.cpp:307
VOM::route::ip_mroute::replay
void replay(void)
replay the object to create it in hardware
Definition: route.cpp:524
VOM::route::path::flags_t
Path flags.
Definition: route.hpp:77
VOM::object_base
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
VOM::route::ip_mroute::key_t
std::pair< route::table_id_t, mprefix_t > key_t
The key for a route.
Definition: route.hpp:431
prefix
vl_api_prefix_t prefix
Definition: ip.api:175
VOM::route::ip_mroute::singular
std::shared_ptr< ip_mroute > singular() const
Return the matching 'singular instance'.
Definition: route.cpp:566
VOM::route::ip_route
A IP route.
Definition: route.hpp:247
VOM::route::ip_mroute::dump
static void dump(std::ostream &os)
Dump all route-doamin into the stream provided.
Definition: route.cpp:572
string
const char *const string
Definition: cJSON.h:172