Skip to content

Commit

Permalink
[dash] Implement PL API
Browse files Browse the repository at this point in the history
Signed-off-by: Lawrence Lee <[email protected]>
  • Loading branch information
theasianpianist committed Feb 14, 2024
1 parent 1221eae commit 0179272
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 14 deletions.
58 changes: 50 additions & 8 deletions orchagent/dash/dashorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ DashOrch::DashOrch(DBConnector *db, vector<string> &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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -231,16 +246,24 @@ 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)
{
dash::route_type::RouteType entry;

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;
}
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions orchagent/dash/dashorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct EniEntry
};

typedef std::map<std::string, dash::appliance::Appliance> ApplianceTable;
typedef std::map<std::string, dash::route_type::RouteType> RoutingTypeTable;
typedef std::map<dash::route_type::RoutingType, dash::route_type::RouteType> RoutingTypeTable;
typedef std::map<std::string, EniEntry> EniTable;
typedef std::map<std::string, dash::qos::Qos> QosTable;

Expand All @@ -39,6 +39,7 @@ class DashOrch : public ZmqOrch
public:
DashOrch(swss::DBConnector *db, std::vector<std::string> &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_;
Expand All @@ -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);
Expand Down
60 changes: 57 additions & 3 deletions orchagent/dash/dashvnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "dashorch.h"
#include "crmorch.h"
#include "saihelper.h"
#include "directory.h"

#include "taskworker.h"
#include "pbutils.h"
Expand All @@ -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<Orch*> gDirectory;

DashVnetOrch::DashVnetOrch(DBConnector *db, vector<string> &tables, ZmqServer *zmqServer) :
vnet_bulker_(sai_dash_vnet_api, gSwitchId, gMaxBulkSize),
Expand Down Expand Up @@ -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<sai_attribute_t> outbound_ca_to_pa_attrs;

DashOrch* dash_orch = gDirectory.get<DashOrch*>();
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));
Expand Down

0 comments on commit 0179272

Please sign in to comment.