VOM: vxlan-tunnel takes egress interface for multicast 34/16434/2
authorNeale Ranns <nranns@cisco.com>
Tue, 11 Dec 2018 16:40:20 +0000 (08:40 -0800)
committerNeale Ranns <nranns@cisco.com>
Wed, 12 Dec 2018 12:05:49 +0000 (12:05 +0000)
Change-Id: I23b44d883fbd7919bf55b96b180f97837fd6dae9
Signed-off-by: Neale Ranns <nranns@cisco.com>
extras/vom/vom/vxlan_gbp_tunnel_cmds.cpp
extras/vom/vom/vxlan_gbp_tunnel_cmds.hpp
extras/vom/vom/vxlan_tunnel.cpp
extras/vom/vom/vxlan_tunnel.hpp
extras/vom/vom/vxlan_tunnel_cmds.cpp
extras/vom/vom/vxlan_tunnel_cmds.hpp
test/ext/vom_test.cpp

index 1447080..a646eac 100644 (file)
@@ -23,9 +23,11 @@ namespace vxlan_gbp_tunnel_cmds {
 
 create_cmd::create_cmd(HW::item<handle_t>& item,
                        const std::string& name,
-                       const vxlan_tunnel::endpoint_t& ep)
+                       const vxlan_tunnel::endpoint_t& ep,
+                       handle_t mcast_itf)
   : interface::create_cmd<vapi::Vxlan_gbp_tunnel_add_del>(item, name)
   , m_ep(ep)
+  , m_mcast_itf(mcast_itf)
 {
 }
 
@@ -46,7 +48,7 @@ create_cmd::issue(connection& con)
 
   to_api(m_ep.src, payload.tunnel.src);
   to_api(m_ep.src, payload.tunnel.dst);
-  payload.tunnel.mcast_sw_if_index = ~0;
+  payload.tunnel.mcast_sw_if_index = m_mcast_itf.value();
   payload.tunnel.encap_table_id = 0;
   payload.tunnel.vni = m_ep.vni;
 
index 34407f6..c7ec872 100644 (file)
@@ -37,7 +37,8 @@ public:
    */
   create_cmd(HW::item<handle_t>& item,
              const std::string& name,
-             const vxlan_tunnel::endpoint_t& ep);
+             const vxlan_tunnel::endpoint_t& ep,
+             handle_t mcast_itf);
 
   /**
    * Issue the command to VPP/HW
@@ -58,6 +59,7 @@ private:
    * Enpoint values of the tunnel to be created
    */
   const vxlan_tunnel::endpoint_t m_ep;
+  handle_t m_mcast_itf;
 };
 
 /**
index 2abff76..2bc386c 100644 (file)
@@ -91,6 +91,21 @@ vxlan_tunnel::vxlan_tunnel(const boost::asio::ip::address& src,
               interface::admin_state_t::UP)
   , m_tep(src, dst, vni)
   , m_mode(mode)
+  , m_mcast_itf()
+{
+}
+
+vxlan_tunnel::vxlan_tunnel(const boost::asio::ip::address& src,
+                           const boost::asio::ip::address& dst,
+                           uint32_t vni,
+                           const interface& mcast_itf,
+                           const mode_t& mode)
+  : interface(mk_name(src, dst, mode, vni),
+              interface::type_t::VXLAN,
+              interface::admin_state_t::UP)
+  , m_tep(src, dst, vni)
+  , m_mode(mode)
+  , m_mcast_itf(mcast_itf.singular())
 {
 }
 
@@ -130,9 +145,13 @@ vxlan_tunnel::replay()
 {
   if (m_hdl) {
     if (mode_t::STANDARD == m_mode)
-      HW::enqueue(new vxlan_tunnel_cmds::create_cmd(m_hdl, name(), m_tep));
+      HW::enqueue(new vxlan_tunnel_cmds::create_cmd(
+        m_hdl, name(), m_tep,
+        (m_mcast_itf ? m_mcast_itf->handle() : handle_t::INVALID)));
     else if (mode_t::GBP == m_mode)
-      HW::enqueue(new vxlan_gbp_tunnel_cmds::create_cmd(m_hdl, name(), m_tep));
+      HW::enqueue(new vxlan_gbp_tunnel_cmds::create_cmd(
+        m_hdl, name(), m_tep,
+        (m_mcast_itf ? m_mcast_itf->handle() : handle_t::INVALID)));
   }
 }
 
@@ -160,9 +179,13 @@ vxlan_tunnel::update(const vxlan_tunnel& desired)
    */
   if (!m_hdl) {
     if (mode_t::STANDARD == m_mode)
-      HW::enqueue(new vxlan_tunnel_cmds::create_cmd(m_hdl, name(), m_tep));
+      HW::enqueue(new vxlan_tunnel_cmds::create_cmd(
+        m_hdl, name(), m_tep,
+        (m_mcast_itf ? m_mcast_itf->handle() : handle_t::INVALID)));
     else if (mode_t::GBP == m_mode)
-      HW::enqueue(new vxlan_gbp_tunnel_cmds::create_cmd(m_hdl, name(), m_tep));
+      HW::enqueue(new vxlan_gbp_tunnel_cmds::create_cmd(
+        m_hdl, name(), m_tep,
+        (m_mcast_itf ? m_mcast_itf->handle() : handle_t::INVALID)));
   }
 }
 
