aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMartin Gálik <magalik@cisco.com>2017-03-27 06:02:47 -0700
committerOle Trøan <otroan@employees.org>2017-03-28 15:33:47 +0000
commitd7f75cdf672ff1b323175a50b853d63c1242e65c (patch)
treed4b202df1d2bb03d6ccec92e6d30f3dcfada55ec /test
parent9a332e1639fbfb4eb4ddf47b1681e05493ae6da3 (diff)
NAT: Test refactoring to avoid redundant code for verification and creating packet streams in additional test cases
Change-Id: I2265f8acfa63a7ea920a7cb981819a14806a3d58 Signed-off-by: Martin Gálik <magalik@cisco.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_snat.py107
1 files changed, 59 insertions, 48 deletions
diff --git a/test/test_snat.py b/test/test_snat.py
index e1dd576e991..0708d440714 100644
--- a/test/test_snat.py
+++ b/test/test_snat.py
@@ -13,57 +13,15 @@ from util import ppp
from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder
-class TestSNAT(VppTestCase):
- """ SNAT Test Cases """
+class MethodHolder(VppTestCase):
+ """ SNAT create capture and verify method holder """
@classmethod
def setUpClass(cls):
- super(TestSNAT, cls).setUpClass()
-
- try:
- cls.tcp_port_in = 6303
- cls.tcp_port_out = 6303
- cls.udp_port_in = 6304
- cls.udp_port_out = 6304
- cls.icmp_id_in = 6305
- cls.icmp_id_out = 6305
- cls.snat_addr = '10.0.0.3'
-
- cls.create_pg_interfaces(range(8))
- cls.interfaces = list(cls.pg_interfaces[0:4])
-
- for i in cls.interfaces:
- i.admin_up()
- i.config_ip4()
- i.resolve_arp()
-
- cls.pg0.generate_remote_hosts(2)
- cls.pg0.configure_ipv4_neighbors()
-
- cls.overlapping_interfaces = list(list(cls.pg_interfaces[4:7]))
-
- cls.pg4._local_ip4 = "172.16.255.1"
- cls.pg4._local_ip4n = socket.inet_pton(socket.AF_INET, i.local_ip4)
- cls.pg4._remote_hosts[0]._ip4 = "172.16.255.2"
- cls.pg4.set_table_ip4(10)
- cls.pg5._local_ip4 = "172.16.255.3"
- cls.pg5._local_ip4n = socket.inet_pton(socket.AF_INET, i.local_ip4)
- cls.pg5._remote_hosts[0]._ip4 = "172.16.255.4"
- cls.pg5.set_table_ip4(10)
- cls.pg6._local_ip4 = "172.16.255.1"
- cls.pg6._local_ip4n = socket.inet_pton(socket.AF_INET, i.local_ip4)
- cls.pg6._remote_hosts[0]._ip4 = "172.16.255.2"
- cls.pg6.set_table_ip4(20)
- for i in cls.overlapping_interfaces:
- i.config_ip4()
- i.admin_up()
- i.resolve_arp()
+ super(MethodHolder, cls).setUpClass()
- cls.pg7.admin_up()
-
- except Exception:
- super(TestSNAT, cls).tearDownClass()
- raise
+ def tearDown(self):
+ super(MethodHolder, self).tearDown()
def create_stream_in(self, in_if, out_if, ttl=64):
"""
@@ -337,6 +295,59 @@ class TestSNAT(VppTestCase):
# natPoolID
self.assertEqual(struct.pack("!I", 0), record[283])
+
+class TestSNAT(MethodHolder):
+ """ SNAT Test Cases """
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestSNAT, cls).setUpClass()
+
+ try:
+ cls.tcp_port_in = 6303
+ cls.tcp_port_out = 6303
+ cls.udp_port_in = 6304
+ cls.udp_port_out = 6304
+ cls.icmp_id_in = 6305
+ cls.icmp_id_out = 6305
+ cls.snat_addr = '10.0.0.3'
+
+ cls.create_pg_interfaces(range(8))
+ cls.interfaces = list(cls.pg_interfaces[0:4])
+
+ for i in cls.interfaces:
+ i.admin_up()
+ i.config_ip4()
+ i.resolve_arp()
+
+ cls.pg0.generate_remote_hosts(2)
+ cls.pg0.configure_ipv4_neighbors()
+
+ cls.overlapping_interfaces = list(list(cls.pg_interfaces[4:7]))
+
+ cls.pg4._local_ip4 = "172.16.255.1"
+ cls.pg4._local_ip4n = socket.inet_pton(socket.AF_INET, i.local_ip4)
+ cls.pg4._remote_hosts[0]._ip4 = "172.16.255.2"
+ cls.pg4.set_table_ip4(10)
+ cls.pg5._local_ip4 = "172.16.255.3"
+ cls.pg5._local_ip4n = socket.inet_pton(socket.AF_INET, i.local_ip4)
+ cls.pg5._remote_hosts[0]._ip4 = "172.16.255.4"
+ cls.pg5.set_table_ip4(10)
+ cls.pg6._local_ip4 = "172.16.255.1"
+ cls.pg6._local_ip4n = socket.inet_pton(socket.AF_INET, i.local_ip4)
+ cls.pg6._remote_hosts[0]._ip4 = "172.16.255.2"
+ cls.pg6.set_table_ip4(20)
+ for i in cls.overlapping_interfaces:
+ i.config_ip4()
+ i.admin_up()
+ i.resolve_arp()
+
+ cls.pg7.admin_up()
+
+ except Exception:
+ super(TestSNAT, cls).tearDownClass()
+ raise
+
def clear_snat(self):
"""
Clear SNAT configuration.
@@ -1276,7 +1287,7 @@ class TestSNAT(VppTestCase):
self.clear_snat()
-class TestDeterministicNAT(VppTestCase):
+class TestDeterministicNAT(MethodHolder):
""" Deterministic NAT Test Cases """
@classmethod