Skip to content

Commit

Permalink
Label pop
Browse files Browse the repository at this point in the history
  • Loading branch information
TACappleman committed Apr 9, 2021
1 parent e804c1f commit 89e2044
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 114 deletions.
51 changes: 25 additions & 26 deletions fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void RouteSync::parseEncap(struct rtattr *tb, uint32_t &encap_value, string &rma
return;
}

void RouteSync::getEvpnNextHopSep(string& nexthops, string& vni_list,
void RouteSync::getEvpnNextHopSep(string& nexthops, string& vni_list,
string& mac_list, string& intf_list)
{
nexthops += string(",");
Expand All @@ -121,8 +121,8 @@ void RouteSync::getEvpnNextHopSep(string& nexthops, string& vni_list,
return;
}

void RouteSync::getEvpnNextHopGwIf(char *gwaddr, int vni_value,
string& nexthops, string& vni_list,
void RouteSync::getEvpnNextHopGwIf(char *gwaddr, int vni_value,
string& nexthops, string& vni_list,
string& mac_list, string& intf_list,
string rmac, string vlan_id)
{
Expand All @@ -132,9 +132,9 @@ void RouteSync::getEvpnNextHopGwIf(char *gwaddr, int vni_value,
intf_list+=vlan_id;
}

bool RouteSync::getEvpnNextHop(struct nlmsghdr *h, int received_bytes,
struct rtattr *tb[], string& nexthops,
string& vni_list, string& mac_list,
bool RouteSync::getEvpnNextHop(struct nlmsghdr *h, int received_bytes,
struct rtattr *tb[], string& nexthops,
string& vni_list, string& mac_list,
string& intf_list)
{
void *gate = NULL;
Expand All @@ -154,9 +154,9 @@ bool RouteSync::getEvpnNextHop(struct nlmsghdr *h, int received_bytes,
if (tb[RTA_GATEWAY])
gate = RTA_DATA(tb[RTA_GATEWAY]);

if (h->nlmsg_type == RTM_NEWROUTE)
if (h->nlmsg_type == RTM_NEWROUTE)
{
if (!tb[RTA_MULTIPATH])
if (!tb[RTA_MULTIPATH])
{
gw_af = AF_INET; // default value
if (gate)
Expand All @@ -169,7 +169,7 @@ bool RouteSync::getEvpnNextHop(struct nlmsghdr *h, int received_bytes,
else
{
memcpy(ipv6_address.s6_addr, gate, IPV6_MAX_BYTE);
gw_af = AF_INET6;
gw_af = AF_INET6;
}
}

Expand Down Expand Up @@ -209,7 +209,7 @@ bool RouteSync::getEvpnNextHop(struct nlmsghdr *h, int received_bytes,
}

if (tb[RTA_ENCAP] && tb[RTA_ENCAP_TYPE]
&& (*(uint16_t *)RTA_DATA(tb[RTA_ENCAP_TYPE]) == NH_ENCAP_VXLAN))
&& (*(uint16_t *)RTA_DATA(tb[RTA_ENCAP_TYPE]) == NH_ENCAP_VXLAN))
{
parseEncap(tb[RTA_ENCAP], encap_value, rmac);
}
Expand All @@ -232,7 +232,7 @@ bool RouteSync::getEvpnNextHop(struct nlmsghdr *h, int received_bytes,
struct rtnexthop *rtnh = (struct rtnexthop *)RTA_DATA(tb[RTA_MULTIPATH]);
len = (int)RTA_PAYLOAD(tb[RTA_MULTIPATH]);

for (;;)
for (;;)
{
uint16_t encap = 0;
if (len < (int)sizeof(*rtnh) || rtnh->rtnh_len > len)
Expand All @@ -241,7 +241,7 @@ bool RouteSync::getEvpnNextHop(struct nlmsghdr *h, int received_bytes,
}

gate = 0;
if (rtnh->rtnh_len > sizeof(*rtnh))
if (rtnh->rtnh_len > sizeof(*rtnh))
{
memset(subtb, 0, sizeof(subtb));

Expand All @@ -263,10 +263,10 @@ bool RouteSync::getEvpnNextHop(struct nlmsghdr *h, int received_bytes,
else
{
memcpy(ipv6_address.s6_addr, gate, IPV6_MAX_BYTE);
gw_af = AF_INET6;
gw_af = AF_INET6;
}
}

if(gw_af == AF_INET6)
{
if (IN6_IS_ADDR_V4MAPPED(&ipv6_address))
Expand All @@ -281,7 +281,7 @@ bool RouteSync::getEvpnNextHop(struct nlmsghdr *h, int received_bytes,
return false;
}
}

inet_ntop(gw_af, gateaddr, nexthopaddr, MAX_ADDR_SIZE);


Expand Down Expand Up @@ -335,7 +335,7 @@ bool RouteSync::getEvpnNextHop(struct nlmsghdr *h, int received_bytes,

len -= NLMSG_ALIGN(rtnh->rtnh_len);
rtnh = RTNH_NEXT(rtnh);
}
}
}
}
return true;
Expand Down Expand Up @@ -380,7 +380,7 @@ void RouteSync::onEvpnRouteMsg(struct nlmsghdr *h, int len)
}
else if (rtm->rtm_family == AF_INET6)
{
if (rtm->rtm_dst_len > IPV6_MAX_BITLEN)
if (rtm->rtm_dst_len > IPV6_MAX_BITLEN)
{
return;
}
Expand Down Expand Up @@ -432,7 +432,7 @@ void RouteSync::onEvpnRouteMsg(struct nlmsghdr *h, int len)
inet_ntop(rtm->rtm_family, dstaddr, buf, MAX_ADDR_SIZE), dst_len);
}

SWSS_LOG_INFO("Receive route message dest ip prefix: %s Op:%s",
SWSS_LOG_INFO("Receive route message dest ip prefix: %s Op:%s",
destipprefix,
nlmsg_type == RTM_NEWROUTE ? "add":"del");

Expand Down Expand Up @@ -554,7 +554,7 @@ void RouteSync::onMsgRaw(struct nlmsghdr *h)
return;
/* Length validity. */
len = (int)(h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ndmsg)));
if (len < 0)
if (len < 0)
{
SWSS_LOG_ERROR("%s: Message received from netlink is of a broken size %d %zu",
__PRETTY_FUNCTION__, h->nlmsg_len,
Expand Down Expand Up @@ -592,7 +592,7 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
{
/* 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)
Expand All @@ -612,8 +612,8 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
}
}

/*
* Handle regular route (include VRF route)
/*
* Handle regular route (include VRF route)
* @arg nlmsg_type Netlink message type
* @arg obj Netlink object
* @arg vrf Vrf name
Expand Down Expand Up @@ -753,7 +753,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
}
}

/*
/*
* Handle label route
* @arg nlmsg_type Netlink message type
* @arg obj Netlink object
Expand Down Expand Up @@ -820,19 +820,18 @@ void RouteSync::onLabelRouteMsg(int nlmsg_type, struct nl_object *obj)

fvVector.push_back(nh);
fvVector.push_back(idx);
fvVector.push_back(wt);

m_label_routeTable.set(destaddr, fvVector);
SWSS_LOG_INFO("LabelRouteTable set msg: %s %s %s",
destaddr, nexthops.c_str(), ifnames.c_str());
}

/*
* Handle vnet route
* 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 Down
9 changes: 5 additions & 4 deletions orchagent/neighorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ bool NeighOrch::hasNextHop(const NextHopKey &nexthop)
return m_syncdNextHops.find(nexthop) != m_syncdNextHops.end();
}

bool NeighOrch::addNextHop(const NextHopKey &nexthop)
bool NeighOrch::addNextHop(NextHopKey &nexthop)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -371,11 +371,11 @@ bool NeighOrch::ifChangeInformNextHop(const string &alias, bool if_up)
return rc;
}

bool NeighOrch::removeNextHop(const NextHopKey& nexthop)
bool NeighOrch::removeNextHop(NextHopKey& nexthop)
{
SWSS_LOG_ENTER();

if(m_intfsOrch->isRemoteSystemPortIntf(alias))
if(m_intfsOrch->isRemoteSystemPortIntf(nexthop.alias))
{
//For remote system ports kernel nexthops are always on inband. Change the key
Port inbp;
Expand Down Expand Up @@ -741,7 +741,8 @@ bool NeighOrch::addNeighbor(const NeighborEntry &neighborEntry, const MacAddress
gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_IPV6_NEIGHBOR);
}

if (!addNextHop(NextHopKey(ip_address, alias)))
NextHopKey nexthop(ip_address, alias);
if (!addNextHop(nexthop))
{
status = sai_neighbor_api->remove_neighbor_entry(&neighbor_entry);
if (status != SAI_STATUS_SUCCESS)
Expand Down
4 changes: 2 additions & 2 deletions orchagent/neighorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class NeighOrch : public Orch, public Subject, public Observer
~NeighOrch();

bool hasNextHop(const NextHopKey&);
bool addNextHop(const NextHopKey&);
bool removeNextHop(const NextHopKey&);
bool addNextHop(NextHopKey&);
bool removeNextHop(NextHopKey&);

sai_object_id_t getNextHopId(const NextHopKey&);
sai_object_id_t getLocalNextHopId(const NextHopKey&);
Expand Down
8 changes: 4 additions & 4 deletions orchagent/nexthopkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct NextHopKey
std::string err = "Error converting " + str + " to NextHop";
throw std::invalid_argument(err);
}
std::size_t label_delimiter = str.find(LABELSTACK_DELIMITER);
std::size_t label_delimiter = str.find(LABEL_DELIMITER);
std::string ip_str;
if (label_delimiter != std::string::npos)
{
Expand Down Expand Up @@ -69,7 +69,7 @@ struct NextHopKey
std::string err = "Error converting " + str + " to NextHop";
throw std::invalid_argument(err);
}
std::size_t label_delimiter = str.find(LABELSTACK_DELIMITER);
std::size_t label_delimiter = str.find(LABEL_DELIMITER);
std::string ip_str;
if (label_delimiter != std::string::npos)
{
Expand Down Expand Up @@ -98,7 +98,7 @@ struct NextHopKey
if (!label_stack.empty())
{
str += label_stack.to_string();
str += LABELSTACK_DELIMITER;
str += LABEL_DELIMITER;
}
str += ip_address.to_string() + NH_DELIMITER + alias;
return str;
Expand All @@ -110,7 +110,7 @@ struct NextHopKey
if (!label_stack.empty())
{
str += label_stack.to_string();
str += LABELSTACK_DELIMITER;
str += LABEL_DELIMITER;
}
str += (ip_address.to_string() + NH_DELIMITER + alias + NH_DELIMITER +
std::to_string(vni) + NH_DELIMITER + mac_address.to_string());
Expand Down
Loading

0 comments on commit 89e2044

Please sign in to comment.