Fixes for 'make UNATTENDED=yes CC=clang CXX=clang verify'
[vpp.git] / src / vpp-api / vom / route.cpp
index 0da2ebb..247afa0 100644 (file)
@@ -15,7 +15,7 @@
 
 #include "vom/route.hpp"
 #include "vom/route_cmds.hpp"
-#include "vom/singular_db.hpp"
+#include "vom/singular_db_funcs.hpp"
 
 namespace VOM {
 namespace route {
@@ -33,9 +33,18 @@ path::special_t::special_t(int v, const std::string& s)
 {
 }
 
+const path::flags_t path::flags_t::NONE(0, "none");
+const path::flags_t path::flags_t::DVR((1 << 0), "dvr");
+
+path::flags_t::flags_t(int v, const std::string& s)
+  : enum_base<path::flags_t>(v, s)
+{
+}
+
 path::path(special_t special)
   : m_type(special)
   , m_nh_proto(nh_proto_t::IPV4)
+  , m_flags(flags_t::NONE)
   , m_nh()
   , m_rd(nullptr)
   , m_interface(nullptr)
@@ -50,6 +59,7 @@ path::path(const boost::asio::ip::address& nh,
            uint8_t preference)
   : m_type(special_t::STANDARD)
   , m_nh_proto(nh_proto_t::from_address(nh))
+  , m_flags(flags_t::NONE)
   , m_nh(nh)
   , m_rd(nullptr)
   , m_interface(interface.singular())
@@ -64,6 +74,7 @@ path::path(const route_domain& rd,
            uint8_t preference)
   : m_type(special_t::STANDARD)
   , m_nh_proto(nh_proto_t::from_address(nh))
+  , m_flags(flags_t::NONE)
   , m_nh(nh)
   , m_rd(rd.singular())
   , m_interface(nullptr)
@@ -74,10 +85,12 @@ path::path(const route_domain& rd,
 
 path::path(const interface& interface,
            const nh_proto_t& proto,
+           const flags_t& flags,
            uint8_t weight,
            uint8_t preference)
   : m_type(special_t::STANDARD)
   , m_nh_proto(proto)
+  , m_flags(flags)
   , m_nh()
   , m_rd(nullptr)
   , m_interface(interface.singular())
@@ -89,6 +102,7 @@ path::path(const interface& interface,
 path::path(const path& p)
   : m_type(p.m_type)
   , m_nh_proto(p.m_nh_proto)
+  , m_flags(p.m_flags)
   , m_nh(p.m_nh)
   , m_rd(p.m_rd)
   , m_interface(p.m_interface)
@@ -100,6 +114,10 @@ path::path(const path& p)
 bool
 path::operator<(const path& p) const
 {
+  if (m_nh_proto < p.m_nh_proto)
+    return true;
+  if (m_flags < p.m_flags)
+    return true;
   if (m_type < p.m_type)
     return true;
   if (m_rd && !p.m_rd)
@@ -140,7 +158,8 @@ path::operator==(const path& p) const
     return false;
   if (m_interface && p.m_interface)
     result &= (*m_interface == *p.m_interface);
-  return (result && (m_type == p.m_type) && (m_nh == p.m_nh));
+  return (result && (m_type == p.m_type) && (m_nh == p.m_nh) &&
+          (m_nh_proto == p.m_nh_proto) && (m_flags == p.m_flags));
 }
 
 std::string
@@ -150,7 +169,7 @@ path::to_string() const
 
   s << "path:["
     << "type:" << m_type.to_string() << " proto:" << m_nh_proto.to_string()
-    << " neighbour:" << m_nh.to_string();
+    << " flags:" << m_flags.to_string() << " neighbour:" << m_nh.to_string();
   if (m_rd) {
     s << " " << m_rd->to_string();
   }
@@ -175,6 +194,12 @@ path::nh_proto() const
   return m_nh_proto;
 }
 
+path::flags_t
+path::flags() const
+{
+  return m_flags;
+}
+
 const boost::asio::ip::address&
 path::nh() const
 {
@@ -342,7 +367,7 @@ ip_route::singular() const
 void
 ip_route::dump(std::ostream& os)
 {
-  m_db.dump(os);
+  db_dump(m_db, os);
 }
 
 ip_route::event_handler::event_handler()
@@ -360,10 +385,10 @@ ip_route::event_handler::handle_replay()
 void
 ip_route::event_handler::handle_populate(const client_db::key_t& key)
 {
-  std::shared_ptr<ip_route_cmds::dump_v4_cmd> cmd_v4(
-    new ip_route_cmds::dump_v4_cmd());
-  std::shared_ptr<ip_route_cmds::dump_v6_cmd> cmd_v6(
-    new ip_route_cmds::dump_v6_cmd());
+  std::shared_ptr<ip_route_cmds::dump_v4_cmd> cmd_v4 =
+    std::make_shared<ip_route_cmds::dump_v4_cmd>();
+  std::shared_ptr<ip_route_cmds::dump_v6_cmd> cmd_v6 =
+    std::make_shared<ip_route_cmds::dump_v6_cmd>();
 
   HW::enqueue(cmd_v4);
   HW::enqueue(cmd_v6);
@@ -378,7 +403,7 @@ ip_route::event_handler::handle_populate(const client_db::key_t& key)
      * populating the route domain here
      */
     route_domain rd_temp(payload.table_id);
-    std::shared_ptr<route_domain> rd = route_domain::find(rd_temp);
+    std::shared_ptr<route_domain> rd = route_domain::find(payload.table_id);
     if (!rd) {
       OM::commit(key, rd_temp);
     }
@@ -399,10 +424,21 @@ ip_route::event_handler::handle_populate(const client_db::key_t& key)
         path path_v4(path::special_t::PROHIBIT);
         ip_r.add(path_v4);
       } else {
-        std::shared_ptr<interface> itf = interface::find(p.sw_if_index);
         boost::asio::ip::address address = from_bytes(0, p.next_hop);
-        path path_v4(address, *itf, p.weight, p.preference);
-        ip_r.add(path_v4);
+        std::shared_ptr<interface> itf = interface::find(p.sw_if_index);
+        if (itf) {
+          if (p.is_dvr) {
+            path path_v4(*itf, nh_proto_t::IPV4, route::path::flags_t::DVR,
+                         p.weight, p.preference);
+            ip_r.add(path_v4);
+          } else {
+            path path_v4(address, *itf, p.weight, p.preference);
+            ip_r.add(path_v4);
+          }
+        } else {
+          path path_v4(rd_temp, address, p.weight, p.preference);
+          ip_r.add(path_v4);
+        }
       }
     }
     VOM_LOG(log_level_t::DEBUG) << "ip-route-dump: " << ip_r.to_string();
@@ -420,7 +456,7 @@ ip_route::event_handler::handle_populate(const client_db::key_t& key)
 
     prefix_t pfx(1, payload.address, payload.address_length);
     route_domain rd_temp(payload.table_id);
-    std::shared_ptr<route_domain> rd = route_domain::find(rd_temp);
+    std::shared_ptr<route_domain> rd = route_domain::find(payload.table_id);
     if (!rd) {
       OM::commit(key, rd_temp);
     }
@@ -443,8 +479,19 @@ ip_route::event_handler::handle_populate(const client_db::key_t& key)
       } else {
         std::shared_ptr<interface> itf = interface::find(p.sw_if_index);
         boost::asio::ip::address address = from_bytes(1, p.next_hop);
-        path path_v6(address, *itf, p.weight, p.preference);
-        ip_r.add(path_v6);
+        if (itf) {
+          if (p.is_dvr) {
+            path path_v6(*itf, nh_proto_t::IPV6, route::path::flags_t::DVR,
+                         p.weight, p.preference);
+            ip_r.add(path_v6);
+          } else {
+            path path_v6(address, *itf, p.weight, p.preference);
+            ip_r.add(path_v6);
+          }
+        } else {
+          path path_v6(rd_temp, address, p.weight, p.preference);
+          ip_r.add(path_v6);
+        }
       }
     }
     VOM_LOG(log_level_t::DEBUG) << "ip-route-dump: " << ip_r.to_string();
@@ -461,13 +508,13 @@ ip_route::event_handler::handle_populate(const client_db::key_t& key)
 dependency_t
 ip_route::event_handler::order() const
 {
-  return (dependency_t::BINDING);
+  return (dependency_t::ENTRY);
 }
 
 void
 ip_route::event_handler::show(std::ostream& os)
 {
-  m_db.dump(os);
+  db_dump(m_db, os);
 }
 
 std::ostream&