GBP: Endpoint flags 82/18282/2
authorNeale Ranns <nranns@cisco.com>
Thu, 14 Mar 2019 09:22:24 +0000 (02:22 -0700)
committerDamjan Marion <dmarion@me.com>
Thu, 14 Mar 2019 13:05:46 +0000 (13:05 +0000)
Change-Id: I4d70985ad078e84ec23ce704c8b76e2ac7809419
Signed-off-by: Neale Ranns <nranns@cisco.com>
extras/vom/vom/gbp_endpoint.cpp
extras/vom/vom/gbp_endpoint.hpp
extras/vom/vom/gbp_endpoint_cmds.cpp
extras/vom/vom/gbp_endpoint_cmds.hpp

index 20f966c..ef406b1 100644 (file)
@@ -24,16 +24,29 @@ singular_db<gbp_endpoint::key_t, gbp_endpoint> gbp_endpoint::m_db;
 
 gbp_endpoint::event_handler gbp_endpoint::m_evh;
 
+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<gbp_endpoint::flags_t>(v, s)
+{
+}
+
 gbp_endpoint::gbp_endpoint(
   const interface& itf,
   const std::vector<boost::asio::ip::address>& ip_addrs,
   const mac_address_t& mac,
-  const gbp_endpoint_group& epg)
+  const gbp_endpoint_group& epg,
+  const flags_t& flags)
   : m_hdl(handle_t::INVALID)
   , m_itf(itf.singular())
   , m_ips(ip_addrs)
   , m_mac(mac)
   , m_epg(epg.singular())
+  , m_flags(flags)
 {
 }
 
@@ -43,6 +56,7 @@ gbp_endpoint::gbp_endpoint(const gbp_endpoint& gbpe)
   , m_ips(gbpe.m_ips)
   , m_mac(gbpe.m_mac)
   , m_epg(gbpe.m_epg)
+  , m_flags(gbpe.m_flags)
 {
 }
 
@@ -61,7 +75,8 @@ gbp_endpoint::key() const
 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
@@ -77,8 +92,8 @@ void
 gbp_endpoint::replay()
 {
   if (m_hdl) {
-    HW::enqueue(new gbp_endpoint_cmds::create_cmd(m_hdl, m_itf->handle(), m_ips,
-                                                  m_mac, m_epg->sclass()));
+    HW::enqueue(new gbp_endpoint_cmds::create_cmd(
+      m_hdl, m_itf->handle(), m_ips, m_mac, m_epg->sclass(), m_flags));
   }
 }
 
@@ -100,8 +115,8 @@ void
 gbp_endpoint::update(const gbp_endpoint& r)
 {
   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()));
+    HW::enqueue(new gbp_endpoint_cmds::create_cmd(
+      m_hdl, m_itf->handle(), m_ips, m_mac, m_epg->sclass(), m_flags));
   }
 }
 
