GBP: fixes for l3-out routing
[vpp.git] / extras / vom / vom / route.cpp
index c713de9..b136c25 100644 (file)
@@ -47,8 +47,8 @@ path::flags_t::flags_t(int v, const std::string& s)
 }
 
 const itf_flags_t itf_flags_t::NONE(0, "none");
-const itf_flags_t itf_flags_t::ACCEPT((1 << 2), "accept");
-const itf_flags_t itf_flags_t::FORWARD((1 << 3), "forward");
+const itf_flags_t itf_flags_t::ACCEPT((1 << 1), "accept");
+const itf_flags_t itf_flags_t::FORWARD((1 << 2), "forward");
 
 itf_flags_t::itf_flags_t(int v, const std::string& s)
   : enum_base<itf_flags_t>(v, s)
@@ -63,9 +63,9 @@ itf_flags_t::from_vpp(uint32_t val)
     return itf_flags_t::FORWARD;
 }
 
-path::path(special_t special)
+path::path(special_t special, const nh_proto_t& proto)
   : m_type(special)
-  , m_nh_proto(nh_proto_t::IPV4)
+  , m_nh_proto(proto)
   , m_flags(flags_t::NONE)
   , m_nh()
   , m_rd(nullptr)
@@ -339,8 +339,9 @@ void
 ip_route::sweep()
 {
   if (m_hw) {
-    HW::enqueue(
-      new ip_route_cmds::delete_cmd(m_hw, m_rd->table_id(), m_prefix));
+    for (auto& p : m_paths)
+      HW::enqueue(
+        new ip_route_cmds::delete_cmd(m_hw, m_rd->table_id(), m_prefix, p));
   }
   HW::write();
 }
@@ -349,8 +350,9 @@ void
 ip_route::replay()
 {
   if (m_hw) {
-    HW::enqueue(
-      new ip_route_cmds::update_cmd(m_hw, m_rd->table_id(), m_prefix, m_paths));
+    for (auto& p : m_paths)
+      HW::enqueue(
+        new ip_route_cmds::update_cmd(m_hw, m_rd->table_id(), m_prefix, p));
   }
 }
 std::string
@@ -367,12 +369,37 @@ ip_route::to_string() const
 void
 ip_route::update(const ip_route& r)
 {
-  /*
-* create the table if it is not yet created
-*/
   if (rc_t::OK != m_hw.rc()) {
-    HW::enqueue(
-      new ip_route_cmds::update_cmd(m_hw, m_rd->table_id(), m_prefix, m_paths));
+    /*
+     * route not yet installed. install each of the desired paths
+     */
+    m_paths = r.m_paths;
+
+    for (auto& p : m_paths)
+      HW::enqueue(
+        new ip_route_cmds::update_cmd(m_hw, m_rd->table_id(), m_prefix, p));
+  } else {
+    /*
+     * add each path that is not installed yet and remove each that is no longer
+     * wanted
+     */
+    path_list_t to_add;
+    set_difference(r.m_paths.begin(), r.m_paths.end(), m_paths.begin(),
+                   m_paths.end(), std::inserter(to_add, to_add.begin()));
+
+    for (auto& p : to_add)
+      HW::enqueue(
+        new ip_route_cmds::update_cmd(m_hw, m_rd->table_id(), m_prefix, p));
+
+    path_list_t to_del;
+    set_difference(m_paths.begin(), m_paths.end(), r.m_paths.begin(),
+                   r.m_paths.end(), std::inserter(to_del, to_del.begin()));
+
+    for (auto& p : to_del)
+      HW::enqueue(
+        new ip_route_cmds::delete_cmd(m_hw, m_rd->table_id(), m_prefix, p));
+
+    m_paths = r.m_paths;
   }
 }
 
@@ -605,7 +632,8 @@ ip_mroute::dump(std::ostream& os)
 ip_mroute::event_handler::event_handler()
 {
   OM::register_listener(this);
-  inspect::register_handler({ "ip-route" }, "ip route configurations", this);
+  inspect::register_handler({ "ip-mroute" },
+                            "ip multicast route configurations", this);
 }
 
 void
@@ -650,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,
@@ -679,7 +707,7 @@ ip_mroute::event_handler::handle_populate(const client_db::key_t& key)
       ip_r.add(from_vpp(p.path, nh_proto_t::IPV6),
                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,