Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge vector packet processing (vpp) from sonic-platform-vpp with virtual switch #1473

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions vslib/BitResourcePool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2024 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once
#include <cstdint>
#include <stdexcept>
namespace saivs
{
class BitResourcePool {
public:
BitResourcePool(uint16_t size, uint32_t base) : resource_size(size), base_index(base){
if (size > MAX_RESOURCE_SIZE_BYTES * 8) {
throw std::invalid_argument("Resource size exceeds maximum size");
}
}
~BitResourcePool() = default;
int alloc() {
for (uint16_t i = 0; i < resource_size; i++) {
if ((resource_bitmap[i / 8] & (1 << (i % 8))) == 0) {
resource_bitmap[i / 8] |= (uint8_t)(1 << (i % 8));
return base_index + i;
}
}
return -1;
}
void free(uint32_t index) {
if (index >= resource_size + base_index || index < base_index) {
throw std::invalid_argument("Invalid index");
}
index -= base_index;
resource_bitmap[index / 8] &= (uint8_t)(~(1 << (index % 8)));
}
private:
static const int MAX_RESOURCE_SIZE_BYTES = 16 * 1024;
uint8_t resource_bitmap[MAX_RESOURCE_SIZE_BYTES] = {0};
uint16_t resource_size;
uint32_t base_index;
};
};
12 changes: 10 additions & 2 deletions vslib/HostInterfaceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,26 @@ 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 (m_vpp) // VPP
{
// threads are disabled for vpp
return;
}

m_e2t = std::make_shared<std::thread>(&HostInterfaceInfo::veth2tap_fun, this);
m_t2e = std::make_shared<std::thread>(&HostInterfaceInfo::tap2veth_fun, this);
}
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;
};
}
41 changes: 41 additions & 0 deletions vslib/IpVrfInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2016 Microsoft, Inc.
* Modifications copyright (c) 2023 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

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

namespace saivs
{
class IpVrfInfo
{
public:
IpVrfInfo(
_In_ sai_object_id_t obj_id,
_In_ uint32_t vrf_id,
_In_ std::string &vrf_name,
bool is_ipv6);

virtual ~IpVrfInfo();

public:
sai_object_id_t m_obj_id;
uint32_t m_vrf_id;
std::string m_vrf_name;
bool m_is_ipv6;
};
}
5 changes: 4 additions & 1 deletion vslib/MACsecAttr.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

namespace saivs
{
using macsec_sci_t = std::string;
using macsec_an_t = std::uint16_t;
using macsec_pn_t = std::uint64_t;
using macsec_ssci_t = std::uint32_t;

struct MACsecAttr
{
Expand Down Expand Up @@ -50,11 +52,12 @@ namespace saivs
std::string m_authKey;
std::string m_sak;
std::string m_sci;
std::string m_ssci;
std::string m_ssciStr;
std::string m_salt;

macsec_an_t m_an;
macsec_pn_t m_pn;
macsec_ssci_t m_ssci;

bool m_sendSci;
bool m_encryptionEnable;
Expand Down
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
14 changes: 11 additions & 3 deletions vslib/MACsecManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ bool MACsecManager::create_macsec_egress_sa(
<< ( attr.is_xpn() ? " xpn " : " pn ")
<< attr.m_pn
<< ( attr.is_xpn() ? " ssci " : "" )
<< ( attr.is_xpn() ? attr.m_ssci : "" )
<< ( attr.is_xpn() ? attr.m_ssciStr : "" )
<< ( attr.is_xpn() ? " salt " : "" )
<< ( attr.is_xpn() ? attr.m_salt : "" )
<< " on key "
Expand Down Expand Up @@ -487,7 +487,7 @@ bool MACsecManager::create_macsec_ingress_sa(
<< ( attr.is_xpn() ? " xpn " : " pn " )
<< attr.m_pn
<< ( attr.is_xpn() ? " ssci " : "" )
<< ( attr.is_xpn() ? attr.m_ssci : "" )
<< ( attr.is_xpn() ? attr.m_ssciStr : "" )
<< ( attr.is_xpn() ? " salt " : "" )
<< ( attr.is_xpn() ? attr.m_salt : "" )
<< " on key "
Expand Down 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;
};
}
21 changes: 20 additions & 1 deletion vslib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
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 = \
Buffer.cpp \
ContextConfigContainer.cpp \
Expand Down Expand Up @@ -54,10 +60,21 @@ libSaiVS_a_SOURCES = \
SwitchStateBaseFdb.cpp \
SwitchStateBaseHostif.cpp \
SwitchStateBaseMACsec.cpp \
SaiObjectDB.cpp \
SwitchStateBaseFdbVpp.cpp \
SwitchStateBaseAcl.cpp \
SwitchStateBaseBfd.cpp \
SwitchStateBaseNbr.cpp \
SwitchStateBaseNexthop.cpp \
SwitchStateBaseRif.cpp \
SwitchStateBaseRoute.cpp \
SwitchStateBaseUtils.cpp \
TunnelManager.cpp \
SwitchState.cpp \
TrafficFilterPipes.cpp \
TrafficForwarder.cpp \
VirtualSwitchSaiInterface.cpp \
VirtualSwitchSaiInterfaceVpp.cpp \
VirtualSwitchSaiInterfaceFdb.cpp \
VirtualSwitchSaiInterfacePort.cpp

Expand All @@ -69,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 @@ -82,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
Loading
Loading