GBP: l3-out subnets
[vpp.git] / extras / vom / vom / gbp_subnet.cpp
index 1bc024d..8404dcd 100644 (file)
@@ -25,36 +25,55 @@ gbp_subnet::type_t::type_t(int v, const std::string s)
 {
 }
 
-const gbp_subnet::type_t gbp_subnet::type_t::INTERNAL(0, "internal");
-const gbp_subnet::type_t gbp_subnet::type_t::EXTERNAL(1, "external");
+const gbp_subnet::type_t gbp_subnet::type_t::STITCHED_INTERNAL(
+  0,
+  "stitched-internal");
+const gbp_subnet::type_t gbp_subnet::type_t::STITCHED_EXTERNAL(
+  1,
+  "stitched-external");
+const gbp_subnet::type_t gbp_subnet::type_t::TRANSPORT(1, "transport");
 
 singular_db<gbp_subnet::key_t, gbp_subnet> gbp_subnet::m_db;
 
 gbp_subnet::event_handler gbp_subnet::m_evh;
 
-gbp_subnet::gbp_subnet(const route_domain& rd, const route::prefix_t& prefix)
+gbp_subnet::gbp_subnet(const gbp_route_domain& rd,
+                       const route::prefix_t& prefix,
+                       const type_t& type)
   : m_hw(false)
   , m_rd(rd.singular())
   , m_prefix(prefix)
-  , m_type(type_t::INTERNAL)
+  , m_type(type)
   , m_recirc(nullptr)
   , m_epg(nullptr)
 {
 }
 
