X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvpp-api%2Fvom%2Fneighbour.cpp;h=44e2760a1ecd51c0e0d25333b6b4050003d5d296;hb=756cd9441752fc8f84104c9ee19099506ba89f85;hp=c4dcf1f81dff4f5eb5771d1723b6c62dff82cc81;hpb=812ed39f9da336310e815c361ab5a9f118657d94;p=vpp.git diff --git a/src/vpp-api/vom/neighbour.cpp b/src/vpp-api/vom/neighbour.cpp index c4dcf1f81df..44e2760a1ec 100644 --- a/src/vpp-api/vom/neighbour.cpp +++ b/src/vpp-api/vom/neighbour.cpp @@ -14,26 +14,28 @@ */ #include "vom/neighbour.hpp" +#include "vom/neighbour_cmds.hpp" +#include "vom/singular_db_funcs.hpp" namespace VOM { singular_db neighbour::m_db; neighbour::event_handler neighbour::m_evh; neighbour::neighbour(const interface& itf, - const mac_address_t& mac, - const boost::asio::ip::address& ip_addr) + const boost::asio::ip::address& ip_addr, + const mac_address_t& mac) : m_hw(false) , m_itf(itf.singular()) - , m_mac(mac) , m_ip_addr(ip_addr) + , m_mac(mac) { } neighbour::neighbour(const neighbour& bde) : m_hw(bde.m_hw) , m_itf(bde.m_itf) - , m_mac(bde.m_mac) , m_ip_addr(bde.m_ip_addr) + , m_mac(bde.m_mac) { } @@ -42,14 +44,27 @@ neighbour::~neighbour() sweep(); // not in the DB anymore. - m_db.release(std::make_tuple(m_itf->key(), m_mac, m_ip_addr), this); + m_db.release(key(), this); +} + +bool +neighbour::operator==(const neighbour& n) const +{ + return ((key() == n.key()) && (m_mac == n.m_mac)); +} + +const neighbour::key_t +neighbour::key() const +{ + return (std::make_pair(m_itf->key(), m_ip_addr)); } void neighbour::sweep() { if (m_hw) { - HW::enqueue(new delete_cmd(m_hw, m_itf->handle(), m_mac, m_ip_addr)); + HW::enqueue( + new neighbour_cmds::delete_cmd(m_hw, m_itf->handle(), m_mac, m_ip_addr)); } HW::write(); } @@ -58,7 +73,8 @@ void neighbour::replay() { if (m_hw) { - HW::enqueue(new create_cmd(m_hw, m_itf->handle(), m_mac, m_ip_addr)); + HW::enqueue( + new neighbour_cmds::create_cmd(m_hw, m_itf->handle(), m_mac, m_ip_addr)); } } @@ -66,7 +82,7 @@ std::string neighbour::to_string() const { std::ostringstream s; - s << "arp-entry:[" << m_itf->to_string() << ", " << m_mac.to_string() << ", " + s << "neighbour:[" << m_itf->to_string() << ", " << m_mac.to_string() << ", " << m_ip_addr.to_string() << "]"; return (s.str()); @@ -79,15 +95,21 @@ neighbour::update(const neighbour& r) * create the table if it is not yet created */ if (rc_t::OK != m_hw.rc()) { - HW::enqueue(new create_cmd(m_hw, m_itf->handle(), m_mac, m_ip_addr)); + HW::enqueue( + new neighbour_cmds::create_cmd(m_hw, m_itf->handle(), m_mac, m_ip_addr)); } } std::shared_ptr neighbour::find_or_add(const neighbour& temp) { - return (m_db.find_or_add( - std::make_tuple(temp.m_itf->key(), temp.m_mac, temp.m_ip_addr), temp)); + return (m_db.find_or_add(temp.key(), temp)); +} + +std::shared_ptr +neighbour::find(const key_t& k) +{ + return (m_db.find(k)); } std::shared_ptr @@ -99,14 +121,13 @@ neighbour::singular() const void neighbour::dump(std::ostream& os) { - m_db.dump(os); + db_dump(m_db, os); } std::ostream& operator<<(std::ostream& os, const neighbour::key_t& key) { - os << "[" << std::get<0>(key) << ", " << std::get<1>(key) << ", " - << std::get<2>(key) << "]"; + os << "[" << key.first << ", " << key.second << "]"; return (os); } @@ -129,34 +150,34 @@ neighbour::populate_i(const client_db::key_t& key, const l3_proto_t& proto) { /* - * dump VPP current states - */ - std::shared_ptr cmd = - std::make_shared( - neighbour::dump_cmd(itf->handle(), proto)); + * dump VPP current states + */ + std::shared_ptr cmd = + std::make_shared( + neighbour_cmds::dump_cmd(itf->handle(), proto)); HW::enqueue(cmd); HW::write(); for (auto& record : *cmd) { /* - * construct a neighbour from each recieved record. - */ + * construct a neighbour from each recieved record. + */ auto& payload = record.get_payload(); mac_address_t mac(payload.mac_address); boost::asio::ip::address ip_addr = from_bytes(payload.is_ipv6, payload.ip_address); - neighbour n(*itf, mac, ip_addr); + neighbour n(*itf, ip_addr, mac); VOM_LOG(log_level_t::DEBUG) << "neighbour-dump: " << itf->to_string() << mac.to_string() << ip_addr.to_string(); /* - * Write each of the discovered interfaces into the OM, - * but disable the HW Command q whilst we do, so that no - * commands are sent to VPP - */ + * Write each of the discovered interfaces into the OM, + * but disable the HW Command q whilst we do, so that no + * commands are sent to VPP + */ OM::commit(key, n); } } @@ -183,7 +204,7 @@ neighbour::event_handler::order() const void neighbour::event_handler::show(std::ostream& os) { - m_db.dump(os); + db_dump(m_db, os); } }