index d27ad90..8008e3b 100644 (file)
@@ -30,6 +30,24 @@ namespace VOM {
 class gbp_endpoint : public object_base
 {
 public:
+  /**
+   * Endpoint flags
+   */
+  struct flags_t : enum_base<flags_t>
+  {
+    const static flags_t NONE;
+    const static flags_t BOUNCE;
+    const static flags_t REMOTE;
+    const static flags_t LEARNT;
+    const static flags_t EXTERNAL;
+
+  private:
+    /**
+     * Private constructor taking the value and the string name
+     */
+    flags_t(int v, const std::string& s);
+  };
+
   /**
    * The key for a GBP endpoint; interface and IP
    */
@@ -41,7 +59,8 @@ public:
   gbp_endpoint(const interface& itf,
                const std::vector<boost::asio::ip::address>& ip_addr,
                const mac_address_t& mac,
-               const gbp_endpoint_group& epg);
+               const gbp_endpoint_group& epg,
+               const flags_t& flags = flags_t::NONE);
 
   /**
    * Copy Construct
@@ -174,6 +193,11 @@ private:
    */
   std::shared_ptr<gbp_endpoint_group> m_epg;
 
+  /**
+   * Endpoint flags
+   */
+  flags_t m_flags;
+
   /**
    * A map of all bridge_domains
    */
index 77c7548..f0c55eb 100644 (file)
@@ -21,16 +21,35 @@ DEFINE_VAPI_MSG_IDS_GBP_API_JSON;
 namespace VOM {
 namespace gbp_endpoint_cmds {
 
+static vapi_enum_gbp_endpoint_flags
+to_api(const gbp_endpoint::flags_t& in)
+{
+  vapi_enum_gbp_endpoint_flags out = GBP_API_ENDPOINT_FLAG_NONE;
+
+  if (in & gbp_endpoint::flags_t::REMOTE)
+    out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_REMOTE);
+  if (in & gbp_endpoint::flags_t::BOUNCE)
+    out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_BOUNCE);
+  if (in & gbp_endpoint::flags_t::LEARNT)
+    out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_LEARNT);
+  if (in & gbp_endpoint::flags_t::EXTERNAL)
+    out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_EXTERNAL);
+
+  return (out);
+}
+
 create_cmd::create_cmd(HW::item<handle_t>& item,
                        const handle_t& itf,
                        const std::vector<boost::asio::ip::address>& ip_addrs,
                        const mac_address_t& mac,
-                       sclass_t sclass)
+                       sclass_t sclass,
+                       const gbp_endpoint::flags_t& flags)
   : rpc_cmd(item)
   , m_itf(itf)
   , m_ip_addrs(ip_addrs)
   , m_mac(mac)
   , m_sclass(sclass)
+  , m_flags(flags)
 {
 }
 
@@ -38,7 +57,8 @@ bool
 create_cmd::operator==(const create_cmd& other) const
 {
   return ((m_itf == other.m_itf) && (m_ip_addrs == other.m_ip_addrs) &&
-          (m_mac == other.m_mac) && (m_sclass == other.m_sclass));
+          (m_mac == other.m_mac) && (m_sclass == other.m_sclass) &&
+          (m_flags == other.m_flags));
 }
 
 rc_t
@@ -52,9 +72,10 @@ create_cmd::issue(connection& con)
   payload.endpoint.sw_if_index = m_itf.value();
   payload.endpoint.sclass = m_sclass;
   payload.endpoint.n_ips = m_ip_addrs.size();
+  payload.endpoint.flags = to_api(m_flags);
 
   for (n = 0; n < payload.endpoint.n_ips; n++) {
-    to_api(m_ip_addrs[n], payload.endpoint.ips[n]);
+    VOM::to_api(m_ip_addrs[n], payload.endpoint.ips[n]);
   }
   to_api(m_mac, payload.endpoint.mac);
 
@@ -92,8 +113,8 @@ create_cmd::to_string() const
   for (auto ip : m_ip_addrs)
     s << ip.to_string();
 
-  s << "] mac:" << m_mac;
-  s << " slcass:" << m_sclass;
+  s << "] mac:" << m_mac << " slcass:" << m_sclass
+    << " flags:" << m_flags.to_string();
 
   return (s.str());
 }
index 2aa56f8..4b9036a 100644 (file)
@@ -37,7 +37,8 @@ public:
              const handle_t& itf,
              const std::vector<boost::asio::ip::address>& ip_addrs,
              const mac_address_t& mac,
-             sclass_t sclass);
+             sclass_t sclass,
+             const gbp_endpoint::flags_t& flags);
 
   /**
    * Issue the command to VPP/HW
@@ -61,6 +62,7 @@ private:
   const std::vector<boost::asio::ip::address> m_ip_addrs;
   const mac_address_t m_mac;
   const sclass_t m_sclass;
+  const gbp_endpoint::flags_t m_flags;
 };
 
 /**