Skip to content

Commit

Permalink
Merge pull request sonic-net#399 from lguohan/v1.2
Browse files Browse the repository at this point in the history
update to use SAI 1.2
  • Loading branch information
lguohan authored Feb 22, 2018
2 parents b7d8746 + 0c8e06c commit 6dd0870
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 54 deletions.
48 changes: 26 additions & 22 deletions orchagent/fdborch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ void FdbOrch::update(sai_fdb_event_t type, const sai_fdb_entry_t* entry, sai_obj

FdbUpdate update;
update.entry.mac = entry->mac_address;
update.entry.vlan = entry->vlan_id;
update.entry.bv_id = entry->bv_id;

switch (type)
{
case SAI_FDB_EVENT_LEARNED:
if (!m_portsOrch->getPortByBridgePortId(bridge_port_id, update.port))
{
SWSS_LOG_ERROR("Failed to get port by bridge port ID %lu", bridge_port_id);
SWSS_LOG_ERROR("Failed to get port by bridge port ID 0x%lx", bridge_port_id);
return;
}

update.add = true;

(void)m_entries.insert(update.entry);
SWSS_LOG_DEBUG("FdbOrch notification: mac %s was inserted into vlan %d", update.entry.mac.to_string().c_str(), entry->vlan_id);
SWSS_LOG_DEBUG("FdbOrch notification: mac %s was inserted into bv_id 0x%lx", update.entry.mac.to_string().c_str(), entry->bv_id);

for (auto observer: m_observers)
{
Expand All @@ -59,7 +59,7 @@ void FdbOrch::update(sai_fdb_event_t type, const sai_fdb_entry_t* entry, sai_obj
update.add = false;

(void)m_entries.erase(update.entry);
SWSS_LOG_DEBUG("FdbOrch notification: mac %s was removed from vlan %d", update.entry.mac.to_string().c_str(), entry->vlan_id);
SWSS_LOG_DEBUG("FdbOrch notification: mac %s was removed from bv_id 0x%lx", update.entry.mac.to_string().c_str(), entry->bv_id);

for (auto observer: m_observers)
{
Expand All @@ -69,7 +69,7 @@ void FdbOrch::update(sai_fdb_event_t type, const sai_fdb_entry_t* entry, sai_obj
break;

case SAI_FDB_EVENT_FLUSHED:
if (bridge_port_id == SAI_NULL_OBJECT_ID && !entry->vlan_id)
if (bridge_port_id == SAI_NULL_OBJECT_ID && entry->bv_id == SAI_NULL_OBJECT_ID)
{
for (auto itr = m_entries.begin(); itr != m_entries.end();)
{
Expand All @@ -80,7 +80,7 @@ void FdbOrch::update(sai_fdb_event_t type, const sai_fdb_entry_t* entry, sai_obj
if there is static mac added, here will have issue.
*/
update.entry.mac = itr->mac;
update.entry.vlan = itr->vlan;
update.entry.bv_id = itr->bv_id;
update.add = false;

itr = m_entries.erase(itr);
Expand All @@ -93,19 +93,19 @@ void FdbOrch::update(sai_fdb_event_t type, const sai_fdb_entry_t* entry, sai_obj
}
}
}
else if (bridge_port_id && !entry->vlan_id)
else if (bridge_port_id && entry->bv_id == SAI_NULL_OBJECT_ID)
{
/*this is a placeholder for flush port fdb case, not supported yet.*/
SWSS_LOG_ERROR("FdbOrch notification: not supported flush port fdb action, port_id = %lu, vlan_id = %d.", bridge_port_id, entry->vlan_id);
SWSS_LOG_ERROR("FdbOrch notification: not supported flush port fdb action, port_id = 0x%lx, bv_id = 0x%lx.", bridge_port_id, entry->bv_id);
}
else if (bridge_port_id == SAI_NULL_OBJECT_ID && entry->vlan_id)
else if (bridge_port_id == SAI_NULL_OBJECT_ID && entry->bv_id != SAI_NULL_OBJECT_ID)
{
/*this is a placeholder for flush vlan fdb case, not supported yet.*/
SWSS_LOG_ERROR("FdbOrch notification: not supported flush vlan fdb action, port_id = %lu, vlan_id = %d.", bridge_port_id, entry->vlan_id);
SWSS_LOG_ERROR("FdbOrch notification: not supported flush vlan fdb action, port_id = 0x%lx, bv_id = 0x%lx.", bridge_port_id, entry->bv_id);
}
else
{
SWSS_LOG_ERROR("FdbOrch notification: not supported flush fdb action, port_id = %lu, vlan_id = %d.", bridge_port_id, entry->vlan_id);
SWSS_LOG_ERROR("FdbOrch notification: not supported flush fdb action, port_id = 0x%lx, bv_id = 0x%lx.", bridge_port_id, entry->bv_id);
}
break;
}
Expand Down Expand Up @@ -137,9 +137,15 @@ bool FdbOrch::getPort(const MacAddress& mac, uint16_t vlan, Port& port)
{
SWSS_LOG_ENTER();

if (!m_portsOrch->getVlanByVlanId(vlan, port))
{
SWSS_LOG_ERROR("Failed to get vlan by vlan ID %d", vlan);
return false;
}

sai_fdb_entry_t entry;
memcpy(entry.mac_address, mac.getMac(), sizeof(sai_mac_t));
entry.vlan_id = vlan;
entry.bv_id = port.m_vlan_info.vlan_oid;

sai_attribute_t attr;
attr.id = SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID;
Expand All @@ -154,7 +160,7 @@ bool FdbOrch::getPort(const MacAddress& mac, uint16_t vlan, Port& port)

if (!m_portsOrch->getPortByBridgePortId(attr.value.oid, port))
{
SWSS_LOG_ERROR("Failed to get port by bridge port ID %lu", attr.value.oid);
SWSS_LOG_ERROR("Failed to get port by bridge port ID 0x%lx", attr.value.oid);
return false;
}

Expand Down Expand Up @@ -189,7 +195,7 @@ void FdbOrch::doTask(Consumer& consumer)

FdbEntry entry;
entry.mac = MacAddress(keys[1]);
entry.vlan = vlan.m_vlan_info.vlan_id;
entry.bv_id = vlan.m_vlan_info.vlan_oid;

if (op == SET_COMMAND)
{
Expand Down Expand Up @@ -320,17 +326,15 @@ bool FdbOrch::addFdbEntry(const FdbEntry& entry, const string& port_name, const
{
// FIXME: should we check that the entry are moving to another port?
// FIXME: should we check that the entry are changing its type?
SWSS_LOG_ERROR("FDB entry already exists. mac=%s vlan=%d", entry.mac.to_string().c_str(), entry.vlan);
SWSS_LOG_ERROR("FDB entry already exists. mac=%s bv_id=0x%lx", entry.mac.to_string().c_str(), entry.bv_id);
return true;
}

sai_fdb_entry_t fdb_entry;

fdb_entry.switch_id = gSwitchId;
memcpy(fdb_entry.mac_address, entry.mac.getMac(), sizeof(sai_mac_t));
fdb_entry.bridge_type = SAI_FDB_ENTRY_BRIDGE_TYPE_1Q;
fdb_entry.vlan_id = entry.vlan;
fdb_entry.bridge_id = SAI_NULL_OBJECT_ID;
fdb_entry.bv_id = entry.bv_id;

Port port;
/* Retry until port is created */
Expand Down Expand Up @@ -387,20 +391,20 @@ bool FdbOrch::removeFdbEntry(const FdbEntry& entry)

if (m_entries.count(entry) == 0)
{
SWSS_LOG_ERROR("FDB entry isn't found. mac=%s vlan=%d", entry.mac.to_string().c_str(), entry.vlan);
SWSS_LOG_ERROR("FDB entry isn't found. mac=%s bv_id=0x%lx", entry.mac.to_string().c_str(), entry.bv_id);
return true;
}

sai_status_t status;
sai_fdb_entry_t fdb_entry;
memcpy(fdb_entry.mac_address, entry.mac.getMac(), sizeof(sai_mac_t));
fdb_entry.vlan_id = entry.vlan;
fdb_entry.bv_id = entry.bv_id;

status = sai_fdb_api->remove_fdb_entry(&fdb_entry);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to remove FDB entry. mac=%s, vlan=%d",
entry.mac.to_string().c_str(), entry.vlan);
SWSS_LOG_ERROR("Failed to remove FDB entry. mac=%s, bv_id=0x%lx",
entry.mac.to_string().c_str(), entry.bv_id);
return true; //FIXME: it should be based on status. Some could be retried. some not
}

Expand Down
4 changes: 2 additions & 2 deletions orchagent/fdborch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
struct FdbEntry
{
MacAddress mac;
sai_vlan_id_t vlan;
sai_object_id_t bv_id;

bool operator<(const FdbEntry& other) const
{
return tie(mac, vlan) < tie(other.mac, other.vlan);
return tie(mac, bv_id) < tie(other.mac, other.bv_id);
}
};

Expand Down
58 changes: 58 additions & 0 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern sai_object_id_t gVirtualRouterId;

extern sai_router_interface_api_t* sai_router_intfs_api;
extern sai_route_api_t* sai_route_api;
extern sai_neighbor_api_t* sai_neighbor_api;

extern PortsOrch *gPortsOrch;
extern sai_object_id_t gSwitchId;
Expand Down Expand Up @@ -145,6 +146,10 @@ void IntfsOrch::doTask(Consumer &consumer)

addSubnetRoute(port, ip_prefix);
addIp2MeRoute(ip_prefix);
if(port.m_type == Port::VLAN && ip_prefix.isV4())
{
addDirectedBroadcast(port, ip_prefix.getBroadcastIp());
}

m_syncdIntfses[alias].ip_addresses.insert(ip_prefix);
it = consumer.m_toSync.erase(it);
Expand Down Expand Up @@ -172,6 +177,10 @@ void IntfsOrch::doTask(Consumer &consumer)
{
removeSubnetRoute(port, ip_prefix);
removeIp2MeRoute(ip_prefix);
if(port.m_type == Port::VLAN && ip_prefix.isV4())
{
removeDirectedBroadcast(port, ip_prefix.getBroadcastIp());
}

m_syncdIntfses[alias].ip_addresses.erase(ip_prefix);
}
Expand Down Expand Up @@ -402,3 +411,52 @@ void IntfsOrch::removeIp2MeRoute(const IpPrefix &ip_prefix)

SWSS_LOG_NOTICE("Remove packet action trap route ip:%s", ip_prefix.getIp().to_string().c_str());
}

void IntfsOrch::addDirectedBroadcast(const Port &port, const IpAddress &ip_addr)
{
sai_status_t status;
sai_neighbor_entry_t neighbor_entry;
neighbor_entry.rif_id = port.m_rif_id;
neighbor_entry.switch_id = gSwitchId;
copy(neighbor_entry.ip_address, ip_addr);

sai_attribute_t neighbor_attr;
neighbor_attr.id = SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS;
memcpy(neighbor_attr.value.mac, MacAddress("ff:ff:ff:ff:ff:ff").getMac(), 6);

status = sai_neighbor_api->create_neighbor_entry(&neighbor_entry, 1, &neighbor_attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create broadcast entry %s rv:%d",
ip_addr.to_string().c_str(), status);
return;
}

SWSS_LOG_NOTICE("Add broadcast route for ip:%s", ip_addr.to_string().c_str());
}

void IntfsOrch::removeDirectedBroadcast(const Port &port, const IpAddress &ip_addr)
{
sai_status_t status;
sai_neighbor_entry_t neighbor_entry;
neighbor_entry.rif_id = port.m_rif_id;
neighbor_entry.switch_id = gSwitchId;
copy(neighbor_entry.ip_address, ip_addr);

status = sai_neighbor_api->remove_neighbor_entry(&neighbor_entry);
if (status != SAI_STATUS_SUCCESS)
{
if (status == SAI_STATUS_ITEM_NOT_FOUND)
{
SWSS_LOG_ERROR("No broadcast entry found for %s", ip_addr.to_string().c_str());
}
else
{
SWSS_LOG_ERROR("Failed to remove broadcast entry %s rv:%d",
ip_addr.to_string().c_str(), status);
}
return;
}

SWSS_LOG_NOTICE("Remove broadcast route ip:%s", ip_addr.to_string().c_str());
}
3 changes: 3 additions & 0 deletions orchagent/intfsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class IntfsOrch : public Orch

void addIp2MeRoute(const IpPrefix &ip_prefix);
void removeIp2MeRoute(const IpPrefix &ip_prefix);

void addDirectedBroadcast(const Port &port, const IpAddress &ip_addr);
void removeDirectedBroadcast(const Port &port, const IpAddress &ip_addr);
};

#endif /* SWSS_INTFSORCH_H */
6 changes: 4 additions & 2 deletions orchagent/mirrororch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ bool MirrorOrch::getNeighborInfo(const string& name, MirrorEntry& session, const
if (session.neighborInfo.port.m_type == Port::VLAN)
{
session.neighborInfo.vlanId = session.neighborInfo.port.m_vlan_info.vlan_id;
session.neighborInfo.vlanOid = session.neighborInfo.port.m_vlan_info.vlan_oid;

Port member;
if (!m_fdbOrch->getPort(session.neighborInfo.mac, session.neighborInfo.vlanId, member))
Expand Down Expand Up @@ -716,7 +717,7 @@ void MirrorOrch::updateFdb(const FdbUpdate& update)

// It is possible to have few session that points to one FDB entry
if (sessionIter->second.neighborInfo.mac != update.entry.mac ||
sessionIter->second.neighborInfo.vlanId != update.entry.vlan)
sessionIter->second.neighborInfo.vlanOid != update.entry.bv_id)
{
continue;
}
Expand Down Expand Up @@ -850,7 +851,8 @@ void MirrorOrch::updateVlanMember(const VlanMemberUpdate& update)
}

// It is possible to have few session that points to one VLAN member
if (sessionIter->second.neighborInfo.port != update.vlan || sessionIter->second.neighborInfo.portId != update.member.m_port_id)
if (sessionIter->second.neighborInfo.port != update.vlan ||
sessionIter->second.neighborInfo.portId != update.member.m_port_id)
{
continue;
}
Expand Down
1 change: 1 addition & 0 deletions orchagent/mirrororch.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct MirrorEntry
MacAddress mac;
Port port;
sai_vlan_id_t vlanId;
sai_object_id_t vlanOid;
sai_object_id_t portId;
} neighborInfo;

Expand Down
2 changes: 1 addition & 1 deletion orchagent/pfcactionhandler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <unordered_map>
#include "pfcactionhandler.h"
#include "logger.h"
#include "saiserialize.h"
#include "sai_serialize.h"
#include "portsorch.h"
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion orchagent/pfcwdorch.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <limits.h>
#include <unordered_map>
#include "pfcwdorch.h"
#include "saiserialize.h"
#include "sai_serialize.h"
#include "portsorch.h"
#include "converter.h"
#include "redisapi.h"
Expand Down
Loading

0 comments on commit 6dd0870

Please sign in to comment.