Skip to content

Commit

Permalink
[254] Add port state change notification support to vslib (sonic-net#255
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kcudnik authored and lguohan committed Nov 6, 2017
1 parent 5dddf52 commit b782d0c
Show file tree
Hide file tree
Showing 10 changed files with 439 additions and 6 deletions.
4 changes: 4 additions & 0 deletions meta/saiserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ sai_status_t transfer_attribute(
transfer_primitive(src_attr.value.ip6, dst_attr.value.ip6);
break;

case SAI_ATTR_VALUE_TYPE_POINTER:
transfer_primitive(src_attr.value.ptr, dst_attr.value.ptr);
break;

case SAI_ATTR_VALUE_TYPE_IP_ADDRESS:
transfer_primitive(src_attr.value.ipaddr, dst_attr.value.ipaddr);
break;
Expand Down
3 changes: 3 additions & 0 deletions meta/saiserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ std::string sai_serialize_object_meta_key(
std::string sai_serialize_mac(
_In_ const sai_mac_t mac);

std::string sai_serialize_port_oper_status(
_In_ sai_port_oper_status_t status);

// serialize ntf

std::string sai_serialize_fdb_event_ntf(
Expand Down
1 change: 0 additions & 1 deletion syncd/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ void bulk_nhgm_consumer_worker()

auto& key = kfvKey(kco);
auto& op = kfvOp(kco);
auto& values = kfvFieldsValues(kco);

if (starts_with(key, "SAI_OBJECT_TYPE_SWITCH")) continue;

Expand Down
2 changes: 2 additions & 0 deletions vslib/inc/sai_vs.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ extern "C" {
#define SAI_VALUE_VS_SWITCH_TYPE_BCM56850 "SAI_VS_SWITCH_TYPE_BCM56850"
#define SAI_VALUE_VS_SWITCH_TYPE_MLNX2700 "SAI_VS_SWITCH_TYPE_MLNX2700"

#define SAI_VS_VETH_PREFIX "v"

typedef enum _sai_vs_switch_type_t
{
SAI_VS_SWITCH_TYPE_NONE,
Expand Down
61 changes: 60 additions & 1 deletion vslib/inc/sai_vs_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "meta/saiserialize.h"
#include "meta/saiattributelist.h"

#include "swss/selectableevent.h"

#include <unordered_map>
#include <string>
#include <set>
Expand Down Expand Up @@ -132,12 +134,69 @@ class SwitchState

sai_object_id_t getSwitchId() const
{
return m_switch_id;
return m_switch_id;
}

bool getRunLinkThread() const
{
return m_run_link_thread;
}

void setRunLinkThread(
_In_ bool run)
{
m_run_link_thread = run;
}

swss::SelectableEvent* getLinkThreadEvent()
{
return &m_link_thread_event;
}

void setLinkThread(
_In_ std::shared_ptr<std::thread> thread)
{
m_link_thread = thread;
}

std::shared_ptr<std::thread> getLinkThread() const
{
return m_link_thread;
}

void setIfNameToPortId(
_In_ const std::string& ifname,
_In_ sai_object_id_t port_id)
{
m_ifname_to_port_id_map[ifname] = port_id;
}

sai_object_id_t getPortIdFromIfName(
_In_ const std::string& ifname) const
{
auto it = m_ifname_to_port_id_map.find(ifname);

if (it == m_ifname_to_port_id_map.end())
{
return SAI_NULL_OBJECT_ID;
}

return it->second;
}

private:

sai_object_id_t m_switch_id;

std::map<std::string, sai_object_id_t> m_ifname_to_port_id;

swss::SelectableEvent m_link_thread_event;

volatile bool m_run_link_thread;

std::shared_ptr<std::thread> m_link_thread;

std::map<std::string, sai_object_id_t> m_ifname_to_port_id_map;
};

typedef std::map<sai_object_id_t, std::shared_ptr<SwitchState>> SwitchStateMap;
Expand Down
2 changes: 1 addition & 1 deletion vslib/src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AM_CPPFLAGS = -I$(top_srcdir)/vslib/inc -I$(top_srcdir)/SAI/inc -I$(top_srcdir)/SAI/meta
AM_CPPFLAGS = -I$(top_srcdir)/vslib/inc -I$(top_srcdir)/SAI/inc -I$(top_srcdir)/SAI/meta -I/usr/include/libnl3

if DEBUG
DBGFLAGS = -ggdb -D_DEBUG_
Expand Down
11 changes: 10 additions & 1 deletion vslib/src/sai_vs_hostintf.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "sai_vs.h"
#include "sai_vs_internal.h"
#include "sai_vs_state.h"

#include "meta/saiserialize.h"

Expand Down Expand Up @@ -244,7 +245,7 @@ bool hostif_create_tap_veth_forwarding(
// host interface, vEthernetX will be used for packet transfer between ip
// namespaces

std::string vethname = "v" + tapname;
std::string vethname = SAI_VS_VETH_PREFIX + tapname;

int packet_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));

Expand Down Expand Up @@ -432,6 +433,14 @@ sai_status_t vs_create_hostif_int(
SWSS_LOG_ERROR("forwarding rule on %s was not added", name.c_str());
}

std::string vname = SAI_VS_VETH_PREFIX + name;

SWSS_LOG_INFO("mapping interface %s to port id %s",
vname.c_str(),
sai_serialize_object_id(obj_id).c_str());

g_switch_state_map.at(switch_id)->setIfNameToPortId(vname, obj_id);

// TODO what about FDB entries notifications, they also should
// be generated if new mac addres will show up on the interface/arp table

Expand Down
Loading

0 comments on commit b782d0c

Please sign in to comment.