tests: Add support for getting corefile patterns on FreeBSD
[vpp.git] / test / test_ipsec_spd_fp_input.py
index 9037ed2..ec4a7c7 100644 (file)
@@ -3,10 +3,11 @@ import unittest
 import ipaddress
 
 from util import ppp
-from framework import VppTestRunner
+from asfframework import VppTestRunner
 from template_ipsec import IPSecIPv4Fwd
 from template_ipsec import IPSecIPv6Fwd
 from test_ipsec_esp import TemplateIpsecEsp
+from template_ipsec import SpdFastPathTemplate
 
 
 def debug_signal_handler(signal, frame):
@@ -20,7 +21,7 @@ import signal
 signal.signal(signal.SIGINT, debug_signal_handler)
 
 
-class SpdFastPathInbound(IPSecIPv4Fwd):
+class SpdFastPathInbound(SpdFastPathTemplate):
     # In test cases derived from this class, packets in IPv4 FWD path
     # are configured to go through IPSec inbound SPD policy lookup.
     # Note that order in which the rules are applied is
@@ -118,7 +119,10 @@ class IPSec4SpdTestCaseBypass(SpdFastPathInbound):
 
         # create input rules
         # bypass rule should take precedence over discard rule,
-        # even though it's lower priority
+        # even though it's lower priority, because for input policies
+        # matching PROTECT policies precedes matching BYPASS policies
+        # which preceeds matching for DISCARD policies.
+        # Any hit stops the process.
         policy_0 = self.spd_add_rem_policy(  # inbound, priority 10
             1,
             self.pg1,
@@ -128,10 +132,10 @@ class IPSec4SpdTestCaseBypass(SpdFastPathInbound):
             priority=10,
             policy_type="bypass",
             ip_range=True,
-            local_ip_start=self.pg0.remote_ip4,
-            local_ip_stop=self.pg0.remote_ip4,
-            remote_ip_start=self.pg1.remote_ip4,
-            remote_ip_stop=self.pg1.remote_ip4,
+            local_ip_start=self.pg1.remote_ip4,
+            local_ip_stop=self.pg1.remote_ip4,
+            remote_ip_start=self.pg0.remote_ip4,
+            remote_ip_stop=self.pg0.remote_ip4,
         )
         policy_1 = self.spd_add_rem_policy(  # inbound, priority 15
             1,
@@ -142,10 +146,10 @@ class IPSec4SpdTestCaseBypass(SpdFastPathInbound):
             priority=15,
             policy_type="discard",
             ip_range=True,
-            local_ip_start=self.pg0.remote_ip4,
-            local_ip_stop=self.pg0.remote_ip4,
-            remote_ip_start=self.pg1.remote_ip4,
-            remote_ip_stop=self.pg1.remote_ip4,
+            local_ip_start=self.pg1.remote_ip4,
+            local_ip_stop=self.pg1.remote_ip4,
+            remote_ip_start=self.pg0.remote_ip4,
+            remote_ip_stop=self.pg0.remote_ip4,
         )
 
         # create output rule so we can capture forwarded packets
@@ -204,8 +208,8 @@ class IPSec4SpdTestCaseDiscard(SpdFastPathInbound):
         # even though it's lower priority
         policy_0 = self.spd_add_rem_policy(  # inbound, priority 10
             1,
-            self.pg0,
             self.pg1,
+            self.pg0,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=10,
@@ -215,8 +219,8 @@ class IPSec4SpdTestCaseDiscard(SpdFastPathInbound):
         # create output rule so we can capture forwarded packets
         policy_1 = self.spd_add_rem_policy(  # outbound, priority 10
             1,
-            self.pg0,
             self.pg1,
+            self.pg0,
             socket.IPPROTO_UDP,
             is_out=1,
             priority=10,
@@ -268,8 +272,8 @@ class IPSec4SpdTestCaseProtect(SpdFastPathInboundProtect):
             p,
             p.scapy_tra_sa,
             self.tra_if,
-            src=self.tra_if.local_ip4,
-            dst=self.tra_if.remote_ip4,
+            src=self.tra_if.remote_ip4,
+            dst=self.tra_if.local_ip4,
             count=pkt_count,
             payload_size=payload_size,
         )
@@ -290,8 +294,8 @@ class IPSec4SpdTestCaseProtect(SpdFastPathInboundProtect):
             pkt_count,
             "incorrect SA out counts: expected %d != %d" % (pkt_count, pkts),
         )
-        self.assertEqual(p.tra_sa_out.get_lost(), 0)
-        self.assertEqual(p.tra_sa_in.get_lost(), 0)
+        self.assertEqual(p.tra_sa_out.get_err("lost"), 0)
+        self.assertEqual(p.tra_sa_in.get_err("lost"), 0)
 
 
 class IPSec4SpdTestCaseAddIPRange(SpdFastPathInbound):
@@ -326,10 +330,10 @@ class IPSec4SpdTestCaseAddIPRange(SpdFastPathInbound):
             priority=10,
             policy_type="bypass",
             ip_range=True,