index 136f038..63124e7 100644 (file)
@@ -97,15 +97,10 @@ public:
                const boost::asio::ip::address& dst,
                uint32_t vni,
                const mode_t& mode = mode_t::STANDARD);
-
-  /**
-   * Construct a new object matching the desried state with a handle
-   * read from VPP
-   */
-  vxlan_tunnel(const handle_t& hdl,
-               const boost::asio::ip::address& src,
+  vxlan_tunnel(const boost::asio::ip::address& src,
                const boost::asio::ip::address& dst,
                uint32_t vni,
+               const interface& mcast_itf,
                const mode_t& mode = mode_t::STANDARD);
 
   /*
@@ -220,6 +215,12 @@ private:
    */
   mode_t m_mode;
 
+  /**
+   * The interface on which to send the packets if the destination
+   * is multicast
+   */
+  std::shared_ptr<interface> m_mcast_itf;
+
   /**
    * Construct a unique name for the tunnel
    */
index dcc06e7..e45b604 100644 (file)
@@ -22,9 +22,11 @@ namespace vxlan_tunnel_cmds {
 
 create_cmd::create_cmd(HW::item<handle_t>& item,
                        const std::string& name,
-                       const vxlan_tunnel::endpoint_t& ep)
+                       const vxlan_tunnel::endpoint_t& ep,
+                       handle_t mcast_itf)
   : interface::create_cmd<vapi::Vxlan_add_del_tunnel>(item, name)
   , m_ep(ep)
+  , m_mcast_itf(mcast_itf)
 {
 }
 
@@ -44,7 +46,7 @@ create_cmd::issue(connection& con)
   payload.is_ipv6 = 0;
   to_bytes(m_ep.src, &payload.is_ipv6, payload.src_address);
   to_bytes(m_ep.dst, &payload.is_ipv6, payload.dst_address);
-  payload.mcast_sw_if_index = ~0;
+  payload.mcast_sw_if_index = m_mcast_itf.value();
   payload.encap_vrf_id = 0;
   payload.decap_next_index = ~0;
   payload.vni = m_ep.vni;
index 4a8e599..423fcda 100644 (file)
@@ -38,7 +38,8 @@ public:
    */
   create_cmd(HW::item<handle_t>& item,
              const std::string& name,
-             const vxlan_tunnel::endpoint_t& ep);
+             const vxlan_tunnel::endpoint_t& ep,
+             handle_t mcast_itf);
 
   /**
    * Issue the command to VPP/HW
@@ -59,6 +60,7 @@ private:
    * Enpoint values of the tunnel to be created
    */
   const vxlan_tunnel::endpoint_t m_ep;
+  handle_t m_mcast_itf;
 };
 
 /**
index f17d749..fa51c38 100644 (file)
@@ -1156,7 +1156,8 @@ BOOST_AUTO_TEST_CASE(test_vxlan) {
     vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
 
     HW::item<handle_t> hw_vxt(3, rc_t::OK);
-    ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
+    ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep,
+                                             handle_t::INVALID));
 
     TRY_CHECK_RC(OM::write(franz, vxt));