aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_snort.py
diff options
context:
space:
mode:
authorAgathiyan Bragadeesh <agathiyan.bragadeesh2@arm.com>2024-11-06 14:33:12 +0000
committerDamjan Marion <dmarion@0xa5.net>2025-01-17 17:27:06 +0000
commit102575492c9199259aa5e468f21b46936d7a1ac4 (patch)
treef7fbad6cfa602d8a56fd3e68a9d4a4611e062b5d /test/test_snort.py
parentb33331925583a83c36aed67521b78e1f3db12a8c (diff)
snort: support multiple instances per interface
Implements load balancing between snort instances via flow hash. New CLI commands have been made to support these changes: snort attach instance <name1> [instance <name2> ... ] interface <ifname> [input|output|inout] snort attach all-instances interface <ifname> [input|output|inout] snort detach instance <name1> interface <ifname> snort detach all-instances interface <ifname> The output of "show snort interfaces" has an extra column to show the direction of each attachment: interface instances direction Ethernet0: snort1 inout snort2 inout snort3 inout Ethernet1: snort1 input snort3 output To maintain backwards compatibility for the snort api, the snort_interface_get api endpoint only returns one of the attached instances and the snort_interface_detach endpoint detaches all attached instances. Type: improvement Signed-off-by: Agathiyan Bragadeesh <agathiyan.bragadeesh2@arm.com> Change-Id: I6b7c26c203496d6a1dba244620907f28c04bb478
Diffstat (limited to 'test/test_snort.py')
-rw-r--r--test/test_snort.py38
1 files changed, 23 insertions, 15 deletions
diff --git a/test/test_snort.py b/test/test_snort.py
index 19401cb7b85..c25c0e65145 100644
--- a/test/test_snort.py
+++ b/test/test_snort.py
@@ -12,10 +12,10 @@ class TestSnort(VppTestCase):
def setUpClass(cls):
super(TestSnort, cls).setUpClass()
try:
- cls.create_pg_interfaces(range(2))
+ cls.create_pg_interfaces(range(4))
for i in cls.pg_interfaces:
i.config_ip4().resolve_arp()
- i.admin_up()
+ i.admin_down()
except Exception:
cls.tearDownClass()
raise
@@ -24,7 +24,6 @@ class TestSnort(VppTestCase):
def tearDownClass(cls):
for i in cls.pg_interfaces:
i.unconfig_ip4()
- i.admin_down()
super(TestSnort, cls).tearDownClass()
def test_snort_cli(self):
@@ -36,14 +35,18 @@ class TestSnort(VppTestCase):
"snort create-instance name snortTest2 queue-size 16 on-disconnect pass": "",
"snort attach instance snortTest interface pg0 output": "",
"snort attach instance snortTest2 interface pg1 input": "",
+ "snort attach all-instances interface pg2 inout": "",
+ "snort attach instance snortTest instance snortTest2 interface pg3 inout": "",
"show snort instances": "snortTest",
"show snort interfaces": "pg0",
"show snort clients": "number of clients",
"show snort mode": "input mode: interrupt",
"snort mode polling": "",
"snort mode interrupt": "",
- "snort detach interface pg0": "",
- "snort detach interface pg1": "",
+ "snort detach instance snortTest interface pg0": "",
+ "snort detach instance snortTest2 interface pg1": "",
+ "snort detach all-instances interface pg2": "",
+ "snort detach instance snortTest instance snortTest2 interface pg3": "",
"snort delete instance snortTest": "",
}
@@ -64,7 +67,7 @@ class TestSnortVapi(VppTestCase):
for i in cls.pg_interfaces:
i.config_ip4()
i.resolve_arp()
- i.admin_up()
+ i.admin_down()
except Exception:
cls.tearDownClass()
raise
@@ -73,7 +76,6 @@ class TestSnortVapi(VppTestCase):
def tearDownClass(cls):
for i in cls.pg_interfaces:
i.unconfig_ip4()
- i.admin_down()
super(TestSnortVapi, cls).tearDownClass()
def test_snort_01_modes_set_interrupt(self):
@@ -109,20 +111,27 @@ class TestSnortVapi(VppTestCase):
reply = self.vapi.snort_interface_attach(
instance_index=0, sw_if_index=1, snort_dir=1
)
+ reply = self.vapi.snort_interface_attach(
+ instance_index=0, sw_if_index=2, snort_dir=2
+ )
+ reply = self.vapi.snort_interface_attach(
+ instance_index=1, sw_if_index=2, snort_dir=3
+ )
+ reply = self.vapi.cli("show snort interfaces")
+ self.assertIn("snortTest0", reply)
+ self.assertIn("snortTest1", reply)
+ self.assertIn("input", reply)
+ self.assertIn("inout", reply)
+ self.assertIn("output", reply)
try:
reply = self.vapi.snort_interface_attach(
- instance_index=1, sw_if_index=1, snort_dir=1
+ instance_index=1, sw_if_index=2, snort_dir=2
)
except:
pass
else:
self.assertNotEqual(reply.retval, 0)
-
- reply = self.vapi.snort_interface_attach(
- instance_index=1, sw_if_index=2, snort_dir=3
- )
reply = self.vapi.cli("show snort interfaces")
- self.assertIn("snortTest0", reply)
self.assertIn("snortTest1", reply)
def test_snort_05_delete_instance(self):
@@ -131,14 +140,13 @@ class TestSnortVapi(VppTestCase):
reply = self.vapi.cli("show snort interfaces")
self.assertNotIn("snortTest0", reply)
self.assertIn("snortTest1", reply)
- reply = self.vapi.cli("show snort interfaces")
self.assertNotIn("pg0", reply)
self.assertIn("pg1", reply)
def test_snort_06_detach_if(self):
"""Interfaces can be detached"""
try:
- reply = self.vapi.snort_interface_detach(sw_if_index=1)
+ reply = self.vapi.snort_interface_detach(sw_if_index=3)
except:
pass
else: