Skip to content

Commit

Permalink
Add MACsecIngressFilter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 23, 2021
1 parent 888197d commit 8142375
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
9 changes: 6 additions & 3 deletions unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/meta -I$(top_srcdir)/vslib
AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/meta -I$(top_srcdir)/vslib -I/usr/include/libnl3

bin_PROGRAMS = tests testslibsaivs

Expand All @@ -19,10 +19,13 @@ tests_SOURCES = main.cpp \
TestLaneMapContainer.cpp \
TestLaneMapFileParser.cpp \
TestMACsecAttr.cpp \
TestMACsecEgressFilter.cpp
TestMACsecEgressFilter.cpp \
TestMACsecForwarder.cpp \
TestMACsecIngressFilter.cpp

tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/vslib/libSaiVS.a -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS)
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/vslib/libSaiVS.a -lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 \
-lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS)

testslibsaivs_SOURCES = main_libsaivs.cpp \
test_sai_vs_acl.cpp \
Expand Down
16 changes: 16 additions & 0 deletions unittest/vslib/TestMACsecForwarder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "MACsecForwarder.h"

#include <gtest/gtest.h>

using namespace saivs;

TEST(MACsecForwarder, ctr)
{
EXPECT_THROW(std::make_shared<MACsecForwarder>("foo", nullptr), std::runtime_error);

auto s = std::make_shared<Signal>();

auto q = std::make_shared<EventQueue>(s);

//auto hii = std::make_shared<HostInterfaceInfo>(0,0,70,"tap",0,q);
}
46 changes: 46 additions & 0 deletions unittest/vslib/TestMACsecIngressFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "MACsecIngressFilter.h"

#include <sys/types.h>
#include <sys/socket.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <arpa/inet.h>
#include <net/if.h>

#define EAPOL_ETHER_TYPE (0x888e)

#include <gtest/gtest.h>

using namespace saivs;

TEST(MACsecIngressFilter, forward)
{
MACsecIngressFilter filter("foo");

filter.set_macsec_fd(0);

uint8_t packet[4000];

memset(packet, 0, sizeof(packet));

ethhdr* eth = (ethhdr*)packet;

eth->h_proto = ntohs(EAPOL_ETHER_TYPE);

size_t len = sizeof(packet);

EXPECT_EQ(filter.execute(packet, len), TrafficFilter::CONTINUE);

eth->h_proto = ntohs(6);

EXPECT_EQ(filter.execute(packet, len), TrafficFilter::TERMINATE);

filter.enable_macsec_device(true);

// fd is ok, stdout
EXPECT_EQ(filter.execute(packet, len), TrafficFilter::TERMINATE);

filter.set_macsec_fd(70); // bad fd

EXPECT_EQ(filter.execute(packet, len), TrafficFilter::TERMINATE);
}

0 comments on commit 8142375

Please sign in to comment.