27 singular_db<ip_route::key_t, ip_route> ip_route::m_db;
28 singular_db<ip_mroute::key_t, ip_mroute> ip_mroute::m_db;
36 path::special_t::special_t(
int v,
const std::string& s)
37 : enum_base<path::special_t>(v, s)
41 const path::flags_t path::flags_t::NONE(0,
"none");
42 const path::flags_t path::flags_t::DVR((1 << 0),
"dvr");
44 path::flags_t::flags_t(
int v,
const std::string& s)
45 : enum_base<path::flags_t>(v, s)
49 const itf_flags_t itf_flags_t::NONE(0,
"none");
50 const itf_flags_t itf_flags_t::ACCEPT((1 << 2),
"accept");
51 const itf_flags_t itf_flags_t::FORWARD((1 << 3),
"forward");
53 itf_flags_t::itf_flags_t(
int v,
const std::string& s)
54 : enum_base<itf_flags_t>(v, s)
60 if (itf_flags_t::ACCEPT == (
int)val)
61 return itf_flags_t::ACCEPT;
63 return itf_flags_t::FORWARD;
72 , m_interface(nullptr)
87 , m_interface(interface.singular())
89 , m_preference(preference)
101 , m_rd(rd.singular())
102 , m_interface(nullptr)
104 , m_preference(preference)
118 , m_interface(interface.singular())
120 , m_preference(preference)
126 , m_nh_proto(p.m_nh_proto)
130 , m_interface(p.m_interface)
131 , m_weight(p.m_weight)
132 , m_preference(p.m_preference)
139 if (m_nh_proto < p.m_nh_proto)
141 if (m_flags < p.m_flags)
143 if (m_type < p.m_type)
149 if (m_rd && p.m_rd) {
150 if (m_rd->table_id() < p.m_rd->table_id())
152 else if (m_rd->table_id() > p.m_rd->table_id())
157 if (m_interface && !p.m_interface)
159 if (!m_interface && p.m_interface)
161 if (m_interface && p.m_interface) {
162 if (m_interface->handle() < p.m_interface->handle())
164 if (p.m_interface->handle() < m_interface->handle())
184 result &= (*m_rd == *p.m_rd);
185 if (m_interface && !p.m_interface)
187 if (!m_interface && p.m_interface)
189 if (m_interface && p.m_interface)
190 result &= (*m_interface == *p.m_interface);
191 return (result && (m_type == p.m_type) && (m_nh == p.m_nh) &&
192 (m_nh_proto == p.m_nh_proto) && (m_flags == p.m_flags));
198 std::ostringstream s;
202 <<
" flags:" << m_flags.
to_string() <<
" neighbour:" << m_nh.to_string();
204 s <<
" " << m_rd->to_string();
207 s <<
" " << m_interface->to_string();
209 s <<
" weight:" <<
static_cast<int>(m_weight)
210 <<
" preference:" << static_cast<int>(m_preference) <<
"]";
239 std::shared_ptr<route_domain>
245 std::shared_ptr<interface>
282 , m_prefix(r.m_prefix)
310 m_db.release(
key(),
this);
317 return (std::make_pair(m_rd->table_id(), m_prefix));
323 return ((
key() == i.
key()) && (m_paths == i.m_paths));
329 m_paths.insert(path);
342 for (
auto& p : m_paths)
353 for (
auto& p : m_paths)
361 std::ostringstream s;
362 s <<
"route:[" << m_rd->to_string() <<
", " << m_prefix.
to_string() <<
" [" 378 for (
auto& p : m_paths)
387 set_difference(r.m_paths.begin(), r.m_paths.end(), m_paths.begin(),
388 m_paths.end(), std::inserter(to_add, to_add.begin()));
390 for (
auto& p : to_add)
395 set_difference(m_paths.begin(), m_paths.end(), r.m_paths.begin(),
396 r.m_paths.end(), std::inserter(to_del, to_del.begin()));
398 for (
auto& p : to_del)
406 std::shared_ptr<ip_route>
407 ip_route::find_or_add(
const ip_route& temp)
409 return (m_db.find_or_add(temp.
key(), temp));
412 std::shared_ptr<ip_route>
415 return (m_db.find(k));
418 std::shared_ptr<ip_route>
421 return find_or_add(*
this);
437 ip_route::event_handler::handle_replay()
445 std::shared_ptr<ip_route_cmds::dump_v4_cmd> cmd_v4 =
446 std::make_shared<ip_route_cmds::dump_v4_cmd>();
447 std::shared_ptr<ip_route_cmds::dump_v6_cmd> cmd_v6 =
448 std::make_shared<ip_route_cmds::dump_v6_cmd>();
454 for (
auto& record : *cmd_v4) {
455 auto& payload = record.get_payload();
457 prefix_t pfx(0, payload.address, payload.address_length);
469 for (
unsigned int i = 0;
i < payload.count;
i++) {
482 for (
auto& record : *cmd_v6) {
483 auto& payload = record.get_payload();
485 prefix_t pfx(1, payload.address, payload.address_length);
493 for (
unsigned int i = 0;
i < payload.count;
i++) {
508 ip_route::event_handler::order()
const 530 , m_mprefix(r.m_mprefix)
546 m_paths.insert(std::make_pair(path, flag));
552 m_db.release(
key(),
this);
558 return (std::make_pair(m_rd->table_id(), m_mprefix));
564 return ((
key() == i.
key()) && (m_paths == i.m_paths));
571 for (
auto& p : m_paths)
573 m_mprefix, p.first, p.second));
582 for (
auto& p : m_paths)
584 m_mprefix, p.first, p.second));
590 std::ostringstream s;
591 s <<
"route:[" << m_rd->to_string() <<
", " << m_mprefix.
to_string() <<
" [" 602 for (
auto& p : m_paths)
604 m_mprefix, p.first, p.second));
608 std::shared_ptr<ip_mroute>
609 ip_mroute::find_or_add(
const ip_mroute& temp)
611 return (m_db.find_or_add(temp.
key(), temp));
614 std::shared_ptr<ip_mroute>
617 return (m_db.find(k));
620 std::shared_ptr<ip_mroute>
623 return find_or_add(*
this);
636 "ip multicast route configurations",
this);
640 ip_mroute::event_handler::handle_replay()
648 std::shared_ptr<ip_mroute_cmds::dump_v4_cmd> cmd_v4 =
649 std::make_shared<ip_mroute_cmds::dump_v4_cmd>();
650 std::shared_ptr<ip_mroute_cmds::dump_v6_cmd> cmd_v6 =
651 std::make_shared<ip_mroute_cmds::dump_v6_cmd>();
659 for (
auto& record : *cmd_v4) {
660 auto& payload = record.get_payload();
664 mprefix_t pfx(saddr, gaddr, payload.address_length);
676 for (
unsigned int i = 0;
i < payload.count;
i++) {
677 vapi_type_mfib_path& p = payload.path[
i];
691 for (
auto& record : *cmd_v6) {
692 auto& payload = record.get_payload();
696 mprefix_t pfx(saddr, gaddr, payload.address_length);
705 for (
unsigned int i = 0;
i < payload.count;
i++) {
706 vapi_type_mfib_path& p = payload.path[
i];
722 ip_mroute::event_handler::order()
const 736 os <<
"[" << key.first <<
", " << key.second.to_string() <<
"]";
744 os <<
"[" << key.first <<
", " << key.second.to_string() <<
"]";
754 os << k.to_string() <<
" ";
766 os <<
"[" << k.first.to_string() <<
", " << k.second.to_string() <<
"]";
void remove(const path &path)
remove a path.
std::pair< route::table_id_t, mprefix_t > key_t
The key for a route.
nh_proto_t nh_proto() const
static std::shared_ptr< route_domain > find(const key_t &temp)
Find the instnace of the route domain in the OM.
boost::asio::ip::address ip_address_t
A cmd class that deletes a route.
static const special_t STANDARD
A standard path type.
A command class that creates or updates the route.
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.
static const nh_proto_t IPV6
static const nh_proto_t IPV4
A path for IP or MPLS routes.
route::path from_vpp(const vapi_type_fib_path &p, const nh_proto_t &nhp)
static void register_handler(const std::vector< std::string > &cmds, const std::string &help, command_handler *ch)
Register a command handler for inspection.
ip_route(const prefix_t &prefix)
Construct a route in the default table.
std::string to_string() const
convert to string format for debug purposes
static rc_t write()
Write/Execute all commands hitherto enqueued.
static const log_level_t DEBUG
std::shared_ptr< interface > itf() const
void add(const path &path)
Add a path.
static const special_t LOCAL
A local/for-us/recieve.
static const special_t DROP
drop path
const key_t key() const
Get the route's key.
std::ostream & operator<<(std::ostream &os, const ip_route::key_t &key)
Types belonging to Routing.
void add(const path &path, const itf_flags_t &flag)
rc_t rc() const
Get the HW return code.
std::string to_string() const
convert to string format for debug purposes
std::string to_string() const
Convert to string for debugging.
static const special_t UNREACH
a path will return ICMP unreachables
std::shared_ptr< route_domain > rd() const
A command class that creates or updates the route.
std::shared_ptr< ip_route > singular() const
Return the matching 'singular instance'.
path(special_t special)
constructor for special paths
bool operator==(const ip_mroute &i) const
Comparison operator.
static const special_t PROHIBIT
a path will return ICMP prohibit
std::string to_string() const
Convert to string for debugging.
static const log_level_t INFO
std::set< path > path_list_t
A path-list is a set of paths.
A representation of an interface in VPP.
std::set< std::pair< path, itf_flags_t > > mpath_list_t
A mpath-list is a set of paths and interface flags.
const key_t key() const
Get the route's key.
std::string to_string() const
convert to string format for debug purposes
static const itf_flags_t & from_vpp(uint32_t val)
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.
void event_handler(void *tls_async)
static std::shared_ptr< ip_mroute > find(const ip_mroute &temp)
Find the instnace of the route domain in the OM.
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
uint8_t preference() const
ip_mroute(const mprefix_t &mprefix)
Construct a route in the default table.
static const rc_t OK
The HW write was successfull.
static void enqueue(cmd *f)
Enqueue A command for execution.
A cmd class that deletes a route.
boost::asio::ip::address from_bytes(uint8_t is_ip6, const uint8_t *bytes)
Convert a VPP byte stinrg into a boost addresss.
const boost::asio::ip::address & nh() const
bool operator==(const ip_route &i) const
Comparison operator.
static std::shared_ptr< ip_route > find(const ip_route &temp)
Find the instnace of the route domain in the OM.
The VPP Object Model (VOM) library.
void replay(void)
replay the object to create it in hardware
bool operator<(const path &p) const
Less than operator for set insertion.
static void dump(std::ostream &os)
Dump all route-doamin into the stream provided.
bool operator==(const path &p) const
comparison operator
special_t type() const
Getters.
void replay(void)
replay the object to create it in hardware
const std::string & to_string() const
convert to string format for debug purposes
std::shared_ptr< ip_mroute > singular() const
Return the matching 'singular instance'.
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.
std::pair< route::table_id_t, prefix_t > key_t
The key for a route.