-            local_ip_start=s_ip_s0,
-            local_ip_stop=s_ip_e0,
-            remote_ip_start=d_ip_s0,
-            remote_ip_stop=d_ip_e0,
+            local_ip_start=d_ip_s0,
+            local_ip_stop=d_ip_e0,
+            remote_ip_start=s_ip_s0,
+            remote_ip_stop=s_ip_e0,
         )
         policy_1 = self.spd_add_rem_policy(  # outbound, priority 5
             1,
@@ -478,8 +482,8 @@ class IPSec4SpdTestCaseRemove(SpdFastPathInbound):
         self.spd_create_and_intf_add(1, [self.pg0, self.pg1])
         policy_0 = self.spd_add_rem_policy(  # inbound, priority 10
             1,
-            self.pg0,
             self.pg1,
+            self.pg0,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=10,
@@ -487,8 +491,8 @@ class IPSec4SpdTestCaseRemove(SpdFastPathInbound):
         )
         policy_1 = self.spd_add_rem_policy(  # inbound, priority 5
             1,
-            self.pg0,
             self.pg1,
+            self.pg0,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=5,
@@ -533,8 +537,8 @@ class IPSec4SpdTestCaseRemove(SpdFastPathInbound):
         # now remove the bypass rule
         self.spd_add_rem_policy(  # outbound, priority 10
             1,
-            self.pg0,
             self.pg1,
+            self.pg0,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=10,
@@ -579,8 +583,8 @@ class IPSec4SpdTestCaseReadd(SpdFastPathInbound):
         self.spd_create_and_intf_add(1, [self.pg0, self.pg1])
         policy_0 = self.spd_add_rem_policy(  # inbound, priority 10
             1,
-            self.pg0,
             self.pg1,
+            self.pg0,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=10,
@@ -588,8 +592,8 @@ class IPSec4SpdTestCaseReadd(SpdFastPathInbound):
         )
         policy_1 = self.spd_add_rem_policy(  # inbound, priority 5
             1,
-            self.pg0,
             self.pg1,
+            self.pg0,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=5,
@@ -633,8 +637,8 @@ class IPSec4SpdTestCaseReadd(SpdFastPathInbound):
         # remove the bypass rule, leaving only the discard rule
         self.spd_add_rem_policy(  # inbound, priority 10
             1,
-            self.pg0,
             self.pg1,
+            self.pg0,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=10,
@@ -659,8 +663,8 @@ class IPSec4SpdTestCaseReadd(SpdFastPathInbound):
         # now readd the bypass rule
         policy_0 = self.spd_add_rem_policy(  # outbound, priority 10
             1,
-            self.pg0,
             self.pg1,
+            self.pg0,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=10,
@@ -712,8 +716,8 @@ class IPSec4SpdTestCaseMultiple(SpdFastPathInbound):
         # add rules on all interfaces
         policy_01 = self.spd_add_rem_policy(  # inbound, priority 10
             1,
-            self.pg0,
             self.pg1,
+            self.pg0,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=10,
@@ -721,8 +725,8 @@ class IPSec4SpdTestCaseMultiple(SpdFastPathInbound):
         )
         policy_02 = self.spd_add_rem_policy(  # inbound, priority 5
             1,
-            self.pg0,
             self.pg1,
+            self.pg0,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=5,
@@ -731,8 +735,8 @@ class IPSec4SpdTestCaseMultiple(SpdFastPathInbound):
 
         policy_11 = self.spd_add_rem_policy(  # inbound, priority 10
             1,
-            self.pg1,
             self.pg2,
+            self.pg1,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=10,
@@ -740,8 +744,8 @@ class IPSec4SpdTestCaseMultiple(SpdFastPathInbound):
         )
         policy_12 = self.spd_add_rem_policy(  # inbound, priority 5
             1,
-            self.pg1,
             self.pg2,
+            self.pg1,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=5,
@@ -750,8 +754,8 @@ class IPSec4SpdTestCaseMultiple(SpdFastPathInbound):
 
         policy_21 = self.spd_add_rem_policy(  # inbound, priority 5
             1,
-            self.pg2,
             self.pg0,
+            self.pg2,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=5,
@@ -759,8 +763,8 @@ class IPSec4SpdTestCaseMultiple(SpdFastPathInbound):
         )
         policy_22 = self.spd_add_rem_policy(  # inbound, priority 10
             1,
-            self.pg2,
             self.pg0,
+            self.pg2,
             socket.IPPROTO_UDP,
             is_out=0,
             priority=10,
@@ -852,8 +856,8 @@ class IPSec6SpdTestCaseProtect(SpdFastPathIPv6InboundProtect):
             p,
             p.scapy_tra_sa,
             self.tra_if,
-            src=self.tra_if.local_ip6,
-            dst=self.tra_if.remote_ip6,
+            src=self.tra_if.remote_ip6,
+            dst=self.tra_if.local_ip6,
             count=pkt_count,
             payload_size=payload_size,
         )
@@ -873,8 +877,8 @@ class IPSec6SpdTestCaseProtect(SpdFastPathIPv6InboundProtect):
             pkt_count,
             "incorrect SA out counts: expected %d != %d" % (pkt_count, pkts),
         )
-        self.assertEqual(p.tra_sa_out.get_lost(), 0)
-        self.assertEqual(p.tra_sa_in.get_lost(), 0)
+        self.assertEqual(p.tra_sa_out.get_err("lost"), 0)
+        self.assertEqual(p.tra_sa_in.get_err("lost"), 0)
 
 
 if __name__ == "__main__":