X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvpp-api%2Fvom%2Fnat_static.cpp;h=3185b56e228b190a1fd4d39cd548692124b6115d;hb=756cd9441752fc8f84104c9ee19099506ba89f85;hp=619cc3b6602f88536e359231cbc2e89cda86cc1f;hpb=9ef1c0adbf9399c55deeede3cf629dd4e8c20304;p=vpp.git diff --git a/src/vpp-api/vom/nat_static.cpp b/src/vpp-api/vom/nat_static.cpp index 619cc3b6602..3185b56e228 100644 --- a/src/vpp-api/vom/nat_static.cpp +++ b/src/vpp-api/vom/nat_static.cpp @@ -15,6 +15,7 @@ #include "vom/nat_static.hpp" #include "vom/nat_static_cmds.hpp" +#include "vom/singular_db_funcs.hpp" namespace VOM { singular_db nat_static::m_db; @@ -52,7 +53,19 @@ nat_static::~nat_static() sweep(); // not in the DB anymore. - m_db.release(std::make_pair(m_rd->key(), m_outside), this); + m_db.release(key(), this); +} + +const nat_static::key_t +nat_static::key() const +{ + return (std::make_pair(m_rd->key(), m_outside)); +} + +bool +nat_static::operator==(const nat_static& n) const +{ + return ((key() == n.key()) && (m_inside == n.m_inside)); } void @@ -97,8 +110,8 @@ nat_static::to_string() const { std::ostringstream s; s << "nat-static:[" - << "table:" << m_rd->to_string() << " inside: " << m_inside.to_string() - << " outside " << m_outside.to_string() << "]"; + << "table:" << m_rd->to_string() << " inside:" << m_inside.to_string() + << " outside:" << m_outside.to_string() << "]"; return (s.str()); } @@ -106,8 +119,13 @@ nat_static::to_string() const std::shared_ptr nat_static::find_or_add(const nat_static& temp) { - return ( - m_db.find_or_add(std::make_pair(temp.m_rd->key(), temp.m_outside), temp)); + return (m_db.find_or_add(temp.key(), temp)); +} + +std::shared_ptr +nat_static::find(const key_t& key) +{ + return (m_db.find(key)); } std::shared_ptr @@ -119,15 +137,7 @@ nat_static::singular() const void nat_static::dump(std::ostream& os) { - m_db.dump(os); -} - -std::ostream& -operator<<(std::ostream& os, const nat_static::key_t& key) -{ - os << "[" << key.first << ", " << key.second << "]"; - - return (os); + db_dump(m_db, os); } nat_static::event_handler::event_handler() @@ -142,61 +152,34 @@ nat_static::event_handler::handle_replay() m_db.replay(); } -/* void nat_static::populate_i(const client_db::key_t &key, */ -/* std::shared_ptr itf, */ -/* const l3_proto_t &proto) */ -/* { */ -/* /\* */ -/* * dump VPP current states */ -/* *\/ */ -/* std::shared_ptr cmd = */ -/* std::make_shared(nat_static::dump_cmd(itf->handle(), - * proto)); */ - -/* HW::enqueue(cmd); */ -/* HW::write(); */ - -/* for (auto & record : *cmd) */ -/* { */ -/* /\* */ -/* * construct a nat_static 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); - */ -/* nat_static n(*itf, mac, ip_addr); */ - -/* VOM_LOG(log_level_t::DEBUG) << "nat_static-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 */ -/* *\/ */ -/* OM::commit(key, n); */ -/* } */ -/* } */ - void nat_static::event_handler::handle_populate(const client_db::key_t& key) { - /* auto it = interface::cbegin(); */ + /* + * dump VPP current states + */ + std::shared_ptr cmd = + std::make_shared(); - /* while (it != interface::cend()) */ - /* { */ - /* nat_static::populate_i(key, it->second.lock(), l3_proto_t::IPV4); - */ - /* nat_static::populate_i(key, it->second.lock(), l3_proto_t::IPV6); - */ + HW::enqueue(cmd); + HW::write(); + + for (auto& record : *cmd) { - /* ++it; */ - /* } */ + auto& payload = record.get_payload(); + + boost::asio::ip::address inside = from_bytes(0, payload.local_ip_address); + boost::asio::ip::address outside = + from_bytes(0, payload.external_ip_address); + nat_static n(route_domain(payload.vrf_id), inside, outside.to_v4()); + + /* + * Write each of the discovered mappings into the OM, + * but disable the HW Command q whilst we do, so that no + * commands are sent to VPP + */ + OM::commit(key, n); + } } dependency_t @@ -208,7 +191,7 @@ nat_static::event_handler::order() const void nat_static::event_handler::show(std::ostream& os) { - m_db.dump(os); + db_dump(m_db, os); } }