VOM: neighbour API flags 25/17525/2
authorNeale Ranns <nranns@cisco.com>
Tue, 12 Feb 2019 14:18:30 +0000 (06:18 -0800)
committerNeale Ranns <nranns@cisco.com>
Wed, 13 Feb 2019 09:06:44 +0000 (09:06 +0000)
Change-Id: Ia664cd4c77f1c5b4bc46c5e191bb57704b3ccc46
Signed-off-by: Neale Ranns <nranns@cisco.com>
extras/vom/vom/api_types.cpp
extras/vom/vom/api_types.hpp
extras/vom/vom/enum_base.hpp
extras/vom/vom/neighbour.cpp
extras/vom/vom/neighbour.hpp
extras/vom/vom/neighbour_cmds.cpp
extras/vom/vom/neighbour_cmds.hpp
extras/vom/vom/route.cpp
test/ext/vom_test.cpp

index 486ebda..ea75d7f 100644 (file)
 
 namespace VOM {
 
+vapi_enum_ip_neighbor_flags
+to_api(const neighbour::flags_t& f)
+{
+  vapi_enum_ip_neighbor_flags out = IP_API_NEIGHBOR_FLAG_NONE;
+
+  if (f & neighbour::flags_t::STATIC)
+    out = static_cast<vapi_enum_ip_neighbor_flags>(out |
+                                                   IP_API_NEIGHBOR_FLAG_STATIC);
+  if (f & neighbour::flags_t::NO_FIB_ENTRY)
+    out = static_cast<vapi_enum_ip_neighbor_flags>(
+      out | IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY);
+
+  return (out);
+}
+
+const neighbour::flags_t
+from_api(vapi_enum_ip_neighbor_flags f)
+{
+  neighbour::flags_t out = neighbour::flags_t::NONE;
+
+  if (f & IP_API_NEIGHBOR_FLAG_STATIC)
+    out |= neighbour::flags_t::STATIC;
+  if (f & IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY)
+    out |= neighbour::flags_t::NO_FIB_ENTRY;
+
+  return out;
+}
+
 void
 to_api(const boost::asio::ip::address_v4& a, vapi_type_ip4_address& v)
 {
index ac9a65e..789bbb1 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #include <boost/asio/ip/address.hpp>
+#include <vom/neighbour.hpp>
 #include <vom/prefix.hpp>
 #include <vom/types.hpp>
 
@@ -23,6 +24,9 @@ namespace VOM {
 
 typedef boost::asio::ip::address ip_address_t;
 
+vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t& f);
+const neighbour::flags_t from_api(vapi_enum_ip_neighbor_flags f);
+
 void to_api(const ip_address_t& a, vapi_type_address& v);
 void to_api(const boost::asio::ip::address_v4& a, vapi_type_ip4_address& v);
 void to_api(const boost::asio::ip::address_v6& a, vapi_type_ip6_address& v);
index 6756e24..015410a 100644 (file)
@@ -51,6 +51,27 @@ public:
     return (*this);
   }
 
+  /**
+   * bitwise or assignemnt
+   */
+  enum_base& operator|=(const enum_base& e)
+  {
+    m_value += e.m_value;
+    m_desc += ":" + e.m_desc;
+
+    return *this;
+  }
+
+  /**
+   * bitwise or
+   */
+  enum_base operator|(const enum_base& e1) const
+  {
+    enum_base e = *this;
+    e |= e1;
+    return e;
+  }
+
   /**
    * Comparison operator
    */
index cbcebd6..a97892d 100644 (file)
@@ -22,21 +22,33 @@ namespace VOM {
 singular_db<neighbour::key_t, neighbour> neighbour::m_db;
 neighbour::event_handler neighbour::m_evh;
 
+const neighbour::flags_t neighbour::flags_t::NONE(0, "");
+const neighbour::flags_t neighbour::flags_t::STATIC(1, "static");
+const neighbour::flags_t neighbour::flags_t::NO_FIB_ENTRY(2, "no-fib-entry");
+
+neighbour::flags_t::flags_t(int v, const std::string s)
+  : enum_base(v, s)
+{
+}
+
 neighbour::neighbour(const interface& itf,
                      const boost::asio::ip::address& ip_addr,
-                     const mac_address_t& mac)
+                     const mac_address_t& mac,
+                     const flags_t flags)
   : m_hw(false)
   , m_itf(itf.singular())
   , m_ip_addr(ip_addr)
   , m_mac(mac)
+  , m_flags(flags)
 {
 }
 
-neighbour::neighbour(const neighbour& bde)
-  : m_hw(bde.m_hw)
-  , m_itf(bde.m_itf)
-  , m_ip_addr(bde.m_ip_addr)
-  , m_mac(bde.m_mac)
+neighbour::neighbour(const neighbour& n)
+  : m_hw(n.m_hw)
+  , m_itf(n.m_itf)
+  , m_ip_addr(n.m_ip_addr)
+  , m_mac(n.m_mac)
+  , m_flags(n.m_flags)
 {
 }
 
@@ -64,8 +76,8 @@ void
 neighbour::sweep()
 {
   if (m_hw) {
-    HW::enqueue(
-      new neighbour_cmds::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, m_flags));
   }
   HW::write();
 }
