summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/vom/neighbour.cpp
diff options
context:
space:
mode:
authorNeale Ranns <neale.ranns@cisco.com>2017-11-23 12:15:00 -0800
committerNeale Ranns <nranns@cisco.com>2017-11-24 14:04:48 +0000
commitfd920609819a5b10d3d7c8d34fe4fa4214c7da22 (patch)
treefb0b5c3b5a9ba56308ef704ef922e959aafad17f /src/vpp-api/vom/neighbour.cpp
parent227bf211ab65e7aed6862fc881cc949c342200fd (diff)
VOM: Additions to allow uses to UT applications that use VOM
- find object by key - compare objects Change-Id: I36ec8612be9482bcef7ceced2a59f7403f77b3e8 Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
Diffstat (limited to 'src/vpp-api/vom/neighbour.cpp')
-rw-r--r--src/vpp-api/vom/neighbour.cpp52
1 files changed, 34 insertions, 18 deletions
diff --git a/src/vpp-api/vom/neighbour.cpp b/src/vpp-api/vom/neighbour.cpp
index 12b13ca6559..35e9c46b8e8 100644
--- a/src/vpp-api/vom/neighbour.cpp
+++ b/src/vpp-api/vom/neighbour.cpp
@@ -21,20 +21,20 @@ singular_db<neighbour::key_t, neighbour> 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)
{
}
@@ -43,7 +43,19 @@ 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
@@ -90,8 +102,13 @@ neighbour::update(const neighbour& r)
std::shared_ptr<neighbour>
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>
+neighbour::find(const key_t& k)
+{
+ return (m_db.find(k));
}
std::shared_ptr<neighbour>
@@ -109,8 +126,7 @@ neighbour::dump(std::ostream& 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);
}
@@ -133,8 +149,8 @@ neighbour::populate_i(const client_db::key_t& key,
const l3_proto_t& proto)
{
/*
- * dump VPP current states
- */
+ * dump VPP current states
+ */
std::shared_ptr<neighbour_cmds::dump_cmd> cmd =
std::make_shared<neighbour_cmds::dump_cmd>(
neighbour_cmds::dump_cmd(itf->handle(), proto));
@@ -144,23 +160,23 @@ neighbour::populate_i(const client_db::key_t& key,
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);
}
}