adrianvillin | 4450aed | 2023-10-19 12:15:52 +0200 | [diff] [blame] | 1 | from framework import VppTestCase, VppTestRunner |
| 2 | import unittest |
| 3 | from config import config |
| 4 | |
| 5 | |
| 6 | @unittest.skipIf("snort" in config.excluded_plugins, "Exclude snort plugin test") |
| 7 | class TestSnort(VppTestCase): |
| 8 | """Simple Snort plugin test""" |
| 9 | |
| 10 | @classmethod |
| 11 | def setUpClass(cls): |
| 12 | super(TestSnort, cls).setUpClass() |
| 13 | try: |
| 14 | cls.create_pg_interfaces(range(2)) |
| 15 | for i in cls.pg_interfaces: |
| 16 | i.config_ip4().resolve_arp() |
| 17 | i.admin_up() |
| 18 | except Exception: |
| 19 | cls.tearDownClass() |
| 20 | raise |
| 21 | |
| 22 | @classmethod |
| 23 | def tearDownClass(cls): |
| 24 | for i in cls.pg_interfaces: |
| 25 | i.unconfig_ip4() |
| 26 | i.admin_down() |
| 27 | super(TestSnort, cls).tearDownClass() |
| 28 | |
| 29 | def test_snort_cli(self): |
| 30 | # TODO: add a test with packets |
| 31 | # { cli command : part of the expected reply } |
| 32 | commands_replies = { |
| 33 | "snort create-instance name snortTest queue-size 16 on-disconnect drop": "", |
| 34 | "snort create-instance name snortTest2 queue-size 16 on-disconnect pass": "", |
| 35 | "snort attach instance snortTest interface pg0 output": "", |
| 36 | "snort attach instance snortTest2 interface pg1 input": "", |
| 37 | "show snort instances": "snortTest", |
| 38 | "show snort interfaces": "pg0", |
| 39 | "show snort clients": "number of clients", |
| 40 | "show snort mode": "input mode: interrupt", |
| 41 | "snort mode polling": "", |
| 42 | "snort mode interrupt": "", |
| 43 | "snort detach interface pg0": "", |
| 44 | "snort detach interface pg1": "", |
| 45 | } |
| 46 | |
| 47 | for command, reply in commands_replies.items(): |
| 48 | actual_reply = self.vapi.cli(command) |
| 49 | self.assertIn(reply, actual_reply) |
| 50 | |
| 51 | |
| 52 | if __name__ == "__main__": |
| 53 | unittest.main(testRunner=VppTestRunner) |