VOM: IP route ECMP support
[vpp.git] / test / ext / vom_test.cpp
index f17d749..d72c4db 100644 (file)
@@ -38,6 +38,7 @@
 #include "vom/prefix.hpp"
 #include "vom/route.hpp"
 #include "vom/route_cmds.hpp"
+#include "vom/mroute_cmds.hpp"
 #include "vom/route_domain.hpp"
 #include "vom/route_domain_cmds.hpp"
 #include "vom/vxlan_tunnel.hpp"
@@ -95,7 +96,7 @@ public:
 class MockListener : public interface::event_listener,
                      public interface::stat_listener
 {
-    void handle_interface_stat(interface_cmds::stats_enable_cmd *cmd)
+    void handle_interface_stat(const interface& itf)
     {
     }
     void handle_interface_event(std::vector<VOM::interface::event> events)
@@ -251,6 +252,14 @@ public:
                     {
                         rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
                     }
+                    else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::update_cmd))
+                    {
+                       rc = handle_derived<route::ip_mroute_cmds::update_cmd>(f_exp, f_act);
+                    }
+                    else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::delete_cmd))
+                    {
+                        rc = handle_derived<route::ip_mroute_cmds::delete_cmd>(f_exp, f_act);
+                    }
                     else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
                     {
                        rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
@@ -1156,7 +1165,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));
 
@@ -1347,9 +1357,9 @@ BOOST_AUTO_TEST_CASE(test_igmp) {
     const std::string Isaiah = "IsaiahBerlin";
     rc_t rc = rc_t::OK;
 
-    boost::asio::ip::address gaddr = boost::asio::ip::address::from_string("232.0.0.1");
-    boost::asio::ip::address saddr1 = boost::asio::ip::address::from_string("192.168.0.20");
-    boost::asio::ip::address saddr2 = boost::asio::ip::address::from_string("192.168.0.30");
+    boost::asio::ip::address_v4 gaddr = boost::asio::ip::address_v4::from_string("232.0.0.1");
+    boost::asio::ip::address_v4 saddr1 = boost::asio::ip::address_v4::from_string("192.168.0.20");
+    boost::asio::ip::address_v4 saddr2 = boost::asio::ip::address_v4::from_string("192.168.0.30");
 
     std::string itf3_name = "host3";
     interface itf3(itf3_name,
@@ -1722,23 +1732,39 @@ BOOST_AUTO_TEST_CASE(test_routing) {
      * A route via interface 1 in the default table
      */
     route::prefix_t pfx_5("5.5.5.5", 32);
+    boost::asio::ip::address nh_9 = boost::asio::ip::address::from_string("10.10.10.9");
+    route::path *path_9 = new route::path(nh_9, itf1);
     boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
     route::path *path_10 = new route::path(nh_10, itf1);
     route::ip_route *route_5 = new route::ip_route(pfx_5);
     route_5->add(*path_10);
+    route_5->add(*path_9);
     HW::item<bool> hw_route_5(true, rc_t::OK);
-    ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
+    ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_9));
+    ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_10));
+    TRY_CHECK_RC(OM::write(ian, *route_5));
+
+    route_5->remove(*path_9);
+    ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_9));
     TRY_CHECK_RC(OM::write(ian, *route_5));
 
+    delete path_9;
+
     /*
      * A route via interface 2 in the non-default table
      */
     boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
     route::path *path_11 = new route::path(nh_11, *itf2);
+    boost::asio::ip::address nh_12 = boost::asio::ip::address::from_string("11.11.11.12");
+    route::path *path_12 = new route::path(nh_12, *itf2);
     route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
     route_5_2->add(*path_11);
     HW::item<bool> hw_route_5_2(true, rc_t::OK);
-    ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
+    ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_11));
+    TRY_CHECK_RC(OM::write(ian, *route_5_2));
+
+    route_5_2->add(*path_12);
+    ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_12));
     TRY_CHECK_RC(OM::write(ian, *route_5_2));
 
     /*
@@ -1758,9 +1784,29 @@ BOOST_AUTO_TEST_CASE(test_routing) {
     route::ip_route *route_dvr = new route::ip_route(pfx_6);
     route_dvr->add(*path_l2);
     HW::item<bool> hw_route_dvr(true, rc_t::OK);
-    ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
+    ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
     TRY_CHECK_RC(OM::write(ian, *route_dvr));
 
+    /*
+     * a multicast route
+     */
+    route::mprefix_t mpfx_4(boost::asio::ip::address::from_string("232.1.1.1"), 32);
+    route::ip_mroute *mroute_4 = new route::ip_mroute(mpfx_4);
+
+    route::path *mp1 = new route::path(itf1, nh_proto_t::IPV4);
+    route::path *mp2 = new route::path(*itf2, nh_proto_t::IPV4);
+    mroute_4->add(*mp1, route::itf_flags_t::FORWARD);
+    mroute_4->add(*mp1, route::itf_flags_t::ACCEPT);
+    mroute_4->add(*mp2, route::itf_flags_t::FORWARD);
+    HW::item<bool> hw_mroute_4(true, rc_t::OK);
+    ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
+                                                 *mp1, route::itf_flags_t::FORWARD));
+    ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
+                                                 *mp2, route::itf_flags_t::FORWARD));
+    ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
+                                                 *mp1, route::itf_flags_t::ACCEPT));
+    TRY_CHECK_RC(OM::write(ian, *mroute_4));
+
     STRICT_ORDER_OFF();
     // delete the stack objects that hold references to others
     // so the OM::remove is the call that removes the last reference
@@ -1768,16 +1814,32 @@ BOOST_AUTO_TEST_CASE(test_routing) {
     delete l3_10;
     delete itf2;
     delete route_5;
-    delete path_10;
     delete route_5_2;
-    delete path_11;
     delete route_dvr;
-    delete path_l2;
     delete ne;
+    delete mroute_4;
+
+    ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
+                                                 *mp1, route::itf_flags_t::FORWARD));
+    ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
+                                                 *mp2, route::itf_flags_t::FORWARD));
+    ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
+                                                 *mp1, route::itf_flags_t::ACCEPT));
+
+    delete mp1;
+    delete mp2;
+
     ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
-    ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
-    ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
-    ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
+    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));
+    ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_10));
+
+    delete path_10;
+    delete path_11;
+    delete path_12;
+    delete path_l2;
+
     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));