Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[routeorch/vrforch] set the default route for non default VRF #1149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 86 additions & 43 deletions orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,49 +62,7 @@ RouteOrch::RouteOrch(DBConnector *db, string tableName, NeighOrch *neighOrch, In
}
SWSS_LOG_NOTICE("Maximum number of ECMP groups supported is %d", m_maxNextHopGroupCount);

IpPrefix default_ip_prefix("0.0.0.0/0");

sai_route_entry_t unicast_route_entry;
unicast_route_entry.vr_id = gVirtualRouterId;
unicast_route_entry.switch_id = gSwitchId;
copy(unicast_route_entry.destination, default_ip_prefix);
subnet(unicast_route_entry.destination, unicast_route_entry.destination);

attr.id = SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION;
attr.value.s32 = SAI_PACKET_ACTION_DROP;

status = sai_route_api->create_route_entry(&unicast_route_entry, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create IPv4 default route with packet action drop");
throw runtime_error("Failed to create IPv4 default route with packet action drop");
}

gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_IPV4_ROUTE);

/* Add default IPv4 route into the m_syncdRoutes */
m_syncdRoutes[gVirtualRouterId][default_ip_prefix] = NextHopGroupKey();

SWSS_LOG_NOTICE("Create IPv4 default route with packet action drop");

IpPrefix v6_default_ip_prefix("::/0");

copy(unicast_route_entry.destination, v6_default_ip_prefix);
subnet(unicast_route_entry.destination, unicast_route_entry.destination);

status = sai_route_api->create_route_entry(&unicast_route_entry, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create IPv6 default route with packet action drop");
throw runtime_error("Failed to create IPv6 default route with packet action drop");
}

gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_IPV6_ROUTE);

/* Add default IPv6 route into the m_syncdRoutes */
m_syncdRoutes[gVirtualRouterId][v6_default_ip_prefix] = NextHopGroupKey();

SWSS_LOG_NOTICE("Create IPv6 default route with packet action drop");
vrfDefaultRoute(gVirtualRouterId, SET_COMMAND);

/* All the interfaces have the same MAC address and hence the same
* auto-generated link-local ipv6 address with eui64 interface-id.
Expand Down Expand Up @@ -1187,3 +1145,88 @@ bool RouteOrch::removeRoute(sai_object_id_t vrf_id, const IpPrefix &ipPrefix)

return true;
}

void RouteOrch::vrfDefaultRoute(sai_object_id_t vrf_id, string op)
{
IpPrefix default_ip_prefix("0.0.0.0/0");

sai_route_entry_t unicast_route_entry;
unicast_route_entry.vr_id = vrf_id;
unicast_route_entry.switch_id = gSwitchId;
copy(unicast_route_entry.destination, default_ip_prefix);
subnet(unicast_route_entry.destination, unicast_route_entry.destination);

sai_status_t status = SAI_STATUS_FAILURE;
sai_attribute_t attr;
attr.id = SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION;
attr.value.s32 = SAI_PACKET_ACTION_DROP;

if (op == SET_COMMAND)
{
sai_status_t status = sai_route_api->create_route_entry(&unicast_route_entry, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create IPv4 default route with packet action drop");
throw runtime_error("Failed to create IPv4 default route with packet action drop");
}

gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_IPV4_ROUTE);

/* Add default IPv4 route into the m_syncdRoutes */
m_syncdRoutes[vrf_id][default_ip_prefix] = NextHopGroupKey();

SWSS_LOG_NOTICE("Create IPv4 default route with packet action drop");
}
else
{
if (vrf_id != gVirtualRouterId)
{
sai_status_t status = sai_route_api->remove_route_entry(&unicast_route_entry);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to remove IPv4 default route for non default VRF!!!");
throw runtime_error("Failed to remove IPv4 default route for non default VRF!!!");
}

gCrmOrch->decCrmResUsedCounter(CrmResourceType::CRM_IPV4_ROUTE);
}
}

IpPrefix v6_default_ip_prefix("::/0");

copy(unicast_route_entry.destination, v6_default_ip_prefix);
subnet(unicast_route_entry.destination, unicast_route_entry.destination);

if (op == SET_COMMAND)
{
status = sai_route_api->create_route_entry(&unicast_route_entry, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create IPv6 default route with packet action drop");
throw runtime_error("Failed to create IPv6 default route with packet action drop");
}

gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_IPV6_ROUTE);

/* Add default IPv6 route into the m_syncdRoutes */
m_syncdRoutes[vrf_id][v6_default_ip_prefix] = NextHopGroupKey();

SWSS_LOG_NOTICE("Create IPv6 default route with packet action drop");
}
else
{
if (vrf_id != gVirtualRouterId)
{
status = sai_route_api->remove_route_entry(&unicast_route_entry);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create IPv6 default route for non default VRF!!!");
throw runtime_error("Failed to create IPv6 default route for non default VRF!!!");
}

gCrmOrch->decCrmResUsedCounter(CrmResourceType::CRM_IPV6_ROUTE);

m_syncdRoutes.erase(vrf_id);
}
}
}
2 changes: 2 additions & 0 deletions orchagent/routeorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class RouteOrch : public Orch, public Subject
bool invalidnexthopinNextHopGroup(const NextHopKey&);

void notifyNextHopChangeObservers(sai_object_id_t, const IpPrefix&, const NextHopGroupKey&, bool);

void vrfDefaultRoute(sai_object_id_t vrf_id, string op);
private:
NeighOrch *m_neighOrch;
IntfsOrch *m_intfsOrch;
Expand Down
4 changes: 4 additions & 0 deletions orchagent/vrforch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
#include "orch.h"
#include "request_parser.h"
#include "vrforch.h"
#include "routeorch.h"

using namespace std;
using namespace swss;

extern sai_virtual_router_api_t* sai_virtual_router_api;
extern sai_object_id_t gSwitchId;
extern RouteOrch *gRouteOrch;

bool VRFOrch::addOperation(const Request& request)
{
Expand Down Expand Up @@ -86,6 +88,7 @@ bool VRFOrch::addOperation(const Request& request)
vrf_id_table_[router_id] = vrf_name;
m_stateVrfObjectTable.hset(vrf_name, "state", "ok");
SWSS_LOG_NOTICE("VRF '%s' was added", vrf_name.c_str());
gRouteOrch->vrfDefaultRoute(router_id, SET_COMMAND);
}
else
{
Expand Down Expand Up @@ -124,6 +127,7 @@ bool VRFOrch::delOperation(const Request& request)
return false;

sai_object_id_t router_id = vrf_table_[vrf_name].vrf_id;
gRouteOrch->vrfDefaultRoute(router_id, DEL_COMMAND);
sai_status_t status = sai_virtual_router_api->remove_virtual_router(router_id);
if (status != SAI_STATUS_SUCCESS)
{
Expand Down