-gbp_subnet::gbp_subnet(const route_domain& rd,
+gbp_subnet::gbp_subnet(const gbp_route_domain& rd,
                        const route::prefix_t& prefix,
                        const gbp_recirc& recirc,
                        const gbp_endpoint_group& epg)
   : m_hw(false)
   , m_rd(rd.singular())
   , m_prefix(prefix)
-  , m_type(type_t::EXTERNAL)
+  , m_type(type_t::STITCHED_EXTERNAL)
   , m_recirc(recirc.singular())
   , m_epg(epg.singular())
 {
 }
 
+gbp_subnet::gbp_subnet(const gbp_route_domain& rd,
+                       const route::prefix_t& prefix,
+                       const gbp_endpoint_group& epg)
+  : m_hw(false)
+  , m_rd(rd.singular())
+  , m_prefix(prefix)
+  , m_type(type_t::L3_OUT)
+  , m_recirc(nullptr)
+  , m_epg(epg.singular())
+{
+}
+
 gbp_subnet::gbp_subnet(const gbp_subnet& o)
   : m_hw(o.m_hw)
   , m_rd(o.m_rd)
@@ -88,8 +107,7 @@ void
 gbp_subnet::sweep()
 {
   if (m_hw) {
-    HW::enqueue(
-      new gbp_subnet_cmds::delete_cmd(m_hw, m_rd->table_id(), m_prefix));
+    HW::enqueue(new gbp_subnet_cmds::delete_cmd(m_hw, m_rd->id(), m_prefix));
   }
   HW::write();
 }
@@ -99,7 +117,7 @@ gbp_subnet::replay()
 {
   if (m_hw) {
     HW::enqueue(new gbp_subnet_cmds::create_cmd(
-      m_hw, m_rd->table_id(), m_prefix, (m_type == type_t::INTERNAL),
+      m_hw, m_rd->id(), m_prefix, m_type,
       (m_recirc ? m_recirc->handle() : handle_t::INVALID),
       (m_epg ? m_epg->id() : ~0)));
   }
@@ -126,7 +144,7 @@ gbp_subnet::update(const gbp_subnet& r)
 {
   if (rc_t::OK != m_hw.rc()) {
     HW::enqueue(new gbp_subnet_cmds::create_cmd(
-      m_hw, m_rd->table_id(), m_prefix, (m_type == type_t::INTERNAL),
+      m_hw, m_rd->id(), m_prefix, m_type,
       (m_recirc ? m_recirc->handle() : handle_t::INVALID),
       (m_epg ? m_epg->id() : ~0)));
   } else {
@@ -136,7 +154,7 @@ gbp_subnet::update(const gbp_subnet& r)
       m_type = r.m_type;
 
       HW::enqueue(new gbp_subnet_cmds::create_cmd(
-        m_hw, m_rd->table_id(), m_prefix, (m_type == type_t::INTERNAL),
+        m_hw, m_rd->id(), m_prefix, m_type,
         (m_recirc ? m_recirc->handle() : handle_t::INVALID),
         (m_epg ? m_epg->id() : ~0)));
     }
@@ -192,27 +210,46 @@ gbp_subnet::event_handler::handle_populate(const client_db::key_t& key)
     auto& payload = record.get_payload();
 
     route::prefix_t pfx = from_api(payload.subnet.prefix);
-    std::shared_ptr<route_domain> rd =
-      route_domain::find(payload.subnet.table_id);
+    std::shared_ptr<gbp_route_domain> rd =
+      gbp_route_domain::find(payload.subnet.rd_id);
 
     if (rd) {
-      if (payload.subnet.is_internal) {
-        gbp_subnet gs(*rd, pfx);
-        OM::commit(key, gs);
-        VOM_LOG(log_level_t::DEBUG) << "read: " << gs.to_string();
-      } else {
-        std::shared_ptr<interface> itf =
-          interface::find(payload.subnet.sw_if_index);
-        std::shared_ptr<gbp_endpoint_group> epg =
-          gbp_endpoint_group::find(payload.subnet.epg_id);
-
-        if (itf && epg) {
-          std::shared_ptr<gbp_recirc> recirc = gbp_recirc::find(itf->key());
-
-          if (recirc) {
-            gbp_subnet gs(*rd, pfx, *recirc, *epg);
-            OM::commit(key, gs);
-            VOM_LOG(log_level_t::DEBUG) << "read: " << gs.to_string();
+      switch (payload.subnet.type) {
+        case GBP_API_SUBNET_TRANSPORT: {
+          gbp_subnet gs(*rd, pfx, type_t::TRANSPORT);
+          OM::commit(key, gs);
+          VOM_LOG(log_level_t::DEBUG) << "read: " << gs.to_string();
+          break;
+        }
+        case GBP_API_SUBNET_STITCHED_INTERNAL: {
+          gbp_subnet gs(*rd, pfx, type_t::STITCHED_INTERNAL);
+          OM::commit(key, gs);
+          VOM_LOG(log_level_t::DEBUG) << "read: " << gs.to_string();
+          break;
+        }
+        case GBP_API_SUBNET_L3_OUT: {
+          std::shared_ptr<gbp_endpoint_group> epg =
+            gbp_endpoint_group::find(payload.subnet.epg_id);
+
+          gbp_subnet gs(*rd, pfx, *epg);
+          OM::commit(key, gs);
+          VOM_LOG(log_level_t::DEBUG) << "read: " << gs.to_string();
+          break;
+        }
+        case GBP_API_SUBNET_STITCHED_EXTERNAL: {
+          std::shared_ptr<interface> itf =
+            interface::find(payload.subnet.sw_if_index);
+          std::shared_ptr<gbp_endpoint_group> epg =
+            gbp_endpoint_group::find(payload.subnet.epg_id);
+
+          if (itf && epg) {
+            std::shared_ptr<gbp_recirc> recirc = gbp_recirc::find(itf->key());
+
+            if (recirc) {
+              gbp_subnet gs(*rd, pfx, *recirc, *epg);
+              OM::commit(key, gs);
+              VOM_LOG(log_level_t::DEBUG) << "read: " << gs.to_string();
+            }
           }
         }
       }
@@ -231,6 +268,15 @@ gbp_subnet::event_handler::show(std::ostream& os)
 {
   db_dump(m_db, os);
 }
+
+std::ostream&
+operator<<(std::ostream& os, const gbp_subnet::key_t& key)
+{
+  os << "[" << key.first << ", " << key.second << "]";
+
+  return os;
+}
+
 } // namespace VOM
 
 /*