22 ip_route::event_handler ip_route::m_evh;
23 singular_db<ip_route::key_t, ip_route> ip_route::m_db;
31 path::special_t::special_t(
int v,
const std::string& s)
32 : enum_base<path::special_t>(v, s)
36 const path::flags_t path::flags_t::NONE(0,
"none");
37 const path::flags_t path::flags_t::DVR((1 << 0),
"dvr");
39 path::flags_t::flags_t(
int v,
const std::string& s)
40 : enum_base<path::flags_t>(v, s)
50 , m_interface(nullptr)
65 , m_interface(interface.singular())
67 , m_preference(preference)
72 const boost::asio::ip::address&
nh,
80 , m_interface(nullptr)
82 , m_preference(preference)
96 , m_interface(interface.singular())
98 , m_preference(preference)
104 , m_nh_proto(p.m_nh_proto)
108 , m_interface(p.m_interface)
109 , m_weight(p.m_weight)
110 , m_preference(p.m_preference)
117 if (m_nh_proto < p.m_nh_proto)
119 if (m_flags < p.m_flags)
121 if (m_type < p.m_type)
127 if (m_rd->table_id() < p.m_rd->table_id())
131 if (m_interface && !p.m_interface)
133 if (!m_interface && p.m_interface)
135 if (m_interface->handle() < p.m_interface->handle())
154 result &= (*m_rd == *p.m_rd);
155 if (m_interface && !p.m_interface)
157 if (!m_interface && p.m_interface)
159 if (m_interface && p.m_interface)
160 result &= (*m_interface == *p.m_interface);
161 return (result && (m_type == p.m_type) && (m_nh == p.m_nh) &&
162 (m_nh_proto == p.m_nh_proto) && (m_flags == p.m_flags));
168 std::ostringstream s;
172 <<
" flags:" << m_flags.
to_string() <<
" neighbour:" << m_nh.to_string();
174 s <<
" " << m_rd->to_string();
177 s <<
" " << m_interface->to_string();
179 s <<
" weight:" <<
static_cast<int>(m_weight)
180 <<
" preference:" << static_cast<int>(m_preference) <<
"]";
203 const boost::asio::ip::address&
209 std::shared_ptr<route_domain>
215 std::shared_ptr<interface>
252 , m_prefix(r.m_prefix)
280 m_db.release(
key(),
this);
287 return (std::make_pair(m_rd->table_id(), m_prefix));
293 return ((
key() == i.
key()) && (m_paths == i.m_paths));
299 m_paths.insert(path);
329 std::ostringstream s;
330 s <<
"route:[" << m_rd->to_string() <<
", " << m_prefix.
to_string() <<
" [" 349 std::shared_ptr<ip_route>
350 ip_route::find_or_add(
const ip_route& temp)
352 return (m_db.find_or_add(temp.
key(), temp));
355 std::shared_ptr<ip_route>
358 return (m_db.find(k));
361 std::shared_ptr<ip_route>
364 return find_or_add(*
this);
373 ip_route::event_handler::event_handler()
380 ip_route::event_handler::handle_replay()
388 std::shared_ptr<ip_route_cmds::dump_v4_cmd> cmd_v4 =
389 std::make_shared<ip_route_cmds::dump_v4_cmd>();
390 std::shared_ptr<ip_route_cmds::dump_v6_cmd> cmd_v6 =
391 std::make_shared<ip_route_cmds::dump_v6_cmd>();
397 for (
auto& record : *cmd_v4) {
398 auto& payload = record.get_payload();
400 prefix_t pfx(0, payload.address, payload.address_length);
412 for (
unsigned int i = 0;
i < payload.count;
i++) {
413 vapi_type_fib_path p = payload.path[
i];
417 }
else if (p.is_drop) {
420 }
else if (p.is_unreach) {
423 }
else if (p.is_prohibit) {
427 boost::asio::ip::address address =
from_bytes(0, p.next_hop);
432 p.weight, p.preference);
435 path path_v4(address, *itf, p.weight, p.preference);
439 path path_v4(rd_temp, address, p.weight, p.preference);
454 for (
auto& record : *cmd_v6) {
455 auto& payload = record.get_payload();
457 prefix_t pfx(1, payload.address, payload.address_length);
465 for (
unsigned int i = 0;
i < payload.count;
i++) {
466 vapi_type_fib_path p = payload.path[
i];
470 }
else if (p.is_drop) {
473 }
else if (p.is_unreach) {
476 }
else if (p.is_prohibit) {
481 boost::asio::ip::address address =
from_bytes(1, p.next_hop);
485 p.weight, p.preference);
488 path path_v6(address, *itf, p.weight, p.preference);
492 path path_v6(rd_temp, address, p.weight, p.preference);
509 ip_route::event_handler::order()
const 523 os <<
"[" << key.first <<
", " << key.second.to_string() <<
"]";
533 os << k.to_string() <<
" ";
void remove(const path &path)
remove a path.
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.
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 std::shared_ptr< interface > find(const handle_t &h)
The the singular instance of the interface in the DB by handle.
static const nh_proto_t IPV6
static const nh_proto_t IPV4
A path for IP or MPLS routes.
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.
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
std::shared_ptr< ip_route > singular() const
Return the matching 'singular instance'.
path(special_t special)
constructor for special paths
static const special_t PROHIBIT
a path will return ICMP prohibit
std::set< path > path_list_t
A path-list is a set of paths.
A representation of an interface in VPP.
static const flags_t DVR
A path that resolves via a DVR next-hop.
boost::asio::ip::address from_bytes(uint8_t is_ip6, uint8_t *bytes)
Convert a VPP byte stinrg into a boost addresss.
static rc_t commit(const client_db::key_t &key, const OBJ &obj)
Make the State in VPP reflect the expressed desired state.
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
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.
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.
const std::string & to_string() const
convert to string format for debug purposes
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.