Skip to content

Commit

Permalink
Propagate m_vpp over classes
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Nov 24, 2024
1 parent 83559fb commit aac2969
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 66 deletions.
10 changes: 5 additions & 5 deletions vslib/HostInterfaceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include <linux/if_packet.h>
#include <linux/if_ether.h>

extern bool g_vpp;

using namespace saivs;

HostInterfaceInfo::HostInterfaceInfo(
Expand All @@ -32,19 +30,21 @@ HostInterfaceInfo::HostInterfaceInfo(
_In_ int tapfd,
_In_ const std::string& tapname,
_In_ sai_object_id_t portId,
_In_ std::shared_ptr<EventQueue> eventQueue):
_In_ std::shared_ptr<EventQueue> eventQueue,
_In_ bool vpp):
m_ifindex(ifindex),
m_packet_socket(socket),
m_name(tapname),
m_portId(portId),
m_eventQueue(eventQueue),
m_tapfd(tapfd)
m_tapfd(tapfd),
m_vpp(vpp)
{
SWSS_LOG_ENTER();

m_run_thread = true;

if (g_vpp) // VPP
if (m_vpp) // VPP
{
// threads are disabled for vpp
return;
Expand Down
5 changes: 4 additions & 1 deletion vslib/HostInterfaceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace saivs
_In_ int tapfd,
_In_ const std::string& tapname,
_In_ sai_object_id_t portId,
_In_ std::shared_ptr<EventQueue> eventQueue);
_In_ std::shared_ptr<EventQueue> eventQueue,
_In_ bool vpp);

virtual ~HostInterfaceInfo();

Expand Down Expand Up @@ -87,5 +88,7 @@ namespace saivs

swss::SelectableEvent m_e2tEvent;
swss::SelectableEvent m_t2eEvent;

bool m_vpp;
};
}
5 changes: 3 additions & 2 deletions vslib/MACsecForwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ using namespace saivs;

MACsecForwarder::MACsecForwarder(
_In_ const std::string &macsecInterfaceName,
_In_ std::shared_ptr<HostInterfaceInfo> info):
_In_ std::shared_ptr<HostInterfaceInfo> info,
_In_ bool vpp):
m_macsecInterfaceName(macsecInterfaceName),
m_runThread(true),
m_info(info)
Expand Down Expand Up @@ -53,7 +54,7 @@ MACsecForwarder::MACsecForwarder(
m_macsecInterfaceName.c_str());
}

if (SwitchStateBase::promisc(m_macsecInterfaceName.c_str()))
if (SwitchStateBase::promisc(m_macsecInterfaceName.c_str(), vpp))
{
close(m_macsecfd);
SWSS_LOG_THROW(
Expand Down
3 changes: 2 additions & 1 deletion vslib/MACsecForwarder.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace saivs

MACsecForwarder(
_In_ const std::string &macsecInterfaceName,
_In_ std::shared_ptr<HostInterfaceInfo> info);
_In_ std::shared_ptr<HostInterfaceInfo> info,
_In_ bool vpp);

virtual ~MACsecForwarder();

Expand Down
10 changes: 9 additions & 1 deletion vslib/MACsecManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ bool MACsecManager::add_macsec_forwarder(

auto &manager = itr->second;

manager.m_forwarder = std::make_shared<MACsecForwarder>(macsecInterface, manager.m_info);
manager.m_forwarder = std::make_shared<MACsecForwarder>(macsecInterface, manager.m_info, m_vpp);
return true;
}

Expand Down Expand Up @@ -957,3 +957,11 @@ bool MACsecManager::exec(

return exec(command, res);
}

void MACsecManager::setVpp(
_In_ bool vpp)
{
SWSS_LOG_ENTER();

m_vpp = vpp;
}
5 changes: 5 additions & 0 deletions vslib/MACsecManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ namespace saivs

void cleanup_macsec_device() const;

void setVpp(
_In_ bool vpp);

protected:

bool create_macsec_egress_sc(
Expand Down Expand Up @@ -143,5 +146,7 @@ namespace saivs
};

std::map<std::string, MACsecTrafficManager> m_macsecTrafficManagers;

bool m_vpp = false;
};
}
14 changes: 9 additions & 5 deletions vslib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib -I/usr/include/libnl3
AM_CFLAGS = -I/usr/include/vpp_plugins -fPIC -I. -I.. -I../../ -I../../../

