vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / vom / vom / gbp_subnet.cpp
index 1a9ee86..bc897f1 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #include "vom/gbp_subnet.hpp"
+#include "vom/api_types.hpp"
 #include "vom/gbp_subnet_cmds.hpp"
 #include "vom/singular_db_funcs.hpp"
 
@@ -24,33 +25,58 @@ 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(2, "transport");
+const gbp_subnet::type_t gbp_subnet::type_t::L3_OUT(3, "l3-out");
+const gbp_subnet::type_t gbp_subnet::type_t::ANON_L3_OUT(4, "anon-l3-out");
 
 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)
+  , m_sclass(~0)
 {
 }
 
-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())
+  , m_sclass(~0)
+{
+}
+
+gbp_subnet::gbp_subnet(const gbp_route_domain& rd,
+                       const route::prefix_t& prefix,
+                       sclass_t sclass,
+                       const type_t& type)
+  : m_hw(false)
+  , m_rd(rd.singular())
+  , m_prefix(prefix)
+  , m_type(type)
+  , m_recirc(nullptr)
+  , m_epg()
+  , m_sclass(sclass)
 {
 }
 
@@ -61,6 +87,7 @@ gbp_subnet::gbp_subnet(const gbp_subnet& o)
   , m_type(o.m_type)
   , m_recirc(o.m_recirc)
   , m_epg(o.m_epg)
+  , m_sclass(o.m_sclass)
 {
 }
 
@@ -80,15 +107,15 @@ bool
 gbp_subnet::operator==(const gbp_subnet& gs) const
 {
   return ((key() == gs.key()) && (m_type == gs.m_type) &&
-          (m_recirc == gs.m_recirc) && (m_epg == gs.m_epg));
+          (m_recirc == gs.m_recirc) && (m_epg == gs.m_epg) &&
+          (m_sclass == gs.m_sclass));
 }
 
 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();
 }
@@ -98,9 +125,9 @@ 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)));
+      (m_epg ? m_epg->sclass() : m_sclass)));
   }
 }
 
@@ -125,9 +152,9 @@ 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)));
+      (m_epg ? m_epg->sclass() : m_sclass)));
   } else {
     if (m_type != r.m_type) {
       m_epg = r.m_epg;
@@ -135,9 +162,9 @@ 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)));
+        (m_epg ? m_epg->sclass() : m_sclass)));
     }
   }
 }
@@ -190,29 +217,50 @@ gbp_subnet::event_handler::handle_populate(const client_db::key_t& key)
   for (auto& record : *cmd) {
     auto& payload = record.get_payload();
 
-    route::prefix_t pfx(payload.subnet.is_ip6, payload.subnet.address,
-                        payload.subnet.address_length);
-    std::shared_ptr<route_domain> rd =
-      route_domain::find(payload.subnet.table_id);
+    route::prefix_t pfx = from_api(payload.subnet.prefix);
+    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: {
+          gbp_subnet gs(*rd, pfx, payload.subnet.sclass);
+          OM::commit(key, gs);
+          VOM_LOG(log_level_t::DEBUG) << "read: " << gs.to_string();
+          break;
+        }
+        case GBP_API_SUBNET_ANON_L3_OUT: {
+          gbp_subnet gs(*rd, pfx, payload.subnet.sclass, type_t::ANON_L3_OUT);
+          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.sclass);
+
+          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 +279,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
 
 /*