X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=extras%2Fvom%2Fvom%2Fgbp_endpoint.cpp;h=ef406b16565d7ed7077d74a356bca66f6bd3c5f2;hb=7c0eb56f4;hp=9762a91429a42da5e3e499973de98e3aec8ec0b8;hpb=164e5f8c63652028ecb9c3570e1ea8618b163071;p=vpp.git diff --git a/extras/vom/vom/gbp_endpoint.cpp b/extras/vom/vom/gbp_endpoint.cpp index 9762a91429a..ef406b16565 100644 --- a/extras/vom/vom/gbp_endpoint.cpp +++ b/extras/vom/vom/gbp_endpoint.cpp @@ -14,6 +14,7 @@ */ #include "vom/gbp_endpoint.hpp" +#include "vom/api_types.hpp" #include "vom/gbp_endpoint_cmds.hpp" #include "vom/singular_db_funcs.hpp" @@ -23,24 +24,39 @@ singular_db gbp_endpoint::m_db; gbp_endpoint::event_handler gbp_endpoint::m_evh; -gbp_endpoint::gbp_endpoint(const interface& itf, - const boost::asio::ip::address& ip_addr, - const mac_address_t& mac, - const gbp_endpoint_group& epg) - : m_hw(false) +const gbp_endpoint::flags_t gbp_endpoint::flags_t::NONE(0, "none"); +const gbp_endpoint::flags_t gbp_endpoint::flags_t::BOUNCE(1, "bounce"); +const gbp_endpoint::flags_t gbp_endpoint::flags_t::LEARNT(2, "learnt"); +const gbp_endpoint::flags_t gbp_endpoint::flags_t::REMOTE(4, "remote"); +const gbp_endpoint::flags_t gbp_endpoint::flags_t::EXTERNAL(8, "external"); + +gbp_endpoint::flags_t::flags_t(int v, const std::string& s) + : enum_base(v, s) +{ +} + +gbp_endpoint::gbp_endpoint( + const interface& itf, + const std::vector& ip_addrs, + const mac_address_t& mac, + const gbp_endpoint_group& epg, + const flags_t& flags) + : m_hdl(handle_t::INVALID) , m_itf(itf.singular()) - , m_ip(ip_addr) + , m_ips(ip_addrs) , m_mac(mac) , m_epg(epg.singular()) + , m_flags(flags) { } gbp_endpoint::gbp_endpoint(const gbp_endpoint& gbpe) - : m_hw(gbpe.m_hw) + : m_hdl(gbpe.m_hdl) , m_itf(gbpe.m_itf) - , m_ip(gbpe.m_ip) + , m_ips(gbpe.m_ips) , m_mac(gbpe.m_mac) , m_epg(gbpe.m_epg) + , m_flags(gbpe.m_flags) { } @@ -53,20 +69,21 @@ gbp_endpoint::~gbp_endpoint() const gbp_endpoint::key_t gbp_endpoint::key() const { - return (std::make_pair(m_itf->key(), m_ip)); + return (std::make_pair(m_itf->key(), m_mac)); } bool gbp_endpoint::operator==(const gbp_endpoint& gbpe) const { - return ((key() == gbpe.key()) && (m_epg == gbpe.m_epg)); + return ((key() == gbpe.key()) && (m_epg == gbpe.m_epg) && + (m_flags == gbpe.m_flags)); } void gbp_endpoint::sweep() { - if (m_hw) { - HW::enqueue(new gbp_endpoint_cmds::delete_cmd(m_hw, m_itf->handle(), m_ip)); + if (m_hdl) { + HW::enqueue(new gbp_endpoint_cmds::delete_cmd(m_hdl)); } HW::write(); } @@ -74,9 +91,9 @@ gbp_endpoint::sweep() void gbp_endpoint::replay() { - if (m_hw) { - HW::enqueue(new gbp_endpoint_cmds::create_cmd(m_hw, m_itf->handle(), m_ip, - m_mac, m_epg->id())); + if (m_hdl) { + HW::enqueue(new gbp_endpoint_cmds::create_cmd( + m_hdl, m_itf->handle(), m_ips, m_mac, m_epg->sclass(), m_flags)); } } @@ -84,8 +101,12 @@ std::string gbp_endpoint::to_string() const { std::ostringstream s; - s << "gbp-endpoint:[" << m_itf->to_string() << ", " << m_ip.to_string() - << ", " << m_mac.to_string() << ", epg:" << m_epg->to_string() << "]"; + s << "gbp-endpoint:[" << m_itf->to_string() << ", ips:["; + + for (auto ip : m_ips) + s << ip.to_string(); + + s << "], " << m_mac.to_string() << ", epg:" << m_epg->to_string() << "]"; return (s.str()); } @@ -93,9 +114,9 @@ gbp_endpoint::to_string() const void gbp_endpoint::update(const gbp_endpoint& r) { - if (rc_t::OK != m_hw.rc()) { - HW::enqueue(new gbp_endpoint_cmds::create_cmd(m_hw, m_itf->handle(), m_ip, - m_mac, m_epg->id())); + if (rc_t::OK != m_hdl.rc()) { + HW::enqueue(new gbp_endpoint_cmds::create_cmd( + m_hdl, m_itf->handle(), m_ips, m_mac, m_epg->sclass(), m_flags)); } } @@ -147,21 +168,27 @@ gbp_endpoint::event_handler::handle_populate(const client_db::key_t& key) for (auto& record : *cmd) { auto& payload = record.get_payload(); - boost::asio::ip::address address = - from_bytes(payload.endpoint.is_ip6, payload.endpoint.address); + std::vector addresses; + + for (uint8_t n = 0; n < payload.endpoint.n_ips; n++) + addresses.push_back(from_api(payload.endpoint.ips[n])); std::shared_ptr itf = interface::find(payload.endpoint.sw_if_index); std::shared_ptr epg = - gbp_endpoint_group::find(payload.endpoint.epg_id); - mac_address_t mac(payload.endpoint.mac); + gbp_endpoint_group::find(payload.endpoint.sclass); + mac_address_t mac = from_api(payload.endpoint.mac); VOM_LOG(log_level_t::DEBUG) << "data: " << payload.endpoint.sw_if_index; if (itf && epg) { - gbp_endpoint gbpe(*itf, address, mac, *epg); + gbp_endpoint gbpe(*itf, addresses, mac, *epg); OM::commit(key, gbpe); VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string(); + } else { + VOM_LOG(log_level_t::ERROR) + << "no interface:" << payload.endpoint.sw_if_index + << "or sclass:" << payload.endpoint.sclass; } } } @@ -177,6 +204,15 @@ gbp_endpoint::event_handler::show(std::ostream& os) { db_dump(m_db, os); } + +std::ostream& +operator<<(std::ostream& os, const gbp_endpoint::key_t& key) +{ + os << key.first << "," << key.second; + + return os; +} + } // namespace VOM /*