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)
41 , m_interface(nullptr)
55 , m_interface(interface.singular())
57 , m_preference(preference)
62 const boost::asio::ip::address&
nh,
69 , m_interface(nullptr)
71 , m_preference(preference)
83 , m_interface(interface.singular())
85 , m_preference(preference)
91 , m_nh_proto(p.m_nh_proto)
94 , m_interface(p.m_interface)
95 , m_weight(p.m_weight)
96 , m_preference(p.m_preference)
103 if (m_type < p.m_type)
109 if (m_rd->table_id() < p.m_rd->table_id())
113 if (m_interface && !p.m_interface)
115 if (!m_interface && p.m_interface)
117 if (m_interface->handle() < p.m_interface->handle())
136 result &= (*m_rd == *p.m_rd);
137 if (m_interface && !p.m_interface)
139 if (!m_interface && p.m_interface)
141 if (m_interface && p.m_interface)
142 result &= (*m_interface == *p.m_interface);
143 return (result && (m_type == p.m_type) && (m_nh == p.m_nh));
149 std::ostringstream s;
153 <<
" neighbour:" << m_nh.to_string();
155 s <<
" " << m_rd->to_string();
158 s <<
" " << m_interface->to_string();
160 s <<
" weight:" <<
static_cast<int>(m_weight)
161 <<
" preference:" << static_cast<int>(m_preference) <<
"]";
178 const boost::asio::ip::address&
184 std::shared_ptr<route_domain>
190 std::shared_ptr<interface>
227 , m_prefix(r.m_prefix)
255 m_db.release(
key(),
this);
262 return (std::make_pair(m_rd->table_id(), m_prefix));
268 return ((
key() == i.
key()) && (m_paths == i.m_paths));
274 m_paths.insert(path);
304 std::ostringstream s;
305 s <<
"route:[" << m_rd->to_string() <<
", " << m_prefix.
to_string() <<
" [" 324 std::shared_ptr<ip_route>
325 ip_route::find_or_add(
const ip_route& temp)
327 return (m_db.find_or_add(temp.
key(), temp));
330 std::shared_ptr<ip_route>
333 return (m_db.find(k));
336 std::shared_ptr<ip_route>
339 return find_or_add(*
this);
348 ip_route::event_handler::event_handler()
355 ip_route::event_handler::handle_replay()
363 std::shared_ptr<ip_route_cmds::dump_v4_cmd> cmd_v4 =
364 std::make_shared<ip_route_cmds::dump_v4_cmd>();
365 std::shared_ptr<ip_route_cmds::dump_v6_cmd> cmd_v6 =
366 std::make_shared<ip_route_cmds::dump_v6_cmd>();
372 for (
auto& record : *cmd_v4) {
373 auto& payload = record.get_payload();
375 prefix_t pfx(0, payload.address, payload.address_length);
387 for (
unsigned int i = 0;
i < payload.count;
i++) {
388 vapi_type_fib_path p = payload.path[
i];
392 }
else if (p.is_drop) {
395 }
else if (p.is_unreach) {
398 }
else if (p.is_prohibit) {
403 boost::asio::ip::address address =
from_bytes(0, p.next_hop);
404 path path_v4(address, *itf, p.weight, p.preference);
418 for (
auto& record : *cmd_v6) {
419 auto& payload = record.get_payload();
421 prefix_t pfx(1, payload.address, payload.address_length);
429 for (
unsigned int i = 0;
i < payload.count;
i++) {
430 vapi_type_fib_path p = payload.path[
i];
434 }
else if (p.is_drop) {
437 }
else if (p.is_unreach) {
440 }
else if (p.is_prohibit) {
445 boost::asio::ip::address address =
from_bytes(1, p.next_hop);
446 path path_v6(address, *itf, p.weight, p.preference);
462 ip_route::event_handler::order()
const 476 os <<
"[" << key.first <<
", " << key.second.to_string() <<
"]";
486 os << k.to_string() <<
" ";
void remove(const path &path)
remove a path.
nh_proto_t nh_proto() const
sll srl srl sll sra u16x4 i
static const special_t STANDARD
A standard path type.
A command class that creates or updates the route.
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.
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 std::shared_ptr< route_domain > find(const route_domain &temp)
Find the instnace of the route domain in the OM.
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)
A next-hop protocol describes the protocol of a peer to which packets are sent after matching a route...
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.
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
Then L2/objects that bind to interfaces, BD, ACLS, etc.
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.