X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvpp-api%2Fvom%2Fnat_binding.cpp;h=eca3f9041f0b1b3c805e6118fc13d7fe8e1a9d09;hb=756cd9441752fc8f84104c9ee19099506ba89f85;hp=beb76bd84945f76979897d06572ef5d06905ce66;hpb=812ed39f9da336310e815c361ab5a9f118657d94;p=vpp.git diff --git a/src/vpp-api/vom/nat_binding.cpp b/src/vpp-api/vom/nat_binding.cpp index beb76bd8494..eca3f9041f0 100644 --- a/src/vpp-api/vom/nat_binding.cpp +++ b/src/vpp-api/vom/nat_binding.cpp @@ -15,6 +15,8 @@ #include "vom/nat_binding.hpp" #include "vom/cmd.hpp" +#include "vom/nat_binding_cmds.hpp" +#include "vom/singular_db_funcs.hpp" namespace VOM { singular_db nat_binding::m_db; @@ -28,6 +30,13 @@ nat_binding::zone_t::zone_t(int v, const std::string s) : enum_base(v, s) { } +const nat_binding::zone_t& +nat_binding::zone_t::from_vpp(u8 is_inside) +{ + if (is_inside) + return zone_t::INSIDE; + return zone_t::OUTSIDE; +} /** * Construct a new object matching the desried state @@ -56,7 +65,19 @@ nat_binding::nat_binding(const nat_binding& o) nat_binding::~nat_binding() { sweep(); - m_db.release(make_tuple(m_itf->key(), m_dir, m_proto), this); + m_db.release(key(), this); +} + +const nat_binding::key_t +nat_binding::key() const +{ + return (make_tuple(m_itf->key(), m_dir, m_proto)); +} + +bool +nat_binding::operator==(const nat_binding& n) const +{ + return ((key() == n.key()) && (m_zone == n.m_zone)); } void @@ -64,9 +85,11 @@ nat_binding::sweep() { if (m_binding) { if (direction_t::INPUT == m_dir) { - HW::enqueue(new unbind_44_input_cmd(m_binding, m_itf->handle(), m_zone)); + HW::enqueue(new nat_binding_cmds::unbind_44_input_cmd( + m_binding, m_itf->handle(), m_zone)); } else { - assert(!"Unimplemented"); + HW::enqueue(new nat_binding_cmds::unbind_44_output_cmd( + m_binding, m_itf->handle(), m_zone)); } } HW::write(); @@ -77,9 +100,11 @@ nat_binding::replay() { if (m_binding) { if (direction_t::INPUT == m_dir) { - HW::enqueue(new bind_44_input_cmd(m_binding, m_itf->handle(), m_zone)); + HW::enqueue(new nat_binding_cmds::bind_44_input_cmd( + m_binding, m_itf->handle(), m_zone)); } else { - assert(!"Unimplemented"); + HW::enqueue(new nat_binding_cmds::bind_44_output_cmd( + m_binding, m_itf->handle(), m_zone)); } } } @@ -92,9 +117,11 @@ nat_binding::update(const nat_binding& desired) */ if (!m_binding) { if (direction_t::INPUT == m_dir) { - HW::enqueue(new bind_44_input_cmd(m_binding, m_itf->handle(), m_zone)); + HW::enqueue(new nat_binding_cmds::bind_44_input_cmd( + m_binding, m_itf->handle(), m_zone)); } else { - assert(!"Unimplemented"); + HW::enqueue(new nat_binding_cmds::bind_44_output_cmd( + m_binding, m_itf->handle(), m_zone)); } } } @@ -103,8 +130,9 @@ std::string nat_binding::to_string() const { std::ostringstream s; - s << "nat-binding:[" << m_itf->to_string() << " " << m_dir.to_string() << " " - << m_proto.to_string() << " " << m_zone.to_string() << "]"; + s << "nat-binding:[" << m_itf->to_string() + << " direction:" << m_dir.to_string() << " proto:" << m_proto.to_string() + << " zone:" << m_zone.to_string() << "]"; return (s.str()); } @@ -112,8 +140,13 @@ nat_binding::to_string() const std::shared_ptr nat_binding::find_or_add(const nat_binding& temp) { - return (m_db.find_or_add( - make_tuple(temp.m_itf->key(), temp.m_dir, temp.m_proto), temp)); + return (m_db.find_or_add(temp.key(), temp)); +} + +std::shared_ptr +nat_binding::find(const key_t& key) +{ + return (m_db.find(key)); } std::shared_ptr @@ -125,7 +158,7 @@ nat_binding::singular() const void nat_binding::dump(std::ostream& os) { - m_db.dump(os); + db_dump(m_db, os); } std::ostream& @@ -152,9 +185,35 @@ nat_binding::event_handler::handle_replay() void nat_binding::event_handler::handle_populate(const client_db::key_t& key) { - /** - * This is done while populating the interfaces - */ + std::shared_ptr icmd = + std::make_shared(); + + HW::enqueue(icmd); + HW::write(); + + for (auto& record : *icmd) { + auto& payload = record.get_payload(); + + std::shared_ptr itf = interface::find(payload.sw_if_index); + nat_binding nb(*itf, direction_t::INPUT, l3_proto_t::IPV4, + zone_t::from_vpp(payload.is_inside)); + OM::commit(key, nb); + } + + std::shared_ptr ocmd = + std::make_shared(); + + HW::enqueue(ocmd); + HW::write(); + + for (auto& record : *ocmd) { + auto& payload = record.get_payload(); + + std::shared_ptr itf = interface::find(payload.sw_if_index); + nat_binding nb(*itf, direction_t::OUTPUT, l3_proto_t::IPV4, + zone_t::from_vpp(payload.is_inside)); + OM::commit(key, nb); + } } dependency_t @@ -166,7 +225,7 @@ nat_binding::event_handler::order() const void nat_binding::event_handler::show(std::ostream& os) { - m_db.dump(os); + db_dump(m_db, os); } }