From c905608809c7b0b115a7bcd6aa9a8b34ff8b1f2e Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 14 Feb 2024 00:55:21 +0000 Subject: [PATCH 01/77] [dash] Implement PL API Signed-off-by: Lawrence Lee --- orchagent/dash/dashorch.cpp | 58 ++++++++++++++++++++++++++----- orchagent/dash/dashorch.h | 7 ++-- orchagent/dash/dashvnetorch.cpp | 60 +++++++++++++++++++++++++++++++-- 3 files changed, 111 insertions(+), 14 deletions(-) diff --git a/orchagent/dash/dashorch.cpp b/orchagent/dash/dashorch.cpp index 95dde9f888..d8e6161283 100644 --- a/orchagent/dash/dashorch.cpp +++ b/orchagent/dash/dashorch.cpp @@ -37,6 +37,21 @@ DashOrch::DashOrch(DBConnector *db, vector &tableName, ZmqServer *zmqSer SWSS_LOG_ENTER(); } +bool DashOrch::getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType* route_type) +{ + SWSS_LOG_ENTER(); + + auto it = routing_type_entries_.find(routing_type); + if (it == routing_type_entries_.end()) + { + SWSS_LOG_WARN("Routing type %s not found", dash::route_type::RoutingType_Name(routing_type).c_str()); + return false; + } + + route_type = &it->second; + return true; +} + bool DashOrch::addApplianceEntry(const string& appliance_id, const dash::appliance::Appliance &entry) { SWSS_LOG_ENTER(); @@ -191,34 +206,34 @@ void DashOrch::doTaskApplianceTable(ConsumerBase& consumer) } } -bool DashOrch::addRoutingTypeEntry(const string& routing_type, const dash::route_type::RouteType &entry) +bool DashOrch::addRoutingTypeEntry(const dash::route_type::RoutingType& routing_type, const dash::route_type::RouteType &entry) { SWSS_LOG_ENTER(); if (routing_type_entries_.find(routing_type) != routing_type_entries_.end()) { - SWSS_LOG_WARN("Routing type entry already exists for %s", routing_type.c_str()); + SWSS_LOG_WARN("Routing type entry already exists for %s", dash::route_type::RoutingType_Name(routing_type).c_str()); return true; } routing_type_entries_[routing_type] = entry; - SWSS_LOG_NOTICE("Routing type entry added %s", routing_type.c_str()); + SWSS_LOG_NOTICE("Routing type entry added %s", dash::route_type::RoutingType_Name(routing_type).c_str()); return true; } -bool DashOrch::removeRoutingTypeEntry(const string& routing_type) +bool DashOrch::removeRoutingTypeEntry(const dash::route_type::RoutingType& routing_type) { SWSS_LOG_ENTER(); if (routing_type_entries_.find(routing_type) == routing_type_entries_.end()) { - SWSS_LOG_WARN("Routing type entry does not exist for %s", routing_type.c_str()); + SWSS_LOG_WARN("Routing type entry does not exist for %s", dash::route_type::RoutingType_Name(routing_type).c_str()); return true; } routing_type_entries_.erase(routing_type); - SWSS_LOG_NOTICE("Routing type entry removed for %s", routing_type.c_str()); + SWSS_LOG_NOTICE("Routing type entry removed for %s", dash::route_type::RoutingType_Name(routing_type).c_str()); return true; } @@ -231,8 +246,16 @@ void DashOrch::doTaskRoutingTypeTable(ConsumerBase& consumer) while (it != consumer.m_toSync.end()) { KeyOpFieldsValuesTuple t = it->second; - string routing_type = kfvKey(t); + string routing_type_str = kfvKey(t); string op = kfvOp(t); + dash::route_type::RoutingType routing_type; + + if (!dash::route_type::RoutingType_Parse(routing_type_str, &routing_type)) + { + SWSS_LOG_WARN("Invalid routing type %s", routing_type_str.c_str()); + it = consumer.m_toSync.erase(it); + continue; + } if (op == SET_COMMAND) { @@ -240,7 +263,7 @@ void DashOrch::doTaskRoutingTypeTable(ConsumerBase& consumer) if (!parsePbMessage(kfvFieldsValues(t), entry)) { - SWSS_LOG_WARN("Requires protobuff at routing type :%s", routing_type.c_str()); + SWSS_LOG_WARN("Requires protobuff at routing type :%s", routing_type_str.c_str()); it = consumer.m_toSync.erase(it); continue; } @@ -356,6 +379,25 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry) eni_attr.value.u32 = app_entry.vm_vni(); eni_attrs.push_back(eni_attr); + if (entry.metadata.has_pl_sip_encoding()) + { + + eni_attr.id = SAI_ENI_ATTR_PL_SIP; + to_sai(entry.metadata.pl_sip_encoding().ip(), eni_attr.value.ipaddr); + eni_attrs.push_back(eni_attr); + + eni_attr.id = SAI_ENI_ATTR_PL_SIP_MASK; + to_sai(entry.metadata.pl_sip_encoding().mask(), eni_attr.value.ipaddr); + eni_attrs.push_back(eni_attr); + } + + if (entry.metadata.has_pl_underlay_sip()) + { + eni_attr.id = SAI_ENI_ATTR_PL_UNDERLAY_SIP; + to_sai(entry.metadata.pl_underlay_sip(), eni_attr.value.ipaddr); + eni_attrs.push_back(eni_attr); + } + sai_status_t status = sai_dash_eni_api->create_eni(&eni_id, gSwitchId, (uint32_t)eni_attrs.size(), eni_attrs.data()); if (status != SAI_STATUS_SUCCESS) diff --git a/orchagent/dash/dashorch.h b/orchagent/dash/dashorch.h index eca365225c..c0df0a4ad4 100644 --- a/orchagent/dash/dashorch.h +++ b/orchagent/dash/dashorch.h @@ -30,7 +30,7 @@ struct EniEntry }; typedef std::map ApplianceTable; -typedef std::map RoutingTypeTable; +typedef std::map RoutingTypeTable; typedef std::map EniTable; typedef std::map QosTable; @@ -39,6 +39,7 @@ class DashOrch : public ZmqOrch public: DashOrch(swss::DBConnector *db, std::vector &tables, swss::ZmqServer *zmqServer); const EniEntry *getEni(const std::string &eni) const; + bool getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType* route_type); private: ApplianceTable appliance_entries_; @@ -52,8 +53,8 @@ class DashOrch : public ZmqOrch void doTaskQosTable(ConsumerBase &consumer); bool addApplianceEntry(const std::string& appliance_id, const dash::appliance::Appliance &entry); bool removeApplianceEntry(const std::string& appliance_id); - bool addRoutingTypeEntry(const std::string& routing_type, const dash::route_type::RouteType &entry); - bool removeRoutingTypeEntry(const std::string& routing_type); + bool addRoutingTypeEntry(const dash::route_type::RoutingType &routing_type, const dash::route_type::RouteType &entry); + bool removeRoutingTypeEntry(const dash::route_type::RoutingType &routing_type); bool addEniObject(const std::string& eni, EniEntry& entry); bool addEniAddrMapEntry(const std::string& eni, const EniEntry& entry); bool addEni(const std::string& eni, EniEntry &entry); diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index e06f1b1e38..a8c0b058e7 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -20,6 +20,7 @@ #include "dashorch.h" #include "crmorch.h" #include "saihelper.h" +#include "directory.h" #include "taskworker.h" #include "pbutils.h" @@ -34,6 +35,7 @@ extern sai_dash_pa_validation_api_t* sai_dash_pa_validation_api; extern sai_object_id_t gSwitchId; extern size_t gMaxBulkSize; extern CrmOrch *gCrmOrch; +extern Directory gDirectory; DashVnetOrch::DashVnetOrch(DBConnector *db, vector &tables, ZmqServer *zmqServer) : vnet_bulker_(sai_dash_vnet_api, gSwitchId, gMaxBulkSize), @@ -283,10 +285,62 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt auto& object_statuses = ctxt.outbound_ca_to_pa_object_statuses; sai_attribute_t outbound_ca_to_pa_attr; vector outbound_ca_to_pa_attrs; + + DashOrch* dash_orch = gDirectory.get(); + dash::route_type::RouteType route_type_actions; + if (!dash_orch->getRouteTypeActions(ctxt.metadata.action_type(), &route_type_actions)) + { + SWSS_LOG_ERROR("Failed to get route type actions for %s", key.c_str()); + return; + } - outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_UNDERLAY_DIP; - to_sai(ctxt.metadata.underlay_ip(), outbound_ca_to_pa_attr.value.ipaddr); - outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + for (auto action: route_type_actions.items()) + { + if (action.action_type() == dash::route_type::ACTION_TYPE_4_to_6) + { + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION; + outbound_ca_to_pa_attr.value.u32 = SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING; + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + } + + if (action.action_type() == dash::route_type::ACTION_TYPE_STATICENCAP) + { + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION; + if (action.encap_type() == dash::route_type::ENCAP_TYPE_VXLAN) + { + outbound_ca_to_pa_attr.value.u32 = SAI_DASH_ENCAPSULATION_VXLAN; + } + else if (action.encap_type() == dash::route_type::ENCAP_TYPE_NVGRE) + { + outbound_ca_to_pa_attr.value.u32 = SAI_DASH_ENCAPSULATION_NVGRE; + } + else + { + SWSS_LOG_ERROR("Invalid encap type %d for %s", action.encap_type(), key.c_str()); + return; + } + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY; + outbound_ca_to_pa_attr.value.u32 = action.vni(); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + } + } + + if (ctxt.metadata.action_type() == dash::route_type::ROUTING_TYPE_PRIVATELINK) + { + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_UNDERLAY_DIP; + to_sai(ctxt.metadata.underlay_ip(), outbound_ca_to_pa_attr.value.ipaddr); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP; + to_sai(ctxt.metadata.overlay_dip(), outbound_ca_to_pa_attr.value.ipaddr); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP; + to_sai(ctxt.metadata.overlay_sip(), outbound_ca_to_pa_attr.value.ipaddr); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + } outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DMAC; memcpy(outbound_ca_to_pa_attr.value.mac, ctxt.metadata.mac_address().c_str(), sizeof(sai_mac_t)); From 3ab9137f2d7c50e8155853e4bd8c79a389a9573f Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 14 Feb 2024 01:10:17 +0000 Subject: [PATCH 02/77] fix parameter use Signed-off-by: Lawrence Lee --- orchagent/dash/dashorch.cpp | 4 ++-- orchagent/dash/dashorch.h | 2 +- orchagent/dash/dashvnetorch.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/orchagent/dash/dashorch.cpp b/orchagent/dash/dashorch.cpp index d8e6161283..144ee4f80e 100644 --- a/orchagent/dash/dashorch.cpp +++ b/orchagent/dash/dashorch.cpp @@ -37,7 +37,7 @@ DashOrch::DashOrch(DBConnector *db, vector &tableName, ZmqServer *zmqSer SWSS_LOG_ENTER(); } -bool DashOrch::getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType* route_type) +bool DashOrch::getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType& route_type) { SWSS_LOG_ENTER(); @@ -48,7 +48,7 @@ bool DashOrch::getRouteTypeActions(dash::route_type::RoutingType routing_type, d return false; } - route_type = &it->second; + route_type = it->second; return true; } diff --git a/orchagent/dash/dashorch.h b/orchagent/dash/dashorch.h index c0df0a4ad4..445f9db464 100644 --- a/orchagent/dash/dashorch.h +++ b/orchagent/dash/dashorch.h @@ -39,7 +39,7 @@ class DashOrch : public ZmqOrch public: DashOrch(swss::DBConnector *db, std::vector &tables, swss::ZmqServer *zmqServer); const EniEntry *getEni(const std::string &eni) const; - bool getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType* route_type); + bool getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType& route_type); private: ApplianceTable appliance_entries_; diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index a8c0b058e7..9b634e479a 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -288,7 +288,7 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt DashOrch* dash_orch = gDirectory.get(); dash::route_type::RouteType route_type_actions; - if (!dash_orch->getRouteTypeActions(ctxt.metadata.action_type(), &route_type_actions)) + if (!dash_orch->getRouteTypeActions(ctxt.metadata.action_type(), route_type_actions)) { SWSS_LOG_ERROR("Failed to get route type actions for %s", key.c_str()); return; From 01792721dae713b725980a17505dd599b37b5476 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 14 Feb 2024 00:55:21 +0000 Subject: [PATCH 03/77] [dash] Implement PL API Signed-off-by: Lawrence Lee --- orchagent/dash/dashorch.cpp | 58 ++++++++++++++++++++++++++----- orchagent/dash/dashorch.h | 7 ++-- orchagent/dash/dashvnetorch.cpp | 60 +++++++++++++++++++++++++++++++-- 3 files changed, 111 insertions(+), 14 deletions(-) diff --git a/orchagent/dash/dashorch.cpp b/orchagent/dash/dashorch.cpp index 95dde9f888..d8e6161283 100644 --- a/orchagent/dash/dashorch.cpp +++ b/orchagent/dash/dashorch.cpp @@ -37,6 +37,21 @@ DashOrch::DashOrch(DBConnector *db, vector &tableName, ZmqServer *zmqSer SWSS_LOG_ENTER(); } +bool DashOrch::getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType* route_type) +{ + SWSS_LOG_ENTER(); + + auto it = routing_type_entries_.find(routing_type); + if (it == routing_type_entries_.end()) + { + SWSS_LOG_WARN("Routing type %s not found", dash::route_type::RoutingType_Name(routing_type).c_str()); + return false; + } + + route_type = &it->second; + return true; +} + bool DashOrch::addApplianceEntry(const string& appliance_id, const dash::appliance::Appliance &entry) { SWSS_LOG_ENTER(); @@ -191,34 +206,34 @@ void DashOrch::doTaskApplianceTable(ConsumerBase& consumer) } } -bool DashOrch::addRoutingTypeEntry(const string& routing_type, const dash::route_type::RouteType &entry) +bool DashOrch::addRoutingTypeEntry(const dash::route_type::RoutingType& routing_type, const dash::route_type::RouteType &entry) { SWSS_LOG_ENTER(); if (routing_type_entries_.find(routing_type) != routing_type_entries_.end()) { - SWSS_LOG_WARN("Routing type entry already exists for %s", routing_type.c_str()); + SWSS_LOG_WARN("Routing type entry already exists for %s", dash::route_type::RoutingType_Name(routing_type).c_str()); return true; } routing_type_entries_[routing_type] = entry; - SWSS_LOG_NOTICE("Routing type entry added %s", routing_type.c_str()); + SWSS_LOG_NOTICE("Routing type entry added %s", dash::route_type::RoutingType_Name(routing_type).c_str()); return true; } -bool DashOrch::removeRoutingTypeEntry(const string& routing_type) +bool DashOrch::removeRoutingTypeEntry(const dash::route_type::RoutingType& routing_type) { SWSS_LOG_ENTER(); if (routing_type_entries_.find(routing_type) == routing_type_entries_.end()) { - SWSS_LOG_WARN("Routing type entry does not exist for %s", routing_type.c_str()); + SWSS_LOG_WARN("Routing type entry does not exist for %s", dash::route_type::RoutingType_Name(routing_type).c_str()); return true; } routing_type_entries_.erase(routing_type); - SWSS_LOG_NOTICE("Routing type entry removed for %s", routing_type.c_str()); + SWSS_LOG_NOTICE("Routing type entry removed for %s", dash::route_type::RoutingType_Name(routing_type).c_str()); return true; } @@ -231,8 +246,16 @@ void DashOrch::doTaskRoutingTypeTable(ConsumerBase& consumer) while (it != consumer.m_toSync.end()) { KeyOpFieldsValuesTuple t = it->second; - string routing_type = kfvKey(t); + string routing_type_str = kfvKey(t); string op = kfvOp(t); + dash::route_type::RoutingType routing_type; + + if (!dash::route_type::RoutingType_Parse(routing_type_str, &routing_type)) + { + SWSS_LOG_WARN("Invalid routing type %s", routing_type_str.c_str()); + it = consumer.m_toSync.erase(it); + continue; + } if (op == SET_COMMAND) { @@ -240,7 +263,7 @@ void DashOrch::doTaskRoutingTypeTable(ConsumerBase& consumer) if (!parsePbMessage(kfvFieldsValues(t), entry)) { - SWSS_LOG_WARN("Requires protobuff at routing type :%s", routing_type.c_str()); + SWSS_LOG_WARN("Requires protobuff at routing type :%s", routing_type_str.c_str()); it = consumer.m_toSync.erase(it); continue; } @@ -356,6 +379,25 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry) eni_attr.value.u32 = app_entry.vm_vni(); eni_attrs.push_back(eni_attr); + if (entry.metadata.has_pl_sip_encoding()) + { + + eni_attr.id = SAI_ENI_ATTR_PL_SIP; + to_sai(entry.metadata.pl_sip_encoding().ip(), eni_attr.value.ipaddr); + eni_attrs.push_back(eni_attr); + + eni_attr.id = SAI_ENI_ATTR_PL_SIP_MASK; + to_sai(entry.metadata.pl_sip_encoding().mask(), eni_attr.value.ipaddr); + eni_attrs.push_back(eni_attr); + } + + if (entry.metadata.has_pl_underlay_sip()) + { + eni_attr.id = SAI_ENI_ATTR_PL_UNDERLAY_SIP; + to_sai(entry.metadata.pl_underlay_sip(), eni_attr.value.ipaddr); + eni_attrs.push_back(eni_attr); + } + sai_status_t status = sai_dash_eni_api->create_eni(&eni_id, gSwitchId, (uint32_t)eni_attrs.size(), eni_attrs.data()); if (status != SAI_STATUS_SUCCESS) diff --git a/orchagent/dash/dashorch.h b/orchagent/dash/dashorch.h index eca365225c..c0df0a4ad4 100644 --- a/orchagent/dash/dashorch.h +++ b/orchagent/dash/dashorch.h @@ -30,7 +30,7 @@ struct EniEntry }; typedef std::map ApplianceTable; -typedef std::map RoutingTypeTable; +typedef std::map RoutingTypeTable; typedef std::map EniTable; typedef std::map QosTable; @@ -39,6 +39,7 @@ class DashOrch : public ZmqOrch public: DashOrch(swss::DBConnector *db, std::vector &tables, swss::ZmqServer *zmqServer); const EniEntry *getEni(const std::string &eni) const; + bool getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType* route_type); private: ApplianceTable appliance_entries_; @@ -52,8 +53,8 @@ class DashOrch : public ZmqOrch void doTaskQosTable(ConsumerBase &consumer); bool addApplianceEntry(const std::string& appliance_id, const dash::appliance::Appliance &entry); bool removeApplianceEntry(const std::string& appliance_id); - bool addRoutingTypeEntry(const std::string& routing_type, const dash::route_type::RouteType &entry); - bool removeRoutingTypeEntry(const std::string& routing_type); + bool addRoutingTypeEntry(const dash::route_type::RoutingType &routing_type, const dash::route_type::RouteType &entry); + bool removeRoutingTypeEntry(const dash::route_type::RoutingType &routing_type); bool addEniObject(const std::string& eni, EniEntry& entry); bool addEniAddrMapEntry(const std::string& eni, const EniEntry& entry); bool addEni(const std::string& eni, EniEntry &entry); diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index e06f1b1e38..a8c0b058e7 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -20,6 +20,7 @@ #include "dashorch.h" #include "crmorch.h" #include "saihelper.h" +#include "directory.h" #include "taskworker.h" #include "pbutils.h" @@ -34,6 +35,7 @@ extern sai_dash_pa_validation_api_t* sai_dash_pa_validation_api; extern sai_object_id_t gSwitchId; extern size_t gMaxBulkSize; extern CrmOrch *gCrmOrch; +extern Directory gDirectory; DashVnetOrch::DashVnetOrch(DBConnector *db, vector &tables, ZmqServer *zmqServer) : vnet_bulker_(sai_dash_vnet_api, gSwitchId, gMaxBulkSize), @@ -283,10 +285,62 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt auto& object_statuses = ctxt.outbound_ca_to_pa_object_statuses; sai_attribute_t outbound_ca_to_pa_attr; vector outbound_ca_to_pa_attrs; + + DashOrch* dash_orch = gDirectory.get(); + dash::route_type::RouteType route_type_actions; + if (!dash_orch->getRouteTypeActions(ctxt.metadata.action_type(), &route_type_actions)) + { + SWSS_LOG_ERROR("Failed to get route type actions for %s", key.c_str()); + return; + } - outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_UNDERLAY_DIP; - to_sai(ctxt.metadata.underlay_ip(), outbound_ca_to_pa_attr.value.ipaddr); - outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + for (auto action: route_type_actions.items()) + { + if (action.action_type() == dash::route_type::ACTION_TYPE_4_to_6) + { + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION; + outbound_ca_to_pa_attr.value.u32 = SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING; + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + } + + if (action.action_type() == dash::route_type::ACTION_TYPE_STATICENCAP) + { + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION; + if (action.encap_type() == dash::route_type::ENCAP_TYPE_VXLAN) + { + outbound_ca_to_pa_attr.value.u32 = SAI_DASH_ENCAPSULATION_VXLAN; + } + else if (action.encap_type() == dash::route_type::ENCAP_TYPE_NVGRE) + { + outbound_ca_to_pa_attr.value.u32 = SAI_DASH_ENCAPSULATION_NVGRE; + } + else + { + SWSS_LOG_ERROR("Invalid encap type %d for %s", action.encap_type(), key.c_str()); + return; + } + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY; + outbound_ca_to_pa_attr.value.u32 = action.vni(); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + } + } + + if (ctxt.metadata.action_type() == dash::route_type::ROUTING_TYPE_PRIVATELINK) + { + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_UNDERLAY_DIP; + to_sai(ctxt.metadata.underlay_ip(), outbound_ca_to_pa_attr.value.ipaddr); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP; + to_sai(ctxt.metadata.overlay_dip(), outbound_ca_to_pa_attr.value.ipaddr); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP; + to_sai(ctxt.metadata.overlay_sip(), outbound_ca_to_pa_attr.value.ipaddr); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + } outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DMAC; memcpy(outbound_ca_to_pa_attr.value.mac, ctxt.metadata.mac_address().c_str(), sizeof(sai_mac_t)); From 8bd8a0e7803675c01369eadc489a302052358367 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 14 Feb 2024 01:10:17 +0000 Subject: [PATCH 04/77] fix parameter use Signed-off-by: Lawrence Lee --- orchagent/dash/dashorch.cpp | 4 ++-- orchagent/dash/dashorch.h | 2 +- orchagent/dash/dashvnetorch.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/orchagent/dash/dashorch.cpp b/orchagent/dash/dashorch.cpp index d8e6161283..144ee4f80e 100644 --- a/orchagent/dash/dashorch.cpp +++ b/orchagent/dash/dashorch.cpp @@ -37,7 +37,7 @@ DashOrch::DashOrch(DBConnector *db, vector &tableName, ZmqServer *zmqSer SWSS_LOG_ENTER(); } -bool DashOrch::getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType* route_type) +bool DashOrch::getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType& route_type) { SWSS_LOG_ENTER(); @@ -48,7 +48,7 @@ bool DashOrch::getRouteTypeActions(dash::route_type::RoutingType routing_type, d return false; } - route_type = &it->second; + route_type = it->second; return true; } diff --git a/orchagent/dash/dashorch.h b/orchagent/dash/dashorch.h index c0df0a4ad4..445f9db464 100644 --- a/orchagent/dash/dashorch.h +++ b/orchagent/dash/dashorch.h @@ -39,7 +39,7 @@ class DashOrch : public ZmqOrch public: DashOrch(swss::DBConnector *db, std::vector &tables, swss::ZmqServer *zmqServer); const EniEntry *getEni(const std::string &eni) const; - bool getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType* route_type); + bool getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType& route_type); private: ApplianceTable appliance_entries_; diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index a8c0b058e7..9b634e479a 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -288,7 +288,7 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt DashOrch* dash_orch = gDirectory.get(); dash::route_type::RouteType route_type_actions; - if (!dash_orch->getRouteTypeActions(ctxt.metadata.action_type(), &route_type_actions)) + if (!dash_orch->getRouteTypeActions(ctxt.metadata.action_type(), route_type_actions)) { SWSS_LOG_ERROR("Failed to get route type actions for %s", key.c_str()); return; From ad81039276852c95cf1fb38a5576addd8a9fe319 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 14 Feb 2024 02:59:39 +0000 Subject: [PATCH 05/77] fix routing_type parsing Signed-off-by: Lawrence Lee --- orchagent/dash/dashorch.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/orchagent/dash/dashorch.cpp b/orchagent/dash/dashorch.cpp index 144ee4f80e..81f67df9f2 100644 --- a/orchagent/dash/dashorch.cpp +++ b/orchagent/dash/dashorch.cpp @@ -250,6 +250,9 @@ void DashOrch::doTaskRoutingTypeTable(ConsumerBase& consumer) string op = kfvOp(t); dash::route_type::RoutingType routing_type; + std::transform(routing_type_str.begin(), routing_type_str.end(), routing_type_str.begin(), ::toupper); + routing_type_str = "ROUTING_TYPE_" + routing_type_str; + if (!dash::route_type::RoutingType_Parse(routing_type_str, &routing_type)) { SWSS_LOG_WARN("Invalid routing type %s", routing_type_str.c_str()); From 1a7685d04015bb0d71495521e99f1c95d5a1be0a Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 14 Feb 2024 22:02:04 +0000 Subject: [PATCH 06/77] Set routing type table in dash_vnet test Signed-off-by: Lawrence Lee --- tests/test_dash_vnet.py | 152 ++++------------------------------------ 1 file changed, 15 insertions(+), 137 deletions(-) diff --git a/tests/test_dash_vnet.py b/tests/test_dash_vnet.py index 031fd7a0ef..950baff983 100644 --- a/tests/test_dash_vnet.py +++ b/tests/test_dash_vnet.py @@ -1,5 +1,3 @@ -from swsscommon import swsscommon - from dash_api.appliance_pb2 import * from dash_api.vnet_pb2 import * from dash_api.eni_pb2 import * @@ -9,138 +7,19 @@ from dash_api.route_type_pb2 import * from dash_api.types_pb2 import * -import typing +from dash_utils import DashDB + import time -import binascii import uuid import ipaddress -import sys import socket - DVS_ENV = ["HWSKU=DPU-2P"] NUM_PORTS = 2 -def to_string(value): - if isinstance(value, bool): - return "true" if value else "false" - elif isinstance(value, bytes): - return value - return str(value) - - -class ProduceStateTable(object): - def __init__(self, database, table_name: str): - self.table = swsscommon.ProducerStateTable( - database.db_connection, - table_name) - - def __setitem__(self, key: str, pairs: typing.Union[dict, list, tuple]): - pairs_str = [] - if isinstance(pairs, dict): - pairs = pairs.items() - for k, v in pairs: - pairs_str.append((to_string(k), to_string(v))) - self.table.set(key, pairs_str) - - def __delitem__(self, key: str): - self.table.delete(str(key)) - - -class Table(object): - def __init__(self, database, table_name: str): - self.table_name = table_name - self.table = swsscommon.Table(database.db_connection, self.table_name) - - def __getitem__(self, key: str): - exists, result = self.table.get(str(key)) - if not exists: - return None - else: - return dict(result) - - def get_keys(self): - return self.table.getKeys() - - def get_newly_created_oid(self, old_oids): - new_oids = self.asic_db.wait_for_n_keys(table, len(old_oids) + 1) - oid = [ids for ids in new_oids if ids not in old_oids] - return oid[0] - - -class Dash(object): - def __init__(self, dvs): - self.dvs = dvs - self.app_dash_appliance_table = ProduceStateTable( - self.dvs.get_app_db(), "DASH_APPLIANCE_TABLE") - self.asic_direction_lookup_table = Table( - self.dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_DIRECTION_LOOKUP_ENTRY") - self.asic_vip_table = Table( - self.dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_VIP_ENTRY") - self.app_dash_vnet_table = ProduceStateTable( - self.dvs.get_app_db(), "DASH_VNET_TABLE") - self.asic_dash_vnet_table = Table( - self.dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_VNET") - self.app_dash_eni_table = ProduceStateTable( - self.dvs.get_app_db(), "DASH_ENI_TABLE") - self.asic_eni_table = Table( - self.dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_ENI") - self.asic_eni_ether_addr_map_table = Table( - self.dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_ENI_ETHER_ADDRESS_MAP_ENTRY") - self.app_dash_vnet_map_table = ProduceStateTable( - self.dvs.get_app_db(), "DASH_VNET_MAPPING_TABLE") - self.asic_dash_outbound_ca_to_pa_table = Table( - self.dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_CA_TO_PA_ENTRY") - self.asic_pa_validation_table = Table( - self.dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_PA_VALIDATION_ENTRY") - self.app_dash_route_table = ProduceStateTable( - self.dvs.get_app_db(), "DASH_ROUTE_TABLE") - self.app_dash_route_rule_table = ProduceStateTable( - self.dvs.get_app_db(), "DASH_ROUTE_RULE_TABLE") - self.asic_outbound_routing_table = Table( - self.dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY") - self.asic_inbound_routing_rule_table = Table( - self.dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_INBOUND_ROUTING_ENTRY") - - def create_appliance(self, appliance_id, attr_maps: dict): - self.app_dash_appliance_table[str(appliance_id)] = attr_maps - - def remove_appliance(self, appliance_id): - del self.app_dash_appliance_table[str(appliance_id)] - - def create_vnet(self, vnet, attr_maps: dict): - self.app_dash_vnet_table[str(vnet)] = attr_maps - - def remove_vnet(self, vnet): - del self.app_dash_vnet_table[str(vnet)] - - def create_eni(self, eni, attr_maps: dict): - self.app_dash_eni_table[str(eni)] = attr_maps - - def remove_eni(self, eni): - del self.app_dash_eni_table[str(eni)] - - def create_vnet_map(self, vnet, ip, attr_maps: dict): - self.app_dash_vnet_map_table[str(vnet) + ":" + str(ip)] = attr_maps - - def remove_vnet_map(self, vnet, ip): - del self.app_dash_vnet_map_table[str(vnet) + ":" + str(ip)] - - def create_outbound_routing(self, mac_string, ip, attr_maps: dict): - self.app_dash_route_table[str(mac_string) + ":" + str(ip)] = attr_maps - - def remove_outbound_routing(self, mac_string, ip): - del self.app_dash_route_table[str(mac_string) + ":" + str(ip)] - - def create_inbound_routing(self, mac_string, vni, ip, attr_maps: dict): - self.app_dash_route_rule_table[str(mac_string) + ":" + str(vni) + ":" + str(ip)] = attr_maps - - def remove_inbound_routing(self, mac_string, vni, ip): - del self.app_dash_route_rule_table[str(mac_string) + ":" + str(vni) + ":" + str(ip)] - class TestDash(object): def test_appliance(self, dvs): - dashobj = Dash(dvs) + dashobj = DashDB(dvs) self.appliance_id = "100" self.sip = "10.0.0.1" self.vm_vni = "4321" @@ -162,10 +41,9 @@ def test_appliance(self, dvs): for fv in fvs.items(): if fv[0] == "SAI_VIP_ENTRY_ATTR_ACTION": assert fv[1] == "SAI_VIP_ENTRY_ACTION_ACCEPT" - return dashobj def test_vnet(self, dvs): - dashobj = Dash(dvs) + dashobj = DashDB(dvs) self.vnet = "Vnet1" self.vni = "45654" self.guid = "559c6ce8-26ab-4193-b946-ccc6e8f930b2" @@ -179,10 +57,9 @@ def test_vnet(self, dvs): self.vnet_oid = vnets[0] vnet_attr = dashobj.asic_dash_vnet_table[self.vnet_oid] assert vnet_attr["SAI_VNET_ATTR_VNI"] == "45654" - return dashobj def test_eni(self, dvs): - dashobj = Dash(dvs) + dashobj = DashDB(dvs) self.vnet = "Vnet1" self.mac_string = "F4939FEFC47E" self.mac_address = "F4:93:9F:EF:C4:7E" @@ -223,16 +100,21 @@ def test_eni(self, dvs): for fv in fvs.items(): if fv[0] == "SAI_ENI_ETHER_ADDRESS_MAP_ENTRY_ATTR_ENI_ID": assert fv[1] == str(self.eni_oid) - return dashobj def test_vnet_map(self, dvs): - dashobj = Dash(dvs) + dashobj = DashDB(dvs) self.vnet = "Vnet1" self.ip1 = "10.1.1.1" self.ip2 = "10.1.1.2" self.mac_address = "F4:93:9F:EF:C4:7E" self.routing_type = "vnet_encap" self.underlay_ip = "101.1.2.3" + route_type_msg = RouteType() + route_action = RouteTypeItem() + route_action.action_name = "action1" + route_action.action_type = ACTION_TYPE_MAPROUTING + route_type_msg.items.append(route_action) + dashobj.create_routing_type(self.routing_type, {"pb": route_type_msg.SerializeToString()}) pb = VnetMapping() pb.mac_address = bytes.fromhex(self.mac_address.replace(":", "")) pb.action_type = RoutingType.ROUTING_TYPE_VNET_ENCAP @@ -257,10 +139,9 @@ def test_vnet_map(self, dvs): for fv in fvs.items(): if fv[0] == "SAI_PA_VALIDATION_ENTRY_ATTR_ACTION": assert fv[1] == "SAI_PA_VALIDATION_ENTRY_ACTION_PERMIT" - return dashobj def test_outbound_routing(self, dvs): - dashobj = Dash(dvs) + dashobj = DashDB(dvs) self.vnet = "Vnet1" self.mac_string = "F4939FEFC47E" self.ip = "10.1.0.0/24" @@ -282,10 +163,9 @@ def test_outbound_routing(self, dvs): if fv[0] == "SAI_OUTBOUND_ROUTING_ENTRY_ATTR_OVERLAY_IP": assert fv[1] == "10.0.0.6" assert "SAI_OUTBOUND_ROUTING_ENTRY_ATTR_DST_VNET_ID" in fvs - return dashobj def test_inbound_routing(self, dvs): - dashobj = Dash(dvs) + dashobj = DashDB(dvs) self.mac_string = "F4939FEFC47E" self.vnet = "Vnet1" self.vni = "3251" @@ -295,7 +175,6 @@ def test_inbound_routing(self, dvs): self.priority = "1" self.protocol = "0" pb = RouteRule() -# pb.action_type = RoutingType.ROUTING_TYPE_DECAP pb.pa_validation = True pb.priority = int(self.priority) pb.protocol = int(self.protocol) @@ -310,10 +189,9 @@ def test_inbound_routing(self, dvs): for fv in fvs.items(): if fv[0] == "SAI_INBOUND_ROUTING_ENTRY_ATTR_ACTION": assert fv[1] == "SAI_INBOUND_ROUTING_ENTRY_ACTION_VXLAN_DECAP_PA_VALIDATE" - return dashobj def test_cleanup(self, dvs): - dashobj = Dash(dvs) + dashobj = DashDB(dvs) self.vnet = "Vnet1" self.mac_string = "F4939FEFC47E" self.vni = "3251" From 11e374e3424b410342eead6857b0a8015810c434 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 14 Feb 2024 22:13:56 +0000 Subject: [PATCH 07/77] add VS test for PL Signed-off-by: Lawrence Lee --- tests/dash_utils.py | 122 +++++++++++++++++++++++++++++++ tests/sai_attrs.py | 11 +++ tests/test_dash_pl.py | 154 ++++++++++++++++++++++++++++++++++++++++ tests/test_dash_vnet.py | 89 +++++++++++------------ 4 files changed, 328 insertions(+), 48 deletions(-) create mode 100644 tests/dash_utils.py create mode 100644 tests/sai_attrs.py create mode 100644 tests/test_dash_pl.py diff --git a/tests/dash_utils.py b/tests/dash_utils.py new file mode 100644 index 0000000000..971ab589d6 --- /dev/null +++ b/tests/dash_utils.py @@ -0,0 +1,122 @@ +from swsscommon import swsscommon +import typing +import pytest + +@pytest.fixture(scope='module') +def dash_db(dvs): + return DashDB(dvs) + +def to_string(value): + if isinstance(value, bool): + return "true" if value else "false" + elif isinstance(value, bytes): + return value + return str(value) + +class ProducerStateTable(swsscommon.ProducerStateTable): + def __setitem__(self, key: str, pairs: typing.Union[dict, list, tuple]): + pairs_str = [] + if isinstance(pairs, dict): + pairs = pairs.items() + for k, v in pairs: + pairs_str.append((to_string(k), to_string(v))) + self.set(key, pairs_str) + + def __delitem__(self, key: str): + self.delete(str(key)) + + +class Table(swsscommon.Table): + def __getitem__(self, key: str): + exists, result = self.get(str(key)) + if not exists: + return None + else: + return dict(result) + + def get_keys(self): + return self.getKeys() + + def get_newly_created_oid(self, old_oids): + new_oids = self.asic_db.wait_for_n_keys(self, len(old_oids) + 1) + oid = [ids for ids in new_oids if ids not in old_oids] + return oid[0] + + +class DashDB(object): + def __init__(self, dvs): + self.dvs = dvs + self.app_dash_routing_type_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_ROUTING_TYPE_TABLE") + self.app_dash_appliance_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_APPLIANCE_TABLE") + self.asic_direction_lookup_table = Table( + self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_DIRECTION_LOOKUP_ENTRY") + self.asic_vip_table = Table( + self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_VIP_ENTRY") + self.app_dash_vnet_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_VNET_TABLE") + self.asic_dash_vnet_table = Table( + self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_VNET") + self.app_dash_eni_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_ENI_TABLE") + self.asic_eni_table = Table( + self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_ENI") + self.asic_eni_ether_addr_map_table = Table( + self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_ENI_ETHER_ADDRESS_MAP_ENTRY") + self.app_dash_vnet_map_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_VNET_MAPPING_TABLE") + self.asic_dash_outbound_ca_to_pa_table = Table( + self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_CA_TO_PA_ENTRY") + self.asic_pa_validation_table = Table( + self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_PA_VALIDATION_ENTRY") + self.app_dash_route_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_ROUTE_TABLE") + self.app_dash_route_rule_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_ROUTE_RULE_TABLE") + self.asic_outbound_routing_table = Table( + self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY") + self.asic_inbound_routing_rule_table = Table( + self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_INBOUND_ROUTING_ENTRY") + + def create_appliance(self, appliance_id, attr_maps: dict): + self.app_dash_appliance_table[str(appliance_id)] = attr_maps + + def remove_appliance(self, appliance_id): + del self.app_dash_appliance_table[str(appliance_id)] + + def create_vnet(self, vnet, attr_maps: dict): + self.app_dash_vnet_table[str(vnet)] = attr_maps + + def remove_vnet(self, vnet): + del self.app_dash_vnet_table[str(vnet)] + + def create_eni(self, eni, attr_maps: dict): + self.app_dash_eni_table[str(eni)] = attr_maps + + def remove_eni(self, eni): + del self.app_dash_eni_table[str(eni)] + + def create_vnet_map(self, vnet, ip, attr_maps: dict): + self.app_dash_vnet_map_table[str(vnet) + ":" + str(ip)] = attr_maps + + def remove_vnet_map(self, vnet, ip): + del self.app_dash_vnet_map_table[str(vnet) + ":" + str(ip)] + + def create_outbound_routing(self, mac_string, ip, attr_maps: dict): + self.app_dash_route_table[str(mac_string) + ":" + str(ip)] = attr_maps + + def remove_outbound_routing(self, mac_string, ip): + del self.app_dash_route_table[str(mac_string) + ":" + str(ip)] + + def create_inbound_routing(self, mac_string, vni, ip, attr_maps: dict): + self.app_dash_route_rule_table[str(mac_string) + ":" + str(vni) + ":" + str(ip)] = attr_maps + + def remove_inbound_routing(self, mac_string, vni, ip): + del self.app_dash_route_rule_table[str(mac_string) + ":" + str(vni) + ":" + str(ip)] + + def create_routing_type(self, routing_type, attr_maps: dict): + self.app_dash_routing_type_table[str(routing_type)] = attr_maps + + def remove_routing_type(self, routing_type): + del self.app_dash_routing_type_table[str(routing_type)] \ No newline at end of file diff --git a/tests/sai_attrs.py b/tests/sai_attrs.py new file mode 100644 index 0000000000..2f3523883e --- /dev/null +++ b/tests/sai_attrs.py @@ -0,0 +1,11 @@ +SAI_ENI_ATTR_PL_SIP = 'SAI_ENI_ATTR_PL_SIP' +SAI_ENI_ATTR_PL_SIP_MASK = 'SAI_ENI_ATTR_PL_SIP_MASK' +SAI_ENI_ATTR_PL_UNDERLAY_SIP = 'SAI_ENI_ATTR_PL_UNDERLAY_SIP' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY' +SAI_DASH_ENCAPSULATION_NVGRE = 'SAI_DASH_ENCAPSULATION_NVGRE' \ No newline at end of file diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py new file mode 100644 index 0000000000..9831b8ed6f --- /dev/null +++ b/tests/test_dash_pl.py @@ -0,0 +1,154 @@ +import base64 +import socket +import pytest +import time +import uuid + +from ipaddress import ip_address as IP + +from dash_api.appliance_pb2 import * +from dash_api.vnet_pb2 import * +from dash_api.eni_pb2 import * +from dash_api.route_pb2 import * +from dash_api.route_rule_pb2 import * +from dash_api.vnet_mapping_pb2 import * +from dash_api.route_type_pb2 import * +from dash_api.types_pb2 import * +from google.protobuf.json_format import ParseDict, MessageToDict + +from dash_utils import dash_db +from sai_attrs import * + +DVS_ENV = ["HWSKU=DPU-2P"] +NUM_PORTS = 2 + +APPLIANCE = { + "sip": { + "ipv4": socket.htonl(int(IP("10.0.0.1"))) + }, + "vm_vni": 4321 +} + +VNET = { + "vni": "45654", + "guid": { + "value": base64.b64encode(bytes.fromhex(uuid.UUID("559c6ce8-26ab-4193-b946-ccc6e8f930b2").hex)) + } +} + +PL_ENCODING_IP = "2001:0:20::" +PL_ENCODING_MASK = "::ffff:ffff" +PL_UNDERLAY_SIP = "55.1.2.3" + +ENI = { + "vnet": "Vnet1", + "underlay_ip": { + "ipv4": socket.htonl(int(IP("25.1.1.1"))) + }, + "mac_address": bytes.fromhex("F4939FEFC47E"), + "eni_id": "497f23d7-f0ac-4c99-a98f-59b470e8c7bd", + "admin_state": State.STATE_ENABLED, + "pl_underlay_sip": { + "ipv4": socket.htonl(int(IP(PL_UNDERLAY_SIP))) + }, + "pl_sip_encoding": { + "ip": { + "ipv6": base64.b64encode(IP(PL_ENCODING_IP).packed) + }, + "mask": { + "ipv6": base64.b64encode(IP(PL_ENCODING_MASK).packed) + } + } +} + +PL_OVERLAY_SIP = "fd40:108:0:d204:0:200::0" +PL_OVERLAY_DIP = "2603:10e1:100:2::3401:203" +VNET_MAPPING = { + "mac_address": bytes.fromhex("F4939FEFC47E"), + "action_type": RoutingType.ROUTING_TYPE_PRIVATELINK, + "underlay_ip": { + "ipv4": socket.htonl(int(IP("101.1.2.3"))) + }, + "overlay_sip": { + "ipv6": base64.b64encode(IP(PL_OVERLAY_SIP).packed) + }, + "overlay_dip": { + "ipv6": base64.b64encode(IP(PL_OVERLAY_DIP).packed) + }, +} + +ROUTE = { + "action_type": RoutingType.ROUTING_TYPE_VNET, + "vnet": "Vnet1", +} + +ENCAP_VNI = 100 +ROUTING_TYPE = { + "items": [ + { + "action_name": "action1", + "action_type": ActionType.ACTION_TYPE_4_to_6 + }, + { + "action_name": "action2", + "action_type": ActionType.ACTION_TYPE_STATICENCAP, + "encap_type": EncapType.ENCAP_TYPE_NVGRE, + "vni": ENCAP_VNI + } + ] +} + +@pytest.fixture(scope='module', autouse=True) +def common_setup_teardown(dash_db): + pb = Vnet() + pb.vni = int("45654") + pb.guid.value = bytes.fromhex(uuid.UUID("559c6ce8-26ab-4193-b946-ccc6e8f930b2").hex) + appliance_id = "100" + appliance_msg = ParseDict(APPLIANCE, Appliance()) + dash_db.create_appliance(appliance_id, {"pb": appliance_msg.SerializeToString()}) + vnet_msg = ParseDict(VNET, Vnet()) + vnet = "Vnet1" + dash_db.create_vnet(vnet, {"pb": vnet_msg.SerializeToString()}) + eni_msg = ParseDict(ENI, Eni()) + eni = "F4939FEFC47E" + dash_db.create_eni(eni, {"pb": eni_msg.SerializeToString()}) + routing_type_msg = ParseDict(ROUTING_TYPE, RouteType()) + dash_db.create_routing_type("privatelink", {"pb": routing_type_msg.SerializeToString()}) + vnet_mapping_msg = ParseDict(VNET_MAPPING, VnetMapping()) + vnet_map_ip = "10.1.1.1" + dash_db.create_vnet_map(vnet, vnet_map_ip, {"pb": vnet_mapping_msg.SerializeToString()}) + route_msg = ParseDict(ROUTE, Route()) + route_prefix = "10.1.0.8/32" + dash_db.create_outbound_routing(eni, route_prefix, {"pb": route_msg.SerializeToString()}) + + time.sleep(3) + +def test_pl_eni_attrs(dash_db): + enis = dash_db.asic_eni_table.get_keys() + assert enis + eni_attrs = dash_db.asic_eni_table[enis[0]] + assert SAI_ENI_ATTR_PL_SIP in eni_attrs + assert eni_attrs[SAI_ENI_ATTR_PL_SIP] == PL_ENCODING_IP + assert SAI_ENI_ATTR_PL_SIP_MASK in eni_attrs + actual_mask = IP(eni_attrs[SAI_ENI_ATTR_PL_SIP_MASK]) + assert actual_mask == IP(PL_ENCODING_MASK) + assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs + assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP + +def test_pl_outbound_ca_to_pa_attrs(dash_db): + outbound_ca_to_pa_keys = dash_db.asic_dash_outbound_ca_to_pa_table.get_keys() + assert outbound_ca_to_pa_keys + outbound_attrs = dash_db.asic_dash_outbound_ca_to_pa_table[outbound_ca_to_pa_keys[0]] + + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION in outbound_attrs + assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION] == SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP in outbound_attrs + actual_overlay_sip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP]) + assert actual_overlay_sip == IP(PL_OVERLAY_SIP) + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP in outbound_attrs + actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP]) + assert actual_overlay_dip == IP(PL_OVERLAY_DIP) + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY in outbound_attrs + assert int(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY]) == ENCAP_VNI + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION in outbound_attrs + assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION] == SAI_DASH_ENCAPSULATION_NVGRE diff --git a/tests/test_dash_vnet.py b/tests/test_dash_vnet.py index 950baff983..20c01e21a6 100644 --- a/tests/test_dash_vnet.py +++ b/tests/test_dash_vnet.py @@ -7,7 +7,7 @@ from dash_api.route_type_pb2 import * from dash_api.types_pb2 import * -from dash_utils import DashDB +from dash_utils import dash_db import time import uuid @@ -18,48 +18,45 @@ NUM_PORTS = 2 class TestDash(object): - def test_appliance(self, dvs): - dashobj = DashDB(dvs) + def test_appliance(self, dash_db): self.appliance_id = "100" self.sip = "10.0.0.1" self.vm_vni = "4321" pb = Appliance() pb.sip.ipv4 = socket.htonl(int(ipaddress.ip_address(self.sip))) pb.vm_vni = int(self.vm_vni) - dashobj.create_appliance(self.appliance_id, {"pb": pb.SerializeToString()}) + dash_db.create_appliance(self.appliance_id, {"pb": pb.SerializeToString()}) time.sleep(3) - direction_entries = dashobj.asic_direction_lookup_table.get_keys() + direction_entries = dash_db.asic_direction_lookup_table.get_keys() assert direction_entries - fvs = dashobj.asic_direction_lookup_table[direction_entries[0]] + fvs = dash_db.asic_direction_lookup_table[direction_entries[0]] for fv in fvs.items(): if fv[0] == "SAI_DIRECTION_LOOKUP_ENTRY_ATTR_ACTION": assert fv[1] == "SAI_DIRECTION_LOOKUP_ENTRY_ACTION_SET_OUTBOUND_DIRECTION" - vip_entries = dashobj.asic_vip_table.get_keys() + vip_entries = dash_db.asic_vip_table.get_keys() assert vip_entries - fvs = dashobj.asic_vip_table[vip_entries[0]] + fvs = dash_db.asic_vip_table[vip_entries[0]] for fv in fvs.items(): if fv[0] == "SAI_VIP_ENTRY_ATTR_ACTION": assert fv[1] == "SAI_VIP_ENTRY_ACTION_ACCEPT" - def test_vnet(self, dvs): - dashobj = DashDB(dvs) + def test_vnet(self, dash_db): self.vnet = "Vnet1" self.vni = "45654" self.guid = "559c6ce8-26ab-4193-b946-ccc6e8f930b2" pb = Vnet() pb.vni = int(self.vni) pb.guid.value = bytes.fromhex(uuid.UUID(self.guid).hex) - dashobj.create_vnet(self.vnet, {"pb": pb.SerializeToString()}) + dash_db.create_vnet(self.vnet, {"pb": pb.SerializeToString()}) time.sleep(3) - vnets = dashobj.asic_dash_vnet_table.get_keys() + vnets = dash_db.asic_dash_vnet_table.get_keys() assert vnets self.vnet_oid = vnets[0] - vnet_attr = dashobj.asic_dash_vnet_table[self.vnet_oid] + vnet_attr = dash_db.asic_dash_vnet_table[self.vnet_oid] assert vnet_attr["SAI_VNET_ATTR_VNI"] == "45654" - def test_eni(self, dvs): - dashobj = DashDB(dvs) + def test_eni(self, dash_db): self.vnet = "Vnet1" self.mac_string = "F4939FEFC47E" self.mac_address = "F4:93:9F:EF:C4:7E" @@ -72,15 +69,15 @@ def test_eni(self, dvs): pb.underlay_ip.ipv4 = socket.htonl(int(ipaddress.ip_address(self.underlay_ip))) pb.admin_state = State.STATE_ENABLED pb.vnet = self.vnet - dashobj.create_eni(self.mac_string, {"pb": pb.SerializeToString()}) + dash_db.create_eni(self.mac_string, {"pb": pb.SerializeToString()}) time.sleep(3) - vnets = dashobj.asic_dash_vnet_table.get_keys() + vnets = dash_db.asic_dash_vnet_table.get_keys() assert vnets self.vnet_oid = vnets[0] - enis = dashobj.asic_eni_table.get_keys() + enis = dash_db.asic_eni_table.get_keys() assert enis self.eni_oid = enis[0]; - fvs = dashobj.asic_eni_table[enis[0]] + fvs = dash_db.asic_eni_table[enis[0]] for fv in fvs.items(): if fv[0] == "SAI_ENI_ATTR_VNET_ID": assert fv[1] == str(self.vnet_oid) @@ -94,15 +91,14 @@ def test_eni(self, dvs): assert fv[1] == "true" time.sleep(3) - eni_addr_maps = dashobj.asic_eni_ether_addr_map_table.get_keys() + eni_addr_maps = dash_db.asic_eni_ether_addr_map_table.get_keys() assert eni_addr_maps - fvs = dashobj.asic_eni_ether_addr_map_table[eni_addr_maps[0]] + fvs = dash_db.asic_eni_ether_addr_map_table[eni_addr_maps[0]] for fv in fvs.items(): if fv[0] == "SAI_ENI_ETHER_ADDRESS_MAP_ENTRY_ATTR_ENI_ID": assert fv[1] == str(self.eni_oid) - def test_vnet_map(self, dvs): - dashobj = DashDB(dvs) + def test_vnet_map(self, dash_db): self.vnet = "Vnet1" self.ip1 = "10.1.1.1" self.ip2 = "10.1.1.2" @@ -114,34 +110,33 @@ def test_vnet_map(self, dvs): route_action.action_name = "action1" route_action.action_type = ACTION_TYPE_MAPROUTING route_type_msg.items.append(route_action) - dashobj.create_routing_type(self.routing_type, {"pb": route_type_msg.SerializeToString()}) + dash_db.create_routing_type(self.routing_type, {"pb": route_type_msg.SerializeToString()}) pb = VnetMapping() pb.mac_address = bytes.fromhex(self.mac_address.replace(":", "")) pb.action_type = RoutingType.ROUTING_TYPE_VNET_ENCAP pb.underlay_ip.ipv4 = socket.htonl(int(ipaddress.ip_address(self.underlay_ip))) - dashobj.create_vnet_map(self.vnet, self.ip1, {"pb": pb.SerializeToString()}) - dashobj.create_vnet_map(self.vnet, self.ip2, {"pb": pb.SerializeToString()}) + dash_db.create_vnet_map(self.vnet, self.ip1, {"pb": pb.SerializeToString()}) + dash_db.create_vnet_map(self.vnet, self.ip2, {"pb": pb.SerializeToString()}) time.sleep(3) - vnet_ca_to_pa_maps = dashobj.asic_dash_outbound_ca_to_pa_table.get_keys() + vnet_ca_to_pa_maps = dash_db.asic_dash_outbound_ca_to_pa_table.get_keys() assert len(vnet_ca_to_pa_maps) >= 2 - fvs = dashobj.asic_dash_outbound_ca_to_pa_table[vnet_ca_to_pa_maps[0]] + fvs = dash_db.asic_dash_outbound_ca_to_pa_table[vnet_ca_to_pa_maps[0]] for fv in fvs.items(): if fv[0] == "SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_UNDERLAY_DIP": assert fv[1] == "101.1.2.3" if fv[0] == "SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DMAC": assert fv[1] == "F4:93:9F:EF:C4:7E" - vnet_pa_validation_maps = dashobj.asic_pa_validation_table.get_keys() + vnet_pa_validation_maps = dash_db.asic_pa_validation_table.get_keys() assert vnet_pa_validation_maps - fvs = dashobj.asic_pa_validation_table[vnet_pa_validation_maps[0]] + fvs = dash_db.asic_pa_validation_table[vnet_pa_validation_maps[0]] for fv in fvs.items(): if fv[0] == "SAI_PA_VALIDATION_ENTRY_ATTR_ACTION": assert fv[1] == "SAI_PA_VALIDATION_ENTRY_ACTION_PERMIT" - def test_outbound_routing(self, dvs): - dashobj = DashDB(dvs) + def test_outbound_routing(self, dash_db): self.vnet = "Vnet1" self.mac_string = "F4939FEFC47E" self.ip = "10.1.0.0/24" @@ -151,12 +146,12 @@ def test_outbound_routing(self, dvs): pb.action_type = RoutingType.ROUTING_TYPE_VNET_DIRECT pb.vnet_direct.vnet = self.vnet pb.vnet_direct.overlay_ip.ipv4 = socket.htonl(int(ipaddress.ip_address(self.overlay_ip))) - dashobj.create_outbound_routing(self.mac_string, self.ip, {"pb": pb.SerializeToString()}) + dash_db.create_outbound_routing(self.mac_string, self.ip, {"pb": pb.SerializeToString()}) time.sleep(3) - outbound_routing_entries = dashobj.asic_outbound_routing_table.get_keys() + outbound_routing_entries = dash_db.asic_outbound_routing_table.get_keys() assert outbound_routing_entries - fvs = dashobj.asic_outbound_routing_table[outbound_routing_entries[0]] + fvs = dash_db.asic_outbound_routing_table[outbound_routing_entries[0]] for fv in fvs.items(): if fv[0] == "SAI_OUTBOUND_ROUTING_ENTRY_ATTR_ACTION": assert fv[1] == "SAI_OUTBOUND_ROUTING_ENTRY_ACTION_ROUTE_VNET_DIRECT" @@ -164,8 +159,7 @@ def test_outbound_routing(self, dvs): assert fv[1] == "10.0.0.6" assert "SAI_OUTBOUND_ROUTING_ENTRY_ATTR_DST_VNET_ID" in fvs - def test_inbound_routing(self, dvs): - dashobj = DashDB(dvs) + def test_inbound_routing(self, dash_db): self.mac_string = "F4939FEFC47E" self.vnet = "Vnet1" self.vni = "3251" @@ -180,30 +174,29 @@ def test_inbound_routing(self, dvs): pb.protocol = int(self.protocol) pb.vnet = self.vnet - dashobj.create_inbound_routing(self.mac_string, self.vni, self.ip, {"pb": pb.SerializeToString()}) + dash_db.create_inbound_routing(self.mac_string, self.vni, self.ip, {"pb": pb.SerializeToString()}) time.sleep(3) - inbound_routing_entries = dashobj.asic_inbound_routing_rule_table.get_keys() + inbound_routing_entries = dash_db.asic_inbound_routing_rule_table.get_keys() assert inbound_routing_entries - fvs = dashobj.asic_inbound_routing_rule_table[inbound_routing_entries[0]] + fvs = dash_db.asic_inbound_routing_rule_table[inbound_routing_entries[0]] for fv in fvs.items(): if fv[0] == "SAI_INBOUND_ROUTING_ENTRY_ATTR_ACTION": assert fv[1] == "SAI_INBOUND_ROUTING_ENTRY_ACTION_VXLAN_DECAP_PA_VALIDATE" - def test_cleanup(self, dvs): - dashobj = DashDB(dvs) + def test_cleanup(self, dash_db): self.vnet = "Vnet1" self.mac_string = "F4939FEFC47E" self.vni = "3251" self.sip = "10.1.1.1" self.dip = "10.1.0.0/24" self.appliance_id = "100" - dashobj.remove_inbound_routing(self.mac_string, self.vni, self.sip) - dashobj.remove_outbound_routing(self.mac_string, self.dip) - dashobj.remove_eni(self.mac_string) - dashobj.remove_vnet_map(self.vnet, self.sip) - dashobj.remove_vnet(self.vnet) - dashobj.remove_appliance(self.appliance_id) + dash_db.remove_inbound_routing(self.mac_string, self.vni, self.sip) + dash_db.remove_outbound_routing(self.mac_string, self.dip) + dash_db.remove_eni(self.mac_string) + dash_db.remove_vnet_map(self.vnet, self.sip) + dash_db.remove_vnet(self.vnet) + dash_db.remove_appliance(self.appliance_id) # Add Dummy always-pass test at end as workaroud # for issue when Flaky fail on final test it invokes module tear-down From 37e347fe1e01c7fb13d742b8c212d73ea58f4bbf Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 15 Feb 2024 01:37:11 +0000 Subject: [PATCH 08/77] Make ROUTING_TYPE_TABLE optional Signed-off-by: Lawrence Lee --- orchagent/dash/dashvnetorch.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index 9b634e479a..c34ec11672 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -290,8 +290,7 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt dash::route_type::RouteType route_type_actions; if (!dash_orch->getRouteTypeActions(ctxt.metadata.action_type(), route_type_actions)) { - SWSS_LOG_ERROR("Failed to get route type actions for %s", key.c_str()); - return; + SWSS_LOG_INFO("Failed to get route type actions for %s", key.c_str()); } for (auto action: route_type_actions.items()) From 134fd99504a38e3277a59893a24b58ffccd408b1 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 15 Feb 2024 22:38:33 +0000 Subject: [PATCH 09/77] Set SAI PL attribute based on ROUTING_TYPE Signed-off-by: Lawrence Lee --- orchagent/dash/dashvnetorch.cpp | 11 ++++------- tests/test_dash_pl.py | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index c34ec11672..40018f5115 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -295,13 +295,6 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt for (auto action: route_type_actions.items()) { - if (action.action_type() == dash::route_type::ACTION_TYPE_4_to_6) - { - outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION; - outbound_ca_to_pa_attr.value.u32 = SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING; - outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); - } - if (action.action_type() == dash::route_type::ACTION_TYPE_STATICENCAP) { outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION; @@ -328,6 +321,10 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt if (ctxt.metadata.action_type() == dash::route_type::ROUTING_TYPE_PRIVATELINK) { + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION; + outbound_ca_to_pa_attr.value.u32 = SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING; + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_UNDERLAY_DIP; to_sai(ctxt.metadata.underlay_ip(), outbound_ca_to_pa_attr.value.ipaddr); outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index 9831b8ed6f..4e7aff9962 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -100,6 +100,8 @@ @pytest.fixture(scope='module', autouse=True) def common_setup_teardown(dash_db): + routing_type_msg = ParseDict(ROUTING_TYPE, RouteType()) + dash_db.create_routing_type("privatelink", {"pb": routing_type_msg.SerializeToString()}) pb = Vnet() pb.vni = int("45654") pb.guid.value = bytes.fromhex(uuid.UUID("559c6ce8-26ab-4193-b946-ccc6e8f930b2").hex) @@ -112,8 +114,6 @@ def common_setup_teardown(dash_db): eni_msg = ParseDict(ENI, Eni()) eni = "F4939FEFC47E" dash_db.create_eni(eni, {"pb": eni_msg.SerializeToString()}) - routing_type_msg = ParseDict(ROUTING_TYPE, RouteType()) - dash_db.create_routing_type("privatelink", {"pb": routing_type_msg.SerializeToString()}) vnet_mapping_msg = ParseDict(VNET_MAPPING, VnetMapping()) vnet_map_ip = "10.1.1.1" dash_db.create_vnet_map(vnet, vnet_map_ip, {"pb": vnet_mapping_msg.SerializeToString()}) From 0c26e58e1880dfddde2a466de1549bbb47576a49 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 7 Aug 2024 06:55:41 +0000 Subject: [PATCH 10/77] Update DASH orchs to use route groups - Create outbound routing groups in SAI - Add ENI route entries to help map ENI->route group->route group OID - Update outbound routing key from ENI to route group. Signed-off-by: Lawrence Lee --- orchagent/dash/dashorch.cpp | 150 +++++++++++++++++++++++++++++++ orchagent/dash/dashorch.h | 6 ++ orchagent/dash/dashrouteorch.cpp | 122 +++++++++++++++++++++++-- orchagent/dash/dashrouteorch.h | 8 +- 4 files changed, 276 insertions(+), 10 deletions(-) diff --git a/orchagent/dash/dashorch.cpp b/orchagent/dash/dashorch.cpp index 81f67df9f2..c3a3a84efc 100644 --- a/orchagent/dash/dashorch.cpp +++ b/orchagent/dash/dashorch.cpp @@ -24,6 +24,7 @@ using namespace std; using namespace swss; +extern std::unordered_map gRouteGroupToOid; extern std::unordered_map gVnetNameToId; extern sai_dash_vip_api_t* sai_dash_vip_api; extern sai_dash_direction_lookup_api_t* sai_dash_direction_lookup_api; @@ -401,6 +402,15 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry) eni_attrs.push_back(eni_attr); } + auto eni_route_it = eni_route_entries_.find(eni); + if (eni_route_it != eni_route_entries_.end()) + { + SWSS_LOG_INFO("ENI %s has route group %s", eni.c_str(), eni_route_it->second.group_id().c_str()); + eni_attr.id = SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID; + eni_attr.value.oid = gRouteGroupToOid[eni_route_it->second.group_id()]; + eni_attrs.push_back(eni_attr); + } + sai_status_t status = sai_dash_eni_api->create_eni(&eni_id, gSwitchId, (uint32_t)eni_attrs.size(), eni_attrs.data()); if (status != SAI_STATUS_SUCCESS) @@ -696,6 +706,142 @@ void DashOrch::doTaskQosTable(ConsumerBase& consumer) } } +bool DashOrch::setEniRoute(const std::string& eni, const dash::eni_route::EniRoute& entry) +{ + SWSS_LOG_ENTER(); + + auto it = gRouteGroupToOid.find(entry.group_id()); + if (it == gRouteGroupToOid.end()) + { + // Don't add entry if route group doesn't exist to avoid needing to check + // the existence of both ENI route and route group entries + SWSS_LOG_WARN("Route group not yet created, skipping route entry for ENI %s", entry.group_id().c_str()); + return false; + } + + if (eni_route_entries_.find(eni) == eni_route_entries_.end() || + eni_route_entries_[eni].group_id() != entry.group_id()) + { + eni_route_entries_[eni] = entry; + SWSS_LOG_INFO("Added ENI route entry for %s", eni.c_str()); + } + else + { + SWSS_LOG_NOTICE("Duplicate ENI route entry already exists for %s", eni.c_str()); + return true; + } + + if (eni_entries_.find(eni) == eni_entries_.end()) + { + SWSS_LOG_INFO("ENI %s not yet created, not programming ENI route entry", eni.c_str()); + // We can treat this as a success since ENI creation will set the route group, no need to retry + return true; + } + + sai_attribute_t eni_attr; + eni_attr.id = SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID; + eni_attr.value.oid = it->second; + + sai_status_t status = sai_dash_eni_api->set_eni_attribute(eni_entries_[eni].eni_id, + &eni_attr); + + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to set ENI route group for %s", eni.c_str()); + task_process_status handle_status = handleSaiSetStatus((sai_api_t) SAI_API_DASH_ENI, status); + if (handle_status != task_success) + { + return parseHandleSaiStatusFailure(handle_status); + } + } + + SWSS_LOG_NOTICE("Updated ENI route group for %s", eni.c_str()); + return true; +} + +bool DashOrch::removeEniRoute(const std::string& eni) +{ + SWSS_LOG_ENTER(); + + if (eni_route_entries_.find(eni) == eni_route_entries_.end()) + { + SWSS_LOG_WARN("ENI route entry does not exist for %s", eni.c_str()); + return true; + } + + eni_route_entries_.erase(eni); + + if (eni_entries_.find(eni) != eni_entries_.end()) + { + sai_attribute_t eni_attr; + eni_attr.id = SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID; + eni_attr.value.oid = SAI_NULL_OBJECT_ID; + + sai_status_t status = sai_dash_eni_api->set_eni_attribute(eni_entries_[eni].eni_id, + &eni_attr); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to remove ENI route for %s", eni.c_str()); + task_process_status handle_status = handleSaiSetStatus((sai_api_t) SAI_API_DASH_ENI, status); + if (handle_status != task_success) + { + return parseHandleSaiStatusFailure(handle_status); + } + } + } + SWSS_LOG_NOTICE("Removed ENI route entry for %s", eni.c_str()); + + return true; +} + +void DashOrch::doTaskEniRouteTable(ConsumerBase& consumer) +{ + auto it = consumer.m_toSync.begin(); + while (it != consumer.m_toSync.end()) + { + KeyOpFieldsValuesTuple t = it->second; + string eni = kfvKey(t); + string op = kfvOp(t); + + if (op == SET_COMMAND) + { + dash::eni_route::EniRoute entry; + + if (!parsePbMessage(kfvFieldsValues(t), entry)) + { + SWSS_LOG_WARN("Requires protobuf at ENI route:%s", eni.c_str()); + it = consumer.m_toSync.erase(it); + continue; + } + + if (setEniRoute(eni, entry)) + { + it = consumer.m_toSync.erase(it); + } + else + { + it++; + } + } + else if (op == DEL_COMMAND) + { + if (removeEniRoute(eni)) + { + it = consumer.m_toSync.erase(it); + } + else + { + it++; + } + } + else + { + SWSS_LOG_ERROR("Unknown operation %s", op.c_str()); + it = consumer.m_toSync.erase(it); + } + } +} + void DashOrch::doTask(ConsumerBase& consumer) { SWSS_LOG_ENTER(); @@ -720,6 +866,10 @@ void DashOrch::doTask(ConsumerBase& consumer) { doTaskQosTable(consumer); } + else if (tn == APP_DASH_ENI_ROUTE_TABLE_NAME) + { + doTaskEniRouteTable(consumer); + } else { SWSS_LOG_ERROR("Unknown table: %s", tn.c_str()); diff --git a/orchagent/dash/dashorch.h b/orchagent/dash/dashorch.h index 445f9db464..dc1f44708f 100644 --- a/orchagent/dash/dashorch.h +++ b/orchagent/dash/dashorch.h @@ -22,6 +22,7 @@ #include "dash_api/route_type.pb.h" #include "dash_api/eni.pb.h" #include "dash_api/qos.pb.h" +#include "dash_api/eni_route.pb.h" struct EniEntry { @@ -33,6 +34,7 @@ typedef std::map ApplianceTable; typedef std::map RoutingTypeTable; typedef std::map EniTable; typedef std::map QosTable; +typedef std::map EniRouteTable; class DashOrch : public ZmqOrch { @@ -46,11 +48,13 @@ class DashOrch : public ZmqOrch RoutingTypeTable routing_type_entries_; EniTable eni_entries_; QosTable qos_entries_; + EniRouteTable eni_route_entries_; void doTask(ConsumerBase &consumer); void doTaskApplianceTable(ConsumerBase &consumer); void doTaskRoutingTypeTable(ConsumerBase &consumer); void doTaskEniTable(ConsumerBase &consumer); void doTaskQosTable(ConsumerBase &consumer); + void doTaskEniRouteTable(ConsumerBase &consumer); bool addApplianceEntry(const std::string& appliance_id, const dash::appliance::Appliance &entry); bool removeApplianceEntry(const std::string& appliance_id); bool addRoutingTypeEntry(const dash::route_type::RoutingType &routing_type, const dash::route_type::RouteType &entry); @@ -64,4 +68,6 @@ class DashOrch : public ZmqOrch bool setEniAdminState(const std::string& eni, const EniEntry& entry); bool addQosEntry(const std::string& qos_name, const dash::qos::Qos &entry); bool removeQosEntry(const std::string& qos_name); + bool setEniRoute(const std::string& eni, const dash::eni_route::EniRoute& entry); + bool removeEniRoute(const std::string& eni); }; diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index 6f99435fb0..33e9c7121e 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -27,6 +27,7 @@ using namespace std; using namespace swss; +std::unordered_map gRouteGroupToOid; extern std::unordered_map gVnetNameToId; extern sai_dash_outbound_routing_api_t* sai_dash_outbound_routing_api; extern sai_dash_inbound_routing_api_t* sai_dash_inbound_routing_api; @@ -61,9 +62,11 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon SWSS_LOG_WARN("Outbound routing entry already exists for %s", key.c_str()); return true; } - if (!dash_orch_->getEni(ctxt.eni)) + + auto route_group_it = gRouteGroupToOid.find(ctxt.route_group); + if (route_group_it == gRouteGroupToOid.end()) { - SWSS_LOG_INFO("Retry as ENI entry %s not found", ctxt.eni.c_str()); + SWSS_LOG_INFO("Retry as route group %s not found", ctxt.route_group.c_str()); return false; } if (ctxt.metadata.has_vnet() && gVnetNameToId.find(ctxt.metadata.vnet()) == gVnetNameToId.end()) @@ -74,7 +77,7 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon sai_outbound_routing_entry_t outbound_routing_entry; outbound_routing_entry.switch_id = gSwitchId; - outbound_routing_entry.eni_id = dash_orch_->getEni(ctxt.eni)->eni_id; + outbound_routing_entry.outbound_routing_group_id = route_group_it->second; swss::copy(outbound_routing_entry.destination, ctxt.destination); sai_attribute_t outbound_routing_attr; vector outbound_routing_attrs; @@ -153,7 +156,7 @@ bool DashRouteOrch::addOutboundRoutingPost(const string& key, const OutboundRout } } - OutboundRoutingEntry entry = { dash_orch_->getEni(ctxt.eni)->eni_id, ctxt.destination, ctxt.metadata }; + OutboundRoutingEntry entry = { gRouteGroupToOid[ctxt.route_group], ctxt.destination, ctxt.metadata }; routing_entries_[key] = entry; gCrmOrch->incCrmResUsedCounter(ctxt.destination.isV4() ? CrmResourceType::CRM_DASH_IPV4_OUTBOUND_ROUTING : CrmResourceType::CRM_DASH_IPV6_OUTBOUND_ROUTING); @@ -178,7 +181,7 @@ bool DashRouteOrch::removeOutboundRouting(const string& key, OutboundRoutingBulk OutboundRoutingEntry entry = routing_entries_[key]; sai_outbound_routing_entry_t outbound_routing_entry; outbound_routing_entry.switch_id = gSwitchId; - outbound_routing_entry.eni_id = entry.eni; + outbound_routing_entry.outbound_routing_group_id = entry.route_group; swss::copy(outbound_routing_entry.destination, entry.destination); object_statuses.emplace_back(); outbound_routing_bulker_.remove_entry(&object_statuses.back(), &outbound_routing_entry); @@ -248,13 +251,13 @@ void DashRouteOrch::doTaskRouteTable(ConsumerBase& consumer) ctxt.clear(); } - string& eni = ctxt.eni; + string& route_group = ctxt.route_group; IpPrefix& destination = ctxt.destination; vector keys = tokenize(key, ':'); - eni = keys[0]; + route_group = keys[0]; string ip_str; - size_t pos = key.find(":", eni.length()); + size_t pos = key.find(":", route_group.length()); ip_str = key.substr(pos + 1); destination = IpPrefix(ip_str); @@ -621,6 +624,105 @@ void DashRouteOrch::doTaskRouteRuleTable(ConsumerBase& consumer) } } +bool addRouteGroup(const string& route_group, const dash::route_group::RouteGroup& entry) +{ + SWSS_LOG_ENTER(); + + sai_object_id_t route_group_oid; + sai_status_t status = sai_dash_outbound_routing_api->create_outbound_routing_group(&route_group_oid, gSwitchId, 0, NULL); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to create route group %s", route_group.c_str()); + task_process_status handle_status = handleSaiCreateStatus((sai_api_t) SAI_API_DASH_OUTBOUND_ROUTING, status); + if (handle_status != task_success) + { + return parseHandleSaiStatusFailure(handle_status); + } + } + + gRouteGroupToOid[route_group] = route_group_oid; + SWSS_LOG_INFO("Route group %s added", route_group.c_str()); + + return true; +} + +bool removeRouteGroup(const string& route_group) +{ + SWSS_LOG_ENTER(); + + auto it = gRouteGroupToOid.find(route_group); + if (it == gRouteGroupToOid.end()) + { + SWSS_LOG_INFO("Failed to find route group %s to remove", route_group.c_str()); + return true; + } + + sai_status_t status = sai_dash_outbound_routing_api->remove_outbound_routing_group(it->second); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to remove route group %s", route_group.c_str()); + task_process_status handle_status = handleSaiRemoveStatus((sai_api_t) SAI_API_DASH_OUTBOUND_ROUTING, status); + if (handle_status != task_success) + { + return parseHandleSaiStatusFailure(handle_status); + } + } + + gRouteGroupToOid.erase(it); + SWSS_LOG_INFO("Route group %s removed", route_group.c_str()); + + return true; +} + +void doTaskRouteGroupTable(ConsumerBase& consumer) +{ + SWSS_LOG_ENTER(); + + auto it = consumer.m_toSync.begin(); + + while (it != consumer.m_toSync.end()) + { + auto t = it->second; + string route_group = kfvKey(t); + string op = kfvOp(t); + if (op == SET_COMMAND) + { + dash::route_group::RouteGroup entry; + if (!parsePbMessage(kfvFieldsValues(t), entry)) + { + SWSS_LOG_WARN("Requires protobuf at RouteGroup :%s", route_group.c_str()); + it = consumer.m_toSync.erase(it); + continue; + } + + if (addRouteGroup(route_group, entry)) + { + it = consumer.m_toSync.erase(it); + } + else + { + it++; + } + } + else if (op == DEL_COMMAND) + { + if (removeRouteGroup(route_group)) + { + it = consumer.m_toSync.erase(it); + } + else + { + it++; + } + } + else + { + SWSS_LOG_ERROR("Unknown operation %s", op.c_str()); + it = consumer.m_toSync.erase(it); + } + } +} + void DashRouteOrch::doTask(ConsumerBase& consumer) { SWSS_LOG_ENTER(); @@ -637,6 +739,10 @@ void DashRouteOrch::doTask(ConsumerBase& consumer) { doTaskRouteRuleTable(consumer); } + else if (tn == APP_DASH_ROUTE_GROUP_TABLE_NAME) + { + doTaskRouteGroupTable(consumer); + } else { SWSS_LOG_ERROR("Unknown table: %s", tn.c_str()); diff --git a/orchagent/dash/dashrouteorch.h b/orchagent/dash/dashrouteorch.h index d61fcaa936..e634e27b39 100644 --- a/orchagent/dash/dashrouteorch.h +++ b/orchagent/dash/dashrouteorch.h @@ -18,11 +18,12 @@ #include "dash_api/route.pb.h" #include "dash_api/route_rule.pb.h" +#include "dash_api/route_group.pb.h" struct OutboundRoutingEntry { - sai_object_id_t eni; + sai_object_id_t route_group; swss::IpPrefix destination; dash::route::Route metadata; }; @@ -41,7 +42,7 @@ typedef std::map RoutingRuleTable; struct OutboundRoutingBulkContext { - std::string eni; + std::string route_group; swss::IpPrefix destination; dash::route::Route metadata; std::deque object_statuses; @@ -88,6 +89,7 @@ class DashRouteOrch : public ZmqOrch void doTask(ConsumerBase &consumer); void doTaskRouteTable(ConsumerBase &consumer); void doTaskRouteRuleTable(ConsumerBase &consumer); + void doTaskRouteGroupTable(ConsumerBase &consumer); bool addOutboundRouting(const std::string& key, OutboundRoutingBulkContext& ctxt); bool addOutboundRoutingPost(const std::string& key, const OutboundRoutingBulkContext& ctxt); bool removeOutboundRouting(const std::string& key, OutboundRoutingBulkContext& ctxt); @@ -96,4 +98,6 @@ class DashRouteOrch : public ZmqOrch bool addInboundRoutingPost(const std::string& key, const InboundRoutingBulkContext& ctxt); bool removeInboundRouting(const std::string& key, InboundRoutingBulkContext& ctxt); bool removeInboundRoutingPost(const std::string& key, const InboundRoutingBulkContext& ctxt); + bool addRouteGroup(const std::string& key, const dash::route_group::RouteGroup& entry); + bool removeRouteGroup(const std::string& key); }; From 47a497e4136ae341c6f81219ac68db5f134e63d1 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Sat, 10 Aug 2024 01:48:00 +0000 Subject: [PATCH 11/77] refactor tests Signed-off-by: Lawrence Lee --- tests/dash_utils/dash_base_test.py | 99 ++++++++++ tests/dash_utils/dash_configs.py | 130 +++++++++++++ .../{dash_utils.py => dash_utils/dash_db.py} | 47 +++-- tests/mock_tests/mac_move_ut.cpp | 172 ++++++++++++++++++ tests/test_dash_pl.py | 163 ++++------------- tests/test_dash_vnet.py | 2 +- 6 files changed, 468 insertions(+), 145 deletions(-) create mode 100644 tests/dash_utils/dash_base_test.py create mode 100644 tests/dash_utils/dash_configs.py rename tests/{dash_utils.py => dash_utils/dash_db.py} (80%) create mode 100644 tests/mock_tests/mac_move_ut.cpp diff --git a/tests/dash_utils/dash_base_test.py b/tests/dash_utils/dash_base_test.py new file mode 100644 index 0000000000..167ec115a4 --- /dev/null +++ b/tests/dash_utils/dash_base_test.py @@ -0,0 +1,99 @@ +from dash_api.appliance_pb2 import * +from dash_api.vnet_pb2 import * +from dash_api.eni_pb2 import * +from dash_api.eni_route_pb2 import * +from dash_api.route_pb2 import * +from dash_api.route_group_pb2 import * +from dash_api.route_rule_pb2 import * +from dash_api.vnet_mapping_pb2 import * +from dash_api.route_type_pb2 import * +from dash_api.types_pb2 import * +from google.protobuf.json_format import ParseDict, MessageToDict + +from dash_utils.dash_db import dash_db + +import time +import uuid +import ipaddress +import socket +import pytest + +from dash_configs import * + + +class DashBaseTest(object): + + @pytest.fixture + def setup_appliance(self, dash_db): + pb = ParseDict(APPLIANCE, Appliance()) + dash_db.create_appliance(APPLIANCE_ID, {"pb": pb.SerializeToString()}) + + yield + + dash_db.remove_appliance(APPLIANCE_ID) + + @pytest.fixture + def setup_vnet(self, dash_db, setup_appliance): + pb = ParseDict(VNET, Vnet()) + dash_db.create_vnet(VNET1, {"pb": pb.SerializeToString()}) + + yield + + dash_db.remove_vnet(VNET1) + + @pytest.fixture + def setup_eni(self, dash_db, setup_vnet): + pb = ParseDict(ENI, Eni()) + dash_db.create_eni(ENI_ID, {"pb": pb.SerializeToString()}) + + yield + + dash_db.remove_eni(ENI_ID) + + @pytest.fixture + def setup_routing_type(self, dash_db): + pb = ParseDict(ROUTING_TYPE_VNET_ENCAP, RouteType()) + dash_db.create_routing_type(VNET_ENCAP, {"pb": pb.SerializeToString()}) + pb = ParseDict(ROUTING_TYPE_PL, RouteType()) + dash_db.create_routing_type(PRIVATELINK, {"pb": pb.SerializeToString()}) + + yield + + dash_db.remove_routing_type(VNET_ENCAP) + dash_db.remove_routing_type(PRIVATELINK) + + @pytest.fixture + def setup_vnet_mapping(self, dash_db, setup_eni): + pb = ParseDict(VNET_MAPPING, VnetMapping()) + dash_db.create_vnet_mapping(VNET1, VNET_MAP_IP1, {"pb": pb.SerializeToString()}) + + yield + + dash_db.remove_vnet_mapping(VNET1, VNET_MAP_IP1) + + @pytest.fixture + def setup_route_group(self, dash_db): + pb = ParseDict(ROUTE_GROUP, RouteGroup()) + dash_db.create_route_group(ROUTE_GROUP1, {"pb": pb.SerializeToString()}) + + yield + + dash_db.remove_route_group(ROUTE_GROUP1) + + @pytest.fixture + def setup_eni_route(self, dash_db, setup_eni, setup_route_group): + pb = ParseDict(ENI_ROUTE, EniRoute()) + dash_db.create_eni_route(ENI_ID, ROUTE_GROUP1, {"pb": pb.SerializeToString()}) + + yield + + dash_db.remove_eni_route(ENI_ID, ROUTE_GROUP1) + + @pytest.fixture + def setup_route(self, dash_db, setup_vnet_mapping, setup_route_group): + pb = ParseDict(ROUTE, Route()) + dash_db.create_outbound_routing(ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, {"pb": pb.SerializeToString()}) + + yield + + dash_db.remove_outbound_routing(ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) \ No newline at end of file diff --git a/tests/dash_utils/dash_configs.py b/tests/dash_utils/dash_configs.py new file mode 100644 index 0000000000..1a085791b0 --- /dev/null +++ b/tests/dash_utils/dash_configs.py @@ -0,0 +1,130 @@ +import base64 +import socket +import uuid +from ipaddress import ip_address as IP + +from dash_api.appliance_pb2 import * +from dash_api.vnet_pb2 import * +from dash_api.eni_pb2 import * +from dash_api.route_pb2 import * +from dash_api.route_rule_pb2 import * +from dash_api.vnet_mapping_pb2 import * +from dash_api.route_type_pb2 import * +from dash_api.types_pb2 import * + +VNET_ENCAP = "vnet_encap" +VNET_DIRECT = "vnet_direct" +PRIVATELINK = "privatelink" +DECAP = "decap" + +SIP = "10.0.0.1" +UNDERLAY_IP = "25.1.1.1" +VNET_MAP_IP1 = "10.1.1.1" +VNET_MAP_IP2 = "10.1.1.2" +UNDERLAY_IP = "101.1.2.3" +OUTBOUND_ROUTE_PREFIX = "10.1.0.8/32" +OVERLAY_IP = "10.0.0.6" +PL_ENCODING_IP = "2001:0:20::" +PL_ENCODING_MASK = "::ffff:ffff" +PL_UNDERLAY_SIP = "55.1.2.3" +PL_OVERLAY_SIP = "fd40:108:0:d204:0:200::0" +PL_OVERLAY_DIP = "2603:10e1:100:2::3401:203" + +APPLIANCE_ID = "100" +VM_VNI = "4321" +VNET1 = "Vnet1" +VNET1_VNI = "45654" +VNET1_GUID = "559c6ce8-26ab-4193-b946-ccc6e8f930b2" +MAC_STRING = "F4939FEFC47E" +MAC_ADDRESS = "F4:93:9F:EF:C4:7E" +ENI_ID = "497f23d7-f0ac-4c99-a98f-59b470e8c7bd" +ROUTE_GROUP1 = "RouteGroup1" +ROUTE_GROUP1_GUID = "48af6ce8-26cc-4293-bfa6-0126e8fcdeb2" + +APPLIANCE = { + "sip": { + "ipv4": socket.htonl(int(IP(SIP))) + }, + "vm_vni": int(VM_VNI) +} + +VNET = { + "vni": VNET1_VNI, + "guid": { + "value": base64.b64encode(bytes.fromhex(uuid.UUID(VNET1_GUID).hex)) + } +} + +ENI = { + "vnet": VNET1, + "underlay_ip": { + "ipv4": socket.htonl(int(IP(UNDERLAY_IP))) + }, + "mac_address": bytes.fromhex(MAC_STRING), + "eni_id": ENI_ID, + "admin_state": State.STATE_ENABLED, + "pl_underlay_sip": { + "ipv4": socket.htonl(int(IP(PL_UNDERLAY_SIP))) + }, + "pl_sip_encoding": { + "ip": { + "ipv6": base64.b64encode(IP(PL_ENCODING_IP).packed) + }, + "mask": { + "ipv6": base64.b64encode(IP(PL_ENCODING_MASK).packed) + } + } +} + +VNET_MAPPING = { + "mac_address": bytes.fromhex(MAC_STRING), + "action_type": RoutingType.ROUTING_TYPE_PRIVATELINK, + "underlay_ip": { + "ipv4": socket.htonl(int(IP(UNDERLAY_IP))) + }, + "overlay_sip": { + "ipv6": base64.b64encode(IP(PL_OVERLAY_SIP).packed) + }, + "overlay_dip": { + "ipv6": base64.b64encode(IP(PL_OVERLAY_DIP).packed) + }, +} + +ROUTE = { + "action_type": RoutingType.ROUTING_TYPE_VNET, + "vnet": "Vnet1", +} + +ENCAP_VNI = 100 + +ROUTING_TYPE_VNET_ENCAP = { + "items": [ + { + "action_name": "action1", + "action_type": ActionType.MAPROUTING + }, + ] +} +ROUTING_TYPE_PL = { + "items": [ + { + "action_name": "action1", + "action_type": ActionType.ACTION_TYPE_4_to_6 + }, + { + "action_name": "action2", + "action_type": ActionType.ACTION_TYPE_STATICENCAP, + "encap_type": EncapType.ENCAP_TYPE_NVGRE, + "vni": ENCAP_VNI + } + ] +} + +ROUTE_GROUP = { + "guid": base64.b64encode(bytes.fromhex(uuid.UUID(ROUTE_GROUP1_GUID).hex)), + "version": "rg_version" +} + +ENI_ROUTE = { + "group_id": ROUTE_GROUP1, +} \ No newline at end of file diff --git a/tests/dash_utils.py b/tests/dash_utils/dash_db.py similarity index 80% rename from tests/dash_utils.py rename to tests/dash_utils/dash_db.py index 971ab589d6..a40e34496f 100644 --- a/tests/dash_utils.py +++ b/tests/dash_utils/dash_db.py @@ -50,34 +50,41 @@ def __init__(self, dvs): self.dvs.get_app_db().db_connection, "DASH_ROUTING_TYPE_TABLE") self.app_dash_appliance_table = ProducerStateTable( self.dvs.get_app_db().db_connection, "DASH_APPLIANCE_TABLE") + self.app_dash_vnet_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_VNET_TABLE") + self.app_dash_eni_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_ENI_TABLE") + self.app_dash_vnet_map_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_VNET_MAPPING_TABLE") + self.app_dash_route_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_ROUTE_TABLE") + self.app_dash_route_rule_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_ROUTE_RULE_TABLE") + self.app_dash_eni_route_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_ENI_ROUTE_TABLE") + self.app_dash_route_group_table = ProducerStateTable( + self.dvs.get_app_db().db_connection, "DASH_ROUTE_GROUP_TABLE") + self.asic_direction_lookup_table = Table( self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_DIRECTION_LOOKUP_ENTRY") self.asic_vip_table = Table( self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_VIP_ENTRY") - self.app_dash_vnet_table = ProducerStateTable( - self.dvs.get_app_db().db_connection, "DASH_VNET_TABLE") self.asic_dash_vnet_table = Table( self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_VNET") - self.app_dash_eni_table = ProducerStateTable( - self.dvs.get_app_db().db_connection, "DASH_ENI_TABLE") self.asic_eni_table = Table( self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_ENI") self.asic_eni_ether_addr_map_table = Table( self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_ENI_ETHER_ADDRESS_MAP_ENTRY") - self.app_dash_vnet_map_table = ProducerStateTable( - self.dvs.get_app_db().db_connection, "DASH_VNET_MAPPING_TABLE") self.asic_dash_outbound_ca_to_pa_table = Table( self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_CA_TO_PA_ENTRY") self.asic_pa_validation_table = Table( self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_PA_VALIDATION_ENTRY") - self.app_dash_route_table = ProducerStateTable( - self.dvs.get_app_db().db_connection, "DASH_ROUTE_TABLE") - self.app_dash_route_rule_table = ProducerStateTable( - self.dvs.get_app_db().db_connection, "DASH_ROUTE_RULE_TABLE") self.asic_outbound_routing_table = Table( self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY") self.asic_inbound_routing_rule_table = Table( self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_INBOUND_ROUTING_ENTRY") + self.asic_outbound_routing_group_table = Table( + self.dvs.get_asic_db().db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_GROUP") def create_appliance(self, appliance_id, attr_maps: dict): self.app_dash_appliance_table[str(appliance_id)] = attr_maps @@ -97,17 +104,29 @@ def create_eni(self, eni, attr_maps: dict): def remove_eni(self, eni): del self.app_dash_eni_table[str(eni)] + def create_eni_route(self, eni, attr_maps: dict): + self.app_dash_eni_route_table[str(eni)] = attr_maps + + def remove_eni_route(self, eni): + del self.app_dash_eni_route_table[str(eni)] + def create_vnet_map(self, vnet, ip, attr_maps: dict): self.app_dash_vnet_map_table[str(vnet) + ":" + str(ip)] = attr_maps def remove_vnet_map(self, vnet, ip): del self.app_dash_vnet_map_table[str(vnet) + ":" + str(ip)] - def create_outbound_routing(self, mac_string, ip, attr_maps: dict): - self.app_dash_route_table[str(mac_string) + ":" + str(ip)] = attr_maps + def create_outbound_routing(self, route_group, ip, attr_maps: dict): + self.app_dash_route_table[str(route_group) + ":" + str(ip)] = attr_maps + + def remove_outbound_routing(self, route_group, ip): + del self.app_dash_route_table[str(route_group) + ":" + str(ip)] + + def create_outbound_routing_group(self, route_group, attr_maps: dict): + self.app_dash_route_group_table[str(route_group)] = attr_maps - def remove_outbound_routing(self, mac_string, ip): - del self.app_dash_route_table[str(mac_string) + ":" + str(ip)] + def remove_outbound_routing_group(self, route_group): + del self.app_dash_route_group_table[str(route_group)] def create_inbound_routing(self, mac_string, vni, ip, attr_maps: dict): self.app_dash_route_rule_table[str(mac_string) + ":" + str(vni) + ":" + str(ip)] = attr_maps diff --git a/tests/mock_tests/mac_move_ut.cpp b/tests/mock_tests/mac_move_ut.cpp new file mode 100644 index 0000000000..0bd2d4228e --- /dev/null +++ b/tests/mock_tests/mac_move_ut.cpp @@ -0,0 +1,172 @@ +#define private public +#include "directory.h" +#undef private +#define protected public +#include "orch.h" +#undef protected +#include "ut_helper.h" +#include "mock_orchagent_main.h" +#include "mock_sai_api.h" +#include "mock_orch_test.h" +#include "gtest/gtest.h" +#include +#include + +EXTERN_MOCK_FNS + +namespace mac_move_test +{ + DEFINE_SAI_API_MOCK(neighbor); + DEFINE_SAI_API_MOCK(route); + DEFINE_SAI_GENERIC_API_MOCK(acl, acl_entry); + DEFINE_SAI_GENERIC_API_MOCK(next_hop, next_hop); + using namespace std; + using namespace mock_orch_test; + using ::testing::Return; + using ::testing::Throw; + + // static const string ACTIVE_INTERFACE = "Ethernet4"; + // static const string STANDBY_INTERFACE = "Ethernet8"; + static const string NEIGH_IP = "192.168.0.100"; + + class MacMoveTest : public MockOrchTest + { + protected: + MuxCable* m_ActiveMuxCable; + MuxCable* m_StandbyMuxCable; + + void SetMuxStateFromAppDb(std::string interface, std::string state) + { + Table mux_cable_table = Table(m_app_db.get(), APP_MUX_CABLE_TABLE_NAME); + mux_cable_table.set(interface, { { STATE, state } }); + m_MuxCableOrch->addExistingData(&mux_cable_table); + static_cast(m_MuxCableOrch)->doTask(); + } + + void SetAndAssertMuxState(MuxCable* cable, std::string state) + { + cable->setState(state); + EXPECT_EQ(state, cable->getState()); + } + + void ApplyInitialConfigs() + { + Table peer_switch_table = Table(m_config_db.get(), CFG_PEER_SWITCH_TABLE_NAME); + Table tunnel_table = Table(m_app_db.get(), APP_TUNNEL_DECAP_TABLE_NAME); + Table mux_cable_table = Table(m_config_db.get(), CFG_MUX_CABLE_TABLE_NAME); + Table port_table = Table(m_app_db.get(), APP_PORT_TABLE_NAME); + Table vlan_table = Table(m_app_db.get(), APP_VLAN_TABLE_NAME); + Table vlan_member_table = Table(m_app_db.get(), APP_VLAN_MEMBER_TABLE_NAME); + Table neigh_table = Table(m_app_db.get(), APP_NEIGH_TABLE_NAME); + Table intf_table = Table(m_app_db.get(), APP_INTF_TABLE_NAME); + + auto ports = ut_helper::getInitialSaiPorts(); + port_table.set(ACTIVE_INTERFACE, ports[ACTIVE_INTERFACE]); + port_table.set(STANDBY_INTERFACE, ports[STANDBY_INTERFACE]); + port_table.set("PortConfigDone", { { "count", to_string(1) } }); + port_table.set("PortInitDone", { {} }); + + neigh_table.set( + VLAN_1000 + neigh_table.getTableNameSeparator() + SERVER_IP1, { { "neigh", MAC1 }, + { "family", "IPv4" } }); + + vlan_table.set(VLAN_1000, { { "admin_status", "up" }, + { "mtu", "9100" }, + { "mac", "00:aa:bb:cc:dd:ee" } }); + vlan_member_table.set( + VLAN_1000 + vlan_member_table.getTableNameSeparator() + ACTIVE_INTERFACE, + { { "tagging_mode", "untagged" } }); + + vlan_member_table.set( + VLAN_1000 + vlan_member_table.getTableNameSeparator() + STANDBY_INTERFACE, + { { "tagging_mode", "untagged" } }); + + intf_table.set(VLAN_1000, { { "grat_arp", "enabled" }, + { "proxy_arp", "enabled" }, + { "mac_addr", "00:00:00:00:00:00" } }); + intf_table.set( + VLAN_1000 + neigh_table.getTableNameSeparator() + "192.168.0.1/21", { + { "scope", "global" }, + { "family", "IPv4" }, + }); + + tunnel_table.set(MUX_TUNNEL, { { "dscp_mode", "uniform" }, + { "dst_ip", "2.2.2.2" }, + { "ecn_mode", "copy_from_outer" }, + { "encap_ecn_mode", "standard" }, + { "ttl_mode", "pipe" }, + { "tunnel_type", "IPINIP" } }); + + peer_switch_table.set(PEER_SWITCH_HOSTNAME, { { "address_ipv4", PEER_IPV4_ADDRESS } }); + + mux_cable_table.set(ACTIVE_INTERFACE, { { "server_ipv4", SERVER_IP1 + "/32" }, + { "server_ipv6", "a::a/128" }, + { "state", "auto" } }); + + mux_cable_table.set(STANDBY_INTERFACE, { { "server_ipv4", SERVER_IP2 + "/32" }, + { "server_ipv6", "a::a/128" }, + { "state", "auto" } }); + + gPortsOrch->addExistingData(&port_table); + gPortsOrch->addExistingData(&vlan_table); + gPortsOrch->addExistingData(&vlan_member_table); + static_cast(gPortsOrch)->doTask(); + + gIntfsOrch->addExistingData(&intf_table); + static_cast(gIntfsOrch)->doTask(); + + m_TunnelDecapOrch->addExistingData(&tunnel_table); + static_cast(m_TunnelDecapOrch)->doTask(); + + m_MuxOrch->addExistingData(&peer_switch_table); + static_cast(m_MuxOrch)->doTask(); + + m_MuxOrch->addExistingData(&mux_cable_table); + static_cast(m_MuxOrch)->doTask(); + + gNeighOrch->addExistingData(&neigh_table); + static_cast(gNeighOrch)->doTask(); + + m_ActiveMuxCable = m_MuxOrch->getMuxCable(ACTIVE_INTERFACE); + m_StandbyMuxCable = m_MuxOrch->getMuxCable(STANDBY_INTERFACE); + + // We always expect the mux to be initialized to standby + SetAndAssertMuxState(m_ActiveMuxCable, ACTIVE_STATE); + SetAndAssertMuxState(m_StandbyMuxCable, STANDBY_STATE); + } + + void PostSetUp() override + { + INIT_SAI_API_MOCK(neighbor); + INIT_SAI_API_MOCK(route); + INIT_SAI_API_MOCK(acl); + INIT_SAI_API_MOCK(next_hop); + MockSaiApis(); + } + + void PreTearDown() override + { + RestoreSaiApis(); + } + }; + + + + TEST_F(MacMoveTest, TestTestTest) + { + FdbEntry activeEntry = {MAC1, 0, ACTIVE_INTERFACE}; + FdbEntry standbyEntry = {MAC1, 0, STANDBY_INTERFACE}; + Port activePort, standbyPort; + gPortsOrch->getPort(ACTIVE_INTERFACE, activePort); + gPortsOrch->getPort(STANDBY_INTERFACE, standbyPort); + FdbUpdate activeUpdate = {activeEntry, activePort, "", true, SAI_FDB_ENTRY_TYPE_DYNAMIC}; + FdbUpdate standbyUpdate = {standbyEntry, standbyPort, "", true, SAI_FDB_ENTRY_TYPE_DYNAMIC}; + sleep(5); + for (int i = 0; i < 1000000; i++) + { + m_MuxOrch->update(SUBJECT_TYPE_FDB_CHANGE, static_cast (&activeUpdate)); + m_MuxOrch->update(SUBJECT_TYPE_FDB_CHANGE, static_cast (&standbyUpdate)); + } + sleep(60); + } +} diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index 4e7aff9962..ca6d74f84f 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -16,139 +16,42 @@ from dash_api.types_pb2 import * from google.protobuf.json_format import ParseDict, MessageToDict -from dash_utils import dash_db +from dash_utils.dash_db import dash_db +from dash_utils.dash_base_test import DashBaseTest +from dash_utils.dash_configs import * from sai_attrs import * DVS_ENV = ["HWSKU=DPU-2P"] NUM_PORTS = 2 -APPLIANCE = { - "sip": { - "ipv4": socket.htonl(int(IP("10.0.0.1"))) - }, - "vm_vni": 4321 -} -VNET = { - "vni": "45654", - "guid": { - "value": base64.b64encode(bytes.fromhex(uuid.UUID("559c6ce8-26ab-4193-b946-ccc6e8f930b2").hex)) - } -} - -PL_ENCODING_IP = "2001:0:20::" -PL_ENCODING_MASK = "::ffff:ffff" -PL_UNDERLAY_SIP = "55.1.2.3" - -ENI = { - "vnet": "Vnet1", - "underlay_ip": { - "ipv4": socket.htonl(int(IP("25.1.1.1"))) - }, - "mac_address": bytes.fromhex("F4939FEFC47E"), - "eni_id": "497f23d7-f0ac-4c99-a98f-59b470e8c7bd", - "admin_state": State.STATE_ENABLED, - "pl_underlay_sip": { - "ipv4": socket.htonl(int(IP(PL_UNDERLAY_SIP))) - }, - "pl_sip_encoding": { - "ip": { - "ipv6": base64.b64encode(IP(PL_ENCODING_IP).packed) - }, - "mask": { - "ipv6": base64.b64encode(IP(PL_ENCODING_MASK).packed) - } - } -} - -PL_OVERLAY_SIP = "fd40:108:0:d204:0:200::0" -PL_OVERLAY_DIP = "2603:10e1:100:2::3401:203" -VNET_MAPPING = { - "mac_address": bytes.fromhex("F4939FEFC47E"), - "action_type": RoutingType.ROUTING_TYPE_PRIVATELINK, - "underlay_ip": { - "ipv4": socket.htonl(int(IP("101.1.2.3"))) - }, - "overlay_sip": { - "ipv6": base64.b64encode(IP(PL_OVERLAY_SIP).packed) - }, - "overlay_dip": { - "ipv6": base64.b64encode(IP(PL_OVERLAY_DIP).packed) - }, -} - -ROUTE = { - "action_type": RoutingType.ROUTING_TYPE_VNET, - "vnet": "Vnet1", -} - -ENCAP_VNI = 100 -ROUTING_TYPE = { - "items": [ - { - "action_name": "action1", - "action_type": ActionType.ACTION_TYPE_4_to_6 - }, - { - "action_name": "action2", - "action_type": ActionType.ACTION_TYPE_STATICENCAP, - "encap_type": EncapType.ENCAP_TYPE_NVGRE, - "vni": ENCAP_VNI - } - ] -} - -@pytest.fixture(scope='module', autouse=True) -def common_setup_teardown(dash_db): - routing_type_msg = ParseDict(ROUTING_TYPE, RouteType()) - dash_db.create_routing_type("privatelink", {"pb": routing_type_msg.SerializeToString()}) - pb = Vnet() - pb.vni = int("45654") - pb.guid.value = bytes.fromhex(uuid.UUID("559c6ce8-26ab-4193-b946-ccc6e8f930b2").hex) - appliance_id = "100" - appliance_msg = ParseDict(APPLIANCE, Appliance()) - dash_db.create_appliance(appliance_id, {"pb": appliance_msg.SerializeToString()}) - vnet_msg = ParseDict(VNET, Vnet()) - vnet = "Vnet1" - dash_db.create_vnet(vnet, {"pb": vnet_msg.SerializeToString()}) - eni_msg = ParseDict(ENI, Eni()) - eni = "F4939FEFC47E" - dash_db.create_eni(eni, {"pb": eni_msg.SerializeToString()}) - vnet_mapping_msg = ParseDict(VNET_MAPPING, VnetMapping()) - vnet_map_ip = "10.1.1.1" - dash_db.create_vnet_map(vnet, vnet_map_ip, {"pb": vnet_mapping_msg.SerializeToString()}) - route_msg = ParseDict(ROUTE, Route()) - route_prefix = "10.1.0.8/32" - dash_db.create_outbound_routing(eni, route_prefix, {"pb": route_msg.SerializeToString()}) - - time.sleep(3) - -def test_pl_eni_attrs(dash_db): - enis = dash_db.asic_eni_table.get_keys() - assert enis - eni_attrs = dash_db.asic_eni_table[enis[0]] - assert SAI_ENI_ATTR_PL_SIP in eni_attrs - assert eni_attrs[SAI_ENI_ATTR_PL_SIP] == PL_ENCODING_IP - assert SAI_ENI_ATTR_PL_SIP_MASK in eni_attrs - actual_mask = IP(eni_attrs[SAI_ENI_ATTR_PL_SIP_MASK]) - assert actual_mask == IP(PL_ENCODING_MASK) - assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs - assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP - -def test_pl_outbound_ca_to_pa_attrs(dash_db): - outbound_ca_to_pa_keys = dash_db.asic_dash_outbound_ca_to_pa_table.get_keys() - assert outbound_ca_to_pa_keys - outbound_attrs = dash_db.asic_dash_outbound_ca_to_pa_table[outbound_ca_to_pa_keys[0]] - - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION in outbound_attrs - assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION] == SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP in outbound_attrs - actual_overlay_sip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP]) - assert actual_overlay_sip == IP(PL_OVERLAY_SIP) - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP in outbound_attrs - actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP]) - assert actual_overlay_dip == IP(PL_OVERLAY_DIP) - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY in outbound_attrs - assert int(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY]) == ENCAP_VNI - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION in outbound_attrs - assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION] == SAI_DASH_ENCAPSULATION_NVGRE +class TestDashPl(DashBaseTest): + def test_pl_eni_attrs(self, dash_db, setup_route): + enis = dash_db.asic_eni_table.get_keys() + assert enis + eni_attrs = dash_db.asic_eni_table[enis[0]] + assert SAI_ENI_ATTR_PL_SIP in eni_attrs + assert eni_attrs[SAI_ENI_ATTR_PL_SIP] == PL_ENCODING_IP + assert SAI_ENI_ATTR_PL_SIP_MASK in eni_attrs + actual_mask = IP(eni_attrs[SAI_ENI_ATTR_PL_SIP_MASK]) + assert actual_mask == IP(PL_ENCODING_MASK) + assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs + assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP + + def test_pl_outbound_ca_to_pa_attrs(self, dash_db, setup_route): + outbound_ca_to_pa_keys = dash_db.asic_dash_outbound_ca_to_pa_table.get_keys() + assert outbound_ca_to_pa_keys + outbound_attrs = dash_db.asic_dash_outbound_ca_to_pa_table[outbound_ca_to_pa_keys[0]] + + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION in outbound_attrs + assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION] == SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP in outbound_attrs + actual_overlay_sip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP]) + assert actual_overlay_sip == IP(PL_OVERLAY_SIP) + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP in outbound_attrs + actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP]) + assert actual_overlay_dip == IP(PL_OVERLAY_DIP) + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY in outbound_attrs + assert int(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY]) == ENCAP_VNI + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION in outbound_attrs + assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION] == SAI_DASH_ENCAPSULATION_NVGRE diff --git a/tests/test_dash_vnet.py b/tests/test_dash_vnet.py index 868047e5d6..217000dc2f 100644 --- a/tests/test_dash_vnet.py +++ b/tests/test_dash_vnet.py @@ -7,7 +7,7 @@ from dash_api.route_type_pb2 import * from dash_api.types_pb2 import * -from dash_utils import dash_db +from dash_utils.dash_db import dash_db import time import uuid From d8252ee221f0d0e33d8466ec16be763f7792f950 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Sat, 10 Aug 2024 01:48:09 +0000 Subject: [PATCH 12/77] use newest sairedis build Signed-off-by: Lawrence Lee --- .azure-pipelines/build-docker-sonic-vs-template.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.azure-pipelines/build-docker-sonic-vs-template.yml b/.azure-pipelines/build-docker-sonic-vs-template.yml index 2610fcb837..127145e949 100644 --- a/.azure-pipelines/build-docker-sonic-vs-template.yml +++ b/.azure-pipelines/build-docker-sonic-vs-template.yml @@ -88,9 +88,12 @@ jobs: project: ${{ parameters.sairedis_artifact_project }} pipeline: ${{ parameters.sairedis_artifact_pipeline }} artifact: ${{ parameters.sairedis_artifact_name }} - runVersion: 'latestFromBranch' - runBranch: 'refs/heads/${{ parameters.sairedis_artifact_branch }}' + runVersion: 'specific' + pipelineId: 613643 + # runVersion: 'latestFromBranch' + # runBranch: 'refs/heads/${{ parameters.sairedis_artifact_branch }}' allowPartiallySucceededBuilds: true + allowFailedBuilds: true path: $(Build.ArtifactStagingDirectory)/download/sairedis patterns: | ${{ parameters.sairedis_artifact_pattern }}/libsaivs_*.deb From 49789b1cf4c20d73def0a0e3bd16a485a72e8cc1 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Sat, 10 Aug 2024 02:10:03 +0000 Subject: [PATCH 13/77] improve naming Signed-off-by: Lawrence Lee --- tests/dash_utils/dash_base_test.py | 99 ------------------------------ tests/dash_utils/dash_configs.py | 22 +++---- tests/dash_utils/dash_db.py | 8 +-- tests/dash_utils/dash_utils.py | 77 +++++++++++++++++++++++ tests/test_dash_pl.py | 85 +++++++++++++++---------- tests/test_dash_vnet.py | 2 +- 6 files changed, 147 insertions(+), 146 deletions(-) delete mode 100644 tests/dash_utils/dash_base_test.py create mode 100644 tests/dash_utils/dash_utils.py diff --git a/tests/dash_utils/dash_base_test.py b/tests/dash_utils/dash_base_test.py deleted file mode 100644 index 167ec115a4..0000000000 --- a/tests/dash_utils/dash_base_test.py +++ /dev/null @@ -1,99 +0,0 @@ -from dash_api.appliance_pb2 import * -from dash_api.vnet_pb2 import * -from dash_api.eni_pb2 import * -from dash_api.eni_route_pb2 import * -from dash_api.route_pb2 import * -from dash_api.route_group_pb2 import * -from dash_api.route_rule_pb2 import * -from dash_api.vnet_mapping_pb2 import * -from dash_api.route_type_pb2 import * -from dash_api.types_pb2 import * -from google.protobuf.json_format import ParseDict, MessageToDict - -from dash_utils.dash_db import dash_db - -import time -import uuid -import ipaddress -import socket -import pytest - -from dash_configs import * - - -class DashBaseTest(object): - - @pytest.fixture - def setup_appliance(self, dash_db): - pb = ParseDict(APPLIANCE, Appliance()) - dash_db.create_appliance(APPLIANCE_ID, {"pb": pb.SerializeToString()}) - - yield - - dash_db.remove_appliance(APPLIANCE_ID) - - @pytest.fixture - def setup_vnet(self, dash_db, setup_appliance): - pb = ParseDict(VNET, Vnet()) - dash_db.create_vnet(VNET1, {"pb": pb.SerializeToString()}) - - yield - - dash_db.remove_vnet(VNET1) - - @pytest.fixture - def setup_eni(self, dash_db, setup_vnet): - pb = ParseDict(ENI, Eni()) - dash_db.create_eni(ENI_ID, {"pb": pb.SerializeToString()}) - - yield - - dash_db.remove_eni(ENI_ID) - - @pytest.fixture - def setup_routing_type(self, dash_db): - pb = ParseDict(ROUTING_TYPE_VNET_ENCAP, RouteType()) - dash_db.create_routing_type(VNET_ENCAP, {"pb": pb.SerializeToString()}) - pb = ParseDict(ROUTING_TYPE_PL, RouteType()) - dash_db.create_routing_type(PRIVATELINK, {"pb": pb.SerializeToString()}) - - yield - - dash_db.remove_routing_type(VNET_ENCAP) - dash_db.remove_routing_type(PRIVATELINK) - - @pytest.fixture - def setup_vnet_mapping(self, dash_db, setup_eni): - pb = ParseDict(VNET_MAPPING, VnetMapping()) - dash_db.create_vnet_mapping(VNET1, VNET_MAP_IP1, {"pb": pb.SerializeToString()}) - - yield - - dash_db.remove_vnet_mapping(VNET1, VNET_MAP_IP1) - - @pytest.fixture - def setup_route_group(self, dash_db): - pb = ParseDict(ROUTE_GROUP, RouteGroup()) - dash_db.create_route_group(ROUTE_GROUP1, {"pb": pb.SerializeToString()}) - - yield - - dash_db.remove_route_group(ROUTE_GROUP1) - - @pytest.fixture - def setup_eni_route(self, dash_db, setup_eni, setup_route_group): - pb = ParseDict(ENI_ROUTE, EniRoute()) - dash_db.create_eni_route(ENI_ID, ROUTE_GROUP1, {"pb": pb.SerializeToString()}) - - yield - - dash_db.remove_eni_route(ENI_ID, ROUTE_GROUP1) - - @pytest.fixture - def setup_route(self, dash_db, setup_vnet_mapping, setup_route_group): - pb = ParseDict(ROUTE, Route()) - dash_db.create_outbound_routing(ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, {"pb": pb.SerializeToString()}) - - yield - - dash_db.remove_outbound_routing(ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) \ No newline at end of file diff --git a/tests/dash_utils/dash_configs.py b/tests/dash_utils/dash_configs.py index 1a085791b0..80a60e7e44 100644 --- a/tests/dash_utils/dash_configs.py +++ b/tests/dash_utils/dash_configs.py @@ -32,6 +32,7 @@ APPLIANCE_ID = "100" VM_VNI = "4321" +ENCAP_VNI = 100 VNET1 = "Vnet1" VNET1_VNI = "45654" VNET1_GUID = "559c6ce8-26ab-4193-b946-ccc6e8f930b2" @@ -41,21 +42,21 @@ ROUTE_GROUP1 = "RouteGroup1" ROUTE_GROUP1_GUID = "48af6ce8-26cc-4293-bfa6-0126e8fcdeb2" -APPLIANCE = { +APPLIANCE_CONFIG = { "sip": { "ipv4": socket.htonl(int(IP(SIP))) }, "vm_vni": int(VM_VNI) } -VNET = { +VNET_CONFIG = { "vni": VNET1_VNI, "guid": { "value": base64.b64encode(bytes.fromhex(uuid.UUID(VNET1_GUID).hex)) } } -ENI = { +ENI_CONFIG = { "vnet": VNET1, "underlay_ip": { "ipv4": socket.htonl(int(IP(UNDERLAY_IP))) @@ -76,7 +77,7 @@ } } -VNET_MAPPING = { +VNET_MAPPING_CONFIG = { "mac_address": bytes.fromhex(MAC_STRING), "action_type": RoutingType.ROUTING_TYPE_PRIVATELINK, "underlay_ip": { @@ -90,14 +91,12 @@ }, } -ROUTE = { +ROUTE_VNET_CONFIG = { "action_type": RoutingType.ROUTING_TYPE_VNET, "vnet": "Vnet1", } -ENCAP_VNI = 100 - -ROUTING_TYPE_VNET_ENCAP = { +ROUTING_TYPE_VNET_ENCAP_CONFIG = { "items": [ { "action_name": "action1", @@ -105,7 +104,8 @@ }, ] } -ROUTING_TYPE_PL = { + +ROUTING_TYPE_PL_CONFIG = { "items": [ { "action_name": "action1", @@ -120,11 +120,11 @@ ] } -ROUTE_GROUP = { +ROUTE_GROUP_CONFIG = { "guid": base64.b64encode(bytes.fromhex(uuid.UUID(ROUTE_GROUP1_GUID).hex)), "version": "rg_version" } -ENI_ROUTE = { +ENI_ROUTE_CONFIG = { "group_id": ROUTE_GROUP1, } \ No newline at end of file diff --git a/tests/dash_utils/dash_db.py b/tests/dash_utils/dash_db.py index a40e34496f..fedd206b7f 100644 --- a/tests/dash_utils/dash_db.py +++ b/tests/dash_utils/dash_db.py @@ -116,16 +116,16 @@ def create_vnet_map(self, vnet, ip, attr_maps: dict): def remove_vnet_map(self, vnet, ip): del self.app_dash_vnet_map_table[str(vnet) + ":" + str(ip)] - def create_outbound_routing(self, route_group, ip, attr_maps: dict): + def create_route(self, route_group, ip, attr_maps: dict): self.app_dash_route_table[str(route_group) + ":" + str(ip)] = attr_maps - def remove_outbound_routing(self, route_group, ip): + def remove_route(self, route_group, ip): del self.app_dash_route_table[str(route_group) + ":" + str(ip)] - def create_outbound_routing_group(self, route_group, attr_maps: dict): + def create_route_group(self, route_group, attr_maps: dict): self.app_dash_route_group_table[str(route_group)] = attr_maps - def remove_outbound_routing_group(self, route_group): + def remove_route_group(self, route_group): del self.app_dash_route_group_table[str(route_group)] def create_inbound_routing(self, mac_string, vni, ip, attr_maps: dict): diff --git a/tests/dash_utils/dash_utils.py b/tests/dash_utils/dash_utils.py new file mode 100644 index 0000000000..12cdc917d0 --- /dev/null +++ b/tests/dash_utils/dash_utils.py @@ -0,0 +1,77 @@ +from dash_api.appliance_pb2 import * +from dash_api.vnet_pb2 import * +from dash_api.eni_pb2 import * +from dash_api.eni_route_pb2 import * +from dash_api.route_pb2 import * +from dash_api.route_group_pb2 import * +from dash_api.route_rule_pb2 import * +from dash_api.vnet_mapping_pb2 import * +from dash_api.route_type_pb2 import * +from dash_api.types_pb2 import * +from google.protobuf.json_format import ParseDict, MessageToDict + +from dash_utils.dash_db import dash_db + +import time +import uuid +import ipaddress +import socket +import pytest + +from dash_configs import * + +def create_appliance(dash_db, appliance_id, appliance_config): + pb = ParseDict(appliance_config, Appliance()) + dash_db.create_appliance(appliance_id, {"pb": pb.SerializeToString()}) + +def remove_appliance(dash_db, appliance_id): + dash_db.remove_appliance(appliance_id) + +def create_vnet(dash_db, vnet, vnet_config): + pb = ParseDict(vnet_config, Vnet()) + dash_db.create_vnet(vnet, {"pb": pb.SerializeToString()}) + +def remove_vnet(dash_db, vnet): + dash_db.remove_vnet(vnet) + +def create_eni(dash_db, eni, eni_config): + pb = ParseDict(eni_config, Eni()) + dash_db.create_eni(eni, {"pb": pb.SerializeToString()}) + +def remove_eni(dash_db, eni): + dash_db.remove_eni(eni) + +def create_routing_type(dash_db, routing_type, routing_type_config): + pb = ParseDict(routing_type_config, RouteType()) + dash_db.create_routing_type(routing_type, {"pb": pb.SerializeToString()}) + +def remove_routing_type(dash_db, routing_type): + dash_db.remove_routing_type(routing_type) + +def create_vnet_mapping(dash_db, vnet, ip, vnet_mapping_config): + pb = ParseDict(vnet_mapping_config, VnetMapping()) + dash_db.create_vnet_mapping(vnet, ip, {"pb": pb.SerializeToString()}) + +def remove_vnet_mapping(dash_db, vnet, ip): + dash_db.remove_vnet_mapping(vnet, ip) + +def create_route_group(dash_db, route_group, route_group_config): + pb = ParseDict(route_group_config, RouteGroup()) + dash_db.create_route_group(route_group, {"pb": pb.SerializeToString()}) + +def remove_route_group(dash_db, route_group): + dash_db.remove_route_group(route_group) + +def create_eni_route(dash_db, eni, route_group, eni_route_config): + pb = ParseDict(eni_route_config, EniRoute()) + dash_db.create_eni_route(eni, route_group, {"pb": pb.SerializeToString()}) + +def remove_eni_route(dash_db, eni, route_group): + dash_db.remove_eni_route(eni, route_group) + +def create_route(dash_db, route_group, route_prefix, route_config): + pb = ParseDict(route_config, Route()) + dash_db.create_route(route_group, route_prefix, {"pb": pb.SerializeToString()}) + +def remove_route(dash_db, route_group, route_prefix): + dash_db.remove_route(route_group, route_prefix) \ No newline at end of file diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index ca6d74f84f..893e3cdf75 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -17,41 +17,64 @@ from google.protobuf.json_format import ParseDict, MessageToDict from dash_utils.dash_db import dash_db -from dash_utils.dash_base_test import DashBaseTest +from dash_utils.dash_utils import * from dash_utils.dash_configs import * from sai_attrs import * DVS_ENV = ["HWSKU=DPU-2P"] NUM_PORTS = 2 +@pytest.fixture(scope='module', autouse=True) +def common_setup_teardown(dash_db): + create_routing_type(dash_db, PRIVATELINK, ROUTING_TYPE_PRIVATELINK) + create_appliance(dash_db, APPLIANCE_ID, APPLIANCE_CONFIG) + create_vnet(dash_db, VNET1, VNET_CONFIG) + create_eni(dash_db, ENI_ID, ENI_CONFIG) + create_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) + create_route_group(dash_db, ROUTE_GROUP1, ROUTE_GROUP_CONFIG) + create_eni_route(dash_db, ENI_ID, ENI_ROUTE_CONFIG) + create_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG) -class TestDashPl(DashBaseTest): - def test_pl_eni_attrs(self, dash_db, setup_route): - enis = dash_db.asic_eni_table.get_keys() - assert enis - eni_attrs = dash_db.asic_eni_table[enis[0]] - assert SAI_ENI_ATTR_PL_SIP in eni_attrs - assert eni_attrs[SAI_ENI_ATTR_PL_SIP] == PL_ENCODING_IP - assert SAI_ENI_ATTR_PL_SIP_MASK in eni_attrs - actual_mask = IP(eni_attrs[SAI_ENI_ATTR_PL_SIP_MASK]) - assert actual_mask == IP(PL_ENCODING_MASK) - assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs - assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP - - def test_pl_outbound_ca_to_pa_attrs(self, dash_db, setup_route): - outbound_ca_to_pa_keys = dash_db.asic_dash_outbound_ca_to_pa_table.get_keys() - assert outbound_ca_to_pa_keys - outbound_attrs = dash_db.asic_dash_outbound_ca_to_pa_table[outbound_ca_to_pa_keys[0]] - - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION in outbound_attrs - assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION] == SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP in outbound_attrs - actual_overlay_sip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP]) - assert actual_overlay_sip == IP(PL_OVERLAY_SIP) - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP in outbound_attrs - actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP]) - assert actual_overlay_dip == IP(PL_OVERLAY_DIP) - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY in outbound_attrs - assert int(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY]) == ENCAP_VNI - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION in outbound_attrs - assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION] == SAI_DASH_ENCAPSULATION_NVGRE + time.sleep(3) + + yield + + remove_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) + remove_eni_route(dash_db, ENI_ID) + remove_route_group(dash_db, ROUTE_GROUP1) + remove_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1) + remove_eni(dash_db, ENI_ID) + remove_vnet(dash_db, VNET1) + remove_appliance(dash_db, APPLIANCE_ID) + remove_routing_type(dash_db, PRIVATELINK) + + +def test_pl_eni_attrs(self, dash_db): + enis = dash_db.asic_eni_table.get_keys() + assert enis + eni_attrs = dash_db.asic_eni_table[enis[0]] + assert SAI_ENI_ATTR_PL_SIP in eni_attrs + assert eni_attrs[SAI_ENI_ATTR_PL_SIP] == PL_ENCODING_IP + assert SAI_ENI_ATTR_PL_SIP_MASK in eni_attrs + actual_mask = IP(eni_attrs[SAI_ENI_ATTR_PL_SIP_MASK]) + assert actual_mask == IP(PL_ENCODING_MASK) + assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs + assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP + +def test_pl_outbound_ca_to_pa_attrs(self, dash_db): + outbound_ca_to_pa_keys = dash_db.asic_dash_outbound_ca_to_pa_table.get_keys() + assert outbound_ca_to_pa_keys + outbound_attrs = dash_db.asic_dash_outbound_ca_to_pa_table[outbound_ca_to_pa_keys[0]] + + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION in outbound_attrs + assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION] == SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP in outbound_attrs + actual_overlay_sip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP]) + assert actual_overlay_sip == IP(PL_OVERLAY_SIP) + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP in outbound_attrs + actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP]) + assert actual_overlay_dip == IP(PL_OVERLAY_DIP) + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY in outbound_attrs + assert int(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY]) == ENCAP_VNI + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION in outbound_attrs + assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION] == SAI_DASH_ENCAPSULATION_NVGRE diff --git a/tests/test_dash_vnet.py b/tests/test_dash_vnet.py index 217000dc2f..bdde51ed15 100644 --- a/tests/test_dash_vnet.py +++ b/tests/test_dash_vnet.py @@ -158,7 +158,7 @@ def test_outbound_routing(self, dash_db): pb.action_type = RoutingType.ROUTING_TYPE_VNET_DIRECT pb.vnet_direct.vnet = self.vnet pb.vnet_direct.overlay_ip.ipv4 = socket.htonl(int(ipaddress.ip_address(self.overlay_ip))) - dash_db.create_outbound_routing(self.mac_string, self.ip, {"pb": pb.SerializeToString()}) + dash_db.create_route(self.mac_string, self.ip, {"pb": pb.SerializeToString()}) time.sleep(3) outbound_routing_entries = dash_db.asic_outbound_routing_table.get_keys() From 8cc622e1819cddb7e1b9c90fb9d3dcc2084ba23d Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Mon, 12 Aug 2024 23:52:56 +0000 Subject: [PATCH 14/77] pin sairedis artifacts for route group changes Signed-off-by: Lawrence Lee --- .azure-pipelines/build-template.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.azure-pipelines/build-template.yml b/.azure-pipelines/build-template.yml index 0a680e35de..94d204f24f 100644 --- a/.azure-pipelines/build-template.yml +++ b/.azure-pipelines/build-template.yml @@ -127,9 +127,12 @@ jobs: project: ${{ parameters.sairedis_artifact_project }} pipeline: ${{ parameters.sairedis_artifact_pipeline }} artifact: ${{ parameters.sairedis_artifact_name }} - runVersion: 'latestFromBranch' - runBranch: 'refs/heads/${{ parameters.sairedis_artifact_branch }}' + runVersion: 'specific' + pipelineId: 613643 + # runVersion: 'latestFromBranch' + # runBranch: 'refs/heads/${{ parameters.sairedis_artifact_branch }}' allowPartiallySucceededBuilds: true + allowFailedBuilds: true path: $(Build.ArtifactStagingDirectory)/download/sairedis patterns: | ${{ parameters.sairedis_artifact_pattern }}/libsaivs_*.deb From 8df922408470c720cf9adc2b47fe83c6877bd0a2 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Tue, 13 Aug 2024 00:56:35 +0000 Subject: [PATCH 15/77] update DASH vnet tests for route group changes Signed-off-by: Lawrence Lee --- tests/test_dash_vnet.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/test_dash_vnet.py b/tests/test_dash_vnet.py index bdde51ed15..cdfa1ebc5e 100644 --- a/tests/test_dash_vnet.py +++ b/tests/test_dash_vnet.py @@ -1,13 +1,16 @@ from dash_api.appliance_pb2 import * from dash_api.vnet_pb2 import * from dash_api.eni_pb2 import * +from dash_api.eni_route_pb2 import * from dash_api.route_pb2 import * +from dash_api.route_group_pb2 import * from dash_api.route_rule_pb2 import * from dash_api.vnet_mapping_pb2 import * from dash_api.route_type_pb2 import * from dash_api.types_pb2 import * from dash_utils.dash_db import dash_db +from dash_utils.dash_configs import * import time import uuid @@ -149,6 +152,14 @@ def test_vnet_map(self, dash_db): assert fv[1] == "SAI_PA_VALIDATION_ENTRY_ACTION_PERMIT" def test_outbound_routing(self, dash_db): + pb = RouteGroup() + self.group_id = ROUTE_GROUP1 + dash_db.create_route_group(self.group_id, {"pb": pb.SerializeToString()}) + + pb = EniRoute() + pb.group_id = self.group_id + dash_db.create_eni_route(self.mac_string, {"pb": pb.SerializeToString()}) + self.vnet = "Vnet1" self.mac_string = "F4939FEFC47E" self.ip = "10.1.0.0/24" @@ -158,9 +169,17 @@ def test_outbound_routing(self, dash_db): pb.action_type = RoutingType.ROUTING_TYPE_VNET_DIRECT pb.vnet_direct.vnet = self.vnet pb.vnet_direct.overlay_ip.ipv4 = socket.htonl(int(ipaddress.ip_address(self.overlay_ip))) - dash_db.create_route(self.mac_string, self.ip, {"pb": pb.SerializeToString()}) + dash_db.create_route(self.group_id, self.ip, {"pb": pb.SerializeToString()}) time.sleep(3) + outbound_routing_group_entries = dash_db.asic_outbound_routing_group_table.get_keys() + + eni_entries = dash_db.asic_eni_table.get_keys() + fvs = dash_db.asic_eni_table[eni_entries[0]] + for fv in fvs.items(): + if fv[0] == "SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID": + assert fv[1] == outbound_routing_group_entries[0] + outbound_routing_entries = dash_db.asic_outbound_routing_table.get_keys() assert outbound_routing_entries fvs = dash_db.asic_outbound_routing_table[outbound_routing_entries[0]] From e5eccb685d2fee70e073070897117259d397f952 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Tue, 13 Aug 2024 02:32:19 +0000 Subject: [PATCH 16/77] update bulker for route group changes Signed-off-by: Lawrence Lee --- orchagent/bulker.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/orchagent/bulker.h b/orchagent/bulker.h index 86308329b9..ee6f1b7568 100644 --- a/orchagent/bulker.h +++ b/orchagent/bulker.h @@ -134,7 +134,7 @@ static inline bool operator==(const sai_pa_validation_entry_t& a, const sai_pa_v static inline bool operator==(const sai_outbound_routing_entry_t& a, const sai_outbound_routing_entry_t& b) { return a.switch_id == b.switch_id - && a.eni_id == b.eni_id + && a.outbound_routing_group_id == b.outbound_routing_group_id && a.destination == b.destination ; } @@ -257,7 +257,7 @@ namespace std { size_t seed = 0; boost::hash_combine(seed, a.switch_id); - boost::hash_combine(seed, a.eni_id); + boost::hash_combine(seed, a.outbound_routing_group_id); boost::hash_combine(seed, a.destination); return seed; } From cf41eedb13d53477b4a1158214c9c35184e33a87 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Tue, 13 Aug 2024 03:01:14 +0000 Subject: [PATCH 17/77] update PL dip/sip mask Signed-off-by: Lawrence Lee --- orchagent/dash/dashorch.cpp | 12 ------------ orchagent/dash/dashvnetorch.cpp | 12 ++++++------ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/orchagent/dash/dashorch.cpp b/orchagent/dash/dashorch.cpp index 54a0661286..52df40f040 100644 --- a/orchagent/dash/dashorch.cpp +++ b/orchagent/dash/dashorch.cpp @@ -385,18 +385,6 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry) eni_attr.value.u32 = app_entry.vm_vni(); eni_attrs.push_back(eni_attr); - if (entry.metadata.has_pl_sip_encoding()) - { - - eni_attr.id = SAI_ENI_ATTR_PL_SIP; - to_sai(entry.metadata.pl_sip_encoding().ip(), eni_attr.value.ipaddr); - eni_attrs.push_back(eni_attr); - - eni_attr.id = SAI_ENI_ATTR_PL_SIP_MASK; - to_sai(entry.metadata.pl_sip_encoding().mask(), eni_attr.value.ipaddr); - eni_attrs.push_back(eni_attr); - } - if (entry.metadata.has_pl_underlay_sip()) { eni_attr.id = SAI_ENI_ATTR_PL_UNDERLAY_SIP; diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index 40018f5115..0d75225aee 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -288,7 +288,7 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt DashOrch* dash_orch = gDirectory.get(); dash::route_type::RouteType route_type_actions; - if (!dash_orch->getRouteTypeActions(ctxt.metadata.action_type(), route_type_actions)) + if (!dash_orch->getRouteTypeActions(ctxt.metadata.routing_type(), route_type_actions)) { SWSS_LOG_INFO("Failed to get route type actions for %s", key.c_str()); } @@ -319,7 +319,7 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt } } - if (ctxt.metadata.action_type() == dash::route_type::ROUTING_TYPE_PRIVATELINK) + if (ctxt.metadata.routing_type() == dash::route_type::ROUTING_TYPE_PRIVATELINK) { outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION; outbound_ca_to_pa_attr.value.u32 = SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING; @@ -329,12 +329,12 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt to_sai(ctxt.metadata.underlay_ip(), outbound_ca_to_pa_attr.value.ipaddr); outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); - outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP; - to_sai(ctxt.metadata.overlay_dip(), outbound_ca_to_pa_attr.value.ipaddr); + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK; + to_sai(ctxt.metadata.overlay_dip_prefix(), outbound_ca_to_pa_attr.value.ipaddr); outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); - outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP; - to_sai(ctxt.metadata.overlay_sip(), outbound_ca_to_pa_attr.value.ipaddr); + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK; + to_sai(ctxt.metadata.overlay_sip_prefix(), outbound_ca_to_pa_attr.value.ipaddr); outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); } From aa2f1e79f33b87c6b12b37fd659aec3780bdb332 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 14 Aug 2024 22:28:59 +0000 Subject: [PATCH 18/77] fix PL test config Signed-off-by: Lawrence Lee --- tests/dash_utils/dash_configs.py | 16 ++++++++++++++-- tests/test_dash_pl.py | 26 ++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/tests/dash_utils/dash_configs.py b/tests/dash_utils/dash_configs.py index 80a60e7e44..4b8e1d9ee3 100644 --- a/tests/dash_utils/dash_configs.py +++ b/tests/dash_utils/dash_configs.py @@ -26,7 +26,8 @@ OVERLAY_IP = "10.0.0.6" PL_ENCODING_IP = "2001:0:20::" PL_ENCODING_MASK = "::ffff:ffff" -PL_UNDERLAY_SIP = "55.1.2.3" +PL_UNDERLAY_SIP1 = "55.1.2.3" +PL_UNDERLAY_SIP2 = "55.2.3.4" PL_OVERLAY_SIP = "fd40:108:0:d204:0:200::0" PL_OVERLAY_DIP = "2603:10e1:100:2::3401:203" @@ -65,7 +66,7 @@ "eni_id": ENI_ID, "admin_state": State.STATE_ENABLED, "pl_underlay_sip": { - "ipv4": socket.htonl(int(IP(PL_UNDERLAY_SIP))) + "ipv4": socket.htonl(int(IP(PL_UNDERLAY_SIP1))) }, "pl_sip_encoding": { "ip": { @@ -96,6 +97,17 @@ "vnet": "Vnet1", } +ROUTE_PL_CONFIG = { + "action_type": RoutingType.ROUTING_TYPE_PRIVATELINK, +} + +ROUTE_PL_CONFIG_WITH_UNDERLAY_SIP = { + "action_type": RoutingType.ROUTING_TYPE_PRIVATELINK, + "underlay_sip": { + "ipv4": socket.htonl(int(IP(PL_UNDERLAY_SIP2))) + } +} + ROUTING_TYPE_VNET_ENCAP_CONFIG = { "items": [ { diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index 893e3cdf75..78e149d986 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -24,6 +24,19 @@ DVS_ENV = ["HWSKU=DPU-2P"] NUM_PORTS = 2 +@pytest.fixture +def apply_base_pl_route(dash_db): + create_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG) + yield + remove_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) + +@pytest.fixture +def apply_pl_route_with_underlay_sip(dash_db): + create_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG_WITH_UNDERLAY_SIP) + yield + remove_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) + + @pytest.fixture(scope='module', autouse=True) def common_setup_teardown(dash_db): create_routing_type(dash_db, PRIVATELINK, ROUTING_TYPE_PRIVATELINK) @@ -33,13 +46,11 @@ def common_setup_teardown(dash_db): create_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) create_route_group(dash_db, ROUTE_GROUP1, ROUTE_GROUP_CONFIG) create_eni_route(dash_db, ENI_ID, ENI_ROUTE_CONFIG) - create_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG) time.sleep(3) yield - remove_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) remove_eni_route(dash_db, ENI_ID) remove_route_group(dash_db, ROUTE_GROUP1) remove_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1) @@ -49,7 +60,7 @@ def common_setup_teardown(dash_db): remove_routing_type(dash_db, PRIVATELINK) -def test_pl_eni_attrs(self, dash_db): +def test_pl_eni_attrs(self, dash_db, apply_base_pl_route): enis = dash_db.asic_eni_table.get_keys() assert enis eni_attrs = dash_db.asic_eni_table[enis[0]] @@ -59,7 +70,14 @@ def test_pl_eni_attrs(self, dash_db): actual_mask = IP(eni_attrs[SAI_ENI_ATTR_PL_SIP_MASK]) assert actual_mask == IP(PL_ENCODING_MASK) assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs - assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP + assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP1 + +def test_pl_eni_override_underlay_sip(self, dash_db, apply_pl_route_with_underlay_sip): + enis = dash_db.asic_eni_table.get_keys() + assert enis + eni_attrs = dash_db.asic_eni_table[enis[0]] + assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs + assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP2 def test_pl_outbound_ca_to_pa_attrs(self, dash_db): outbound_ca_to_pa_keys = dash_db.asic_dash_outbound_ca_to_pa_table.get_keys() From 933c24b19a41caa5ec1a0f6ce87c436aaee4c7fa Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 14 Aug 2024 23:10:14 +0000 Subject: [PATCH 19/77] fix ipaddr to ipprefix for sai attribute Signed-off-by: Lawrence Lee --- orchagent/dash/dashvnetorch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index 0d75225aee..72f064118d 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -330,11 +330,11 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK; - to_sai(ctxt.metadata.overlay_dip_prefix(), outbound_ca_to_pa_attr.value.ipaddr); + to_sai(ctxt.metadata.overlay_dip_prefix(), outbound_ca_to_pa_attr.value.ipprefix); outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK; - to_sai(ctxt.metadata.overlay_sip_prefix(), outbound_ca_to_pa_attr.value.ipaddr); + to_sai(ctxt.metadata.overlay_sip_prefix(), outbound_ca_to_pa_attr.value.ipprefix); outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); } From 4342d40050a2c833a825dfa43117bd78f114b6fe Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 15 Aug 2024 04:21:55 +0000 Subject: [PATCH 20/77] fix build Signed-off-by: Lawrence Lee --- orchagent/dash/dashorch.h | 1 + orchagent/dash/dashrouteorch.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/orchagent/dash/dashorch.h b/orchagent/dash/dashorch.h index dc1f44708f..e2b6e3554d 100644 --- a/orchagent/dash/dashorch.h +++ b/orchagent/dash/dashorch.h @@ -55,6 +55,7 @@ class DashOrch : public ZmqOrch void doTaskEniTable(ConsumerBase &consumer); void doTaskQosTable(ConsumerBase &consumer); void doTaskEniRouteTable(ConsumerBase &consumer); + void doTaskRouteGroupTable(ConsumerBase &consumer); bool addApplianceEntry(const std::string& appliance_id, const dash::appliance::Appliance &entry); bool removeApplianceEntry(const std::string& appliance_id); bool addRoutingTypeEntry(const dash::route_type::RoutingType &routing_type, const dash::route_type::RouteType &entry); diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index 10d6390f16..59b85dc72f 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -633,7 +633,7 @@ void DashRouteOrch::doTaskRouteRuleTable(ConsumerBase& consumer) } } -bool addRouteGroup(const string& route_group, const dash::route_group::RouteGroup& entry) +bool DashRouteOrch::addRouteGroup(const string& route_group, const dash::route_group::RouteGroup& entry) { SWSS_LOG_ENTER(); @@ -655,7 +655,7 @@ bool addRouteGroup(const string& route_group, const dash::route_group::RouteGrou return true; } -bool removeRouteGroup(const string& route_group) +bool DashRouteOrch::removeRouteGroup(const string& route_group) { SWSS_LOG_ENTER(); @@ -683,7 +683,7 @@ bool removeRouteGroup(const string& route_group) return true; } -void doTaskRouteGroupTable(ConsumerBase& consumer) +void DashRouteOrch::doTaskRouteGroupTable(ConsumerBase& consumer) { SWSS_LOG_ENTER(); From 16fbe6d6c23c5197b83bc6be2d6a3bbdb068248d Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 15 Aug 2024 12:22:42 -0700 Subject: [PATCH 21/77] Update import file path --- tests/dash_utils/dash_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dash_utils/dash_utils.py b/tests/dash_utils/dash_utils.py index 12cdc917d0..a1e71c4525 100644 --- a/tests/dash_utils/dash_utils.py +++ b/tests/dash_utils/dash_utils.py @@ -18,7 +18,7 @@ import socket import pytest -from dash_configs import * +from dash_utils.dash_configs import * def create_appliance(dash_db, appliance_id, appliance_config): pb = ParseDict(appliance_config, Appliance()) From 2cee9c3218ac2903a8b1711c08e99e984c43e3ee Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 15 Aug 2024 12:25:48 -0700 Subject: [PATCH 22/77] Fix action type enum usage --- tests/dash_utils/dash_configs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dash_utils/dash_configs.py b/tests/dash_utils/dash_configs.py index 4b8e1d9ee3..c3eee03c69 100644 --- a/tests/dash_utils/dash_configs.py +++ b/tests/dash_utils/dash_configs.py @@ -112,7 +112,7 @@ "items": [ { "action_name": "action1", - "action_type": ActionType.MAPROUTING + "action_type": ActionType.ACTION_TYPE_MAPROUTING }, ] } From 913fd27149a226a565efaba75140f9bcd4108773 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 15 Aug 2024 15:01:50 -0700 Subject: [PATCH 23/77] fix test config naming --- tests/test_dash_pl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index 78e149d986..81bf80d642 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -39,7 +39,7 @@ def apply_pl_route_with_underlay_sip(dash_db): @pytest.fixture(scope='module', autouse=True) def common_setup_teardown(dash_db): - create_routing_type(dash_db, PRIVATELINK, ROUTING_TYPE_PRIVATELINK) + create_routing_type(dash_db, PRIVATELINK, ROUTING_TYPE_PL_CONFIG) create_appliance(dash_db, APPLIANCE_ID, APPLIANCE_CONFIG) create_vnet(dash_db, VNET1, VNET_CONFIG) create_eni(dash_db, ENI_ID, ENI_CONFIG) From d4877a883da48af0d4e8c56c842f79ad2b7d1da9 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 15 Aug 2024 15:07:03 -0700 Subject: [PATCH 24/77] fix test errors --- tests/test_dash_vnet.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_dash_vnet.py b/tests/test_dash_vnet.py index cdfa1ebc5e..baee5b8ed7 100644 --- a/tests/test_dash_vnet.py +++ b/tests/test_dash_vnet.py @@ -158,13 +158,13 @@ def test_outbound_routing(self, dash_db): pb = EniRoute() pb.group_id = self.group_id + self.mac_string = "F4939FEFC47E" dash_db.create_eni_route(self.mac_string, {"pb": pb.SerializeToString()}) self.vnet = "Vnet1" - self.mac_string = "F4939FEFC47E" self.ip = "10.1.0.0/24" self.action_type = "vnet_direct" - self.overlay_ip= "10.0.0.6" + self.overlay_ip = "10.0.0.6" pb = Route() pb.action_type = RoutingType.ROUTING_TYPE_VNET_DIRECT pb.vnet_direct.vnet = self.vnet @@ -218,12 +218,13 @@ def test_inbound_routing(self, dash_db): def test_cleanup(self, dash_db): self.vnet = "Vnet1" self.mac_string = "F4939FEFC47E" + self.group_id = ROUTE_GROUP1 self.vni = "3251" self.sip = "10.1.1.1" self.dip = "10.1.0.0/24" self.appliance_id = "100" dash_db.remove_inbound_routing(self.mac_string, self.vni, self.sip) - dash_db.remove_outbound_routing(self.mac_string, self.dip) + dash_db.remove_route(self.group_id, self.dip) dash_db.remove_eni(self.mac_string) dash_db.remove_vnet_map(self.vnet, self.sip) dash_db.remove_vnet(self.vnet) From c45f56c02cc0e26b40975c6b97b767db43f0346a Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 15 Aug 2024 16:29:54 -0700 Subject: [PATCH 25/77] Update test_dash_pl.py --- tests/test_dash_pl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index 81bf80d642..392d8a3af7 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -43,7 +43,7 @@ def common_setup_teardown(dash_db): create_appliance(dash_db, APPLIANCE_ID, APPLIANCE_CONFIG) create_vnet(dash_db, VNET1, VNET_CONFIG) create_eni(dash_db, ENI_ID, ENI_CONFIG) - create_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) + create_vnet_map(dash_db, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) create_route_group(dash_db, ROUTE_GROUP1, ROUTE_GROUP_CONFIG) create_eni_route(dash_db, ENI_ID, ENI_ROUTE_CONFIG) @@ -53,7 +53,7 @@ def common_setup_teardown(dash_db): remove_eni_route(dash_db, ENI_ID) remove_route_group(dash_db, ROUTE_GROUP1) - remove_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1) + remove_vnet_map(dash_db, VNET1, VNET_MAP_IP1) remove_eni(dash_db, ENI_ID) remove_vnet(dash_db, VNET1) remove_appliance(dash_db, APPLIANCE_ID) From 0e76c0541c8f8402cf873838c2c62f7573257f07 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 16 Aug 2024 00:11:07 -0700 Subject: [PATCH 26/77] Deprecate VnetMapping::action_type --- orchagent/dash/dashvnetorch.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index 72f064118d..e0c72a57de 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -714,6 +714,16 @@ void DashVnetOrch::doTaskVnetMapTable(ConsumerBase& consumer) it = consumer.m_toSync.erase(it); continue; } + if (ctxt.metadata.routing_type() == dash::route_type::RoutingType::ROUTING_TYPE_UNSPECIFIED) + { + // VnetMapping::action_type is deprecated in favor of VnetMapping::routing_type. For messages still using the old action_type field, + // copy it to the new routing_type field. All subsequent operations will use the new field. + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" + SWSS_LOG_WARN("VnetMapping::action_type is deprecated. Use VnetMapping::routing_type instead") + ctxt.metadata.set_routing_type(ctxt.metadata.action_type()); + #pragma GCC diagnostic pop + } if (addVnetMap(key, ctxt)) { it = consumer.m_toSync.erase(it); From bfb3c5259af2aa4efa619f010f23dd64eafe8d98 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 16 Aug 2024 00:14:42 -0700 Subject: [PATCH 27/77] fix function call --- tests/test_dash_pl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index 392d8a3af7..81bf80d642 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -43,7 +43,7 @@ def common_setup_teardown(dash_db): create_appliance(dash_db, APPLIANCE_ID, APPLIANCE_CONFIG) create_vnet(dash_db, VNET1, VNET_CONFIG) create_eni(dash_db, ENI_ID, ENI_CONFIG) - create_vnet_map(dash_db, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) + create_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) create_route_group(dash_db, ROUTE_GROUP1, ROUTE_GROUP_CONFIG) create_eni_route(dash_db, ENI_ID, ENI_ROUTE_CONFIG) @@ -53,7 +53,7 @@ def common_setup_teardown(dash_db): remove_eni_route(dash_db, ENI_ID) remove_route_group(dash_db, ROUTE_GROUP1) - remove_vnet_map(dash_db, VNET1, VNET_MAP_IP1) + remove_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1) remove_eni(dash_db, ENI_ID) remove_vnet(dash_db, VNET1) remove_appliance(dash_db, APPLIANCE_ID) From abdfa7ea8de08cc35fc52437e1c7ff6171606781 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 16 Aug 2024 00:40:10 -0700 Subject: [PATCH 28/77] oops --- orchagent/dash/dashvnetorch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index e0c72a57de..f250ec0430 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -720,7 +720,7 @@ void DashVnetOrch::doTaskVnetMapTable(ConsumerBase& consumer) // copy it to the new routing_type field. All subsequent operations will use the new field. #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" - SWSS_LOG_WARN("VnetMapping::action_type is deprecated. Use VnetMapping::routing_type instead") + SWSS_LOG_WARN("VnetMapping::action_type is deprecated. Use VnetMapping::routing_type instead"); ctxt.metadata.set_routing_type(ctxt.metadata.action_type()); #pragma GCC diagnostic pop } From ebf3f7d394d64d40df8f48f587f790f15ac4de80 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 16 Aug 2024 11:47:59 -0700 Subject: [PATCH 29/77] Fix dash_db function name --- tests/dash_utils/dash_db.py | 4 ++-- tests/test_dash_vnet.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/dash_utils/dash_db.py b/tests/dash_utils/dash_db.py index fedd206b7f..7d4a8ced99 100644 --- a/tests/dash_utils/dash_db.py +++ b/tests/dash_utils/dash_db.py @@ -110,10 +110,10 @@ def create_eni_route(self, eni, attr_maps: dict): def remove_eni_route(self, eni): del self.app_dash_eni_route_table[str(eni)] - def create_vnet_map(self, vnet, ip, attr_maps: dict): + def create_vnet_mapping(self, vnet, ip, attr_maps: dict): self.app_dash_vnet_map_table[str(vnet) + ":" + str(ip)] = attr_maps - def remove_vnet_map(self, vnet, ip): + def remove_vnet_mapping(self, vnet, ip): del self.app_dash_vnet_map_table[str(vnet) + ":" + str(ip)] def create_route(self, route_group, ip, attr_maps: dict): diff --git a/tests/test_dash_vnet.py b/tests/test_dash_vnet.py index baee5b8ed7..5ce730fc43 100644 --- a/tests/test_dash_vnet.py +++ b/tests/test_dash_vnet.py @@ -131,8 +131,8 @@ def test_vnet_map(self, dash_db): pb.action_type = RoutingType.ROUTING_TYPE_VNET_ENCAP pb.underlay_ip.ipv4 = socket.htonl(int(ipaddress.ip_address(self.underlay_ip))) - dash_db.create_vnet_map(self.vnet, self.ip1, {"pb": pb.SerializeToString()}) - dash_db.create_vnet_map(self.vnet, self.ip2, {"pb": pb.SerializeToString()}) + dash_db.create_vnet_mapping(self.vnet, self.ip1, {"pb": pb.SerializeToString()}) + dash_db.create_vnet_mapping(self.vnet, self.ip2, {"pb": pb.SerializeToString()}) time.sleep(3) vnet_ca_to_pa_maps = dash_db.asic_dash_outbound_ca_to_pa_table.get_keys() From 9da66f2e7c1f1a11e025af553b6762e8cc22e807 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 16 Aug 2024 11:53:49 -0700 Subject: [PATCH 30/77] Check route group creation --- tests/test_dash_vnet.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/test_dash_vnet.py b/tests/test_dash_vnet.py index 5ce730fc43..0d21766dec 100644 --- a/tests/test_dash_vnet.py +++ b/tests/test_dash_vnet.py @@ -155,11 +155,21 @@ def test_outbound_routing(self, dash_db): pb = RouteGroup() self.group_id = ROUTE_GROUP1 dash_db.create_route_group(self.group_id, {"pb": pb.SerializeToString()}) + time.sleep(3) + outbound_routing_group_entries = dash_db.asic_outbound_routing_group_table.get_keys() + assert outbound_routing_group_entries pb = EniRoute() pb.group_id = self.group_id self.mac_string = "F4939FEFC47E" dash_db.create_eni_route(self.mac_string, {"pb": pb.SerializeToString()}) + time.sleep(3) + eni_entries = dash_db.asic_eni_table.get_keys() + fvs = dash_db.asic_eni_table[eni_entries[0]] + for fv in fvs.items(): + if fv[0] == "SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID": + assert fv[1] == outbound_routing_group_entries[0] + self.vnet = "Vnet1" self.ip = "10.1.0.0/24" @@ -171,15 +181,6 @@ def test_outbound_routing(self, dash_db): pb.vnet_direct.overlay_ip.ipv4 = socket.htonl(int(ipaddress.ip_address(self.overlay_ip))) dash_db.create_route(self.group_id, self.ip, {"pb": pb.SerializeToString()}) time.sleep(3) - - outbound_routing_group_entries = dash_db.asic_outbound_routing_group_table.get_keys() - - eni_entries = dash_db.asic_eni_table.get_keys() - fvs = dash_db.asic_eni_table[eni_entries[0]] - for fv in fvs.items(): - if fv[0] == "SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID": - assert fv[1] == outbound_routing_group_entries[0] - outbound_routing_entries = dash_db.asic_outbound_routing_table.get_keys() assert outbound_routing_entries fvs = dash_db.asic_outbound_routing_table[outbound_routing_entries[0]] From 3b0926a91f175fa6880709cd4f13ce4e023eb6f6 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 16 Aug 2024 13:21:24 -0700 Subject: [PATCH 31/77] Fix route group guid type --- tests/dash_utils/dash_configs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dash_utils/dash_configs.py b/tests/dash_utils/dash_configs.py index c3eee03c69..6351a5cb54 100644 --- a/tests/dash_utils/dash_configs.py +++ b/tests/dash_utils/dash_configs.py @@ -133,7 +133,7 @@ } ROUTE_GROUP_CONFIG = { - "guid": base64.b64encode(bytes.fromhex(uuid.UUID(ROUTE_GROUP1_GUID).hex)), + "guid": ROUTE_GROUP1_GUID, "version": "rg_version" } From 2004f9f83f8006de8ed2ad4e0109ac291c8aa913 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 16 Aug 2024 13:25:14 -0700 Subject: [PATCH 32/77] oops --- tests/test_dash_vnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_dash_vnet.py b/tests/test_dash_vnet.py index 0d21766dec..13a47a5079 100644 --- a/tests/test_dash_vnet.py +++ b/tests/test_dash_vnet.py @@ -227,7 +227,7 @@ def test_cleanup(self, dash_db): dash_db.remove_inbound_routing(self.mac_string, self.vni, self.sip) dash_db.remove_route(self.group_id, self.dip) dash_db.remove_eni(self.mac_string) - dash_db.remove_vnet_map(self.vnet, self.sip) + dash_db.remove_vnet_mapping(self.vnet, self.sip) dash_db.remove_vnet(self.vnet) dash_db.remove_appliance(self.appliance_id) From 5a3dbcc03b6689e91a6be39722361d3f5b96fdfc Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 16 Aug 2024 13:35:53 -0700 Subject: [PATCH 33/77] subscribe to new DASH APPL_DB tables --- orchagent/orchdaemon.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 047263c93a..0d2ab1c200 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -261,6 +261,7 @@ bool OrchDaemon::init() APP_DASH_APPLIANCE_TABLE_NAME, APP_DASH_ROUTING_TYPE_TABLE_NAME, APP_DASH_ENI_TABLE_NAME, + APP_DASH_ENI_ROUTE_TABLE_NAME, APP_DASH_QOS_TABLE_NAME }; @@ -269,7 +270,8 @@ bool OrchDaemon::init() vector dash_route_tables = { APP_DASH_ROUTE_TABLE_NAME, - APP_DASH_ROUTE_RULE_TABLE_NAME + APP_DASH_ROUTE_RULE_TABLE_NAME, + APP_DASH_ROUTE_GROUP_TABLE_NAME }; DashRouteOrch *dash_route_orch = new DashRouteOrch(m_applDb, dash_route_tables, dash_orch, m_zmqServer); From ea70423c9f0594b84137a379c2cd899cc655d8b3 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 16 Aug 2024 16:12:30 -0700 Subject: [PATCH 34/77] fix eni route creation --- tests/dash_utils/dash_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/dash_utils/dash_utils.py b/tests/dash_utils/dash_utils.py index a1e71c4525..72fb8e9da2 100644 --- a/tests/dash_utils/dash_utils.py +++ b/tests/dash_utils/dash_utils.py @@ -62,9 +62,9 @@ def create_route_group(dash_db, route_group, route_group_config): def remove_route_group(dash_db, route_group): dash_db.remove_route_group(route_group) -def create_eni_route(dash_db, eni, route_group, eni_route_config): +def create_eni_route(dash_db, eni, eni_route_config): pb = ParseDict(eni_route_config, EniRoute()) - dash_db.create_eni_route(eni, route_group, {"pb": pb.SerializeToString()}) + dash_db.create_eni_route(eni, {"pb": pb.SerializeToString()}) def remove_eni_route(dash_db, eni, route_group): dash_db.remove_eni_route(eni, route_group) From 17449626e9daa131b73ed4fbd0adc1e3634b54c6 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Sun, 18 Aug 2024 16:23:47 -0700 Subject: [PATCH 35/77] fix tests --- tests/dash_utils/dash_utils.py | 4 ++-- tests/test_dash_pl.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/dash_utils/dash_utils.py b/tests/dash_utils/dash_utils.py index 72fb8e9da2..7bec15f7ea 100644 --- a/tests/dash_utils/dash_utils.py +++ b/tests/dash_utils/dash_utils.py @@ -66,8 +66,8 @@ def create_eni_route(dash_db, eni, eni_route_config): pb = ParseDict(eni_route_config, EniRoute()) dash_db.create_eni_route(eni, {"pb": pb.SerializeToString()}) -def remove_eni_route(dash_db, eni, route_group): - dash_db.remove_eni_route(eni, route_group) +def remove_eni_route(dash_db, eni): + dash_db.remove_eni_route(eni) def create_route(dash_db, route_group, route_prefix, route_config): pb = ParseDict(route_config, Route()) diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index 81bf80d642..28dd823fb7 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -60,7 +60,7 @@ def common_setup_teardown(dash_db): remove_routing_type(dash_db, PRIVATELINK) -def test_pl_eni_attrs(self, dash_db, apply_base_pl_route): +def test_pl_eni_attrs(dash_db, apply_base_pl_route): enis = dash_db.asic_eni_table.get_keys() assert enis eni_attrs = dash_db.asic_eni_table[enis[0]] @@ -72,14 +72,14 @@ def test_pl_eni_attrs(self, dash_db, apply_base_pl_route): assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP1 -def test_pl_eni_override_underlay_sip(self, dash_db, apply_pl_route_with_underlay_sip): +def test_pl_eni_override_underlay_sip(dash_db, apply_pl_route_with_underlay_sip): enis = dash_db.asic_eni_table.get_keys() assert enis eni_attrs = dash_db.asic_eni_table[enis[0]] assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP2 -def test_pl_outbound_ca_to_pa_attrs(self, dash_db): +def test_pl_outbound_ca_to_pa_attrs(dash_db): outbound_ca_to_pa_keys = dash_db.asic_dash_outbound_ca_to_pa_table.get_keys() assert outbound_ca_to_pa_keys outbound_attrs = dash_db.asic_dash_outbound_ca_to_pa_table[outbound_ca_to_pa_keys[0]] From e6bcb5326902e9b60564f8d6f161560b25efc4e1 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Sun, 18 Aug 2024 16:03:45 -1000 Subject: [PATCH 36/77] fix inconsistent SAI attr names --- orchagent/dash/dashrouteorch.cpp | 2 ++ tests/dash_utils/dash_configs.py | 12 ++++++------ tests/sai_attrs.py | 4 ++-- tests/test_dash_pl.py | 12 ++++++------ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index 59b85dc72f..d4dfbd8154 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -115,6 +115,8 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon } outbound_routing_attrs.push_back(outbound_routing_attr); } + else if (ctxt.metadata.routing_type() == dash::route_type::RoutingType::ROUTING_TYPE_PRIVATELINK + && ctxt.metadata.has_service_tunnel()) else { SWSS_LOG_WARN("Attribute action for outbound routing entry %s", key.c_str()); diff --git a/tests/dash_utils/dash_configs.py b/tests/dash_utils/dash_configs.py index 6351a5cb54..7ca29507a3 100644 --- a/tests/dash_utils/dash_configs.py +++ b/tests/dash_utils/dash_configs.py @@ -28,8 +28,8 @@ PL_ENCODING_MASK = "::ffff:ffff" PL_UNDERLAY_SIP1 = "55.1.2.3" PL_UNDERLAY_SIP2 = "55.2.3.4" -PL_OVERLAY_SIP = "fd40:108:0:d204:0:200::0" -PL_OVERLAY_DIP = "2603:10e1:100:2::3401:203" +PL_OVERLAY_SIP_PREFIX = "fd40:108:0:d204:0:200::0/96" +PL_OVERLAY_DIP_PREFIX = "2603:10e1:100:2::3401:203/96" APPLIANCE_ID = "100" VM_VNI = "4321" @@ -84,11 +84,11 @@ "underlay_ip": { "ipv4": socket.htonl(int(IP(UNDERLAY_IP))) }, - "overlay_sip": { - "ipv6": base64.b64encode(IP(PL_OVERLAY_SIP).packed) + "overlay_sip_prefix": { + "ipv6": base64.b64encode(IP(PL_OVERLAY_SIP_PREFIX).packed) }, - "overlay_dip": { - "ipv6": base64.b64encode(IP(PL_OVERLAY_DIP).packed) + "overlay_dip_prefix": { + "ipv6": base64.b64encode(IP(PL_OVERLAY_DIP_PREFIX).packed) }, } diff --git a/tests/sai_attrs.py b/tests/sai_attrs.py index 2f3523883e..1a3b194a8e 100644 --- a/tests/sai_attrs.py +++ b/tests/sai_attrs.py @@ -4,8 +4,8 @@ SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING' SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION' -SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP' -SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_SIP_MASK = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_SIP_MASK' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY' SAI_DASH_ENCAPSULATION_NVGRE = 'SAI_DASH_ENCAPSULATION_NVGRE' \ No newline at end of file diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index 28dd823fb7..096243c8e4 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -86,12 +86,12 @@ def test_pl_outbound_ca_to_pa_attrs(dash_db): assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION in outbound_attrs assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION] == SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP in outbound_attrs - actual_overlay_sip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP]) - assert actual_overlay_sip == IP(PL_OVERLAY_SIP) - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP in outbound_attrs - actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP]) - assert actual_overlay_dip == IP(PL_OVERLAY_DIP) + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK in outbound_attrs + actual_overlay_sip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK]) + assert actual_overlay_sip == IP(PL_OVERLAY_SIP_PREFIX) + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK in outbound_attrs + actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK]) + assert actual_overlay_dip == IP(PL_OVERLAY_DIP_PREFIX) assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY in outbound_attrs assert int(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY]) == ENCAP_VNI assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION in outbound_attrs From 3de2db2cf426cd77085ab9cb50cca7956c6045cf Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Sun, 18 Aug 2024 17:04:13 -1000 Subject: [PATCH 37/77] fix outbound_ca_to_pa overlay IP and mask --- orchagent/dash/dashvnetorch.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index f250ec0430..b2f257ecc4 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -329,12 +329,21 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt to_sai(ctxt.metadata.underlay_ip(), outbound_ca_to_pa_attr.value.ipaddr); outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP; + to_sai(ctxt.metadata.overlay_dip_prefix().ip(), outbound_ca_to_pa_attr.value.ipaddr); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK; - to_sai(ctxt.metadata.overlay_dip_prefix(), outbound_ca_to_pa_attr.value.ipprefix); + to_sai(ctxt.metadata.overlay_dip_prefix().mask(), outbound_ca_to_pa_attr.value.ipaddr); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + + + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP; + to_sai(ctxt.metadata.overlay_sip_prefix().ip(), outbound_ca_to_pa_attr.value.ipaddr); outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK; - to_sai(ctxt.metadata.overlay_sip_prefix(), outbound_ca_to_pa_attr.value.ipprefix); + to_sai(ctxt.metadata.overlay_sip_prefix().mask(), outbound_ca_to_pa_attr.value.ipaddr); outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); } From 3ca5e96c6210719ea1b41afdfbc8dc9c29b22112 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Sun, 18 Aug 2024 17:19:07 -1000 Subject: [PATCH 38/77] update tests for outbound_ca_to_pa overlay SIP and DIP changes --- tests/dash_utils/dash_configs.py | 20 ++++++++++++++++---- tests/sai_attrs.py | 2 ++ tests/test_dash_pl.py | 17 +++++++++++++---- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/tests/dash_utils/dash_configs.py b/tests/dash_utils/dash_configs.py index 7ca29507a3..e3f10d6766 100644 --- a/tests/dash_utils/dash_configs.py +++ b/tests/dash_utils/dash_configs.py @@ -28,8 +28,10 @@ PL_ENCODING_MASK = "::ffff:ffff" PL_UNDERLAY_SIP1 = "55.1.2.3" PL_UNDERLAY_SIP2 = "55.2.3.4" -PL_OVERLAY_SIP_PREFIX = "fd40:108:0:d204:0:200::0/96" -PL_OVERLAY_DIP_PREFIX = "2603:10e1:100:2::3401:203/96" +PL_OVERLAY_SIP = "fd40:108:0:d204:0:200::0" +PL_OVERLAY_SIP_MASK = "ffff:ffff:ffff:ffff:ffff:ffff::" +PL_OVERLAY_DIP = "2603:10e1:100:2::3401:203" +PL_OVERLAY_DIP_MASK = "ffff:ffff:ffff:ffff:ffff:ffff::" APPLIANCE_ID = "100" VM_VNI = "4321" @@ -85,10 +87,20 @@ "ipv4": socket.htonl(int(IP(UNDERLAY_IP))) }, "overlay_sip_prefix": { - "ipv6": base64.b64encode(IP(PL_OVERLAY_SIP_PREFIX).packed) + "ip": { + "ipv6": base64.b64encode(IP(PL_OVERLAY_SIP).packed) + }, + "mask": { + "ipv6": base64.b64encode(IP(PL_OVERLAY_SIP_MASK).packed) + } }, "overlay_dip_prefix": { - "ipv6": base64.b64encode(IP(PL_OVERLAY_DIP_PREFIX).packed) + "ip": { + "ipv6": base64.b64encode(IP(PL_OVERLAY_DIP).packed) + }, + "mask": { + "ipv6": base64.b64encode(IP(PL_OVERLAY_DIP_MASK).packed) + } }, } diff --git a/tests/sai_attrs.py b/tests/sai_attrs.py index 1a3b194a8e..9354bfc05a 100644 --- a/tests/sai_attrs.py +++ b/tests/sai_attrs.py @@ -4,6 +4,8 @@ SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING' SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_SIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_SIP' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_SIP_MASK = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_SIP_MASK' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION' diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index 096243c8e4..e1718a364a 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -86,12 +86,21 @@ def test_pl_outbound_ca_to_pa_attrs(dash_db): assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION in outbound_attrs assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION] == SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING + + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK in outbound_attrs + actual_overlay_sip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP]) + assert actual_overlay_sip == IP(PL_OVERLAY_SIP) assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK in outbound_attrs - actual_overlay_sip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK]) - assert actual_overlay_sip == IP(PL_OVERLAY_SIP_PREFIX) + actual_overlay_sip_mask = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK]) + assert actual_overlay_sip_mask == IP(PL_OVERLAY_SIP_MASK) + + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP in outbound_attrs + actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP]) + assert actual_overlay_dip == IP(PL_OVERLAY_DIP) assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK in outbound_attrs - actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK]) - assert actual_overlay_dip == IP(PL_OVERLAY_DIP_PREFIX) + actual_overlay_dip_mask = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK]) + assert actual_overlay_dip == IP(PL_OVERLAY_DIP_MASK) + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY in outbound_attrs assert int(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY]) == ENCAP_VNI assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION in outbound_attrs From 0ba041aad5dcbbfe006d7ee39aecd4d8a1289d2d Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Sun, 18 Aug 2024 17:31:53 -1000 Subject: [PATCH 39/77] add dash_route_table override underlay_sip for PL --- orchagent/dash/dashrouteorch.cpp | 11 ++++++++++- tests/sai_attrs.py | 3 ++- tests/test_dash_pl.py | 10 +++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index d4dfbd8154..a90727d15c 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -116,7 +116,16 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon outbound_routing_attrs.push_back(outbound_routing_attr); } else if (ctxt.metadata.routing_type() == dash::route_type::RoutingType::ROUTING_TYPE_PRIVATELINK - && ctxt.metadata.has_service_tunnel()) + && ctxt.metadata.has_underlay_sip() + && ctxt.metadata.underlay_sip().has_ipv4()) + { + outbound_routing_attr.id = SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP; + if (!to_sai(ctxt.metadata.underlay_sip(), outbound_routing_attr.value.ipaddr)) + { + return false; + } + outbound_routing_attrs.push_back(outbound_routing_attr); + } else { SWSS_LOG_WARN("Attribute action for outbound routing entry %s", key.c_str()); diff --git a/tests/sai_attrs.py b/tests/sai_attrs.py index 9354bfc05a..52a940c7fe 100644 --- a/tests/sai_attrs.py +++ b/tests/sai_attrs.py @@ -10,4 +10,5 @@ SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY' -SAI_DASH_ENCAPSULATION_NVGRE = 'SAI_DASH_ENCAPSULATION_NVGRE' \ No newline at end of file +SAI_DASH_ENCAPSULATION_NVGRE = 'SAI_DASH_ENCAPSULATION_NVGRE' +SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP = 'SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP' \ No newline at end of file diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index e1718a364a..356cc63b5c 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -73,11 +73,11 @@ def test_pl_eni_attrs(dash_db, apply_base_pl_route): assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP1 def test_pl_eni_override_underlay_sip(dash_db, apply_pl_route_with_underlay_sip): - enis = dash_db.asic_eni_table.get_keys() - assert enis - eni_attrs = dash_db.asic_eni_table[enis[0]] - assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs - assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP2 + outbound_routing_keys = dash_db.asic_outbound_routing_table.get_keys() + assert outbonud_routing_keys + outbound_routing_attrs = dash_db.asic_outbound_routing_table[outbound_routing_keys[0]] + assert SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP in outbound_routing_attrs + assert IP(outbound_routing_attrs[SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP]) == IP(PL_UNDERLAY_SIP2) def test_pl_outbound_ca_to_pa_attrs(dash_db): outbound_ca_to_pa_keys = dash_db.asic_dash_outbound_ca_to_pa_table.get_keys() From f0e7f8c9371f8bc06ba41ebd6e5d0192172c72a9 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Mon, 26 Aug 2024 23:44:09 +0000 Subject: [PATCH 40/77] fix SAI attribute constants Signed-off-by: Lawrence Lee --- tests/sai_attrs.py | 10 ++++++---- tests/test_dash_pl.py | 10 +++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/sai_attrs.py b/tests/sai_attrs.py index 52a940c7fe..daec8373a8 100644 --- a/tests/sai_attrs.py +++ b/tests/sai_attrs.py @@ -3,11 +3,13 @@ SAI_ENI_ATTR_PL_UNDERLAY_SIP = 'SAI_ENI_ATTR_PL_UNDERLAY_SIP' SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING' SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION' -SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_SIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_SIP' -SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP' -SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_SIP_MASK = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_SIP_MASK' -SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK' +SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY' SAI_DASH_ENCAPSULATION_NVGRE = 'SAI_DASH_ENCAPSULATION_NVGRE' diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index 356cc63b5c..b209273ff2 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -74,7 +74,7 @@ def test_pl_eni_attrs(dash_db, apply_base_pl_route): def test_pl_eni_override_underlay_sip(dash_db, apply_pl_route_with_underlay_sip): outbound_routing_keys = dash_db.asic_outbound_routing_table.get_keys() - assert outbonud_routing_keys + assert outbound_routing_keys outbound_routing_attrs = dash_db.asic_outbound_routing_table[outbound_routing_keys[0]] assert SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP in outbound_routing_attrs assert IP(outbound_routing_attrs[SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP]) == IP(PL_UNDERLAY_SIP2) @@ -94,11 +94,11 @@ def test_pl_outbound_ca_to_pa_attrs(dash_db): actual_overlay_sip_mask = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK]) assert actual_overlay_sip_mask == IP(PL_OVERLAY_SIP_MASK) - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP in outbound_attrs - actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP]) + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP in outbound_attrs + actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP]) assert actual_overlay_dip == IP(PL_OVERLAY_DIP) - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK in outbound_attrs - actual_overlay_dip_mask = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTRY_OVERLAY_DIP_MASK]) + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK in outbound_attrs + actual_overlay_dip_mask = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK]) assert actual_overlay_dip == IP(PL_OVERLAY_DIP_MASK) assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY in outbound_attrs From e26658dde93efd38110d9c513f0993efe829a82f Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Mon, 26 Aug 2024 23:54:11 +0000 Subject: [PATCH 41/77] remove unrelated file Signed-off-by: Lawrence Lee --- tests/mock_tests/mac_move_ut.cpp | 172 ------------------------------- 1 file changed, 172 deletions(-) delete mode 100644 tests/mock_tests/mac_move_ut.cpp diff --git a/tests/mock_tests/mac_move_ut.cpp b/tests/mock_tests/mac_move_ut.cpp deleted file mode 100644 index 0bd2d4228e..0000000000 --- a/tests/mock_tests/mac_move_ut.cpp +++ /dev/null @@ -1,172 +0,0 @@ -#define private public -#include "directory.h" -#undef private -#define protected public -#include "orch.h" -#undef protected -#include "ut_helper.h" -#include "mock_orchagent_main.h" -#include "mock_sai_api.h" -#include "mock_orch_test.h" -#include "gtest/gtest.h" -#include -#include - -EXTERN_MOCK_FNS - -namespace mac_move_test -{ - DEFINE_SAI_API_MOCK(neighbor); - DEFINE_SAI_API_MOCK(route); - DEFINE_SAI_GENERIC_API_MOCK(acl, acl_entry); - DEFINE_SAI_GENERIC_API_MOCK(next_hop, next_hop); - using namespace std; - using namespace mock_orch_test; - using ::testing::Return; - using ::testing::Throw; - - // static const string ACTIVE_INTERFACE = "Ethernet4"; - // static const string STANDBY_INTERFACE = "Ethernet8"; - static const string NEIGH_IP = "192.168.0.100"; - - class MacMoveTest : public MockOrchTest - { - protected: - MuxCable* m_ActiveMuxCable; - MuxCable* m_StandbyMuxCable; - - void SetMuxStateFromAppDb(std::string interface, std::string state) - { - Table mux_cable_table = Table(m_app_db.get(), APP_MUX_CABLE_TABLE_NAME); - mux_cable_table.set(interface, { { STATE, state } }); - m_MuxCableOrch->addExistingData(&mux_cable_table); - static_cast(m_MuxCableOrch)->doTask(); - } - - void SetAndAssertMuxState(MuxCable* cable, std::string state) - { - cable->setState(state); - EXPECT_EQ(state, cable->getState()); - } - - void ApplyInitialConfigs() - { - Table peer_switch_table = Table(m_config_db.get(), CFG_PEER_SWITCH_TABLE_NAME); - Table tunnel_table = Table(m_app_db.get(), APP_TUNNEL_DECAP_TABLE_NAME); - Table mux_cable_table = Table(m_config_db.get(), CFG_MUX_CABLE_TABLE_NAME); - Table port_table = Table(m_app_db.get(), APP_PORT_TABLE_NAME); - Table vlan_table = Table(m_app_db.get(), APP_VLAN_TABLE_NAME); - Table vlan_member_table = Table(m_app_db.get(), APP_VLAN_MEMBER_TABLE_NAME); - Table neigh_table = Table(m_app_db.get(), APP_NEIGH_TABLE_NAME); - Table intf_table = Table(m_app_db.get(), APP_INTF_TABLE_NAME); - - auto ports = ut_helper::getInitialSaiPorts(); - port_table.set(ACTIVE_INTERFACE, ports[ACTIVE_INTERFACE]); - port_table.set(STANDBY_INTERFACE, ports[STANDBY_INTERFACE]); - port_table.set("PortConfigDone", { { "count", to_string(1) } }); - port_table.set("PortInitDone", { {} }); - - neigh_table.set( - VLAN_1000 + neigh_table.getTableNameSeparator() + SERVER_IP1, { { "neigh", MAC1 }, - { "family", "IPv4" } }); - - vlan_table.set(VLAN_1000, { { "admin_status", "up" }, - { "mtu", "9100" }, - { "mac", "00:aa:bb:cc:dd:ee" } }); - vlan_member_table.set( - VLAN_1000 + vlan_member_table.getTableNameSeparator() + ACTIVE_INTERFACE, - { { "tagging_mode", "untagged" } }); - - vlan_member_table.set( - VLAN_1000 + vlan_member_table.getTableNameSeparator() + STANDBY_INTERFACE, - { { "tagging_mode", "untagged" } }); - - intf_table.set(VLAN_1000, { { "grat_arp", "enabled" }, - { "proxy_arp", "enabled" }, - { "mac_addr", "00:00:00:00:00:00" } }); - intf_table.set( - VLAN_1000 + neigh_table.getTableNameSeparator() + "192.168.0.1/21", { - { "scope", "global" }, - { "family", "IPv4" }, - }); - - tunnel_table.set(MUX_TUNNEL, { { "dscp_mode", "uniform" }, - { "dst_ip", "2.2.2.2" }, - { "ecn_mode", "copy_from_outer" }, - { "encap_ecn_mode", "standard" }, - { "ttl_mode", "pipe" }, - { "tunnel_type", "IPINIP" } }); - - peer_switch_table.set(PEER_SWITCH_HOSTNAME, { { "address_ipv4", PEER_IPV4_ADDRESS } }); - - mux_cable_table.set(ACTIVE_INTERFACE, { { "server_ipv4", SERVER_IP1 + "/32" }, - { "server_ipv6", "a::a/128" }, - { "state", "auto" } }); - - mux_cable_table.set(STANDBY_INTERFACE, { { "server_ipv4", SERVER_IP2 + "/32" }, - { "server_ipv6", "a::a/128" }, - { "state", "auto" } }); - - gPortsOrch->addExistingData(&port_table); - gPortsOrch->addExistingData(&vlan_table); - gPortsOrch->addExistingData(&vlan_member_table); - static_cast(gPortsOrch)->doTask(); - - gIntfsOrch->addExistingData(&intf_table); - static_cast(gIntfsOrch)->doTask(); - - m_TunnelDecapOrch->addExistingData(&tunnel_table); - static_cast(m_TunnelDecapOrch)->doTask(); - - m_MuxOrch->addExistingData(&peer_switch_table); - static_cast(m_MuxOrch)->doTask(); - - m_MuxOrch->addExistingData(&mux_cable_table); - static_cast(m_MuxOrch)->doTask(); - - gNeighOrch->addExistingData(&neigh_table); - static_cast(gNeighOrch)->doTask(); - - m_ActiveMuxCable = m_MuxOrch->getMuxCable(ACTIVE_INTERFACE); - m_StandbyMuxCable = m_MuxOrch->getMuxCable(STANDBY_INTERFACE); - - // We always expect the mux to be initialized to standby - SetAndAssertMuxState(m_ActiveMuxCable, ACTIVE_STATE); - SetAndAssertMuxState(m_StandbyMuxCable, STANDBY_STATE); - } - - void PostSetUp() override - { - INIT_SAI_API_MOCK(neighbor); - INIT_SAI_API_MOCK(route); - INIT_SAI_API_MOCK(acl); - INIT_SAI_API_MOCK(next_hop); - MockSaiApis(); - } - - void PreTearDown() override - { - RestoreSaiApis(); - } - }; - - - - TEST_F(MacMoveTest, TestTestTest) - { - FdbEntry activeEntry = {MAC1, 0, ACTIVE_INTERFACE}; - FdbEntry standbyEntry = {MAC1, 0, STANDBY_INTERFACE}; - Port activePort, standbyPort; - gPortsOrch->getPort(ACTIVE_INTERFACE, activePort); - gPortsOrch->getPort(STANDBY_INTERFACE, standbyPort); - FdbUpdate activeUpdate = {activeEntry, activePort, "", true, SAI_FDB_ENTRY_TYPE_DYNAMIC}; - FdbUpdate standbyUpdate = {standbyEntry, standbyPort, "", true, SAI_FDB_ENTRY_TYPE_DYNAMIC}; - sleep(5); - for (int i = 0; i < 1000000; i++) - { - m_MuxOrch->update(SUBJECT_TYPE_FDB_CHANGE, static_cast (&activeUpdate)); - m_MuxOrch->update(SUBJECT_TYPE_FDB_CHANGE, static_cast (&standbyUpdate)); - } - sleep(60); - } -} From ae761f8f58cdcb69ea9a1423e2cf75b37a66415a Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Mon, 26 Aug 2024 23:54:52 +0000 Subject: [PATCH 42/77] fix DASH test configs and formatting Signed-off-by: Lawrence Lee --- tests/dash_utils/dash_configs.py | 8 ++++---- tests/dash_utils/dash_db.py | 2 +- tests/dash_utils/dash_utils.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/dash_utils/dash_configs.py b/tests/dash_utils/dash_configs.py index e3f10d6766..8290d6ab0b 100644 --- a/tests/dash_utils/dash_configs.py +++ b/tests/dash_utils/dash_configs.py @@ -24,14 +24,14 @@ UNDERLAY_IP = "101.1.2.3" OUTBOUND_ROUTE_PREFIX = "10.1.0.8/32" OVERLAY_IP = "10.0.0.6" -PL_ENCODING_IP = "2001:0:20::" -PL_ENCODING_MASK = "::ffff:ffff" +PL_ENCODING_IP = "::56b2:0:20:0:0" +PL_ENCODING_MASK = "::ffff:ffff:ffff:0:0" PL_UNDERLAY_SIP1 = "55.1.2.3" PL_UNDERLAY_SIP2 = "55.2.3.4" PL_OVERLAY_SIP = "fd40:108:0:d204:0:200::0" PL_OVERLAY_SIP_MASK = "ffff:ffff:ffff:ffff:ffff:ffff::" PL_OVERLAY_DIP = "2603:10e1:100:2::3401:203" -PL_OVERLAY_DIP_MASK = "ffff:ffff:ffff:ffff:ffff:ffff::" +PL_OVERLAY_DIP_MASK = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" APPLIANCE_ID = "100" VM_VNI = "4321" @@ -151,4 +151,4 @@ ENI_ROUTE_CONFIG = { "group_id": ROUTE_GROUP1, -} \ No newline at end of file +} diff --git a/tests/dash_utils/dash_db.py b/tests/dash_utils/dash_db.py index 7d4a8ced99..84298ba6d3 100644 --- a/tests/dash_utils/dash_db.py +++ b/tests/dash_utils/dash_db.py @@ -138,4 +138,4 @@ def create_routing_type(self, routing_type, attr_maps: dict): self.app_dash_routing_type_table[str(routing_type)] = attr_maps def remove_routing_type(self, routing_type): - del self.app_dash_routing_type_table[str(routing_type)] \ No newline at end of file + del self.app_dash_routing_type_table[str(routing_type)] diff --git a/tests/dash_utils/dash_utils.py b/tests/dash_utils/dash_utils.py index 7bec15f7ea..eeba641cd4 100644 --- a/tests/dash_utils/dash_utils.py +++ b/tests/dash_utils/dash_utils.py @@ -74,4 +74,4 @@ def create_route(dash_db, route_group, route_prefix, route_config): dash_db.create_route(route_group, route_prefix, {"pb": pb.SerializeToString()}) def remove_route(dash_db, route_group, route_prefix): - dash_db.remove_route(route_group, route_prefix) \ No newline at end of file + dash_db.remove_route(route_group, route_prefix) From c8156a1171a9c20816b7baea5f8fef9314f9be99 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Tue, 27 Aug 2024 21:08:45 +0000 Subject: [PATCH 43/77] remove tests for deprecated attributes Signed-off-by: Lawrence Lee --- tests/test_dash_pl.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index b209273ff2..b270987519 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -64,11 +64,6 @@ def test_pl_eni_attrs(dash_db, apply_base_pl_route): enis = dash_db.asic_eni_table.get_keys() assert enis eni_attrs = dash_db.asic_eni_table[enis[0]] - assert SAI_ENI_ATTR_PL_SIP in eni_attrs - assert eni_attrs[SAI_ENI_ATTR_PL_SIP] == PL_ENCODING_IP - assert SAI_ENI_ATTR_PL_SIP_MASK in eni_attrs - actual_mask = IP(eni_attrs[SAI_ENI_ATTR_PL_SIP_MASK]) - assert actual_mask == IP(PL_ENCODING_MASK) assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP1 From 26e2a22317b272a2e5c786f7f1f6a0cceafee434 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Tue, 27 Aug 2024 23:28:09 +0000 Subject: [PATCH 44/77] poll continuously for asic DB changes Signed-off-by: Lawrence Lee --- tests/dash_utils/dash_db.py | 73 ++++++++++++++++++++++++++++ tests/test_dash_pl.py | 97 +++++++++++++++++++++++-------------- 2 files changed, 134 insertions(+), 36 deletions(-) diff --git a/tests/dash_utils/dash_db.py b/tests/dash_utils/dash_db.py index 84298ba6d3..7b5937dda7 100644 --- a/tests/dash_utils/dash_db.py +++ b/tests/dash_utils/dash_db.py @@ -1,7 +1,33 @@ from swsscommon import swsscommon +from dvslib.dvs_common import wait_for_result import typing import pytest +from dash_api.appliance_pb2 import * +from dash_api.vnet_pb2 import * +from dash_api.eni_pb2 import * +from dash_api.eni_route_pb2 import * +from dash_api.route_pb2 import * +from dash_api.route_group_pb2 import * +from dash_api.route_rule_pb2 import * +from dash_api.vnet_mapping_pb2 import * +from dash_api.route_type_pb2 import * +from dash_api.types_pb2 import * +from google.protobuf.json_format import ParseDict +from google.protobuf.message import Message + +APP_DB_TO_PROTOBUF_MAP = { + swsscommon.APP_DASH_APPLIANCE_TABLE_NAME: Appliance, + swsscommon.APP_DASH_VNET_TABLE_NAME: Vnet, + swsscommon.APP_DASH_ENI_TABLE_NAME: Eni, + swsscommon.APP_DASH_VNET_MAPPING_TABLE_NAME: VnetMapping, + swsscommon.APP_DASH_ROUTE_TABLE_NAME: Route, + swsscommon.APP_DASH_ROUTE_RULE_TABLE_NAME: RouteRule, + swsscommon.APP_DASH_ENI_ROUTE_TABLE_NAME: EniRoute, + swsscommon.APP_DASH_ROUTING_TYPE_TABLE_NAME: RouteType, + swsscommon.APP_DASH_ROUTE_GROUP_TABLE_NAME: RouteGroup +} + @pytest.fixture(scope='module') def dash_db(dvs): return DashDB(dvs) @@ -44,6 +70,53 @@ def get_newly_created_oid(self, old_oids): class DashDB(object): + + def parse_key_value(self, arglist): + if len(arglist) < 2: + raise ValueError("Invalid number of arguments") + # elif len(arglist) == 1: + # handle case where no value is passed (e.g. in remove_app_db_entry) + # key = arglist[0] + # value = None + else: + # concat all parts of the key, assume last arg to be the value + key = ":".join(arglist[:-1]) + value = arglist[-1] + return key, value + + def set_app_db_entry(self, table_name, *args): + key, value = self.parse_key_value(args) + if isinstance(value, dict): + pb = ParseDict(value, APP_DB_TO_PROTOBUF_MAP[table_name]()) + pb_string = pb.SerializeToString() + elif isinstance(value, Message): + pb_string = value.SerializeToString() + else: + pb_string = value + + table = ProducerStateTable(self.dvs.get_app_db().db_connection, table_name) + table[key] = {'pb': pb_string} + + def remove_app_db_entry(self, table_name, *key_parts): + # key, _ = self.parse_key_value(args) + key = ":".join(key_parts) + table = ProducerStateTable(self.dvs.get_app_db().db_connection, table_name) + del table[key] + + def get_asic_db_entry(self, table_name, key): + table = Table(self.dvs.get_asic_db().db_connection, table_name) + return table[key] + + def wait_for_asic_db_keys(self, table_name): + + def polling_function(): + table = Table(self.dvs.get_asic_db().db_connection, table_name) + keys = table.get_keys() + return bool(keys), keys + + _, keys = wait_for_result(polling_function) + return keys + def __init__(self, dvs): self.dvs = dvs self.app_dash_routing_type_table = ProducerStateTable( diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index b270987519..f233df9dca 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -5,6 +5,7 @@ import uuid from ipaddress import ip_address as IP +from dvslib.dvs_common import wait_for_result from dash_api.appliance_pb2 import * from dash_api.vnet_pb2 import * @@ -16,73 +17,97 @@ from dash_api.types_pb2 import * from google.protobuf.json_format import ParseDict, MessageToDict -from dash_utils.dash_db import dash_db +from dash_utils.dash_db import dash_db, DashDB from dash_utils.dash_utils import * from dash_utils.dash_configs import * from sai_attrs import * +from swsscommon.swsscommon import APP_DASH_APPLIANCE_TABLE_NAME, APP_DASH_ENI_TABLE_NAME, APP_DASH_VNET_TABLE_NAME, APP_DASH_VNET_MAPPING_TABLE_NAME, APP_DASH_ROUTE_TABLE_NAME, APP_DASH_ROUTE_RULE_TABLE_NAME, APP_DASH_ENI_ROUTE_TABLE_NAME, APP_DASH_ROUTING_TYPE_TABLE_NAME, APP_DASH_ROUTE_GROUP_TABLE_NAME DVS_ENV = ["HWSKU=DPU-2P"] NUM_PORTS = 2 @pytest.fixture -def apply_base_pl_route(dash_db): - create_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG) +def apply_base_pl_route(dash_db: DashDB): + + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_CONFIG) + #create_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG) yield - remove_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) + dash_db.remove_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID ) + dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) + #remove_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) @pytest.fixture -def apply_pl_route_with_underlay_sip(dash_db): - create_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG_WITH_UNDERLAY_SIP) +def apply_pl_route_with_underlay_sip(dash_db: DashDB): + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG_WITH_UNDERLAY_SIP) + dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_CONFIG) + #create_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG_WITH_UNDERLAY_SIP) + #create_eni_route(dash_db, ENI_ID, ENI_ROUTE_CONFIG) yield - remove_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) + dash_db.remove_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID) + dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) + #remove_eni_route(dash_db, ENI_ID) + #remove_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) -@pytest.fixture(scope='module', autouse=True) -def common_setup_teardown(dash_db): - create_routing_type(dash_db, PRIVATELINK, ROUTING_TYPE_PL_CONFIG) - create_appliance(dash_db, APPLIANCE_ID, APPLIANCE_CONFIG) - create_vnet(dash_db, VNET1, VNET_CONFIG) - create_eni(dash_db, ENI_ID, ENI_CONFIG) - create_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) - create_route_group(dash_db, ROUTE_GROUP1, ROUTE_GROUP_CONFIG) - create_eni_route(dash_db, ENI_ID, ENI_ROUTE_CONFIG) - time.sleep(3) +@pytest.fixture(scope='module', autouse=True) +def common_setup_teardown(dash_db: DashDB): + dash_db.set_app_db_entry(APP_DASH_ROUTING_TYPE_TABLE_NAME, PRIVATELINK, ROUTING_TYPE_PL_CONFIG) + dash_db.set_app_db_entry(APP_DASH_APPLIANCE_TABLE_NAME, APPLIANCE_ID, APPLIANCE_CONFIG) + dash_db.set_app_db_entry(APP_DASH_VNET_TABLE_NAME, VNET1, VNET_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ENI_TABLE_NAME, ENI_ID, ENI_CONFIG) + dash_db.set_app_db_entry(APP_DASH_VNET_MAPPING_TABLE_NAME, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1, ROUTE_GROUP_CONFIG) + + # create_routing_type(dash_db, PRIVATELINK, ROUTING_TYPE_PL_CONFIG) + # create_appliance(dash_db, APPLIANCE_ID, APPLIANCE_CONFIG) + # create_vnet(dash_db, VNET1, VNET_CONFIG) + # create_eni(dash_db, ENI_ID, ENI_CONFIG) + # create_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) + # create_route_group(dash_db, ROUTE_GROUP1, ROUTE_GROUP_CONFIG) yield - remove_eni_route(dash_db, ENI_ID) - remove_route_group(dash_db, ROUTE_GROUP1) - remove_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1) - remove_eni(dash_db, ENI_ID) - remove_vnet(dash_db, VNET1) - remove_appliance(dash_db, APPLIANCE_ID) - remove_routing_type(dash_db, PRIVATELINK) + dash_db.remove_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1) + dash_db.remove_app_db_entry(APP_DASH_VNET_MAPPING_TABLE_NAME, VNET1, VNET_MAP_IP1) + dash_db.remove_app_db_entry(APP_DASH_ENI_TABLE_NAME, ENI_ID) + dash_db.remove_app_db_entry(APP_DASH_VNET_TABLE_NAME, VNET1) + dash_db.remove_app_db_entry(APP_DASH_APPLIANCE_TABLE_NAME, APPLIANCE_ID) + dash_db.remove_app_db_entry(APP_DASH_ROUTING_TYPE_TABLE_NAME, PRIVATELINK) + # remove_route_group(dash_db, ROUTE_GROUP1) + # remove_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1) + # remove_eni(dash_db, ENI_ID) + # remove_vnet(dash_db, VNET1) + # remove_appliance(dash_db, APPLIANCE_ID) + # remove_routing_type(dash_db, PRIVATELINK) -def test_pl_eni_attrs(dash_db, apply_base_pl_route): - enis = dash_db.asic_eni_table.get_keys() + +def test_pl_eni_attrs(dash_db: DashDB, apply_base_pl_route): + enis= dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_ENI") assert enis - eni_attrs = dash_db.asic_eni_table[enis[0]] + eni_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_ENI", enis[0]) + # eni_attrs = dash_db.asic_eni_table[enis[0]] assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP1 -def test_pl_eni_override_underlay_sip(dash_db, apply_pl_route_with_underlay_sip): - outbound_routing_keys = dash_db.asic_outbound_routing_table.get_keys() - assert outbound_routing_keys - outbound_routing_attrs = dash_db.asic_outbound_routing_table[outbound_routing_keys[0]] +def test_pl_eni_override_underlay_sip(dash_db: DashDB, apply_pl_route_with_underlay_sip): + outbound_routing_keys = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY") + assert outbound_routing_keys + outbound_routing_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY", outbound_routing_keys[0]) assert SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP in outbound_routing_attrs assert IP(outbound_routing_attrs[SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP]) == IP(PL_UNDERLAY_SIP2) -def test_pl_outbound_ca_to_pa_attrs(dash_db): - outbound_ca_to_pa_keys = dash_db.asic_dash_outbound_ca_to_pa_table.get_keys() +def test_pl_outbound_ca_to_pa_attrs(dash_db: DashDB): + outbound_ca_to_pa_keys = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_CA_TO_PA_ENTRY") assert outbound_ca_to_pa_keys - outbound_attrs = dash_db.asic_dash_outbound_ca_to_pa_table[outbound_ca_to_pa_keys[0]] + outbound_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_CA_TO_PA_ENTRY", outbound_ca_to_pa_keys[0]) assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION in outbound_attrs assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION] == SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK in outbound_attrs + assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP in outbound_attrs actual_overlay_sip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP]) assert actual_overlay_sip == IP(PL_OVERLAY_SIP) assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK in outbound_attrs @@ -94,7 +119,7 @@ def test_pl_outbound_ca_to_pa_attrs(dash_db): assert actual_overlay_dip == IP(PL_OVERLAY_DIP) assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK in outbound_attrs actual_overlay_dip_mask = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK]) - assert actual_overlay_dip == IP(PL_OVERLAY_DIP_MASK) + assert actual_overlay_dip_mask == IP(PL_OVERLAY_DIP_MASK) assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY in outbound_attrs assert int(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY]) == ENCAP_VNI From a770e872d012fd52519d442b437e2d240320723d Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Tue, 27 Aug 2024 23:29:12 +0000 Subject: [PATCH 45/77] cleanup imports Signed-off-by: Lawrence Lee --- tests/test_dash_pl.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index f233df9dca..d3b1e51741 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -1,11 +1,6 @@ -import base64 -import socket import pytest -import time -import uuid from ipaddress import ip_address as IP -from dvslib.dvs_common import wait_for_result from dash_api.appliance_pb2 import * from dash_api.vnet_pb2 import * @@ -15,7 +10,6 @@ from dash_api.vnet_mapping_pb2 import * from dash_api.route_type_pb2 import * from dash_api.types_pb2 import * -from google.protobuf.json_format import ParseDict, MessageToDict from dash_utils.dash_db import dash_db, DashDB from dash_utils.dash_utils import * From 62888f934f22efb769b60fdc7575e280d1beee73 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Tue, 27 Aug 2024 23:29:57 +0000 Subject: [PATCH 46/77] remove deprecated yield_fixture use Signed-off-by: Lawrence Lee --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 93f54c824e..c94224539b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1877,7 +1877,7 @@ def dvs(request, manage_dvs) -> DockerVirtualSwitch: return manage_dvs(log_path, dvs_env) -@pytest.yield_fixture(scope="module") +@pytest.fixture(scope="module") def vst(request): vctns = request.config.getoption("--vctns") topo = request.config.getoption("--topo") From d3a8291ca8493118fbd3582c2190b6799ce12ee7 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Tue, 27 Aug 2024 23:47:08 +0000 Subject: [PATCH 47/77] remove unneeded return Signed-off-by: Lawrence Lee --- tests/test_dash_vnet.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_dash_vnet.py b/tests/test_dash_vnet.py index 13a47a5079..ee3a236697 100644 --- a/tests/test_dash_vnet.py +++ b/tests/test_dash_vnet.py @@ -111,8 +111,6 @@ def test_eni(self, dash_db): eni_attrs = dash_db.asic_eni_table[self.eni_oid] assert eni_attrs["SAI_ENI_ATTR_ADMIN_STATE"] == "false" - return dash_db - def test_vnet_map(self, dash_db): self.vnet = "Vnet1" self.ip1 = "10.1.1.1" From cd2f84885c529c598dba73d4b8b490a139ef417f Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 28 Aug 2024 00:01:40 +0000 Subject: [PATCH 48/77] Access route group OID through getter Signed-off-by: Lawrence Lee --- orchagent/dash/dashorch.cpp | 14 +++++++----- orchagent/dash/dashrouteorch.cpp | 38 +++++++++++++++++++++++--------- orchagent/dash/dashrouteorch.h | 3 +++ 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/orchagent/dash/dashorch.cpp b/orchagent/dash/dashorch.cpp index 52df40f040..13b523da25 100644 --- a/orchagent/dash/dashorch.cpp +++ b/orchagent/dash/dashorch.cpp @@ -17,14 +17,16 @@ #include "tokenize.h" #include "crmorch.h" #include "saihelper.h" +#include "directory.h" #include "taskworker.h" #include "pbutils.h" +#include "dashrouteorch.h" using namespace std; using namespace swss; -extern std::unordered_map gRouteGroupToOid; +extern Directory gDirectory; extern std::unordered_map gVnetNameToId; extern sai_dash_vip_api_t* sai_dash_vip_api; extern sai_dash_direction_lookup_api_t* sai_dash_direction_lookup_api; @@ -396,8 +398,9 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry) if (eni_route_it != eni_route_entries_.end()) { SWSS_LOG_INFO("ENI %s has route group %s", eni.c_str(), eni_route_it->second.group_id().c_str()); + DashRouteOrch *dash_route_orch = gDirectory.get(); eni_attr.id = SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID; - eni_attr.value.oid = gRouteGroupToOid[eni_route_it->second.group_id()]; + eni_attr.value.oid = dash_route_orch->getRouteGroupOid(eni_route_it->second.group_id()); eni_attrs.push_back(eni_attr); } @@ -700,8 +703,9 @@ bool DashOrch::setEniRoute(const std::string& eni, const dash::eni_route::EniRou { SWSS_LOG_ENTER(); - auto it = gRouteGroupToOid.find(entry.group_id()); - if (it == gRouteGroupToOid.end()) + DashRouteOrch *dash_route_orch = gDirectory.get(); + sai_object_id_t route_group_oid = dash_route_orch->getRouteGroupOid(entry.group_id()); + if (route_group_oid == SAI_NULL_OBJECT_ID) { // Don't add entry if route group doesn't exist to avoid needing to check // the existence of both ENI route and route group entries @@ -730,7 +734,7 @@ bool DashOrch::setEniRoute(const std::string& eni, const dash::eni_route::EniRou sai_attribute_t eni_attr; eni_attr.id = SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID; - eni_attr.value.oid = it->second; + eni_attr.value.oid = route_group_oid; sai_status_t status = sai_dash_eni_api->set_eni_attribute(eni_entries_[eni].eni_id, &eni_attr); diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index a90727d15c..25a22d2e2b 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -27,7 +27,6 @@ using namespace std; using namespace swss; -std::unordered_map gRouteGroupToOid; extern std::unordered_map gVnetNameToId; extern sai_dash_outbound_routing_api_t* sai_dash_outbound_routing_api; extern sai_dash_inbound_routing_api_t* sai_dash_inbound_routing_api; @@ -63,8 +62,8 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon return true; } - auto route_group_it = gRouteGroupToOid.find(ctxt.route_group); - if (route_group_it == gRouteGroupToOid.end()) + sai_object_id_t route_group_oid = this->getRouteGroupOid(ctxt.route_group); + if (route_group_oid == SAI_NULL_OBJECT_ID) { SWSS_LOG_INFO("Retry as route group %s not found", ctxt.route_group.c_str()); return false; @@ -77,7 +76,7 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon sai_outbound_routing_entry_t outbound_routing_entry; outbound_routing_entry.switch_id = gSwitchId; - outbound_routing_entry.outbound_routing_group_id = route_group_it->second; + outbound_routing_entry.outbound_routing_group_id = route_group_oid; swss::copy(outbound_routing_entry.destination, ctxt.destination); sai_attribute_t outbound_routing_attr; vector outbound_routing_attrs; @@ -167,7 +166,7 @@ bool DashRouteOrch::addOutboundRoutingPost(const string& key, const OutboundRout } } - OutboundRoutingEntry entry = { gRouteGroupToOid[ctxt.route_group], ctxt.destination, ctxt.metadata }; + OutboundRoutingEntry entry = { this->getRouteGroupOid(ctxt.route_group), ctxt.destination, ctxt.metadata }; routing_entries_[key] = entry; gCrmOrch->incCrmResUsedCounter(ctxt.destination.isV4() ? CrmResourceType::CRM_DASH_IPV4_OUTBOUND_ROUTING : CrmResourceType::CRM_DASH_IPV6_OUTBOUND_ROUTING); @@ -648,7 +647,13 @@ bool DashRouteOrch::addRouteGroup(const string& route_group, const dash::route_g { SWSS_LOG_ENTER(); - sai_object_id_t route_group_oid; + sai_object_id_t route_group_oid = this->getRouteGroupOid(route_group); + if (route_group_oid != SAI_NULL_OBJECT_ID) + { + SWSS_LOG_WARN("Route group %s already exists", route_group.c_str()); + return true; + } + sai_status_t status = sai_dash_outbound_routing_api->create_outbound_routing_group(&route_group_oid, gSwitchId, 0, NULL); if (status != SAI_STATUS_SUCCESS) { @@ -660,7 +665,7 @@ bool DashRouteOrch::addRouteGroup(const string& route_group, const dash::route_g } } - gRouteGroupToOid[route_group] = route_group_oid; + route_group_oid_map_[route_group] = route_group_oid; SWSS_LOG_INFO("Route group %s added", route_group.c_str()); return true; @@ -670,8 +675,8 @@ bool DashRouteOrch::removeRouteGroup(const string& route_group) { SWSS_LOG_ENTER(); - auto it = gRouteGroupToOid.find(route_group); - if (it == gRouteGroupToOid.end()) + sai_object_id_t route_group_oid = this->getRouteGroupOid(route_group); + if (route_group_oid == SAI_NULL_OBJECT_ID) { SWSS_LOG_INFO("Failed to find route group %s to remove", route_group.c_str()); return true; @@ -688,12 +693,25 @@ bool DashRouteOrch::removeRouteGroup(const string& route_group) } } - gRouteGroupToOid.erase(it); + route_group_oid_map_.erase(it); SWSS_LOG_INFO("Route group %s removed", route_group.c_str()); return true; } +sai_object_id_t DashRouteOrch::getRouteGroupOid(const string& route_group) const +{ + SWSS_LOG_ENTER(); + + auto it = route_group_oid_map_.find(route_group); + if (it == route_group_oid_map_.end()) + { + return SAI_NULL_OBJECT_ID; + } + + return it->second; +} + void DashRouteOrch::doTaskRouteGroupTable(ConsumerBase& consumer) { SWSS_LOG_ENTER(); diff --git a/orchagent/dash/dashrouteorch.h b/orchagent/dash/dashrouteorch.h index e634e27b39..a21382f76b 100644 --- a/orchagent/dash/dashrouteorch.h +++ b/orchagent/dash/dashrouteorch.h @@ -78,6 +78,7 @@ class DashRouteOrch : public ZmqOrch { public: DashRouteOrch(swss::DBConnector *db, std::vector &tables, DashOrch *dash_orch, swss::ZmqServer *zmqServer); + sai_object_id_t getRouteGroupOid(const std::string& route_group) const; private: RoutingTable routing_entries_; @@ -85,6 +86,7 @@ class DashRouteOrch : public ZmqOrch EntityBulker outbound_routing_bulker_; EntityBulker inbound_routing_bulker_; DashOrch *dash_orch_; + std::unordered_map route_group_oid_map_; void doTask(ConsumerBase &consumer); void doTaskRouteTable(ConsumerBase &consumer); @@ -100,4 +102,5 @@ class DashRouteOrch : public ZmqOrch bool removeInboundRoutingPost(const std::string& key, const InboundRoutingBulkContext& ctxt); bool addRouteGroup(const std::string& key, const dash::route_group::RouteGroup& entry); bool removeRouteGroup(const std::string& key); + }; From 8c83788485ea66032b3f8d1086d0f169ae21f139 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 28 Aug 2024 00:49:59 +0000 Subject: [PATCH 49/77] track route group bindings and make bound route groups immutable Signed-off-by: Lawrence Lee --- orchagent/dash/dashorch.cpp | 66 +++++++++++++++++--------------- orchagent/dash/dashrouteorch.cpp | 50 +++++++++++++++++++++++- orchagent/dash/dashrouteorch.h | 6 ++- 3 files changed, 88 insertions(+), 34 deletions(-) diff --git a/orchagent/dash/dashorch.cpp b/orchagent/dash/dashorch.cpp index 13b523da25..db2eda689a 100644 --- a/orchagent/dash/dashorch.cpp +++ b/orchagent/dash/dashorch.cpp @@ -394,15 +394,15 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry) eni_attrs.push_back(eni_attr); } - auto eni_route_it = eni_route_entries_.find(eni); - if (eni_route_it != eni_route_entries_.end()) - { - SWSS_LOG_INFO("ENI %s has route group %s", eni.c_str(), eni_route_it->second.group_id().c_str()); - DashRouteOrch *dash_route_orch = gDirectory.get(); - eni_attr.id = SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID; - eni_attr.value.oid = dash_route_orch->getRouteGroupOid(eni_route_it->second.group_id()); - eni_attrs.push_back(eni_attr); - } + // auto eni_route_it = eni_route_entries_.find(eni); + // if (eni_route_it != eni_route_entries_.end()) + // { + // SWSS_LOG_INFO("ENI %s has route group %s", eni.c_str(), eni_route_it->second.group_id().c_str()); + // DashRouteOrch *dash_route_orch = gDirectory.get(); + // eni_attr.id = SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID; + // eni_attr.value.oid = dash_route_orch->getRouteGroupOid(eni_route_it->second.group_id()); + // eni_attrs.push_back(eni_attr); + // } sai_status_t status = sai_dash_eni_api->create_eni(&eni_id, gSwitchId, (uint32_t)eni_attrs.size(), eni_attrs.data()); @@ -703,35 +703,34 @@ bool DashOrch::setEniRoute(const std::string& eni, const dash::eni_route::EniRou { SWSS_LOG_ENTER(); + + if (eni_entries_.find(eni) == eni_entries_.end()) + { + SWSS_LOG_INFO("ENI %s not yet created, not programming ENI route entry", eni.c_str()); + return false; + } + DashRouteOrch *dash_route_orch = gDirectory.get(); sai_object_id_t route_group_oid = dash_route_orch->getRouteGroupOid(entry.group_id()); if (route_group_oid == SAI_NULL_OBJECT_ID) { - // Don't add entry if route group doesn't exist to avoid needing to check - // the existence of both ENI route and route group entries - SWSS_LOG_WARN("Route group not yet created, skipping route entry for ENI %s", entry.group_id().c_str()); + SWSS_LOG_INFO("Route group not yet created, skipping route entry for ENI %s", entry.group_id().c_str()); return false; } - if (eni_route_entries_.find(eni) == eni_route_entries_.end() || - eni_route_entries_[eni].group_id() != entry.group_id()) - { - eni_route_entries_[eni] = entry; - SWSS_LOG_INFO("Added ENI route entry for %s", eni.c_str()); - } - else + if (eni_route_entries_.find(eni) != eni_route_entries_.end()) { - SWSS_LOG_NOTICE("Duplicate ENI route entry already exists for %s", eni.c_str()); - return true; + if (eni_route_entries_[eni].group_id() != entry.group_id()) + { + SWSS_LOG_INFO("Updating route entry from %s to %s for ENI %s", eni_route_entries_[eni].group_id().c_str(), entry.group_id().c_str(), eni.c_str()); + } + else + { + SWSS_LOG_WARN("Duplicate ENI route entry already exists for %s", eni.c_str()); + return true; + } } - if (eni_entries_.find(eni) == eni_entries_.end()) - { - SWSS_LOG_INFO("ENI %s not yet created, not programming ENI route entry", eni.c_str()); - // We can treat this as a success since ENI creation will set the route group, no need to retry - return true; - } - sai_attribute_t eni_attr; eni_attr.id = SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID; eni_attr.value.oid = route_group_oid; @@ -748,8 +747,10 @@ bool DashOrch::setEniRoute(const std::string& eni, const dash::eni_route::EniRou return parseHandleSaiStatusFailure(handle_status); } } + eni_route_entries_[eni] = entry; + dash_route_orch->bindRouteGroup(entry.group_id()); - SWSS_LOG_NOTICE("Updated ENI route group for %s", eni.c_str()); + SWSS_LOG_NOTICE("Updated ENI route group for %s to route group %s", eni.c_str(), entry.group_id().c_str()); return true; } @@ -763,8 +764,6 @@ bool DashOrch::removeEniRoute(const std::string& eni) return true; } - eni_route_entries_.erase(eni); - if (eni_entries_.find(eni) != eni_entries_.end()) { sai_attribute_t eni_attr; @@ -783,6 +782,11 @@ bool DashOrch::removeEniRoute(const std::string& eni) } } } + + DashRouteOrch *dash_route_orch = gDirectory.get(); + dash_route_orch->unbindRouteGroup(eni_route_entries_[eni].group_id()); + eni_route_entries_.erase(eni); + SWSS_LOG_NOTICE("Removed ENI route entry for %s", eni.c_str()); return true; diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index 25a22d2e2b..b46e7ea10c 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -62,6 +62,11 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon return true; } + if (isRouteGroupBound(ctxt.route_group)) + { + SWSS_LOG_WARN("Cannot add new route to route group %s as it is already bound", ctxt.route_group.c_str()); + return true; + } sai_object_id_t route_group_oid = this->getRouteGroupOid(ctxt.route_group); if (route_group_oid == SAI_NULL_OBJECT_ID) { @@ -675,6 +680,12 @@ bool DashRouteOrch::removeRouteGroup(const string& route_group) { SWSS_LOG_ENTER(); + if (isRouteGroupBound(route_group)) + { + SWSS_LOG_WARN("Cannot remove bound route group %s", route_group.c_str()); + return true; + } + sai_object_id_t route_group_oid = this->getRouteGroupOid(route_group); if (route_group_oid == SAI_NULL_OBJECT_ID) { @@ -682,7 +693,7 @@ bool DashRouteOrch::removeRouteGroup(const string& route_group) return true; } - sai_status_t status = sai_dash_outbound_routing_api->remove_outbound_routing_group(it->second); + sai_status_t status = sai_dash_outbound_routing_api->remove_outbound_routing_group(route_group_oid); if (status != SAI_STATUS_SUCCESS) { SWSS_LOG_ERROR("Failed to remove route group %s", route_group.c_str()); @@ -693,7 +704,7 @@ bool DashRouteOrch::removeRouteGroup(const string& route_group) } } - route_group_oid_map_.erase(it); + route_group_oid_map_.erase(route_group); SWSS_LOG_INFO("Route group %s removed", route_group.c_str()); return true; @@ -712,6 +723,41 @@ sai_object_id_t DashRouteOrch::getRouteGroupOid(const string& route_group) const return it->second; } +void DashRouteOrch::bindRouteGroup(const std::string& route_group) +{ + auto it = route_group_bind_count_.find(route_group); + + if (it == route_group_bind_count_.end()) + { + route_group_bind_count_[route_group] = 0; + } + it->second++; +} + +void DashRouteOrch::unbindRouteGroup(const std::string& route_group) +{ + auto it = route_group_bind_count_.find(route_group); + + if (it == route_group_bind_count_.end()) + { + SWSS_LOG_WARN("Cannot unbind route group %s since it is not bound to any ENIs", route_group.c_str()); + return; + } + it->second--; + + if (it->second == 0) + { + SWSS_LOG_INFO("Route group %s completely unbound", route_group.c_str()); + route_group_bind_count_.erase(it); + } +} + +bool DashRouteOrch::isRouteGroupBound(const std::string& route_group) const +{ + auto it = route_group_bind_count_.find(route_group); + return it->second > 0; +} + void DashRouteOrch::doTaskRouteGroupTable(ConsumerBase& consumer) { SWSS_LOG_ENTER(); diff --git a/orchagent/dash/dashrouteorch.h b/orchagent/dash/dashrouteorch.h index a21382f76b..0813de7e21 100644 --- a/orchagent/dash/dashrouteorch.h +++ b/orchagent/dash/dashrouteorch.h @@ -79,6 +79,9 @@ class DashRouteOrch : public ZmqOrch public: DashRouteOrch(swss::DBConnector *db, std::vector &tables, DashOrch *dash_orch, swss::ZmqServer *zmqServer); sai_object_id_t getRouteGroupOid(const std::string& route_group) const; + void bindRouteGroup(const std::string& route_group); + void unbindRouteGroup(const std::string& route_group); + bool isRouteGroupBound(const std::string& route_group) const; private: RoutingTable routing_entries_; @@ -87,6 +90,7 @@ class DashRouteOrch : public ZmqOrch EntityBulker inbound_routing_bulker_; DashOrch *dash_orch_; std::unordered_map route_group_oid_map_; + std::unordered_map route_group_bind_count_; void doTask(ConsumerBase &consumer); void doTaskRouteTable(ConsumerBase &consumer); @@ -102,5 +106,5 @@ class DashRouteOrch : public ZmqOrch bool removeInboundRoutingPost(const std::string& key, const InboundRoutingBulkContext& ctxt); bool addRouteGroup(const std::string& key, const dash::route_group::RouteGroup& entry); bool removeRouteGroup(const std::string& key); - + }; From 0b0d443914183a3772c9c2cc651b45bcacb177be Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 28 Aug 2024 01:00:00 +0000 Subject: [PATCH 50/77] remove old code Signed-off-by: Lawrence Lee --- tests/test_dash_pl.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index d3b1e51741..a4f8b07df2 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -25,24 +25,17 @@ def apply_base_pl_route(dash_db: DashDB): dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG) dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_CONFIG) - #create_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG) yield dash_db.remove_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID ) dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) - #remove_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) @pytest.fixture def apply_pl_route_with_underlay_sip(dash_db: DashDB): dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG_WITH_UNDERLAY_SIP) dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_CONFIG) - #create_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG_WITH_UNDERLAY_SIP) - #create_eni_route(dash_db, ENI_ID, ENI_ROUTE_CONFIG) yield - dash_db.remove_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID) dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) - #remove_eni_route(dash_db, ENI_ID) - #remove_route(dash_db, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) @pytest.fixture(scope='module', autouse=True) @@ -54,13 +47,6 @@ def common_setup_teardown(dash_db: DashDB): dash_db.set_app_db_entry(APP_DASH_VNET_MAPPING_TABLE_NAME, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1, ROUTE_GROUP_CONFIG) - # create_routing_type(dash_db, PRIVATELINK, ROUTING_TYPE_PL_CONFIG) - # create_appliance(dash_db, APPLIANCE_ID, APPLIANCE_CONFIG) - # create_vnet(dash_db, VNET1, VNET_CONFIG) - # create_eni(dash_db, ENI_ID, ENI_CONFIG) - # create_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) - # create_route_group(dash_db, ROUTE_GROUP1, ROUTE_GROUP_CONFIG) - yield dash_db.remove_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1) @@ -70,19 +56,11 @@ def common_setup_teardown(dash_db: DashDB): dash_db.remove_app_db_entry(APP_DASH_APPLIANCE_TABLE_NAME, APPLIANCE_ID) dash_db.remove_app_db_entry(APP_DASH_ROUTING_TYPE_TABLE_NAME, PRIVATELINK) - # remove_route_group(dash_db, ROUTE_GROUP1) - # remove_vnet_mapping(dash_db, VNET1, VNET_MAP_IP1) - # remove_eni(dash_db, ENI_ID) - # remove_vnet(dash_db, VNET1) - # remove_appliance(dash_db, APPLIANCE_ID) - # remove_routing_type(dash_db, PRIVATELINK) - def test_pl_eni_attrs(dash_db: DashDB, apply_base_pl_route): enis= dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_ENI") assert enis eni_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_ENI", enis[0]) - # eni_attrs = dash_db.asic_eni_table[enis[0]] assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP1 From e5a65c094d7ae1dc221442e061954d917024a98a Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 28 Aug 2024 01:02:43 +0000 Subject: [PATCH 51/77] remove unused utils Signed-off-by: Lawrence Lee --- tests/dash_utils/dash_utils.py | 77 ---------------------------------- tests/test_dash_pl.py | 1 - 2 files changed, 78 deletions(-) delete mode 100644 tests/dash_utils/dash_utils.py diff --git a/tests/dash_utils/dash_utils.py b/tests/dash_utils/dash_utils.py deleted file mode 100644 index eeba641cd4..0000000000 --- a/tests/dash_utils/dash_utils.py +++ /dev/null @@ -1,77 +0,0 @@ -from dash_api.appliance_pb2 import * -from dash_api.vnet_pb2 import * -from dash_api.eni_pb2 import * -from dash_api.eni_route_pb2 import * -from dash_api.route_pb2 import * -from dash_api.route_group_pb2 import * -from dash_api.route_rule_pb2 import * -from dash_api.vnet_mapping_pb2 import * -from dash_api.route_type_pb2 import * -from dash_api.types_pb2 import * -from google.protobuf.json_format import ParseDict, MessageToDict - -from dash_utils.dash_db import dash_db - -import time -import uuid -import ipaddress -import socket -import pytest - -from dash_utils.dash_configs import * - -def create_appliance(dash_db, appliance_id, appliance_config): - pb = ParseDict(appliance_config, Appliance()) - dash_db.create_appliance(appliance_id, {"pb": pb.SerializeToString()}) - -def remove_appliance(dash_db, appliance_id): - dash_db.remove_appliance(appliance_id) - -def create_vnet(dash_db, vnet, vnet_config): - pb = ParseDict(vnet_config, Vnet()) - dash_db.create_vnet(vnet, {"pb": pb.SerializeToString()}) - -def remove_vnet(dash_db, vnet): - dash_db.remove_vnet(vnet) - -def create_eni(dash_db, eni, eni_config): - pb = ParseDict(eni_config, Eni()) - dash_db.create_eni(eni, {"pb": pb.SerializeToString()}) - -def remove_eni(dash_db, eni): - dash_db.remove_eni(eni) - -def create_routing_type(dash_db, routing_type, routing_type_config): - pb = ParseDict(routing_type_config, RouteType()) - dash_db.create_routing_type(routing_type, {"pb": pb.SerializeToString()}) - -def remove_routing_type(dash_db, routing_type): - dash_db.remove_routing_type(routing_type) - -def create_vnet_mapping(dash_db, vnet, ip, vnet_mapping_config): - pb = ParseDict(vnet_mapping_config, VnetMapping()) - dash_db.create_vnet_mapping(vnet, ip, {"pb": pb.SerializeToString()}) - -def remove_vnet_mapping(dash_db, vnet, ip): - dash_db.remove_vnet_mapping(vnet, ip) - -def create_route_group(dash_db, route_group, route_group_config): - pb = ParseDict(route_group_config, RouteGroup()) - dash_db.create_route_group(route_group, {"pb": pb.SerializeToString()}) - -def remove_route_group(dash_db, route_group): - dash_db.remove_route_group(route_group) - -def create_eni_route(dash_db, eni, eni_route_config): - pb = ParseDict(eni_route_config, EniRoute()) - dash_db.create_eni_route(eni, {"pb": pb.SerializeToString()}) - -def remove_eni_route(dash_db, eni): - dash_db.remove_eni_route(eni) - -def create_route(dash_db, route_group, route_prefix, route_config): - pb = ParseDict(route_config, Route()) - dash_db.create_route(route_group, route_prefix, {"pb": pb.SerializeToString()}) - -def remove_route(dash_db, route_group, route_prefix): - dash_db.remove_route(route_group, route_prefix) diff --git a/tests/test_dash_pl.py b/tests/test_dash_pl.py index a4f8b07df2..6ec5812c0e 100644 --- a/tests/test_dash_pl.py +++ b/tests/test_dash_pl.py @@ -12,7 +12,6 @@ from dash_api.types_pb2 import * from dash_utils.dash_db import dash_db, DashDB -from dash_utils.dash_utils import * from dash_utils.dash_configs import * from sai_attrs import * from swsscommon.swsscommon import APP_DASH_APPLIANCE_TABLE_NAME, APP_DASH_ENI_TABLE_NAME, APP_DASH_VNET_TABLE_NAME, APP_DASH_VNET_MAPPING_TABLE_NAME, APP_DASH_ROUTE_TABLE_NAME, APP_DASH_ROUTE_RULE_TABLE_NAME, APP_DASH_ENI_ROUTE_TABLE_NAME, APP_DASH_ROUTING_TYPE_TABLE_NAME, APP_DASH_ROUTE_GROUP_TABLE_NAME From 29f83c0daa7886a4eea9512763530aa1534ed485 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 28 Aug 2024 04:33:22 +0000 Subject: [PATCH 52/77] fix route group bind check Signed-off-by: Lawrence Lee --- orchagent/dash/dashrouteorch.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index b46e7ea10c..a1b2e11207 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -755,6 +755,10 @@ void DashRouteOrch::unbindRouteGroup(const std::string& route_group) bool DashRouteOrch::isRouteGroupBound(const std::string& route_group) const { auto it = route_group_bind_count_.find(route_group); + if (it == route_group_bind_count_.end()) + { + return false; + } return it->second > 0; } From d8232f47b9e7f20385fd0d38a474956726ecfba8 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 28 Aug 2024 07:17:29 +0000 Subject: [PATCH 53/77] fix route group ref counter Signed-off-by: Lawrence Lee --- orchagent/dash/dashrouteorch.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index a1b2e11207..12ac35b78e 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -729,7 +729,8 @@ void DashRouteOrch::bindRouteGroup(const std::string& route_group) if (it == route_group_bind_count_.end()) { - route_group_bind_count_[route_group] = 0; + route_group_bind_count_[route_group] = 1; + return; } it->second++; } From 0bbe94c85051552e69431b3042909f02850cc3f5 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 28 Aug 2024 20:19:41 +0000 Subject: [PATCH 54/77] fix test object creation order Signed-off-by: Lawrence Lee --- tests/dash_utils/dash_configs.py | 6 +++--- tests/test_dash_vnet.py | 31 ++++++++++++++++++------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/tests/dash_utils/dash_configs.py b/tests/dash_utils/dash_configs.py index 8290d6ab0b..dd86e5b3a3 100644 --- a/tests/dash_utils/dash_configs.py +++ b/tests/dash_utils/dash_configs.py @@ -105,16 +105,16 @@ } ROUTE_VNET_CONFIG = { - "action_type": RoutingType.ROUTING_TYPE_VNET, + "routing_type": RoutingType.ROUTING_TYPE_VNET, "vnet": "Vnet1", } ROUTE_PL_CONFIG = { - "action_type": RoutingType.ROUTING_TYPE_PRIVATELINK, + "routing_type": RoutingType.ROUTING_TYPE_PRIVATELINK, } ROUTE_PL_CONFIG_WITH_UNDERLAY_SIP = { - "action_type": RoutingType.ROUTING_TYPE_PRIVATELINK, + "routing_type": RoutingType.ROUTING_TYPE_PRIVATELINK, "underlay_sip": { "ipv4": socket.htonl(int(IP(PL_UNDERLAY_SIP2))) } diff --git a/tests/test_dash_vnet.py b/tests/test_dash_vnet.py index ee3a236697..ac038c9257 100644 --- a/tests/test_dash_vnet.py +++ b/tests/test_dash_vnet.py @@ -157,18 +157,6 @@ def test_outbound_routing(self, dash_db): outbound_routing_group_entries = dash_db.asic_outbound_routing_group_table.get_keys() assert outbound_routing_group_entries - pb = EniRoute() - pb.group_id = self.group_id - self.mac_string = "F4939FEFC47E" - dash_db.create_eni_route(self.mac_string, {"pb": pb.SerializeToString()}) - time.sleep(3) - eni_entries = dash_db.asic_eni_table.get_keys() - fvs = dash_db.asic_eni_table[eni_entries[0]] - for fv in fvs.items(): - if fv[0] == "SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID": - assert fv[1] == outbound_routing_group_entries[0] - - self.vnet = "Vnet1" self.ip = "10.1.0.0/24" self.action_type = "vnet_direct" @@ -189,6 +177,17 @@ def test_outbound_routing(self, dash_db): assert fv[1] == "10.0.0.6" assert "SAI_OUTBOUND_ROUTING_ENTRY_ATTR_DST_VNET_ID" in fvs + pb = EniRoute() + pb.group_id = self.group_id + self.mac_string = "F4939FEFC47E" + dash_db.create_eni_route(self.mac_string, {"pb": pb.SerializeToString()}) + time.sleep(3) + eni_entries = dash_db.asic_eni_table.get_keys() + fvs = dash_db.asic_eni_table[eni_entries[0]] + for fv in fvs.items(): + if fv[0] == "SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID": + assert fv[1] == outbound_routing_group_entries[0] + def test_inbound_routing(self, dash_db): self.mac_string = "F4939FEFC47E" self.vnet = "Vnet1" @@ -221,11 +220,17 @@ def test_cleanup(self, dash_db): self.vni = "3251" self.sip = "10.1.1.1" self.dip = "10.1.0.0/24" + self.ip2 = "10.1.1.2" self.appliance_id = "100" + self.routing_type = "vnet_encap" dash_db.remove_inbound_routing(self.mac_string, self.vni, self.sip) + dash_db.remove_eni_route(self.mac_string) dash_db.remove_route(self.group_id, self.dip) - dash_db.remove_eni(self.mac_string) + dash_db.remove_route_group(self.group_id) dash_db.remove_vnet_mapping(self.vnet, self.sip) + dash_db.remove_vnet_mapping(self.vnet, self.ip2) + dash_db.remove_routing_type(self.routing_type) + dash_db.remove_eni(self.mac_string) dash_db.remove_vnet(self.vnet) dash_db.remove_appliance(self.appliance_id) From 35f3c547c25245f1920490b42c12bd286d9a8a04 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 29 Aug 2024 01:16:18 +0000 Subject: [PATCH 55/77] restrict route table routing_types Signed-off-by: Lawrence Lee --- orchagent/dash/dashrouteorch.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index 12ac35b78e..5b70d626ac 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -87,8 +87,16 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon vector outbound_routing_attrs; auto& object_statuses = ctxt.object_statuses; + auto it = sOutboundAction.find(ctxt.metadata.routing_type()); + if (it == sOutboundAction.end()) + { + std::string routing_type_str = dash::route_type::RoutingType_Name(ctxt.metadata.routing_type()); + SWSS_LOG_WARN("Routing type %d for outbound routing entry %s not allowed", routing_type_str.c_str(), key.c_str()); + return false; + } + outbound_routing_attr.id = SAI_OUTBOUND_ROUTING_ENTRY_ATTR_ACTION; - outbound_routing_attr.value.u32 = sOutboundAction[ctxt.metadata.routing_type()]; + outbound_routing_attr.value.u32 = it->second; outbound_routing_attrs.push_back(outbound_routing_attr); if (ctxt.metadata.routing_type() == dash::route_type::RoutingType::ROUTING_TYPE_DIRECT) From d467e48387b35e2e2e1afd2306378153b5b58830 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 29 Aug 2024 01:20:04 +0000 Subject: [PATCH 56/77] Use VNET routing type for PL routes Signed-off-by: Lawrence Lee --- orchagent/dash/dashrouteorch.cpp | 23 ++++++++++++----------- tests/dash_utils/dash_configs.py | 6 ++++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index 5b70d626ac..e7d28c4aac 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -110,6 +110,18 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon outbound_routing_attr.id = SAI_OUTBOUND_ROUTING_ENTRY_ATTR_DST_VNET_ID; outbound_routing_attr.value.oid = gVnetNameToId[ctxt.metadata.vnet()]; outbound_routing_attrs.push_back(outbound_routing_attr); + + if (ctxt.metadata.has_underlay_sip() + && ctxt.metadata.underlay_sip().has_ipv4()) + { + outbound_routing_attr.id = SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP; + if (!to_sai(ctxt.metadata.underlay_sip(), outbound_routing_attr.value.ipaddr)) + { + return false; + } + outbound_routing_attrs.push_back(outbound_routing_attr); + } + } else if (ctxt.metadata.routing_type() == dash::route_type::RoutingType::ROUTING_TYPE_VNET_DIRECT && ctxt.metadata.has_vnet_direct() @@ -127,17 +139,6 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon } outbound_routing_attrs.push_back(outbound_routing_attr); } - else if (ctxt.metadata.routing_type() == dash::route_type::RoutingType::ROUTING_TYPE_PRIVATELINK - && ctxt.metadata.has_underlay_sip() - && ctxt.metadata.underlay_sip().has_ipv4()) - { - outbound_routing_attr.id = SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP; - if (!to_sai(ctxt.metadata.underlay_sip(), outbound_routing_attr.value.ipaddr)) - { - return false; - } - outbound_routing_attrs.push_back(outbound_routing_attr); - } else { SWSS_LOG_WARN("Attribute action for outbound routing entry %s", key.c_str()); diff --git a/tests/dash_utils/dash_configs.py b/tests/dash_utils/dash_configs.py index dd86e5b3a3..b392d63044 100644 --- a/tests/dash_utils/dash_configs.py +++ b/tests/dash_utils/dash_configs.py @@ -110,11 +110,13 @@ } ROUTE_PL_CONFIG = { - "routing_type": RoutingType.ROUTING_TYPE_PRIVATELINK, + "routing_type": RoutingType.ROUTING_TYPE_VNET, + "vnet": VNET1, } ROUTE_PL_CONFIG_WITH_UNDERLAY_SIP = { - "routing_type": RoutingType.ROUTING_TYPE_PRIVATELINK, + "routing_type": RoutingType.ROUTING_TYPE_VNET, + "vnet": VNET1, "underlay_sip": { "ipv4": socket.htonl(int(IP(PL_UNDERLAY_SIP2))) } From 2ce30f0b59baf45e561c0d4c7bec107350d535b0 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 29 Aug 2024 01:25:11 +0000 Subject: [PATCH 57/77] fix log format Signed-off-by: Lawrence Lee --- orchagent/dash/dashrouteorch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index e7d28c4aac..f197007903 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -91,7 +91,7 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon if (it == sOutboundAction.end()) { std::string routing_type_str = dash::route_type::RoutingType_Name(ctxt.metadata.routing_type()); - SWSS_LOG_WARN("Routing type %d for outbound routing entry %s not allowed", routing_type_str.c_str(), key.c_str()); + SWSS_LOG_WARN("Routing type %s for outbound routing entry %s not allowed", routing_type_str.c_str(), key.c_str()); return false; } From 226bf8afa3f2ad994681eb85b774e60d85cbcda0 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 29 Aug 2024 06:40:56 +0000 Subject: [PATCH 58/77] move all dash VS tests to single folder Signed-off-by: Lawrence Lee --- .azure-pipelines/test-docker-sonic-vs-template.yml | 2 +- tests/{dash_utils => dash}/dash_configs.py | 0 tests/{dash_utils => dash}/dash_db.py | 0 tests/{ => dash}/test_dash_acl.py | 0 tests/{ => dash}/test_dash_pl.py | 4 ++-- tests/{ => dash}/test_dash_vnet.py | 4 ++-- 6 files changed, 5 insertions(+), 5 deletions(-) rename tests/{dash_utils => dash}/dash_configs.py (100%) rename tests/{dash_utils => dash}/dash_db.py (100%) rename tests/{ => dash}/test_dash_acl.py (100%) rename tests/{ => dash}/test_dash_pl.py (98%) rename tests/{ => dash}/test_dash_vnet.py (99%) diff --git a/.azure-pipelines/test-docker-sonic-vs-template.yml b/.azure-pipelines/test-docker-sonic-vs-template.yml index db66b03472..24fc8b8738 100644 --- a/.azure-pipelines/test-docker-sonic-vs-template.yml +++ b/.azure-pipelines/test-docker-sonic-vs-template.yml @@ -136,7 +136,7 @@ jobs: fi all_tests=$(ls test_*.py | xargs) - all_tests="${all_tests} p4rt" + all_tests="${all_tests} p4rt dash" if [ -n '${{ parameters.run_tests_pattern }}' ]; then all_tests=" $(ls ${{ parameters.run_tests_pattern }} | xargs) " diff --git a/tests/dash_utils/dash_configs.py b/tests/dash/dash_configs.py similarity index 100% rename from tests/dash_utils/dash_configs.py rename to tests/dash/dash_configs.py diff --git a/tests/dash_utils/dash_db.py b/tests/dash/dash_db.py similarity index 100% rename from tests/dash_utils/dash_db.py rename to tests/dash/dash_db.py diff --git a/tests/test_dash_acl.py b/tests/dash/test_dash_acl.py similarity index 100% rename from tests/test_dash_acl.py rename to tests/dash/test_dash_acl.py diff --git a/tests/test_dash_pl.py b/tests/dash/test_dash_pl.py similarity index 98% rename from tests/test_dash_pl.py rename to tests/dash/test_dash_pl.py index 6ec5812c0e..87eb56aaca 100644 --- a/tests/test_dash_pl.py +++ b/tests/dash/test_dash_pl.py @@ -11,8 +11,8 @@ from dash_api.route_type_pb2 import * from dash_api.types_pb2 import * -from dash_utils.dash_db import dash_db, DashDB -from dash_utils.dash_configs import * +from dash_db import dash_db, DashDB +from dash_configs import * from sai_attrs import * from swsscommon.swsscommon import APP_DASH_APPLIANCE_TABLE_NAME, APP_DASH_ENI_TABLE_NAME, APP_DASH_VNET_TABLE_NAME, APP_DASH_VNET_MAPPING_TABLE_NAME, APP_DASH_ROUTE_TABLE_NAME, APP_DASH_ROUTE_RULE_TABLE_NAME, APP_DASH_ENI_ROUTE_TABLE_NAME, APP_DASH_ROUTING_TYPE_TABLE_NAME, APP_DASH_ROUTE_GROUP_TABLE_NAME diff --git a/tests/test_dash_vnet.py b/tests/dash/test_dash_vnet.py similarity index 99% rename from tests/test_dash_vnet.py rename to tests/dash/test_dash_vnet.py index ac038c9257..ab46d1b1ac 100644 --- a/tests/test_dash_vnet.py +++ b/tests/dash/test_dash_vnet.py @@ -9,8 +9,8 @@ from dash_api.route_type_pb2 import * from dash_api.types_pb2 import * -from dash_utils.dash_db import dash_db -from dash_utils.dash_configs import * +from dash_db import dash_db +from dash_configs import * import time import uuid From dd0cdf2448851736c446156c0660aec709d2d883 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 29 Aug 2024 07:09:49 +0000 Subject: [PATCH 59/77] Make route underlay_sip independent of routing_type Signed-off-by: Lawrence Lee --- orchagent/dash/dashrouteorch.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index f197007903..f630945da8 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -110,18 +110,6 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon outbound_routing_attr.id = SAI_OUTBOUND_ROUTING_ENTRY_ATTR_DST_VNET_ID; outbound_routing_attr.value.oid = gVnetNameToId[ctxt.metadata.vnet()]; outbound_routing_attrs.push_back(outbound_routing_attr); - - if (ctxt.metadata.has_underlay_sip() - && ctxt.metadata.underlay_sip().has_ipv4()) - { - outbound_routing_attr.id = SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP; - if (!to_sai(ctxt.metadata.underlay_sip(), outbound_routing_attr.value.ipaddr)) - { - return false; - } - outbound_routing_attrs.push_back(outbound_routing_attr); - } - } else if (ctxt.metadata.routing_type() == dash::route_type::RoutingType::ROUTING_TYPE_VNET_DIRECT && ctxt.metadata.has_vnet_direct() @@ -141,10 +129,21 @@ bool DashRouteOrch::addOutboundRouting(const string& key, OutboundRoutingBulkCon } else { - SWSS_LOG_WARN("Attribute action for outbound routing entry %s", key.c_str()); + SWSS_LOG_WARN("Routing type %s for outbound routing entry %s either invalid or missing required attributes", + dash::route_type::RoutingType_Name(ctxt.metadata.routing_type()).c_str(), key.c_str()); return false; } + if (ctxt.metadata.has_underlay_sip() && ctxt.metadata.underlay_sip().has_ipv4()) + { + outbound_routing_attr.id = SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP; + if (!to_sai(ctxt.metadata.underlay_sip(), outbound_routing_attr.value.ipaddr)) + { + return false; + } + outbound_routing_attrs.push_back(outbound_routing_attr); + } + object_statuses.emplace_back(); outbound_routing_bulker_.create_entry(&object_statuses.back(), &outbound_routing_entry, (uint32_t)outbound_routing_attrs.size(), outbound_routing_attrs.data()); From 58b6e18b8a9464186eb95addd1698c87ab9688d0 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 29 Aug 2024 22:47:58 +0000 Subject: [PATCH 60/77] add ASIC_DB check helper Signed-off-by: Lawrence Lee --- tests/dash/test_dash_pl.py | 35 ++++++++++------------------------- tests/utils/sai_utils.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 tests/utils/sai_utils.py diff --git a/tests/dash/test_dash_pl.py b/tests/dash/test_dash_pl.py index 87eb56aaca..b71bb6f37f 100644 --- a/tests/dash/test_dash_pl.py +++ b/tests/dash/test_dash_pl.py @@ -1,6 +1,7 @@ import pytest from ipaddress import ip_address as IP +from utils.sai_utils import assert_sai_attribute_exists from dash_api.appliance_pb2 import * from dash_api.vnet_pb2 import * @@ -60,39 +61,23 @@ def test_pl_eni_attrs(dash_db: DashDB, apply_base_pl_route): enis= dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_ENI") assert enis eni_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_ENI", enis[0]) - assert SAI_ENI_ATTR_PL_UNDERLAY_SIP in eni_attrs - assert eni_attrs[SAI_ENI_ATTR_PL_UNDERLAY_SIP] == PL_UNDERLAY_SIP1 + assert_sai_attribute_exists(SAI_ENI_ATTR_PL_UNDERLAY_SIP, eni_attrs, PL_UNDERLAY_SIP1) def test_pl_eni_override_underlay_sip(dash_db: DashDB, apply_pl_route_with_underlay_sip): outbound_routing_keys = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY") assert outbound_routing_keys outbound_routing_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY", outbound_routing_keys[0]) - assert SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP in outbound_routing_attrs - assert IP(outbound_routing_attrs[SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP]) == IP(PL_UNDERLAY_SIP2) + assert_sai_attribute_exists(SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP, outbound_routing_attrs, PL_UNDERLAY_SIP2) def test_pl_outbound_ca_to_pa_attrs(dash_db: DashDB): outbound_ca_to_pa_keys = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_CA_TO_PA_ENTRY") assert outbound_ca_to_pa_keys outbound_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_CA_TO_PA_ENTRY", outbound_ca_to_pa_keys[0]) - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION in outbound_attrs - assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION] == SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING - - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP in outbound_attrs - actual_overlay_sip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP]) - assert actual_overlay_sip == IP(PL_OVERLAY_SIP) - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK in outbound_attrs - actual_overlay_sip_mask = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK]) - assert actual_overlay_sip_mask == IP(PL_OVERLAY_SIP_MASK) - - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP in outbound_attrs - actual_overlay_dip = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP]) - assert actual_overlay_dip == IP(PL_OVERLAY_DIP) - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK in outbound_attrs - actual_overlay_dip_mask = IP(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK]) - assert actual_overlay_dip_mask == IP(PL_OVERLAY_DIP_MASK) - - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY in outbound_attrs - assert int(outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY]) == ENCAP_VNI - assert SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION in outbound_attrs - assert outbound_attrs[SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION] == SAI_DASH_ENCAPSULATION_NVGRE + assert_sai_attribute_exists(SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION, outbound_attrs, SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING) + assert_sai_attribute_exists(SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP, outbound_attrs, PL_OVERLAY_SIP) + assert_sai_attribute_exists(SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_SIP_MASK, outbound_attrs, PL_OVERLAY_SIP_MASK) + assert_sai_attribute_exists(SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP, outbound_attrs, PL_OVERLAY_DIP) + assert_sai_attribute_exists(SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP_MASK, outbound_attrs, PL_OVERLAY_DIP_MASK) + assert_sai_attribute_exists(SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY, outbound_attrs, ENCAP_VNI) + assert_sai_attribute_exists(SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION, outbound_attrs, SAI_DASH_ENCAPSULATION_NVGRE) diff --git a/tests/utils/sai_utils.py b/tests/utils/sai_utils.py new file mode 100644 index 0000000000..f5e245f3cd --- /dev/null +++ b/tests/utils/sai_utils.py @@ -0,0 +1,16 @@ +from ipaddress import ip_address as IP + +def assert_sai_attribute_exists(attr_name, attrs, expected_val=None): + assert attr_name in attrs, f"Attribute {attr_name} not found in {attrs}" + if expected_val is not None: + expected = expected_val + actual = attrs[attr_name] + # Attempt to convert to specific types to avoid string comparison when possible + for type in [int, IP]: + try: + expected = type(expected) + actual = type(actual) + break + except ValueError: + continue + assert actual == expected, f"Attribute {attr_name} value mismatch. Expected: {expected}, Actual: {actual}" From 6b35f64524fd3103c2bbe73e731736bf7f1af611 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 29 Aug 2024 22:51:57 +0000 Subject: [PATCH 61/77] formatting fix Signed-off-by: Lawrence Lee --- tests/dash/test_dash_pl.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/dash/test_dash_pl.py b/tests/dash/test_dash_pl.py index b71bb6f37f..08644acf7b 100644 --- a/tests/dash/test_dash_pl.py +++ b/tests/dash/test_dash_pl.py @@ -1,6 +1,5 @@ import pytest -from ipaddress import ip_address as IP from utils.sai_utils import assert_sai_attribute_exists from dash_api.appliance_pb2 import * @@ -15,7 +14,16 @@ from dash_db import dash_db, DashDB from dash_configs import * from sai_attrs import * -from swsscommon.swsscommon import APP_DASH_APPLIANCE_TABLE_NAME, APP_DASH_ENI_TABLE_NAME, APP_DASH_VNET_TABLE_NAME, APP_DASH_VNET_MAPPING_TABLE_NAME, APP_DASH_ROUTE_TABLE_NAME, APP_DASH_ROUTE_RULE_TABLE_NAME, APP_DASH_ENI_ROUTE_TABLE_NAME, APP_DASH_ROUTING_TYPE_TABLE_NAME, APP_DASH_ROUTE_GROUP_TABLE_NAME +from swsscommon.swsscommon import ( + APP_DASH_APPLIANCE_TABLE_NAME, + APP_DASH_ENI_TABLE_NAME, + APP_DASH_VNET_TABLE_NAME, + APP_DASH_VNET_MAPPING_TABLE_NAME, + APP_DASH_ROUTE_TABLE_NAME, + APP_DASH_ENI_ROUTE_TABLE_NAME, + APP_DASH_ROUTING_TYPE_TABLE_NAME, + APP_DASH_ROUTE_GROUP_TABLE_NAME, +) DVS_ENV = ["HWSKU=DPU-2P"] NUM_PORTS = 2 From 6923d1b500b1564acbcfd8f2faaa9be2072affd0 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 30 Aug 2024 01:29:11 +0000 Subject: [PATCH 62/77] restructure PL tests Signed-off-by: Lawrence Lee --- tests/dash/dash_configs.py | 17 ++++++++++------- tests/dash/test_dash_pl.py | 35 +++++++++++++---------------------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/tests/dash/dash_configs.py b/tests/dash/dash_configs.py index b392d63044..6fa3b6d4aa 100644 --- a/tests/dash/dash_configs.py +++ b/tests/dash/dash_configs.py @@ -80,7 +80,15 @@ } } -VNET_MAPPING_CONFIG = { +VNET_MAPPING_CONFIG_VNET_ENCAP = { + "mac_address": bytes.fromhex(MAC_STRING), + "action_type": RoutingType.ROUTING_TYPE_VNET_ENCAP, + "underlay_ip": { + "ipv4": socket.htonl(int(IP(UNDERLAY_IP))) + }, +} + +VNET_MAPPING_CONFIG_PRIVATELINK = { "mac_address": bytes.fromhex(MAC_STRING), "action_type": RoutingType.ROUTING_TYPE_PRIVATELINK, "underlay_ip": { @@ -109,12 +117,7 @@ "vnet": "Vnet1", } -ROUTE_PL_CONFIG = { - "routing_type": RoutingType.ROUTING_TYPE_VNET, - "vnet": VNET1, -} - -ROUTE_PL_CONFIG_WITH_UNDERLAY_SIP = { +ROUTE_VNET_CONFIG_UNDERLAY_SIP = { "routing_type": RoutingType.ROUTING_TYPE_VNET, "vnet": VNET1, "underlay_sip": { diff --git a/tests/dash/test_dash_pl.py b/tests/dash/test_dash_pl.py index 08644acf7b..ff1d4be0fc 100644 --- a/tests/dash/test_dash_pl.py +++ b/tests/dash/test_dash_pl.py @@ -28,35 +28,20 @@ DVS_ENV = ["HWSKU=DPU-2P"] NUM_PORTS = 2 -@pytest.fixture -def apply_base_pl_route(dash_db: DashDB): - - dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG) - dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_CONFIG) - yield - dash_db.remove_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID ) - dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) - -@pytest.fixture -def apply_pl_route_with_underlay_sip(dash_db: DashDB): - dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_PL_CONFIG_WITH_UNDERLAY_SIP) - dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_CONFIG) - yield - dash_db.remove_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID) - dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) - - @pytest.fixture(scope='module', autouse=True) def common_setup_teardown(dash_db: DashDB): dash_db.set_app_db_entry(APP_DASH_ROUTING_TYPE_TABLE_NAME, PRIVATELINK, ROUTING_TYPE_PL_CONFIG) dash_db.set_app_db_entry(APP_DASH_APPLIANCE_TABLE_NAME, APPLIANCE_ID, APPLIANCE_CONFIG) dash_db.set_app_db_entry(APP_DASH_VNET_TABLE_NAME, VNET1, VNET_CONFIG) dash_db.set_app_db_entry(APP_DASH_ENI_TABLE_NAME, ENI_ID, ENI_CONFIG) - dash_db.set_app_db_entry(APP_DASH_VNET_MAPPING_TABLE_NAME, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG) + dash_db.set_app_db_entry(APP_DASH_VNET_MAPPING_TABLE_NAME, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG_PRIVATELINK) dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1, ROUTE_GROUP_CONFIG) + # Don't set DASH_ROUTE_TABLE and DASH_ENI_ROUTE_TABLE entries here for flexibility, test cases will set them as needed yield + dash_db.remove_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID) + dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) dash_db.remove_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1) dash_db.remove_app_db_entry(APP_DASH_VNET_MAPPING_TABLE_NAME, VNET1, VNET_MAP_IP1) dash_db.remove_app_db_entry(APP_DASH_ENI_TABLE_NAME, ENI_ID) @@ -65,13 +50,19 @@ def common_setup_teardown(dash_db: DashDB): dash_db.remove_app_db_entry(APP_DASH_ROUTING_TYPE_TABLE_NAME, PRIVATELINK) -def test_pl_eni_attrs(dash_db: DashDB, apply_base_pl_route): - enis= dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_ENI") +def test_pl_eni_attrs(dash_db: DashDB): + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_CONFIG) + + enis = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_ENI") assert enis eni_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_ENI", enis[0]) assert_sai_attribute_exists(SAI_ENI_ATTR_PL_UNDERLAY_SIP, eni_attrs, PL_UNDERLAY_SIP1) -def test_pl_eni_override_underlay_sip(dash_db: DashDB, apply_pl_route_with_underlay_sip): +def test_pl_eni_override_underlay_sip(dash_db: DashDB): + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG_UNDERLAY_SIP) + dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_CONFIG) + outbound_routing_keys = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY") assert outbound_routing_keys outbound_routing_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY", outbound_routing_keys[0]) From ca712cc69ae0c22d580c1b55aa27bb341cd442c2 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 30 Aug 2024 21:38:43 +0000 Subject: [PATCH 63/77] unbind old route group from ENI Signed-off-by: Lawrence Lee --- orchagent/dash/dashorch.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/orchagent/dash/dashorch.cpp b/orchagent/dash/dashorch.cpp index db2eda689a..c43092b1cf 100644 --- a/orchagent/dash/dashorch.cpp +++ b/orchagent/dash/dashorch.cpp @@ -718,10 +718,12 @@ bool DashOrch::setEniRoute(const std::string& eni, const dash::eni_route::EniRou return false; } + std::string old_group_id; if (eni_route_entries_.find(eni) != eni_route_entries_.end()) { if (eni_route_entries_[eni].group_id() != entry.group_id()) { + old_group_id = eni_route_entries_[eni].group_id(); SWSS_LOG_INFO("Updating route entry from %s to %s for ENI %s", eni_route_entries_[eni].group_id().c_str(), entry.group_id().c_str(), eni.c_str()); } else @@ -750,6 +752,11 @@ bool DashOrch::setEniRoute(const std::string& eni, const dash::eni_route::EniRou eni_route_entries_[eni] = entry; dash_route_orch->bindRouteGroup(entry.group_id()); + if (!old_group_id.empty()) + { + dash_route_orch->unbindRouteGroup(old_group_id); + } + SWSS_LOG_NOTICE("Updated ENI route group for %s to route group %s", eni.c_str(), entry.group_id().c_str()); return true; } From 52b6013a3218540e0528e3c2d314a47de89bae55 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Tue, 3 Sep 2024 20:28:25 +0000 Subject: [PATCH 64/77] retry route group deletion if bound Signed-off-by: Lawrence Lee --- orchagent/dash/dashrouteorch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index f630945da8..324004c482 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -691,7 +691,7 @@ bool DashRouteOrch::removeRouteGroup(const string& route_group) if (isRouteGroupBound(route_group)) { SWSS_LOG_WARN("Cannot remove bound route group %s", route_group.c_str()); - return true; + return false; } sai_object_id_t route_group_oid = this->getRouteGroupOid(route_group); From 07408d63ec09c70220f9430c86dfa1a0c518775b Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Tue, 3 Sep 2024 22:11:51 +0000 Subject: [PATCH 65/77] setup/teardown per test case Signed-off-by: Lawrence Lee --- tests/dash/test_dash_pl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dash/test_dash_pl.py b/tests/dash/test_dash_pl.py index ff1d4be0fc..17e6c7d571 100644 --- a/tests/dash/test_dash_pl.py +++ b/tests/dash/test_dash_pl.py @@ -28,7 +28,7 @@ DVS_ENV = ["HWSKU=DPU-2P"] NUM_PORTS = 2 -@pytest.fixture(scope='module', autouse=True) +@pytest.fixture(autouse=True) def common_setup_teardown(dash_db: DashDB): dash_db.set_app_db_entry(APP_DASH_ROUTING_TYPE_TABLE_NAME, PRIVATELINK, ROUTING_TYPE_PL_CONFIG) dash_db.set_app_db_entry(APP_DASH_APPLIANCE_TABLE_NAME, APPLIANCE_ID, APPLIANCE_CONFIG) From e097983a44be9df3a4bc6ab6412795217091f0f5 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 4 Sep 2024 00:32:27 +0000 Subject: [PATCH 66/77] add __init__.py for utils folder Signed-off-by: Lawrence Lee --- tests/utils/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/utils/__init__.py diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py new file mode 100644 index 0000000000..e69de29bb2 From cf34994db5aa37519c1047e0bf52bb87857d43b1 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 4 Sep 2024 02:17:03 +0000 Subject: [PATCH 67/77] fix test package Signed-off-by: Lawrence Lee --- tests/dash/dash_db.py | 2 +- tests/dash/test_dash_pl.py | 2 +- tests/{utils => dvslib}/sai_utils.py | 0 tests/utils/__init__.py | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename tests/{utils => dvslib}/sai_utils.py (100%) delete mode 100644 tests/utils/__init__.py diff --git a/tests/dash/dash_db.py b/tests/dash/dash_db.py index 7b5937dda7..2802daedb2 100644 --- a/tests/dash/dash_db.py +++ b/tests/dash/dash_db.py @@ -1,5 +1,5 @@ from swsscommon import swsscommon -from dvslib.dvs_common import wait_for_result +from dvslib.dvs_common import wait_for_result import typing import pytest diff --git a/tests/dash/test_dash_pl.py b/tests/dash/test_dash_pl.py index 17e6c7d571..c2ef5f2a99 100644 --- a/tests/dash/test_dash_pl.py +++ b/tests/dash/test_dash_pl.py @@ -1,6 +1,6 @@ import pytest -from utils.sai_utils import assert_sai_attribute_exists +from dvslib.sai_utils import assert_sai_attribute_exists from dash_api.appliance_pb2 import * from dash_api.vnet_pb2 import * diff --git a/tests/utils/sai_utils.py b/tests/dvslib/sai_utils.py similarity index 100% rename from tests/utils/sai_utils.py rename to tests/dvslib/sai_utils.py diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 From 8ff6bb87748bfe5a459caaac10f58fe7bb1b876c Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 4 Sep 2024 19:18:59 +0000 Subject: [PATCH 68/77] Test ENI route group rebinding Signed-off-by: Lawrence Lee --- tests/dash/dash_configs.py | 17 +++++++-- tests/dash/dash_db.py | 29 +++++++++++++-- tests/dash/test_dash_pl.py | 9 ++--- tests/dash/test_dash_route_group.py | 55 +++++++++++++++++++++++++++++ tests/sai_attrs.py | 1 + 5 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 tests/dash/test_dash_route_group.py diff --git a/tests/dash/dash_configs.py b/tests/dash/dash_configs.py index 6fa3b6d4aa..afbbac1812 100644 --- a/tests/dash/dash_configs.py +++ b/tests/dash/dash_configs.py @@ -43,7 +43,9 @@ MAC_ADDRESS = "F4:93:9F:EF:C4:7E" ENI_ID = "497f23d7-f0ac-4c99-a98f-59b470e8c7bd" ROUTE_GROUP1 = "RouteGroup1" +ROUTE_GROUP2 = "RouteGroup2" ROUTE_GROUP1_GUID = "48af6ce8-26cc-4293-bfa6-0126e8fcdeb2" +ROUTE_GROUP2_GUID = "58cf62e0-22cc-4693-baa6-012358fcdec9" APPLIANCE_CONFIG = { "sip": { @@ -114,7 +116,7 @@ ROUTE_VNET_CONFIG = { "routing_type": RoutingType.ROUTING_TYPE_VNET, - "vnet": "Vnet1", + "vnet": VNET1, } ROUTE_VNET_CONFIG_UNDERLAY_SIP = { @@ -149,11 +151,20 @@ ] } -ROUTE_GROUP_CONFIG = { +ROUTE_GROUP1_CONFIG = { "guid": ROUTE_GROUP1_GUID, "version": "rg_version" } -ENI_ROUTE_CONFIG = { +ROUTE_GROUP2_CONFIG = { + "guid": ROUTE_GROUP2_GUID, + "version": "rg_version" +} + +ENI_ROUTE_GROUP1_CONFIG = { "group_id": ROUTE_GROUP1, } + +ENI_ROUTE_GROUP2_CONFIG = { + "group_id": ROUTE_GROUP2, +} \ No newline at end of file diff --git a/tests/dash/dash_db.py b/tests/dash/dash_db.py index 2802daedb2..7dbb19b1fe 100644 --- a/tests/dash/dash_db.py +++ b/tests/dash/dash_db.py @@ -107,16 +107,39 @@ def get_asic_db_entry(self, table_name, key): table = Table(self.dvs.get_asic_db().db_connection, table_name) return table[key] - def wait_for_asic_db_keys(self, table_name): + def wait_for_asic_db_keys(self, table_name, min_keys=1): def polling_function(): table = Table(self.dvs.get_asic_db().db_connection, table_name) keys = table.get_keys() - return bool(keys), keys + return len(keys) >= min_keys, keys - _, keys = wait_for_result(polling_function) + _, keys = wait_for_result(polling_function, failure_message=f"Found fewer than {min_keys} keys in ASIC_DB table {table_name}") return keys + def wait_for_asic_db_field(self, table_name, key, field, expected_value=None): + + def polling_function(): + table = Table(self.dvs.get_asic_db().db_connection, table_name) + attrs = table[key] + if attrs is None or field not in attrs: + return False, None + + if expected_value is not None: + return attrs[field] == expected_value, attrs[field] + else: + return True, attrs[field] + + if expected_value is not None: + failure_message = f"Field {field} in ASIC_DB table {table_name} not equal to {expected_value}" + else: + failure_message = f"Field {field} not found in ASIC_DB table {table_name}" + success, value = wait_for_result(polling_function, failure_message=failure_message) + if success: + return value + else: + return None + def __init__(self, dvs): self.dvs = dvs self.app_dash_routing_type_table = ProducerStateTable( diff --git a/tests/dash/test_dash_pl.py b/tests/dash/test_dash_pl.py index c2ef5f2a99..c6a3e7a69d 100644 --- a/tests/dash/test_dash_pl.py +++ b/tests/dash/test_dash_pl.py @@ -35,7 +35,7 @@ def common_setup_teardown(dash_db: DashDB): dash_db.set_app_db_entry(APP_DASH_VNET_TABLE_NAME, VNET1, VNET_CONFIG) dash_db.set_app_db_entry(APP_DASH_ENI_TABLE_NAME, ENI_ID, ENI_CONFIG) dash_db.set_app_db_entry(APP_DASH_VNET_MAPPING_TABLE_NAME, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG_PRIVATELINK) - dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1, ROUTE_GROUP_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1, ROUTE_GROUP1_CONFIG) # Don't set DASH_ROUTE_TABLE and DASH_ENI_ROUTE_TABLE entries here for flexibility, test cases will set them as needed yield @@ -52,25 +52,22 @@ def common_setup_teardown(dash_db: DashDB): def test_pl_eni_attrs(dash_db: DashDB): dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG) - dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP1_CONFIG) enis = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_ENI") - assert enis eni_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_ENI", enis[0]) assert_sai_attribute_exists(SAI_ENI_ATTR_PL_UNDERLAY_SIP, eni_attrs, PL_UNDERLAY_SIP1) def test_pl_eni_override_underlay_sip(dash_db: DashDB): dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG_UNDERLAY_SIP) - dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP1_CONFIG) outbound_routing_keys = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY") - assert outbound_routing_keys outbound_routing_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY", outbound_routing_keys[0]) assert_sai_attribute_exists(SAI_OUTBOUND_ROUTING_ENTRY_ATTR_UNDERLAY_SIP, outbound_routing_attrs, PL_UNDERLAY_SIP2) def test_pl_outbound_ca_to_pa_attrs(dash_db: DashDB): outbound_ca_to_pa_keys = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_CA_TO_PA_ENTRY") - assert outbound_ca_to_pa_keys outbound_attrs = dash_db.get_asic_db_entry("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_CA_TO_PA_ENTRY", outbound_ca_to_pa_keys[0]) assert_sai_attribute_exists(SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION, outbound_attrs, SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING) diff --git a/tests/dash/test_dash_route_group.py b/tests/dash/test_dash_route_group.py new file mode 100644 index 0000000000..81fd4a6205 --- /dev/null +++ b/tests/dash/test_dash_route_group.py @@ -0,0 +1,55 @@ +import pytest +import json +from dash_db import DashDB, dash_db +from dash_configs import * +from dvslib.sai_utils import assert_sai_attribute_exists +from sai_attrs import * +from swsscommon.swsscommon import ( + APP_DASH_APPLIANCE_TABLE_NAME, + APP_DASH_ENI_TABLE_NAME, + APP_DASH_VNET_TABLE_NAME, + APP_DASH_VNET_MAPPING_TABLE_NAME, + APP_DASH_ROUTE_TABLE_NAME, + APP_DASH_ENI_ROUTE_TABLE_NAME, + APP_DASH_ROUTING_TYPE_TABLE_NAME, + APP_DASH_ROUTE_GROUP_TABLE_NAME, +) + +@pytest.fixture(scope='module', autouse=True) +def common_setup_teardown(dash_db: DashDB): + dash_db.set_app_db_entry(APP_DASH_APPLIANCE_TABLE_NAME, APPLIANCE_ID, APPLIANCE_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ROUTING_TYPE_TABLE_NAME, PRIVATELINK, ROUTING_TYPE_PL_CONFIG) + dash_db.set_app_db_entry(APP_DASH_VNET_TABLE_NAME, VNET1, VNET_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ENI_TABLE_NAME, ENI_ID, ENI_CONFIG) + dash_db.set_app_db_entry(APP_DASH_VNET_MAPPING_TABLE_NAME, VNET1, VNET_MAP_IP1, VNET_MAPPING_CONFIG_PRIVATELINK) + # Don't set DASH_ROUTE_TABLE and DASH_ENI_ROUTE_TABLE entries here for flexibility, test cases will set them as needed + + yield + + dash_db.remove_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID) + dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) + dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP2, OUTBOUND_ROUTE_PREFIX) + dash_db.remove_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1) + dash_db.remove_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP2) + dash_db.remove_app_db_entry(APP_DASH_VNET_MAPPING_TABLE_NAME, VNET1, VNET_MAP_IP1) + dash_db.remove_app_db_entry(APP_DASH_ENI_TABLE_NAME, ENI_ID) + dash_db.remove_app_db_entry(APP_DASH_VNET_TABLE_NAME, VNET1) + dash_db.remove_app_db_entry(APP_DASH_ROUTING_TYPE_TABLE_NAME, PRIVATELINK) + dash_db.remove_app_db_entry(APP_DASH_APPLIANCE_TABLE_NAME, APPLIANCE_ID) + +def test_rebind_eni_route_group(dash_db: DashDB): + dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1, ROUTE_GROUP1_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG) + rg1_oid = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_GROUP")[0] + + dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP2, ROUTE_GROUP2_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP2, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG_UNDERLAY_SIP) + rg2_oid = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_GROUP", min_keys=2)[1] + + dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP1_CONFIG) + + eni_key = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_ENI")[0] + dash_db.wait_for_asic_db_field("ASIC_STATE:SAI_OBJECT_TYPE_ENI", eni_key, SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID, rg1_oid) + + dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP2_CONFIG) + dash_db.wait_for_asic_db_field("ASIC_STATE:SAI_OBJECT_TYPE_ENI", eni_key, SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID, rg2_oid) \ No newline at end of file diff --git a/tests/sai_attrs.py b/tests/sai_attrs.py index daec8373a8..207eb545ed 100644 --- a/tests/sai_attrs.py +++ b/tests/sai_attrs.py @@ -1,6 +1,7 @@ SAI_ENI_ATTR_PL_SIP = 'SAI_ENI_ATTR_PL_SIP' SAI_ENI_ATTR_PL_SIP_MASK = 'SAI_ENI_ATTR_PL_SIP_MASK' SAI_ENI_ATTR_PL_UNDERLAY_SIP = 'SAI_ENI_ATTR_PL_UNDERLAY_SIP' +SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID = 'SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID' SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING' SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING' SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP = 'SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DIP' From 0d4859a71f5eeb51f7fb8911dfa86dfc017fcf23 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 4 Sep 2024 21:50:13 +0000 Subject: [PATCH 69/77] refactor orchagent mock base class Signed-off-by: Lawrence Lee --- tests/mock_tests/Makefile.am | 5 +- tests/mock_tests/mock_orch_test.cpp | 275 ++++++++++++++++++++++++++++ tests/mock_tests/mock_orch_test.h | 273 +-------------------------- 3 files changed, 287 insertions(+), 266 deletions(-) create mode 100644 tests/mock_tests/mock_orch_test.cpp diff --git a/tests/mock_tests/Makefile.am b/tests/mock_tests/Makefile.am index c3a305b1eb..0f5afa4486 100644 --- a/tests/mock_tests/Makefile.am +++ b/tests/mock_tests/Makefile.am @@ -1,6 +1,7 @@ FLEX_CTR_DIR = $(top_srcdir)/orchagent/flex_counter DEBUG_CTR_DIR = $(top_srcdir)/orchagent/debug_counter P4_ORCH_DIR = $(top_srcdir)/orchagent/p4orch +DASH_ORCH_DIR = $(top_srcdir)/orchagent/dash DASH_PROTO_DIR = $(top_srcdir)/orchagent/dash/proto CFLAGS_SAI = -I /usr/include/sai @@ -22,7 +23,7 @@ LDADD_GTEST = -L/usr/src/gtest ## Orchagent Unit Tests -tests_INCLUDES = -I $(FLEX_CTR_DIR) -I $(DEBUG_CTR_DIR) -I $(top_srcdir)/lib -I$(top_srcdir)/cfgmgr -I$(top_srcdir)/orchagent -I$(P4_ORCH_DIR)/tests -I$(top_srcdir)/warmrestart +tests_INCLUDES = -I $(FLEX_CTR_DIR) -I $(DEBUG_CTR_DIR) -I $(top_srcdir)/lib -I$(top_srcdir)/cfgmgr -I$(top_srcdir)/orchagent -I$(P4_ORCH_DIR)/tests -I$(DASH_ORCH_DIR) -I$(top_srcdir)/warmrestart tests_SOURCES = aclorch_ut.cpp \ portsorch_ut.cpp \ @@ -60,8 +61,10 @@ tests_SOURCES = aclorch_ut.cpp \ switchorch_ut.cpp \ warmrestarthelper_ut.cpp \ neighorch_ut.cpp \ + dashorch_ut.cpp \ twamporch_ut.cpp \ flexcounter_ut.cpp \ + mock_orch_test.cpp \ $(top_srcdir)/warmrestart/warmRestartHelper.cpp \ $(top_srcdir)/lib/gearboxutils.cpp \ $(top_srcdir)/lib/subintf.cpp \ diff --git a/tests/mock_tests/mock_orch_test.cpp b/tests/mock_tests/mock_orch_test.cpp new file mode 100644 index 0000000000..9912ecdd6a --- /dev/null +++ b/tests/mock_tests/mock_orch_test.cpp @@ -0,0 +1,275 @@ +#include "mock_orch_test.h" + +using namespace std; + +namespace mock_orch_test +{ + +void MockOrchTest::PrepareSai() +{ + sai_attribute_t attr; + + attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; + attr.value.booldata = true; + + sai_status_t status = sai_switch_api->create_switch(&gSwitchId, 1, &attr); + ASSERT_EQ(status, SAI_STATUS_SUCCESS); + + // Get switch source MAC address + attr.id = SAI_SWITCH_ATTR_SRC_MAC_ADDRESS; + status = sai_switch_api->get_switch_attribute(gSwitchId, 1, &attr); + + ASSERT_EQ(status, SAI_STATUS_SUCCESS); + + gMacAddress = attr.value.mac; + + attr.id = SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID; + status = sai_switch_api->get_switch_attribute(gSwitchId, 1, &attr); + + ASSERT_EQ(status, SAI_STATUS_SUCCESS); + + gVirtualRouterId = attr.value.oid; + + /* Create a loopback underlay router interface */ + vector underlay_intf_attrs; + + sai_attribute_t underlay_intf_attr; + underlay_intf_attr.id = SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID; + underlay_intf_attr.value.oid = gVirtualRouterId; + underlay_intf_attrs.push_back(underlay_intf_attr); + + underlay_intf_attr.id = SAI_ROUTER_INTERFACE_ATTR_TYPE; + underlay_intf_attr.value.s32 = SAI_ROUTER_INTERFACE_TYPE_LOOPBACK; + underlay_intf_attrs.push_back(underlay_intf_attr); + + underlay_intf_attr.id = SAI_ROUTER_INTERFACE_ATTR_MTU; + underlay_intf_attr.value.u32 = 9100; + underlay_intf_attrs.push_back(underlay_intf_attr); + + status = sai_router_intfs_api->create_router_interface(&gUnderlayIfId, gSwitchId, (uint32_t)underlay_intf_attrs.size(), underlay_intf_attrs.data()); + ASSERT_EQ(status, SAI_STATUS_SUCCESS); +} + +void MockOrchTest::SetUp() +{ + map profile = { + { "SAI_VS_SWITCH_TYPE", "SAI_VS_SWITCH_TYPE_BCM56850" }, + { "KV_DEVICE_MAC_ADDRESS", "20:03:04:05:06:00" } + }; + + ut_helper::initSaiApi(profile); + m_app_db = make_shared("APPL_DB", 0); + m_config_db = make_shared("CONFIG_DB", 0); + m_state_db = make_shared("STATE_DB", 0); + m_chassis_app_db = make_shared("CHASSIS_APP_DB", 0); + + PrepareSai(); + + const int portsorch_base_pri = 40; + vector ports_tables = { + { APP_PORT_TABLE_NAME, portsorch_base_pri + 5 }, + { APP_VLAN_TABLE_NAME, portsorch_base_pri + 2 }, + { APP_VLAN_MEMBER_TABLE_NAME, portsorch_base_pri }, + { APP_LAG_TABLE_NAME, portsorch_base_pri + 4 }, + { APP_LAG_MEMBER_TABLE_NAME, portsorch_base_pri } + }; + + TableConnector stateDbSwitchTable(m_state_db.get(), STATE_SWITCH_CAPABILITY_TABLE_NAME); + TableConnector app_switch_table(m_app_db.get(), APP_SWITCH_TABLE_NAME); + TableConnector conf_asic_sensors(m_config_db.get(), CFG_ASIC_SENSORS_TABLE_NAME); + + vector switch_tables = { + conf_asic_sensors, + app_switch_table + }; + + gSwitchOrch = new SwitchOrch(m_app_db.get(), switch_tables, stateDbSwitchTable); + gDirectory.set(gSwitchOrch); + ut_orch_list.push_back((Orch **)&gSwitchOrch); + + vector flex_counter_tables = { + CFG_FLEX_COUNTER_TABLE_NAME + }; + + m_FlexCounterOrch = new FlexCounterOrch(m_config_db.get(), flex_counter_tables); + gDirectory.set(m_FlexCounterOrch); + ut_orch_list.push_back((Orch **)&m_FlexCounterOrch); + + static const vector route_pattern_tables = { + CFG_FLOW_COUNTER_ROUTE_PATTERN_TABLE_NAME, + }; + gFlowCounterRouteOrch = new FlowCounterRouteOrch(m_config_db.get(), route_pattern_tables); + gDirectory.set(gFlowCounterRouteOrch); + ut_orch_list.push_back((Orch **)&gFlowCounterRouteOrch); + + gVrfOrch = new VRFOrch(m_app_db.get(), APP_VRF_TABLE_NAME, m_state_db.get(), STATE_VRF_OBJECT_TABLE_NAME); + gDirectory.set(gVrfOrch); + ut_orch_list.push_back((Orch **)&gVrfOrch); + + gIntfsOrch = new IntfsOrch(m_app_db.get(), APP_INTF_TABLE_NAME, gVrfOrch, m_chassis_app_db.get()); + gDirectory.set(gIntfsOrch); + ut_orch_list.push_back((Orch **)&gIntfsOrch); + + gPortsOrch = new PortsOrch(m_app_db.get(), m_state_db.get(), ports_tables, m_chassis_app_db.get()); + gDirectory.set(gPortsOrch); + ut_orch_list.push_back((Orch **)&gPortsOrch); + + const int fgnhgorch_pri = 15; + + vector fgnhg_tables = { + { CFG_FG_NHG, fgnhgorch_pri }, + { CFG_FG_NHG_PREFIX, fgnhgorch_pri }, + { CFG_FG_NHG_MEMBER, fgnhgorch_pri } + }; + + gFgNhgOrch = new FgNhgOrch(m_config_db.get(), m_app_db.get(), m_state_db.get(), fgnhg_tables, gNeighOrch, gIntfsOrch, gVrfOrch); + gDirectory.set(gFgNhgOrch); + ut_orch_list.push_back((Orch **)&gFgNhgOrch); + + const int fdborch_pri = 20; + + vector app_fdb_tables = { + { APP_FDB_TABLE_NAME, FdbOrch::fdborch_pri }, + { APP_VXLAN_FDB_TABLE_NAME, FdbOrch::fdborch_pri }, + { APP_MCLAG_FDB_TABLE_NAME, fdborch_pri } + }; + + TableConnector stateDbFdb(m_state_db.get(), STATE_FDB_TABLE_NAME); + TableConnector stateMclagDbFdb(m_state_db.get(), STATE_MCLAG_REMOTE_FDB_TABLE_NAME); + gFdbOrch = new FdbOrch(m_app_db.get(), app_fdb_tables, stateDbFdb, stateMclagDbFdb, gPortsOrch); + gDirectory.set(gFdbOrch); + ut_orch_list.push_back((Orch **)&gFdbOrch); + + gNeighOrch = new NeighOrch(m_app_db.get(), APP_NEIGH_TABLE_NAME, gIntfsOrch, gFdbOrch, gPortsOrch, m_chassis_app_db.get()); + gDirectory.set(gNeighOrch); + ut_orch_list.push_back((Orch **)&gNeighOrch); + + vector tunnel_tables = { + APP_TUNNEL_DECAP_TABLE_NAME, + APP_TUNNEL_DECAP_TERM_TABLE_NAME + }; + m_TunnelDecapOrch = new TunnelDecapOrch(m_app_db.get(), m_state_db.get(), m_config_db.get(), tunnel_tables); + gDirectory.set(m_TunnelDecapOrch); + ut_orch_list.push_back((Orch **)&m_TunnelDecapOrch); + vector mux_tables = { + CFG_MUX_CABLE_TABLE_NAME, + CFG_PEER_SWITCH_TABLE_NAME + }; + + vector buffer_tables = { + APP_BUFFER_POOL_TABLE_NAME, + APP_BUFFER_PROFILE_TABLE_NAME, + APP_BUFFER_QUEUE_TABLE_NAME, + APP_BUFFER_PG_TABLE_NAME, + APP_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME, + APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME + }; + gBufferOrch = new BufferOrch(m_app_db.get(), m_config_db.get(), m_state_db.get(), buffer_tables); + ut_orch_list.push_back((Orch **)&gBufferOrch); + + vector policer_tables = { + TableConnector(m_config_db.get(), CFG_POLICER_TABLE_NAME), + TableConnector(m_config_db.get(), CFG_PORT_STORM_CONTROL_TABLE_NAME) + }; + + TableConnector stateDbStorm(m_state_db.get(), STATE_BUM_STORM_CAPABILITY_TABLE_NAME); + gPolicerOrch = new PolicerOrch(policer_tables, gPortsOrch); + gDirectory.set(gPolicerOrch); + ut_orch_list.push_back((Orch **)&gPolicerOrch); + + gNhgOrch = new NhgOrch(m_app_db.get(), APP_NEXTHOP_GROUP_TABLE_NAME); + gDirectory.set(gNhgOrch); + ut_orch_list.push_back((Orch **)&gNhgOrch); + + vector srv6_tables = { + APP_SRV6_SID_LIST_TABLE_NAME, + APP_SRV6_MY_SID_TABLE_NAME + }; + gSrv6Orch = new Srv6Orch(m_app_db.get(), srv6_tables, gSwitchOrch, gVrfOrch, gNeighOrch); + gDirectory.set(gSrv6Orch); + ut_orch_list.push_back((Orch **)&gSrv6Orch); + gCrmOrch = new CrmOrch(m_config_db.get(), CFG_CRM_TABLE_NAME); + gDirectory.set(gCrmOrch); + ut_orch_list.push_back((Orch **)&gCrmOrch); + + const int routeorch_pri = 5; + vector route_tables = { + { APP_ROUTE_TABLE_NAME, routeorch_pri }, + { APP_LABEL_ROUTE_TABLE_NAME, routeorch_pri } + }; + gRouteOrch = new RouteOrch(m_app_db.get(), route_tables, gSwitchOrch, gNeighOrch, gIntfsOrch, gVrfOrch, gFgNhgOrch, gSrv6Orch); + gDirectory.set(gRouteOrch); + ut_orch_list.push_back((Orch **)&gRouteOrch); + TableConnector stateDbMirrorSession(m_state_db.get(), STATE_MIRROR_SESSION_TABLE_NAME); + TableConnector confDbMirrorSession(m_config_db.get(), CFG_MIRROR_SESSION_TABLE_NAME); + gMirrorOrch = new MirrorOrch(stateDbMirrorSession, confDbMirrorSession, gPortsOrch, gRouteOrch, gNeighOrch, gFdbOrch, gPolicerOrch); + gDirectory.set(gMirrorOrch); + ut_orch_list.push_back((Orch **)&gMirrorOrch); + + vector dash_tables = { + APP_DASH_APPLIANCE_TABLE_NAME, + APP_DASH_ROUTING_TYPE_TABLE_NAME, + APP_DASH_ENI_TABLE_NAME, + APP_DASH_ENI_ROUTE_TABLE_NAME, + APP_DASH_QOS_TABLE_NAME + }; + + m_DashOrch = new DashOrch(m_app_db.get(), dash_tables, nullptr); + gDirectory.set(m_DashOrch); + ut_orch_list.push_back((Orch **)&m_DashOrch); + + TableConnector confDbAclTable(m_config_db.get(), CFG_ACL_TABLE_TABLE_NAME); + TableConnector confDbAclTableType(m_config_db.get(), CFG_ACL_TABLE_TYPE_TABLE_NAME); + TableConnector confDbAclRuleTable(m_config_db.get(), CFG_ACL_RULE_TABLE_NAME); + TableConnector appDbAclTable(m_app_db.get(), APP_ACL_TABLE_TABLE_NAME); + TableConnector appDbAclTableType(m_app_db.get(), APP_ACL_TABLE_TYPE_TABLE_NAME); + TableConnector appDbAclRuleTable(m_app_db.get(), APP_ACL_RULE_TABLE_NAME); + + vector acl_table_connectors = { + confDbAclTableType, + confDbAclTable, + confDbAclRuleTable, + appDbAclTable, + appDbAclRuleTable, + appDbAclTableType, + }; + gAclOrch = new AclOrch(acl_table_connectors, m_state_db.get(), + gSwitchOrch, gPortsOrch, gMirrorOrch, gNeighOrch, gRouteOrch, NULL); + gDirectory.set(gAclOrch); + ut_orch_list.push_back((Orch **)&gAclOrch); + + m_MuxOrch = new MuxOrch(m_config_db.get(), mux_tables, m_TunnelDecapOrch, gNeighOrch, gFdbOrch); + gDirectory.set(m_MuxOrch); + ut_orch_list.push_back((Orch **)&m_MuxOrch); + + m_MuxCableOrch = new MuxCableOrch(m_app_db.get(), m_state_db.get(), APP_MUX_CABLE_TABLE_NAME); + gDirectory.set(m_MuxCableOrch); + ut_orch_list.push_back((Orch **)&m_MuxCableOrch); + + m_MuxStateOrch = new MuxStateOrch(m_state_db.get(), STATE_HW_MUX_CABLE_TABLE_NAME); + gDirectory.set(m_MuxStateOrch); + ut_orch_list.push_back((Orch **)&m_MuxStateOrch); + + m_VxlanTunnelOrch = new VxlanTunnelOrch(m_state_db.get(), m_app_db.get(), APP_VXLAN_TUNNEL_TABLE_NAME); + gDirectory.set(m_VxlanTunnelOrch); + ut_orch_list.push_back((Orch **)&m_VxlanTunnelOrch); + + ApplyInitialConfigs(); + PostSetUp(); +} + +void MockOrchTest::TearDown() +{ + PreTearDown(); + for (std::vector::reverse_iterator rit = ut_orch_list.rbegin(); rit != ut_orch_list.rend(); ++rit) + { + Orch **orch = *rit; + delete *orch; + *orch = nullptr; + } + + gDirectory.m_values.clear(); + + ut_helper::uninitSaiApi(); +} +} \ No newline at end of file diff --git a/tests/mock_tests/mock_orch_test.h b/tests/mock_tests/mock_orch_test.h index fe6d3a0e07..b0988932a6 100644 --- a/tests/mock_tests/mock_orch_test.h +++ b/tests/mock_tests/mock_orch_test.h @@ -9,9 +9,6 @@ #include "gtest/gtest.h" #include -using namespace std; -using ::testing::Return; -using ::testing::Throw; namespace mock_orch_test { @@ -53,267 +50,13 @@ namespace mock_orch_test MuxStateOrch *m_MuxStateOrch; FlexCounterOrch *m_FlexCounterOrch; VxlanTunnelOrch *m_VxlanTunnelOrch; - - virtual void ApplyInitialConfigs() {} - - void PrepareSai() - { - sai_attribute_t attr; - - attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; - attr.value.booldata = true; - - sai_status_t status = sai_switch_api->create_switch(&gSwitchId, 1, &attr); - ASSERT_EQ(status, SAI_STATUS_SUCCESS); - - // Get switch source MAC address - attr.id = SAI_SWITCH_ATTR_SRC_MAC_ADDRESS; - status = sai_switch_api->get_switch_attribute(gSwitchId, 1, &attr); - - ASSERT_EQ(status, SAI_STATUS_SUCCESS); - - gMacAddress = attr.value.mac; - - attr.id = SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID; - status = sai_switch_api->get_switch_attribute(gSwitchId, 1, &attr); - - ASSERT_EQ(status, SAI_STATUS_SUCCESS); - - gVirtualRouterId = attr.value.oid; - - /* Create a loopback underlay router interface */ - vector underlay_intf_attrs; - - sai_attribute_t underlay_intf_attr; - underlay_intf_attr.id = SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID; - underlay_intf_attr.value.oid = gVirtualRouterId; - underlay_intf_attrs.push_back(underlay_intf_attr); - - underlay_intf_attr.id = SAI_ROUTER_INTERFACE_ATTR_TYPE; - underlay_intf_attr.value.s32 = SAI_ROUTER_INTERFACE_TYPE_LOOPBACK; - underlay_intf_attrs.push_back(underlay_intf_attr); - - underlay_intf_attr.id = SAI_ROUTER_INTERFACE_ATTR_MTU; - underlay_intf_attr.value.u32 = 9100; - underlay_intf_attrs.push_back(underlay_intf_attr); - - status = sai_router_intfs_api->create_router_interface(&gUnderlayIfId, gSwitchId, (uint32_t)underlay_intf_attrs.size(), underlay_intf_attrs.data()); - ASSERT_EQ(status, SAI_STATUS_SUCCESS); - } - - virtual void PostSetUp() {}; - - void SetUp() override - { - map profile = { - { "SAI_VS_SWITCH_TYPE", "SAI_VS_SWITCH_TYPE_BCM56850" }, - { "KV_DEVICE_MAC_ADDRESS", "20:03:04:05:06:00" } - }; - - ut_helper::initSaiApi(profile); - m_app_db = make_shared("APPL_DB", 0); - m_config_db = make_shared("CONFIG_DB", 0); - m_state_db = make_shared("STATE_DB", 0); - m_chassis_app_db = make_shared("CHASSIS_APP_DB", 0); - - PrepareSai(); - - const int portsorch_base_pri = 40; - vector ports_tables = { - { APP_PORT_TABLE_NAME, portsorch_base_pri + 5 }, - { APP_VLAN_TABLE_NAME, portsorch_base_pri + 2 }, - { APP_VLAN_MEMBER_TABLE_NAME, portsorch_base_pri }, - { APP_LAG_TABLE_NAME, portsorch_base_pri + 4 }, - { APP_LAG_MEMBER_TABLE_NAME, portsorch_base_pri } - }; - - TableConnector stateDbSwitchTable(m_state_db.get(), STATE_SWITCH_CAPABILITY_TABLE_NAME); - TableConnector app_switch_table(m_app_db.get(), APP_SWITCH_TABLE_NAME); - TableConnector conf_asic_sensors(m_config_db.get(), CFG_ASIC_SENSORS_TABLE_NAME); - - vector switch_tables = { - conf_asic_sensors, - app_switch_table - }; - - gSwitchOrch = new SwitchOrch(m_app_db.get(), switch_tables, stateDbSwitchTable); - gDirectory.set(gSwitchOrch); - ut_orch_list.push_back((Orch **)&gSwitchOrch); - - vector flex_counter_tables = { - CFG_FLEX_COUNTER_TABLE_NAME - }; - - m_FlexCounterOrch = new FlexCounterOrch(m_config_db.get(), flex_counter_tables); - gDirectory.set(m_FlexCounterOrch); - ut_orch_list.push_back((Orch **)&m_FlexCounterOrch); - - static const vector route_pattern_tables = { - CFG_FLOW_COUNTER_ROUTE_PATTERN_TABLE_NAME, - }; - gFlowCounterRouteOrch = new FlowCounterRouteOrch(m_config_db.get(), route_pattern_tables); - gDirectory.set(gFlowCounterRouteOrch); - ut_orch_list.push_back((Orch **)&gFlowCounterRouteOrch); - - gVrfOrch = new VRFOrch(m_app_db.get(), APP_VRF_TABLE_NAME, m_state_db.get(), STATE_VRF_OBJECT_TABLE_NAME); - gDirectory.set(gVrfOrch); - ut_orch_list.push_back((Orch **)&gVrfOrch); - - gIntfsOrch = new IntfsOrch(m_app_db.get(), APP_INTF_TABLE_NAME, gVrfOrch, m_chassis_app_db.get()); - gDirectory.set(gIntfsOrch); - ut_orch_list.push_back((Orch **)&gIntfsOrch); - - gPortsOrch = new PortsOrch(m_app_db.get(), m_state_db.get(), ports_tables, m_chassis_app_db.get()); - gDirectory.set(gPortsOrch); - ut_orch_list.push_back((Orch **)&gPortsOrch); - - const int fgnhgorch_pri = 15; - - vector fgnhg_tables = { - { CFG_FG_NHG, fgnhgorch_pri }, - { CFG_FG_NHG_PREFIX, fgnhgorch_pri }, - { CFG_FG_NHG_MEMBER, fgnhgorch_pri } - }; - - gFgNhgOrch = new FgNhgOrch(m_config_db.get(), m_app_db.get(), m_state_db.get(), fgnhg_tables, gNeighOrch, gIntfsOrch, gVrfOrch); - gDirectory.set(gFgNhgOrch); - ut_orch_list.push_back((Orch **)&gFgNhgOrch); - - const int fdborch_pri = 20; - - vector app_fdb_tables = { - { APP_FDB_TABLE_NAME, FdbOrch::fdborch_pri }, - { APP_VXLAN_FDB_TABLE_NAME, FdbOrch::fdborch_pri }, - { APP_MCLAG_FDB_TABLE_NAME, fdborch_pri } - }; - - TableConnector stateDbFdb(m_state_db.get(), STATE_FDB_TABLE_NAME); - TableConnector stateMclagDbFdb(m_state_db.get(), STATE_MCLAG_REMOTE_FDB_TABLE_NAME); - gFdbOrch = new FdbOrch(m_app_db.get(), app_fdb_tables, stateDbFdb, stateMclagDbFdb, gPortsOrch); - gDirectory.set(gFdbOrch); - ut_orch_list.push_back((Orch **)&gFdbOrch); - - gNeighOrch = new NeighOrch(m_app_db.get(), APP_NEIGH_TABLE_NAME, gIntfsOrch, gFdbOrch, gPortsOrch, m_chassis_app_db.get()); - gDirectory.set(gNeighOrch); - ut_orch_list.push_back((Orch **)&gNeighOrch); - - vector tunnel_tables = { - APP_TUNNEL_DECAP_TABLE_NAME, - APP_TUNNEL_DECAP_TERM_TABLE_NAME - }; - m_TunnelDecapOrch = new TunnelDecapOrch(m_app_db.get(), m_state_db.get(), m_config_db.get(), tunnel_tables); - gDirectory.set(m_TunnelDecapOrch); - ut_orch_list.push_back((Orch **)&m_TunnelDecapOrch); - vector mux_tables = { - CFG_MUX_CABLE_TABLE_NAME, - CFG_PEER_SWITCH_TABLE_NAME - }; - - vector buffer_tables = { - APP_BUFFER_POOL_TABLE_NAME, - APP_BUFFER_PROFILE_TABLE_NAME, - APP_BUFFER_QUEUE_TABLE_NAME, - APP_BUFFER_PG_TABLE_NAME, - APP_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME, - APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME - }; - gBufferOrch = new BufferOrch(m_app_db.get(), m_config_db.get(), m_state_db.get(), buffer_tables); - ut_orch_list.push_back((Orch **)&gBufferOrch); - - vector policer_tables = { - TableConnector(m_config_db.get(), CFG_POLICER_TABLE_NAME), - TableConnector(m_config_db.get(), CFG_PORT_STORM_CONTROL_TABLE_NAME) - }; - - TableConnector stateDbStorm(m_state_db.get(), STATE_BUM_STORM_CAPABILITY_TABLE_NAME); - gPolicerOrch = new PolicerOrch(policer_tables, gPortsOrch); - gDirectory.set(gPolicerOrch); - ut_orch_list.push_back((Orch **)&gPolicerOrch); - - gNhgOrch = new NhgOrch(m_app_db.get(), APP_NEXTHOP_GROUP_TABLE_NAME); - gDirectory.set(gNhgOrch); - ut_orch_list.push_back((Orch **)&gNhgOrch); - - vector srv6_tables = { - APP_SRV6_SID_LIST_TABLE_NAME, - APP_SRV6_MY_SID_TABLE_NAME - }; - gSrv6Orch = new Srv6Orch(m_app_db.get(), srv6_tables, gSwitchOrch, gVrfOrch, gNeighOrch); - gDirectory.set(gSrv6Orch); - ut_orch_list.push_back((Orch **)&gSrv6Orch); - gCrmOrch = new CrmOrch(m_config_db.get(), CFG_CRM_TABLE_NAME); - gDirectory.set(gCrmOrch); - ut_orch_list.push_back((Orch **)&gCrmOrch); - - const int routeorch_pri = 5; - vector route_tables = { - { APP_ROUTE_TABLE_NAME, routeorch_pri }, - { APP_LABEL_ROUTE_TABLE_NAME, routeorch_pri } - }; - gRouteOrch = new RouteOrch(m_app_db.get(), route_tables, gSwitchOrch, gNeighOrch, gIntfsOrch, gVrfOrch, gFgNhgOrch, gSrv6Orch); - gDirectory.set(gRouteOrch); - ut_orch_list.push_back((Orch **)&gRouteOrch); - TableConnector stateDbMirrorSession(m_state_db.get(), STATE_MIRROR_SESSION_TABLE_NAME); - TableConnector confDbMirrorSession(m_config_db.get(), CFG_MIRROR_SESSION_TABLE_NAME); - gMirrorOrch = new MirrorOrch(stateDbMirrorSession, confDbMirrorSession, gPortsOrch, gRouteOrch, gNeighOrch, gFdbOrch, gPolicerOrch); - gDirectory.set(gMirrorOrch); - ut_orch_list.push_back((Orch **)&gMirrorOrch); - - TableConnector confDbAclTable(m_config_db.get(), CFG_ACL_TABLE_TABLE_NAME); - TableConnector confDbAclTableType(m_config_db.get(), CFG_ACL_TABLE_TYPE_TABLE_NAME); - TableConnector confDbAclRuleTable(m_config_db.get(), CFG_ACL_RULE_TABLE_NAME); - TableConnector appDbAclTable(m_app_db.get(), APP_ACL_TABLE_TABLE_NAME); - TableConnector appDbAclTableType(m_app_db.get(), APP_ACL_TABLE_TYPE_TABLE_NAME); - TableConnector appDbAclRuleTable(m_app_db.get(), APP_ACL_RULE_TABLE_NAME); - - vector acl_table_connectors = { - confDbAclTableType, - confDbAclTable, - confDbAclRuleTable, - appDbAclTable, - appDbAclRuleTable, - appDbAclTableType, - }; - gAclOrch = new AclOrch(acl_table_connectors, m_state_db.get(), - gSwitchOrch, gPortsOrch, gMirrorOrch, gNeighOrch, gRouteOrch, NULL); - gDirectory.set(gAclOrch); - ut_orch_list.push_back((Orch **)&gAclOrch); - - m_MuxOrch = new MuxOrch(m_config_db.get(), mux_tables, m_TunnelDecapOrch, gNeighOrch, gFdbOrch); - gDirectory.set(m_MuxOrch); - ut_orch_list.push_back((Orch **)&m_MuxOrch); - - m_MuxCableOrch = new MuxCableOrch(m_app_db.get(), m_state_db.get(), APP_MUX_CABLE_TABLE_NAME); - gDirectory.set(m_MuxCableOrch); - ut_orch_list.push_back((Orch **)&m_MuxCableOrch); - - m_MuxStateOrch = new MuxStateOrch(m_state_db.get(), STATE_HW_MUX_CABLE_TABLE_NAME); - gDirectory.set(m_MuxStateOrch); - ut_orch_list.push_back((Orch **)&m_MuxStateOrch); - - m_VxlanTunnelOrch = new VxlanTunnelOrch(m_state_db.get(), m_app_db.get(), APP_VXLAN_TUNNEL_TABLE_NAME); - gDirectory.set(m_VxlanTunnelOrch); - ut_orch_list.push_back((Orch **)&m_VxlanTunnelOrch); - - ApplyInitialConfigs(); - PostSetUp(); - } - - virtual void PreTearDown() {}; - - void TearDown() override - { - PreTearDown(); - for (std::vector::reverse_iterator rit = ut_orch_list.rbegin(); rit != ut_orch_list.rend(); ++rit) - { - Orch **orch = *rit; - delete *orch; - *orch = nullptr; - } - - gDirectory.m_values.clear(); - - ut_helper::uninitSaiApi(); - } + DashOrch *m_DashOrch; + + virtual void ApplyInitialConfigs(); + void PrepareSai(); + virtual void PostSetUp(); + void SetUp() override; + virtual void PreTearDown(); + void TearDown() override; }; } From 3c33ac11991810d11e30b9157e8a58046e8642a9 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 4 Sep 2024 21:59:56 +0000 Subject: [PATCH 70/77] add dashorch UT Signed-off-by: Lawrence Lee --- tests/mock_tests/dashorch_ut.cpp | 44 ++++++++++++++++++++++++++ tests/mock_tests/mock_orchagent_main.h | 4 +++ tests/mock_tests/ut_saihelper.cpp | 6 ++++ 3 files changed, 54 insertions(+) create mode 100644 tests/mock_tests/dashorch_ut.cpp diff --git a/tests/mock_tests/dashorch_ut.cpp b/tests/mock_tests/dashorch_ut.cpp new file mode 100644 index 0000000000..2852ad6fd8 --- /dev/null +++ b/tests/mock_tests/dashorch_ut.cpp @@ -0,0 +1,44 @@ +#define private public +#include "directory.h" +#undef private +#define protected public +#include "orch.h" +#undef protected +#include "ut_helper.h" +#include "mock_orchagent_main.h" +#include "mock_sai_api.h" +#include "mock_orch_test.h" +#include "dash_api/appliance.pb.h" +#include "dash_api/route_type.pb.h" +#include "dash_api/eni.pb.h" +#include "dash_api/qos.pb.h" +#include "dash_api/eni_route.pb.h" + + +EXTERN_MOCK_FNS + +namespace dashorch_test +{ + using namespace mock_orch_test; + class DashOrchTest : public MockOrchTest + { + protected: + bool GetRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType& route_type) + { + return m_DashOrch->getRouteTypeActions(routing_type, route_type); + } + }; + + TEST_F(DashOrchTest, GetNonExistRoutingType) + { + dash::route_type::RouteType route_type; + bool success = m_DashOrch->getRouteTypeActions(dash::route_type::RoutingType::ROUTING_TYPE_DIRECT, route_type); + EXPECT_FALSE(success); + } + + TEST_F(DashOrchTest, RemoveNonExistRoutingType) + { + bool success = m_DashOrch->removeRoutingTypeEntry(dash::route_type::RoutingType::ROUTING_TYPE_VNET); + EXPECT_TRUE(success); + } +} \ No newline at end of file diff --git a/tests/mock_tests/mock_orchagent_main.h b/tests/mock_tests/mock_orchagent_main.h index 3437d7e22f..f2469a09ef 100644 --- a/tests/mock_tests/mock_orchagent_main.h +++ b/tests/mock_tests/mock_orchagent_main.h @@ -11,6 +11,7 @@ #include "fdborch.h" #include "mirrororch.h" #define private public +#include "dashorch.h" #include "bufferorch.h" #include "qosorch.h" #define protected public @@ -90,3 +91,6 @@ extern sai_samplepacket_api_t *sai_samplepacket_api; extern sai_fdb_api_t* sai_fdb_api; extern sai_twamp_api_t* sai_twamp_api; extern sai_tam_api_t* sai_tam_api; +extern sai_dash_vip_api_t* sai_dash_vip_api; +extern sai_dash_direction_lookup_api_t* sai_dash_direction_lookup_api; +extern sai_dash_eni_api_t* sai_dash_eni_api; diff --git a/tests/mock_tests/ut_saihelper.cpp b/tests/mock_tests/ut_saihelper.cpp index f2b7c54ad5..269f54f06b 100644 --- a/tests/mock_tests/ut_saihelper.cpp +++ b/tests/mock_tests/ut_saihelper.cpp @@ -91,6 +91,9 @@ namespace ut_helper sai_api_query(SAI_API_FDB, (void**)&sai_fdb_api); sai_api_query(SAI_API_TWAMP, (void**)&sai_twamp_api); sai_api_query(SAI_API_TAM, (void**)&sai_tam_api); + sai_api_query((sai_api_t)SAI_API_DASH_VIP, (void**)&sai_dash_vip_api); + sai_api_query((sai_api_t)SAI_API_DASH_DIRECTION_LOOKUP, (void**)&sai_dash_direction_lookup_api); + sai_api_query((sai_api_t)SAI_API_DASH_ENI, (void**)&sai_dash_eni_api); return SAI_STATUS_SUCCESS; } @@ -122,6 +125,9 @@ namespace ut_helper sai_counter_api = nullptr; sai_twamp_api = nullptr; sai_tam_api = nullptr; + sai_dash_vip_api = nullptr; + sai_dash_direction_lookup_api = nullptr; + sai_dash_eni_api = nullptr; return SAI_STATUS_SUCCESS; } From ae68c5aca276c8eb7832a6181a52ad0410f2c693 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 4 Sep 2024 22:19:08 +0000 Subject: [PATCH 71/77] add more route group tests Signed-off-by: Lawrence Lee --- tests/dash/test_dash_route_group.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/dash/test_dash_route_group.py b/tests/dash/test_dash_route_group.py index 81fd4a6205..e80e3d15d2 100644 --- a/tests/dash/test_dash_route_group.py +++ b/tests/dash/test_dash_route_group.py @@ -52,4 +52,15 @@ def test_rebind_eni_route_group(dash_db: DashDB): dash_db.wait_for_asic_db_field("ASIC_STATE:SAI_OBJECT_TYPE_ENI", eni_key, SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID, rg1_oid) dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP2_CONFIG) - dash_db.wait_for_asic_db_field("ASIC_STATE:SAI_OBJECT_TYPE_ENI", eni_key, SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID, rg2_oid) \ No newline at end of file + dash_db.wait_for_asic_db_field("ASIC_STATE:SAI_OBJECT_TYPE_ENI", eni_key, SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID, rg2_oid) + +def test_duplicate_eni_route_group(dash_db: DashDB): + dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1, ROUTE_GROUP1_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG) + rg1_oid = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_GROUP")[0] + + dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP1_CONFIG) + + eni_key = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_ENI")[0] + dash_db.wait_for_asic_db_field("ASIC_STATE:SAI_OBJECT_TYPE_ENI", eni_key, SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID, rg1_oid) + From 8b3a3d6865d01f92d5ff980c64ea4ac0c9bb2eb9 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 4 Sep 2024 23:17:31 +0000 Subject: [PATCH 72/77] fix build Signed-off-by: Lawrence Lee --- tests/mock_tests/dashorch_ut.cpp | 9 +-------- tests/mock_tests/mock_orch_test.cpp | 2 +- tests/mock_tests/mock_orch_test.h | 6 +++--- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/mock_tests/dashorch_ut.cpp b/tests/mock_tests/dashorch_ut.cpp index 2852ad6fd8..66c2704311 100644 --- a/tests/mock_tests/dashorch_ut.cpp +++ b/tests/mock_tests/dashorch_ut.cpp @@ -20,14 +20,7 @@ EXTERN_MOCK_FNS namespace dashorch_test { using namespace mock_orch_test; - class DashOrchTest : public MockOrchTest - { - protected: - bool GetRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType& route_type) - { - return m_DashOrch->getRouteTypeActions(routing_type, route_type); - } - }; + class DashOrchTest : public MockOrchTest {}; TEST_F(DashOrchTest, GetNonExistRoutingType) { diff --git a/tests/mock_tests/mock_orch_test.cpp b/tests/mock_tests/mock_orch_test.cpp index 9912ecdd6a..df584bd769 100644 --- a/tests/mock_tests/mock_orch_test.cpp +++ b/tests/mock_tests/mock_orch_test.cpp @@ -217,7 +217,7 @@ void MockOrchTest::SetUp() m_DashOrch = new DashOrch(m_app_db.get(), dash_tables, nullptr); gDirectory.set(m_DashOrch); ut_orch_list.push_back((Orch **)&m_DashOrch); - + TableConnector confDbAclTable(m_config_db.get(), CFG_ACL_TABLE_TABLE_NAME); TableConnector confDbAclTableType(m_config_db.get(), CFG_ACL_TABLE_TYPE_TABLE_NAME); TableConnector confDbAclRuleTable(m_config_db.get(), CFG_ACL_RULE_TABLE_NAME); diff --git a/tests/mock_tests/mock_orch_test.h b/tests/mock_tests/mock_orch_test.h index b0988932a6..cd6ac5a05c 100644 --- a/tests/mock_tests/mock_orch_test.h +++ b/tests/mock_tests/mock_orch_test.h @@ -52,11 +52,11 @@ namespace mock_orch_test VxlanTunnelOrch *m_VxlanTunnelOrch; DashOrch *m_DashOrch; - virtual void ApplyInitialConfigs(); + void ApplyInitialConfigs(); void PrepareSai(); - virtual void PostSetUp(); + void PostSetUp(); void SetUp() override; - virtual void PreTearDown(); + void PreTearDown(); void TearDown() override; }; } From 6fcb7af8c2f903c4dd6e50537231d1fdabf4d9bf Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 4 Sep 2024 16:52:54 -0700 Subject: [PATCH 73/77] Update mock_orch_test.h --- tests/mock_tests/mock_orch_test.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/mock_tests/mock_orch_test.h b/tests/mock_tests/mock_orch_test.h index cd6ac5a05c..7d56637938 100644 --- a/tests/mock_tests/mock_orch_test.h +++ b/tests/mock_tests/mock_orch_test.h @@ -55,8 +55,8 @@ namespace mock_orch_test void ApplyInitialConfigs(); void PrepareSai(); void PostSetUp(); - void SetUp() override; + void SetUp(); void PreTearDown(); - void TearDown() override; + void TearDown(); }; } From 9060640259739254121b991e69ff813729d242b6 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 5 Sep 2024 00:43:28 +0000 Subject: [PATCH 74/77] fix test override error Signed-off-by: Lawrence Lee --- tests/mock_tests/mock_orch_test.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/mock_tests/mock_orch_test.h b/tests/mock_tests/mock_orch_test.h index 7d56637938..86c5a36655 100644 --- a/tests/mock_tests/mock_orch_test.h +++ b/tests/mock_tests/mock_orch_test.h @@ -52,11 +52,11 @@ namespace mock_orch_test VxlanTunnelOrch *m_VxlanTunnelOrch; DashOrch *m_DashOrch; - void ApplyInitialConfigs(); void PrepareSai(); - void PostSetUp(); void SetUp(); - void PreTearDown(); void TearDown(); + virtual void ApplyInitialConfigs(); + virtual void PostSetUp(); + virtual void PreTearDown(); }; } From a7e3ae5901e0924cde64fd0eb22e2078b63e513d Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 5 Sep 2024 01:00:33 +0000 Subject: [PATCH 75/77] define mock_orch_test base fns Signed-off-by: Lawrence Lee --- tests/mock_tests/mock_orch_test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/mock_tests/mock_orch_test.cpp b/tests/mock_tests/mock_orch_test.cpp index df584bd769..c6898188b4 100644 --- a/tests/mock_tests/mock_orch_test.cpp +++ b/tests/mock_tests/mock_orch_test.cpp @@ -5,6 +5,10 @@ using namespace std; namespace mock_orch_test { +void MockOrchTest::ApplyInitialConfigs() {} +void MockOrchTest::PostSetUp() {} +void MockOrchTest::PreTearDown() {} + void MockOrchTest::PrepareSai() { sai_attribute_t attr; From 3665aab1e33480f4a9c294ed6baaa2cf511d38d8 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 5 Sep 2024 09:09:18 +0000 Subject: [PATCH 76/77] restrict route removal from bound groups Signed-off-by: Lawrence Lee --- orchagent/dash/dashrouteorch.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/orchagent/dash/dashrouteorch.cpp b/orchagent/dash/dashrouteorch.cpp index 324004c482..06de34a05d 100644 --- a/orchagent/dash/dashrouteorch.cpp +++ b/orchagent/dash/dashrouteorch.cpp @@ -200,6 +200,12 @@ bool DashRouteOrch::removeOutboundRouting(const string& key, OutboundRoutingBulk return true; } + if (isRouteGroupBound(ctxt.route_group)) + { + SWSS_LOG_WARN("Cannot remove route from route group %s as it is already bound", ctxt.route_group.c_str()); + return true; + } + auto& object_statuses = ctxt.object_statuses; OutboundRoutingEntry entry = routing_entries_[key]; sai_outbound_routing_entry_t outbound_routing_entry; From f4af126f69ff5f076ea55d555bc5da106eeeb577 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 5 Sep 2024 09:10:14 +0000 Subject: [PATCH 77/77] add more tests Signed-off-by: Lawrence Lee --- tests/dash/dash_configs.py | 3 ++- tests/dash/test_dash_pl.py | 6 +++--- tests/dash/test_dash_route_group.py | 33 +++++++++++++++++++++++------ tests/mock_tests/dashorch_ut.cpp | 20 ++++++++++++++++- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/tests/dash/dash_configs.py b/tests/dash/dash_configs.py index afbbac1812..2f1590ebaa 100644 --- a/tests/dash/dash_configs.py +++ b/tests/dash/dash_configs.py @@ -22,7 +22,8 @@ VNET_MAP_IP1 = "10.1.1.1" VNET_MAP_IP2 = "10.1.1.2" UNDERLAY_IP = "101.1.2.3" -OUTBOUND_ROUTE_PREFIX = "10.1.0.8/32" +OUTBOUND_ROUTE_PREFIX1 = "10.1.0.8/32" +OUTBOUND_ROUTE_PREFIX2 = "10.1.0.9/32" OVERLAY_IP = "10.0.0.6" PL_ENCODING_IP = "::56b2:0:20:0:0" PL_ENCODING_MASK = "::ffff:ffff:ffff:0:0" diff --git a/tests/dash/test_dash_pl.py b/tests/dash/test_dash_pl.py index c6a3e7a69d..93ee8d19b3 100644 --- a/tests/dash/test_dash_pl.py +++ b/tests/dash/test_dash_pl.py @@ -41,7 +41,7 @@ def common_setup_teardown(dash_db: DashDB): yield dash_db.remove_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID) - dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) + dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX1) dash_db.remove_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1) dash_db.remove_app_db_entry(APP_DASH_VNET_MAPPING_TABLE_NAME, VNET1, VNET_MAP_IP1) dash_db.remove_app_db_entry(APP_DASH_ENI_TABLE_NAME, ENI_ID) @@ -51,7 +51,7 @@ def common_setup_teardown(dash_db: DashDB): def test_pl_eni_attrs(dash_db: DashDB): - dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX1, ROUTE_VNET_CONFIG) dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP1_CONFIG) enis = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_ENI") @@ -59,7 +59,7 @@ def test_pl_eni_attrs(dash_db: DashDB): assert_sai_attribute_exists(SAI_ENI_ATTR_PL_UNDERLAY_SIP, eni_attrs, PL_UNDERLAY_SIP1) def test_pl_eni_override_underlay_sip(dash_db: DashDB): - dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG_UNDERLAY_SIP) + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX1, ROUTE_VNET_CONFIG_UNDERLAY_SIP) dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP1_CONFIG) outbound_routing_keys = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY") diff --git a/tests/dash/test_dash_route_group.py b/tests/dash/test_dash_route_group.py index e80e3d15d2..10860465f2 100644 --- a/tests/dash/test_dash_route_group.py +++ b/tests/dash/test_dash_route_group.py @@ -1,5 +1,5 @@ import pytest -import json +import time from dash_db import DashDB, dash_db from dash_configs import * from dvslib.sai_utils import assert_sai_attribute_exists @@ -27,8 +27,8 @@ def common_setup_teardown(dash_db: DashDB): yield dash_db.remove_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID) - dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX) - dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP2, OUTBOUND_ROUTE_PREFIX) + dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX1) + dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP2, OUTBOUND_ROUTE_PREFIX1) dash_db.remove_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1) dash_db.remove_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP2) dash_db.remove_app_db_entry(APP_DASH_VNET_MAPPING_TABLE_NAME, VNET1, VNET_MAP_IP1) @@ -39,11 +39,11 @@ def common_setup_teardown(dash_db: DashDB): def test_rebind_eni_route_group(dash_db: DashDB): dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1, ROUTE_GROUP1_CONFIG) - dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX1, ROUTE_VNET_CONFIG) rg1_oid = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_GROUP")[0] dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP2, ROUTE_GROUP2_CONFIG) - dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP2, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG_UNDERLAY_SIP) + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP2, OUTBOUND_ROUTE_PREFIX1, ROUTE_VNET_CONFIG_UNDERLAY_SIP) rg2_oid = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_GROUP", min_keys=2)[1] dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP1_CONFIG) @@ -56,7 +56,7 @@ def test_rebind_eni_route_group(dash_db: DashDB): def test_duplicate_eni_route_group(dash_db: DashDB): dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1, ROUTE_GROUP1_CONFIG) - dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX, ROUTE_VNET_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX1, ROUTE_VNET_CONFIG) rg1_oid = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_GROUP")[0] dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP1_CONFIG) @@ -64,3 +64,24 @@ def test_duplicate_eni_route_group(dash_db: DashDB): eni_key = dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_ENI")[0] dash_db.wait_for_asic_db_field("ASIC_STATE:SAI_OBJECT_TYPE_ENI", eni_key, SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID, rg1_oid) + dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP1_CONFIG) + dash_db.wait_for_asic_db_field("ASIC_STATE:SAI_OBJECT_TYPE_ENI", eni_key, SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID, rg1_oid) + +def test_bound_route_group_immutable(dash_db: DashDB): + dash_db.set_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1, ROUTE_GROUP1_CONFIG) + num_route_groups = len(dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_GROUP")) + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX1, ROUTE_VNET_CONFIG) + num_routes = len(dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY")) + + dash_db.set_app_db_entry(APP_DASH_ENI_ROUTE_TABLE_NAME, ENI_ID, ENI_ROUTE_GROUP1_CONFIG) + dash_db.set_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX2, ROUTE_VNET_CONFIG_UNDERLAY_SIP) + time.sleep(3) + assert len(dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY")) == num_routes + + dash_db.remove_app_db_entry(APP_DASH_ROUTE_TABLE_NAME, ROUTE_GROUP1, OUTBOUND_ROUTE_PREFIX1) + time.sleep(3) + assert len(dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY")) == num_routes + + dash_db.remove_app_db_entry(APP_DASH_ROUTE_GROUP_TABLE_NAME, ROUTE_GROUP1) + time.sleep(3) + assert len(dash_db.wait_for_asic_db_keys("ASIC_STATE:SAI_OBJECT_TYPE_OUTBOUND_ROUTING_GROUP")) == num_route_groups diff --git a/tests/mock_tests/dashorch_ut.cpp b/tests/mock_tests/dashorch_ut.cpp index 66c2704311..7786596fd7 100644 --- a/tests/mock_tests/dashorch_ut.cpp +++ b/tests/mock_tests/dashorch_ut.cpp @@ -29,9 +29,27 @@ namespace dashorch_test EXPECT_FALSE(success); } + TEST_F(DashOrchTest, DuplicateRoutingTypeEntry) + { + dash::route_type::RouteType route_type1; + dash::route_type::RouteTypeItem *item1 = route_type1.add_items(); + item1->set_action_type(dash::route_type::ActionType::ACTION_TYPE_STATICENCAP); + bool success = m_DashOrch->addRoutingTypeEntry(dash::route_type::RoutingType::ROUTING_TYPE_VNET, route_type1); + EXPECT_TRUE(success); + EXPECT_EQ(m_DashOrch->routing_type_entries_.size(), 1); + EXPECT_EQ(m_DashOrch->routing_type_entries_[dash::route_type::RoutingType::ROUTING_TYPE_VNET].items()[0].action_type(), item1->action_type()); + + dash::route_type::RouteType route_type2; + dash::route_type::RouteTypeItem *item2 = route_type2.add_items(); + item2->set_action_type(dash::route_type::ActionType::ACTION_TYPE_DECAP); + success = m_DashOrch->addRoutingTypeEntry(dash::route_type::RoutingType::ROUTING_TYPE_VNET, route_type2); + EXPECT_TRUE(success); + EXPECT_EQ(m_DashOrch->routing_type_entries_[dash::route_type::RoutingType::ROUTING_TYPE_VNET].items()[0].action_type(), item1->action_type()); + } + TEST_F(DashOrchTest, RemoveNonExistRoutingType) { - bool success = m_DashOrch->removeRoutingTypeEntry(dash::route_type::RoutingType::ROUTING_TYPE_VNET); + bool success = m_DashOrch->removeRoutingTypeEntry(dash::route_type::RoutingType::ROUTING_TYPE_DROP); EXPECT_TRUE(success); } } \ No newline at end of file