Skip to content

Commit

Permalink
[fpmsyncd] Improve VNET routes support (sonic-net#838)
Browse files Browse the repository at this point in the history
* Classify routes based on the name of the master device

* Remove extra space

* Change marco name
  • Loading branch information
baiwei0427 authored and prsunny committed Apr 19, 2019
1 parent a64f9ad commit cc6f8f6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
51 changes: 27 additions & 24 deletions fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
using namespace std;
using namespace swss;

#define VXLAN_IF_NAME_PREFIX "brvxlan"
#define VXLAN_IF_NAME_PREFIX "Brvxlan"
#define VNET_PREFIX "Vnet"

RouteSync::RouteSync(RedisPipeline *pipeline) :
m_routeTable(pipeline, APP_ROUTE_TABLE_NAME, true),
Expand All @@ -39,22 +40,31 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
return;
}

/* Get the index of routing table */
unsigned int table_index = rtnl_route_get_table(route_obj);
/* Get the index of the master device */
unsigned int master_index = rtnl_route_get_table(route_obj);
char master_name[IFNAMSIZ] = {0};

/* Default routing table. This line may have problems. */
if (table_index == RT_TABLE_UNSPEC)
/* Get the name of the master device */
getIfName(master_index, master_name, IFNAMSIZ);

/* If the master device name starts with VNET_PREFIX, it is a VNET route.
The VNET name is exactly the name of the associated master device. */
if (string(master_name).find(VNET_PREFIX) == 0)
{
onRouteMsg(nlmsg_type, obj);
onVnetRouteMsg(nlmsg_type, obj, string(master_name));
}
/* VNET route. We will handle VRF routes in the future. */
/* Otherwise, it is a regular route (include VRF route). */
else
{
onVnetRouteMsg(nlmsg_type, obj);
onRouteMsg(nlmsg_type, obj);
}
}

/* Handle regular route (without vnet) */
/*
* Handle regular route (include VRF route)
* @arg nlmsg_type Netlink message type
* @arg obj Netlink object
*/
void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj)
{
struct rtnl_route *route_obj = (struct rtnl_route *)obj;
Expand Down Expand Up @@ -161,8 +171,13 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj)
}
}

/* Handle vnet route */
void RouteSync::onVnetRouteMsg(int nlmsg_type, struct nl_object *obj)
/*
* Handle vnet route
* @arg nlmsg_type Netlink message type
* @arg obj Netlink object
* @arg vnet Vnet name
*/
void RouteSync::onVnetRouteMsg(int nlmsg_type, struct nl_object *obj, string vnet)
{
struct rtnl_route *route_obj = (struct rtnl_route *)obj;

Expand All @@ -171,19 +186,7 @@ void RouteSync::onVnetRouteMsg(int nlmsg_type, struct nl_object *obj)
char destipprefix[MAX_ADDR_SIZE + 1] = {0};
nl_addr2str(dip, destipprefix, MAX_ADDR_SIZE);

/* Get VRF index and VRF name */
unsigned int vrf_index = rtnl_route_get_table(route_obj);
char vrf_name[IFNAMSIZ] = {0};

/* If we cannot get the VRF name */
if (!getIfName(vrf_index, vrf_name, IFNAMSIZ))
{
SWSS_LOG_INFO("Fail to get the VRF name (table ID %u)", vrf_index);
return;
}

/* vrf name = vnet name */
string vnet_dip = vrf_name + string(":") + destipprefix;
string vnet_dip = vnet + string(":") + destipprefix;
SWSS_LOG_DEBUG("Receive new vnet route message %s", vnet_dip.c_str());

if (nlmsg_type == RTM_DELROUTE)
Expand Down
16 changes: 8 additions & 8 deletions fpmsyncd/routesync.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ class RouteSync : public NetMsg
private:
/* regular route table */
ProducerStateTable m_routeTable;
/* vnet route table */
/* vnet route table */
ProducerStateTable m_vnet_routeTable;
/* vnet vxlan tunnel table */
ProducerStateTable m_vnet_tunnelTable;
struct nl_cache *m_link_cache;
struct nl_sock *m_nl_sock;

/* Handle regular route (without vnet) */
/* Handle regular route (include VRF route) */
void onRouteMsg(int nlmsg_type, struct nl_object *obj);

/* Handle vnet route */
void onVnetRouteMsg(int nlmsg_type, struct nl_object *obj);
/* Handle vnet route */
void onVnetRouteMsg(int nlmsg_type, struct nl_object *obj, string vnet);

/* Get interface/VRF name based on interface/VRF index */
/* Get interface name based on interface index */
bool getIfName(int if_index, char *if_name, size_t name_len);

/* Get next hop gateway IP addresses */
string getNextHopGw(struct rtnl_route *route_obj);
string getNextHopGw(struct rtnl_route *route_obj);

/* Get next hop interfaces */
string getNextHopIf(struct rtnl_route *route_obj);
/* Get next hop interfaces */
string getNextHopIf(struct rtnl_route *route_obj);
};

}
Expand Down

0 comments on commit cc6f8f6

Please sign in to comment.