lib_LTLIBRARIES = libsaivs.la

noinst_LIBRARIES = libSaiVS.a

#vppxlate/SaiVppXlate.c \
# vppxlate/SaiVppStats.c \
# vppxlate/SaiAclStats.c \
# vppxlate/SaiIntfStats.c

libSaiVS_a_SOURCES = \
vppxlate/SaiAclStats.c \
vppxlate/SaiIntfStats.c \
vppxlate/SaiVppStats.c \
vppxlate/SaiVppXlate.c \
Buffer.cpp \
ContextConfigContainer.cpp \
ContextConfig.cpp \
Expand Down Expand Up @@ -84,6 +86,8 @@ sai_vs.cpp: ../stub.pl $(top_srcdir)/SAI/meta/saimetadata.c
clean-local:
rm -f sai_vs.cpp

VPP_LIBS = -lvlibapi -lvapiclient -lvppapiclient -lvlibmemoryclient -lsvm -lvppinfra -lvlib -lvatplugin

libsaivs_la_SOURCES = sai_vs.cpp

libSaiVS_a_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS)
Expand All @@ -97,6 +101,6 @@ bin_PROGRAMS = tests

tests_SOURCES = tests.cpp
tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
tests_LDADD = -lhiredis -lswsscommon -lpthread libsaivs.la -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq
tests_LDADD = -lhiredis -lswsscommon -lpthread libsaivs.la -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(VPP_LIBS)

TESTS = tests
8 changes: 7 additions & 1 deletion vslib/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,13 @@ sai_status_t Sai::apiInitialize(

// TODO move to Context class

m_vsSai = std::make_shared<VirtualSwitchSaiInterface>(contextConfig);
sai_vs_packet_engine_t pe;

SwitchConfig::parseSaiVsPacketEngine(service_method_table->profile_get_value(0, SAI_KEY_VS_PACKET_ENGINE), pe);

bool vpp = (pe == SAI_VS_PACKET_ENGINE_VPP);

m_vsSai = std::make_shared<VirtualSwitchSaiInterface>(contextConfig, vpp);

m_meta = std::make_shared<saimeta::Meta>(m_vsSai);

Expand Down
28 changes: 27 additions & 1 deletion vslib/SwitchConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ SwitchConfig::SwitchConfig(
m_bootType(SAI_VS_BOOT_TYPE_COLD),
m_switchIndex(switchIndex),
m_hardwareInfo(hwinfo),
m_useTapDevice(false)
m_useTapDevice(false),
m_vpp(false)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -153,3 +154,28 @@ bool SwitchConfig::parseUseTapDevice(

return false;
}

bool SwitchConfig::parseSaiVsPacketEngine(
_In_ const char* pe,
_Out_ sai_vs_packet_engine_t& vsPacketEngine)
{
SWSS_LOG_ENTER();

std::string st = (pe == NULL) ? "unknown" : pe;

if (st == SAI_VALUE_VS_PACKET_ENGINE_VS)
{
vsPacketEngine = SAI_VS_PACKET_ENGINE_VS;
}
else if (st == SAI_VALUE_VS_PACKET_ENGINE_VPP)
{
vsPacketEngine = SAI_VS_PACKET_ENGINE_VPP;
}
else
{
// default is VS
vsPacketEngine = SAI_VS_PACKET_ENGINE_VS;
}

return true;
}
7 changes: 7 additions & 0 deletions vslib/SwitchConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

extern "C" {
#include "sai.h"
#include "saivs.h"
}

namespace saivs
Expand Down Expand Up @@ -67,6 +68,10 @@ namespace saivs
static bool parseUseTapDevice(
_In_ const char* useTapDeviceStr);

static bool parseSaiVsPacketEngine(
_In_ const char* pe,
_Out_ sai_vs_packet_engine_t& vsPacketEngine);

public:

sai_switch_type_t m_saiSwitchType;
Expand All @@ -90,5 +95,7 @@ namespace saivs
std::shared_ptr<ResourceLimiter> m_resourceLimiter;

std::shared_ptr<CorePortIndexMap> m_corePortIndexMap;

bool m_vpp;
};
}
Loading

0 comments on commit aac2969

Please sign in to comment.