@@ -74,8 +86,8 @@ void
 neighbour::replay()
 {
   if (m_hw) {
-    HW::enqueue(
-      new neighbour_cmds::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, m_flags));
   }
 }
 
@@ -84,7 +96,7 @@ neighbour::to_string() const
 {
   std::ostringstream s;
   s << "neighbour:[" << m_itf->to_string() << ", " << m_mac.to_string() << ", "
-    << m_ip_addr.to_string() << "]";
+    << m_ip_addr.to_string() << " " << m_flags.to_string() << "]";
 
   return (s.str());
 }
@@ -96,8 +108,8 @@ neighbour::update(const neighbour& r)
  * create the table if it is not yet created
  */
   if (rc_t::OK != m_hw.rc()) {
-    HW::enqueue(
-      new neighbour_cmds::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, m_flags));
   }
 }
 
@@ -168,10 +180,13 @@ neighbour::populate_i(const client_db::key_t& key,
 
     mac_address_t mac = from_api(payload.neighbor.mac_address);
     boost::asio::ip::address ip_addr = from_api(payload.neighbor.ip_address);
-    neighbour n(*itf, ip_addr, mac);
+    neighbour::flags_t f = from_api(payload.neighbor.flags);
+    neighbour n(*itf, ip_addr, mac, f);
+    ;
 
-    VOM_LOG(log_level_t::DEBUG) << "neighbour-dump: " << itf->to_string()
-                                << mac.to_string() << ip_addr.to_string();
+    VOM_LOG(log_level_t::DEBUG) << "neighbour-dump: " << itf->to_string() << " "
+                                << mac.to_string() << " " << ip_addr.to_string()
+                                << " " << f.to_string();
 
     /*
      * Write each of the discovered interfaces into the OM,
index 500f03d..4e074bf 100644 (file)
@@ -27,6 +27,30 @@ namespace VOM {
 class neighbour : public object_base
 {
 public:
+  struct flags_t : public enum_base<flags_t>
+  {
+    /**
+     * Constructor
+     */
+    flags_t(int v, const std::string s);
+
+    /**
+     * Destructor
+     */
+    ~flags_t() = default;
+
+    flags_t operator|(const flags_t& e1) const
+    {
+      flags_t e = *this;
+      e |= e1;
+      return e;
+    }
+
+    const static flags_t NONE;
+    const static flags_t STATIC;
+    const static flags_t NO_FIB_ENTRY;
+  };
+
   /**
    * The key for a neighbour entry;
    *  the interface and IP address
@@ -38,7 +62,8 @@ public:
    */
   neighbour(const interface& itf,
             const boost::asio::ip::address& ip_addr,
-            const mac_address_t& mac);
+            const mac_address_t& mac,
+            const flags_t flags = flags_t::STATIC);
 
   /**
    * Copy Construct
@@ -173,6 +198,11 @@ private:
    */
   mac_address_t m_mac;
 
+  /**
+   * flags on the entry
+   */
+  flags_t m_flags;
+
   /**
    * A map of all bridge_domains
    */
index d43e508..5f9e180 100644 (file)
@@ -21,11 +21,13 @@ namespace neighbour_cmds {
 create_cmd::create_cmd(HW::item<bool>& item,
                        handle_t itf,
                        const mac_address_t& mac,
-                       const boost::asio::ip::address& ip_addr)
+                       const boost::asio::ip::address& ip_addr,
+                       const neighbour::flags_t& flags)
   : rpc_cmd(item)
   , m_itf(itf)
   , m_mac(mac)
   , m_ip_addr(ip_addr)
+  , m_flags(flags)
 {
 }
 
