38 std::map<handle_t, std::weak_ptr<interface>> interface::m_hdl_db;
45 std::shared_ptr<interface_cmds::events_cmd> interface::m_events_cmd;
53 const std::string& tag)
72 const std::string& tag)
78 , m_table_id(m_rd->table_id())
94 , m_table_id(o.m_table_id)
95 , m_l2_address(o.m_l2_address)
96 , m_stats_type(o.m_stats_type)
98 , m_listener(o.m_listener)
107 return ((
key() == i.
key()) &&
108 (m_l2_address.
data() == i.m_l2_address.
data()) &&
109 (m_state == i.m_state) && (m_rd == i.m_rd) && (m_type == i.m_type) &&
110 (m_oper == i.m_oper));
114 : m_status(
rc_t::NOOP)
151 interface::handle_i()
const 159 return (m_l2_address.data());
196 std::queue<cmd*> cmds;
206 std::queue<cmd*> cmds;
236 m_db.release(m_name,
this);
242 std::ostringstream s;
243 s <<
"interface:[" << m_name <<
" type:" << m_type.to_string()
245 << m_l2_address.to_string() <<
"]";
248 s <<
" rd:" << m_rd->to_string();
251 s <<
" admin-state:" << m_state.to_string()
252 <<
" oper-state:" << m_oper.to_string();
254 if (!m_tag.empty()) {
255 s <<
" tag:[" << m_tag <<
"]";
322 interface::update(
const interface& desired)
328 std::queue<cmd*> cmds;
345 if (m_state.update(desired.m_state)) {
352 if (m_l2_address.update(desired.m_l2_address)) {
360 if (m_rd != desired.m_rd) {
368 if (it->second.lock()->itf().key() ==
key())
369 it->second.lock()->sweep();
382 if (it->second.lock()->itf().key() ==
key())
383 it->second.lock()->replay();
386 }
else if (!m_table_id && m_rd) {
427 if (
"rx" == stat_type)
428 m_stats.m_rx =
count;
429 else if (
"tx" == stat_type)
430 m_stats.m_tx =
count;
431 else if (
"drops" == stat_type)
432 m_stats.m_drop =
count;
433 else if (
"rx-unicast" == stat_type)
434 m_stats.m_rx_unicast =
count;
435 else if (
"tx-unicast" == stat_type)
436 m_stats.m_tx_unicast =
count;
437 else if (
"rx-multicast" == stat_type)
438 m_stats.m_rx_multicast =
count;
439 else if (
"tx-multicast" == stat_type)
440 m_stats.m_tx_multicast =
count;
441 else if (
"rx-broadcast" == stat_type)
442 m_stats.m_rx_broadcast =
count;
443 else if (
"tx-broadcast" == stat_type)
444 m_stats.m_rx_broadcast =
count;
454 interface::publish_stats()
456 m_listener->handle_interface_stat(*
this);
480 m_stats_type, handle_i(),
true));
482 stat_reader::registers(*
this);
494 interface::disable_stats_i()
496 if (m_listener !=
NULL) {
499 m_stats_type, handle_i(),
false));
501 stat_reader::unregisters(*
this);
512 std::shared_ptr<interface>
515 return (
m_db.find_or_add(
key(), *
this));
518 std::shared_ptr<interface>
524 std::shared_ptr<interface>
527 return (
m_db.find(k));
530 std::shared_ptr<interface>
533 return (m_hdl_db[handle].lock());
539 std::shared_ptr<interface> sp =
find(key);
542 m_hdl_db[item.
data()] = sp;
549 m_hdl_db.erase(item.
data());
561 m_events_cmd = std::make_shared<interface_cmds::events_cmd>(el);
569 m_events_cmd.reset();
578 std::shared_ptr<interface_cmds::vhost_dump_cmd> vcmd =
579 std::make_shared<interface_cmds::vhost_dump_cmd>();
584 for (
auto& vhost_itf_record : *vcmd) {
585 std::shared_ptr<interface> vitf =
587 vhost_itf_record.get_payload());
595 std::shared_ptr<interface_cmds::af_packet_dump_cmd> afcmd =
596 std::make_shared<interface_cmds::af_packet_dump_cmd>();
601 for (
auto& af_packet_itf_record : *afcmd) {
602 std::shared_ptr<interface> afitf =
604 af_packet_itf_record.get_payload());
612 std::shared_ptr<tap_interface_cmds::tapv2_dump_cmd> tapv2cmd =
613 std::make_shared<tap_interface_cmds::tapv2_dump_cmd>();
618 for (
auto& tapv2_record : *tapv2cmd) {
619 std::shared_ptr<tap_interface> tapv2itf =
634 std::shared_ptr<interface_cmds::dump_cmd>
cmd =
635 std::make_shared<interface_cmds::dump_cmd>();
640 for (
auto& itf_record : *cmd) {
641 auto payload = itf_record.get_payload();
643 <<
" name:" << (
char*)payload.interface_name
644 <<
" tag:" << (
char*)payload.tag <<
"]";
660 std::shared_ptr<l3_binding_cmds::dump_v4_cmd> dcmd =
661 std::make_shared<l3_binding_cmds::dump_v4_cmd>(
667 for (
auto& l3_record : *dcmd) {
668 auto& payload = l3_record.get_payload();
670 payload.prefix_length);
683 std::shared_ptr<bond_interface_cmds::dump_cmd> bcmd =
684 std::make_shared<bond_interface_cmds::dump_cmd>();
689 for (
auto& bond_itf_record : *bcmd) {
690 std::shared_ptr<bond_interface> bond_itf =
702 std::shared_ptr<bond_group_binding_cmds::dump_cmd> scmd =
703 std::make_shared<bond_group_binding_cmds::dump_cmd>(
711 for (
auto& slave_itf_record : *scmd) {
713 slave_itf_record.get_payload());
723 enslaved_itfs.insert(slave_itf);
726 if (!enslaved_itfs.empty()) {
745 interface::event_handler::handle_replay()
751 interface::event_handler::order()
const
static const rc_t NOOP
The HW write/update action was/has not been attempted.
void release()
release/remove an interface form the singular store
virtual ~interface()
Destructor.
static void dump(std::ostream &os)
Dump all interfaces into the stream provided.
void disable_stats()
Disable stats for this interface.
interface(const std::string &name, type_t type, admin_state_t state, const std::string &tag="")
Construct a new object matching the desried state.
static void disable_events()
disable the reception of events of all interfaces
static const type_t AFPACKET
AF-Packet interface type.
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
std::string to_string() const
convert to string format for debug purposes
virtual bool operator==(const interface &i) const
Comparison operator - only used for UT.
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.
HW::item< handle_t > m_hdl
The SW interface handle VPP has asigned to the interface.
const handle_t & handle() const
Return VPP's handle to this object.
virtual void sweep(void)
Sweep/reap the object if still stale.
static void register_handler(const std::vector< std::string > &cmds, const std::string &help, command_handler *ch)
Register a command handler for inspection.
void enable_stats(stat_listener *el, const stats_type_t &st=stats_type_t::NORMAL)
Enable stats for this interface.
virtual std::queue< cmd * > & mk_create_cmd(std::queue< cmd *> &cmds)
Virtual functions to construct an interface create commands.
void set(const admin_state_t &state)
Set the admin state of the interface.
static rc_t write()
Write/Execute all commands hitherto enqueued.
rc_t rc() const
Get the HW return code.
HW::item< bool > & status()
Return the HW::item representing the status.
A command class to set tag on interfaces.
Error codes that VPP will return during a HW write.
static const log_level_t DEBUG
virtual std::string to_string(void) const
convert to string format for debug purposes
static const_iterator_t cbegin()
static const stats_type_t DETAILED
A representation of bond interface binding.
A cmd class that Dumps slave itfs.
const stats_t & get_stats(void) const
Get the interface stats.
const l2_address_t & l2_address() const
Return the L2 Address.
A command class that enables detailed stats collection on an interface.
The oper state of the interface.
Type def of a L2 address as read from VPP.
T & data()
Return the data read/written.
std::string to_string() const
convert to string format for debug purposes
static const_iterator_t cbegin()
static singular_db< key_t, interface > m_db
A map of all interfaces key against the interface's name.
static std::shared_ptr< interface > new_af_packet_interface(const vapi_payload_af_packet_details &vd)
static const type_t LOCAL
Local interface type (specific to VPP)
virtual std::queue< cmd * > & mk_delete_cmd(std::queue< cmd *> &cmds)
Virtual functions to construct an interface delete commands.
const std::string & name() const
Return the interface type.
vhost_vring_state_t state
A command class that changes the MAC address on an interface.
static const l3_proto_t IPV4
static const_iterator_t cend()
static const l3_proto_t IPV6
HW::item< bool > m_status
The status of the subscription.
static const table_id_t DEFAULT_TABLE
The table-id for the default table.
static void remove(const HW::item< handle_t > &item)
remove an interface from the DB keyed on handle
static const oper_state_t DOWN
Operational DOWN state.
event_listener()
Default Constructor.
virtual std::shared_ptr< interface > singular_i() const
Return the matching 'singular' of the interface.
A class that listens to interface Stats.
stat_listener()
Default Constructor.
std::string to_string(void) const
convert to string
static std::shared_ptr< interface > new_interface(const vapi_payload_sw_interface_details &vd)
Factory method to construct a new interface from the VPP record.
A class that listens to interface Events.
A command class to create Loopback interfaces in VPP.
static std::shared_ptr< interface > new_vhost_user_interface(const vapi_payload_sw_interface_vhost_user_details &vd)
A command class to create bvi interfaces in VPP.
A cmd class that changes the admin state.
static void add(const key_t &name, const HW::item< handle_t > &item)
Add an interface to the DB keyed on handle.
std::set< bond_member > enslaved_itf_t
The container type for enslaved itfs.
A command class that binds an interface to an L3 table.
static bond_member new_bond_member_interface(const vapi_payload_sw_interface_slave_details &vd)
The admin state of the interface.
static std::shared_ptr< tap_interface > new_tap_interface(const vapi_payload_sw_interface_tap_v2_details &vd)
A representation of an interface in VPP.
HW::item< bool > & status()
Return the HW::item representing the status.
A command class to create af_packet interfaces in VPP.
A type declaration of an interface handle in VPP.
A functor class that deletes a Vhost interface.
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)
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
static const rc_t OK
The HW write was successfull.
std::shared_ptr< interface > singular() const
Return the matching'singular' of the interface.
static void enqueue(cmd *f)
Enqueue A command for execution.
A cmd class that Dumps all the IPv4 L3 configs.
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
A command class to delete bvi interfaces in VPP.
A command class to delete af-packet interfaces in VPP.
The VPP Object Model (VOM) library.
A command class to delete loopback interfaces in VPP.
static const admin_state_t UP
Admin UP state.
A representation of a method call to VPP.
void set(const rc_t &rc)
Set the HW return code - should only be called from the family of Command objects.
static const type_t BVI
A brideged Virtual interface (aka SVI or IRB)
const type_t & type() const
Return the interface type.
HW::item< bool > m_status
The status of the subscription.
A functor class that creates an interface.
static const admin_state_t DOWN
Admin DOWN state.
A representation of L3 configuration on an interface.
static const_iterator_t cend()
singular_db< const std::string, interface >::const_iterator const_iterator_t
The iterator type.
static const type_t TAPV2
TAPv2 interface type.
const key_t & key() const
Return the interface type.
static const type_t LOOPBACK
loopback interface type
std::string key_t
The key for interface's key.
static const type_t VHOST
vhost-user interface type
static bool register_listener(listener *listener)
Register a listener of events.
static void enable_events(interface::event_listener &el)
Enable the reception of events of all interfaces.
static std::shared_ptr< bond_interface > new_bond_interface(const vapi_payload_sw_interface_bond_details &vd)
interfaces are the root of the dependency graph