@@ -33,7 +35,7 @@ bool
 create_cmd::operator==(const create_cmd& other) const
 {
   return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
-          (m_itf == other.m_itf));
+          (m_itf == other.m_itf) && (m_flags == other.m_flags));
 }
 
 rc_t
@@ -44,10 +46,10 @@ create_cmd::issue(connection& con)
   auto& payload = req.get_request().get_payload();
   payload.is_add = 1;
   payload.neighbor.sw_if_index = m_itf.value();
-  payload.neighbor.flags = IP_API_NEIGHBOR_FLAG_STATIC;
 
   to_api(m_mac, payload.neighbor.mac_address);
   to_api(m_ip_addr, payload.neighbor.ip_address);
+  payload.neighbor.flags = to_api(m_flags);
 
   VAPI_CALL(req.execute());
 
@@ -68,11 +70,13 @@ create_cmd::to_string() const
 delete_cmd::delete_cmd(HW::item<bool>& item,
                        handle_t itf,
                        const mac_address_t& mac,
-                       const boost::asio::ip::address& ip_addr)
+                       const boost::asio::ip::address& ip_addr,
+                       const neighbour::flags_t& flags)
   : rpc_cmd(item)
   , m_itf(itf)
   , m_mac(mac)
   , m_ip_addr(ip_addr)
+  , m_flags(flags)
 {
 }
 
@@ -91,10 +95,10 @@ delete_cmd::issue(connection& con)
   auto& payload = req.get_request().get_payload();
   payload.is_add = 0;
   payload.neighbor.sw_if_index = m_itf.value();
-  payload.neighbor.flags = IP_API_NEIGHBOR_FLAG_STATIC;
 
   to_api(m_mac, payload.neighbor.mac_address);
   to_api(m_ip_addr, payload.neighbor.ip_address);
+  payload.neighbor.flags = to_api(m_flags);
 
   VAPI_CALL(req.execute());
 
index 388dbf1..d43a6fe 100644 (file)
@@ -37,7 +37,8 @@ public:
   create_cmd(HW::item<bool>& item,
              handle_t itf,
              const mac_address_t& mac,
-             const boost::asio::ip::address& ip_addr);
+             const boost::asio::ip::address& ip_addr,
+             const neighbour::flags_t &flags);
 
   /**
    * Issue the command to VPP/HW
@@ -58,6 +59,7 @@ private:
   handle_t m_itf;
   mac_address_t m_mac;
   boost::asio::ip::address m_ip_addr;
+  const neighbour::flags_t &m_flags;
 };
 
 /**
@@ -73,7 +75,8 @@ public:
   delete_cmd(HW::item<bool>& item,
              handle_t itf,
              const mac_address_t& mac,
-             const boost::asio::ip::address& ip_addr);
+             const boost::asio::ip::address& ip_addr,
+             const neighbour::flags_t &flags);
 
   /**
    * Issue the command to VPP/HW
@@ -94,6 +97,7 @@ private:
   handle_t m_itf;
   mac_address_t m_mac;
   boost::asio::ip::address m_ip_addr;
+  const neighbour::flags_t &m_flags;
 };
 
 /**
index ae80fd9..722628f 100644 (file)
@@ -678,7 +678,7 @@ ip_mroute::event_handler::handle_populate(const client_db::key_t& key)
       ip_r.add(from_vpp(p.path, nh_proto_t::IPV4),
                itf_flags_t::from_vpp(p.itf_flags));
     }
-    VOM_LOG(log_level_t::INFO) << "ip-mroute-dump: " << ip_r.to_string();
+    VOM_LOG(log_level_t::DEBUG) << "ip-mroute-dump: " << ip_r.to_string();
 
     /*
      * Write each of the discovered interfaces into the OM,
index d72c4db..c259bb0 100644 (file)
@@ -1773,7 +1773,9 @@ BOOST_AUTO_TEST_CASE(test_routing) {
     HW::item<bool> hw_neighbour(true, rc_t::OK);
     mac_address_t mac_n({0,1,2,4,5,6});
     neighbour *ne = new neighbour(itf1, nh_10, mac_n);
-    ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
+    ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(),
+                                          mac_n, nh_10,
+                                          neighbour::flags_t::STATIC));
     TRY_CHECK_RC(OM::write(ian, *ne));
 
     /*
@@ -1829,7 +1831,9 @@ BOOST_AUTO_TEST_CASE(test_routing) {
     delete mp1;
     delete mp2;
 
-    ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
+    ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(),
+                                          mac_n, nh_10,
+                                          neighbour::flags_t::STATIC));
     ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
     ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_11));
     ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_12));