blob: 7888a6788abfdcdc29179cabb8ee0d48148e1e41 [file] [log] [blame]
Klement Sekera31da2e32018-06-24 22:49:55 +02001import unittest
Klement Sekera611864f2018-09-26 11:19:00 +02002import socket
Klement Sekera31da2e32018-06-24 22:49:55 +02003
4from scapy.layers.inet import IP, ICMP, TCP
5from scapy.layers.ipsec import SecurityAssociation
6from scapy.layers.l2 import Ether, Raw
Klement Sekera611864f2018-09-26 11:19:00 +02007from scapy.layers.inet6 import IPv6, ICMPv6EchoRequest
Klement Sekera31da2e32018-06-24 22:49:55 +02008
9from framework import VppTestCase, VppTestRunner
10from util import ppp
Neale Ranns17dcec02019-01-09 21:22:20 -080011from vpp_papi import VppEnum
Klement Sekera31da2e32018-06-24 22:49:55 +020012
13
Klement Sekera611864f2018-09-26 11:19:00 +020014class IPsecIPv4Params(object):
Neale Ranns17dcec02019-01-09 21:22:20 -080015
Klement Sekera611864f2018-09-26 11:19:00 +020016 addr_type = socket.AF_INET
17 addr_any = "0.0.0.0"
18 addr_bcast = "255.255.255.255"
19 addr_len = 32
20 is_ipv6 = 0
Klement Sekera611864f2018-09-26 11:19:00 +020021
Neale Ranns17dcec02019-01-09 21:22:20 -080022 def __init__(self):
23 self.remote_tun_if_host = '1.1.1.1'
Klement Sekera611864f2018-09-26 11:19:00 +020024
Neale Ranns17dcec02019-01-09 21:22:20 -080025 self.scapy_tun_sa_id = 10
26 self.scapy_tun_spi = 1001
27 self.vpp_tun_sa_id = 20
28 self.vpp_tun_spi = 1000
Klement Sekera611864f2018-09-26 11:19:00 +020029
Neale Ranns17dcec02019-01-09 21:22:20 -080030 self.scapy_tra_sa_id = 30
31 self.scapy_tra_spi = 2001
32 self.vpp_tra_sa_id = 40
33 self.vpp_tra_spi = 2000
Klement Sekera611864f2018-09-26 11:19:00 +020034
Neale Ranns17dcec02019-01-09 21:22:20 -080035 self.auth_algo_vpp_id = (VppEnum.vl_api_ipsec_integ_alg_t.
36 IPSEC_API_INTEG_ALG_SHA1_96)
37 self.auth_algo = 'HMAC-SHA1-96' # scapy name
38 self.auth_key = 'C91KUR9GYMm5GfkEvNjX'
39
40 self.crypt_algo_vpp_id = (VppEnum.vl_api_ipsec_crypto_alg_t.
41 IPSEC_API_CRYPTO_ALG_AES_CBC_128)
42 self.crypt_algo = 'AES-CBC' # scapy name
43 self.crypt_key = 'JPjyOWBeVEQiMe7h'
Klement Sekera611864f2018-09-26 11:19:00 +020044
45
46class IPsecIPv6Params(object):
Neale Ranns17dcec02019-01-09 21:22:20 -080047
Klement Sekera611864f2018-09-26 11:19:00 +020048 addr_type = socket.AF_INET6
49 addr_any = "0::0"
50 addr_bcast = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
51 addr_len = 128
52 is_ipv6 = 1
Klement Sekera611864f2018-09-26 11:19:00 +020053
Neale Ranns17dcec02019-01-09 21:22:20 -080054 def __init__(self):
55 self.remote_tun_if_host = '1111:1111:1111:1111:1111:1111:1111:1111'
Klement Sekera611864f2018-09-26 11:19:00 +020056
Neale Ranns17dcec02019-01-09 21:22:20 -080057 self.scapy_tun_sa_id = 50
58 self.scapy_tun_spi = 3001
59 self.vpp_tun_sa_id = 60
60 self.vpp_tun_spi = 3000
Klement Sekera611864f2018-09-26 11:19:00 +020061
Neale Ranns17dcec02019-01-09 21:22:20 -080062 self.scapy_tra_sa_id = 70
63 self.scapy_tra_spi = 4001
64 self.vpp_tra_sa_id = 80
65 self.vpp_tra_spi = 4000
Klement Sekera611864f2018-09-26 11:19:00 +020066
Neale Ranns17dcec02019-01-09 21:22:20 -080067 self.auth_algo_vpp_id = (VppEnum.vl_api_ipsec_integ_alg_t.
68 IPSEC_API_INTEG_ALG_SHA_256_128)
69 self.auth_algo = 'SHA2-256-128' # scapy name
70 self.auth_key = 'C91KUR9GYMm5GfkEvNjX'
71
72 self.crypt_algo_vpp_id = (VppEnum.vl_api_ipsec_crypto_alg_t.
73 IPSEC_API_CRYPTO_ALG_AES_CBC_256)
74 self.crypt_algo = 'AES-CBC' # scapy name
75 self.crypt_key = 'JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h'
Klement Sekera611864f2018-09-26 11:19:00 +020076
77
Klement Sekera31da2e32018-06-24 22:49:55 +020078class TemplateIpsec(VppTestCase):
79 """
80 TRANSPORT MODE:
81
82 ------ encrypt ---
83 |tra_if| <-------> |VPP|
84 ------ decrypt ---
85
86 TUNNEL MODE:
87
88 ------ encrypt --- plain ---
89 |tun_if| <------- |VPP| <------ |pg1|
90 ------ --- ---
91
92 ------ decrypt --- plain ---
93 |tun_if| -------> |VPP| ------> |pg1|
94 ------ --- ---
95 """
96
Neale Ranns8e4a89b2019-01-23 08:16:17 -080097 def ipsec_select_backend(self):
Klement Sekerab4d30532018-11-08 13:00:02 +010098 """ empty method to be overloaded when necessary """
99 pass
100
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800101 def setUp(self):
102 super(TemplateIpsec, self).setUp()
103
104 self.ipv4_params = IPsecIPv4Params()
105 self.ipv6_params = IPsecIPv6Params()
106 self.params = {self.ipv4_params.addr_type: self.ipv4_params,
107 self.ipv6_params.addr_type: self.ipv6_params}
108
109 self.payload = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"\
110 "XXXXXXXXXXXXXXXXXXXXX"
111
112 self.tun_spd_id = 1
113 self.tra_spd_id = 2
114
Neale Ranns17dcec02019-01-09 21:22:20 -0800115 self.vpp_esp_protocol = (VppEnum.vl_api_ipsec_proto_t.
116 IPSEC_API_PROTO_ESP)
117 self.vpp_ah_protocol = (VppEnum.vl_api_ipsec_proto_t.
118 IPSEC_API_PROTO_AH)
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800119
120 self.create_pg_interfaces(range(3))
121 self.interfaces = list(self.pg_interfaces)
122 for i in self.interfaces:
Klement Sekera31da2e32018-06-24 22:49:55 +0200123 i.admin_up()
124 i.config_ip4()
125 i.resolve_arp()
Klement Sekera611864f2018-09-26 11:19:00 +0200126 i.config_ip6()
127 i.resolve_ndp()
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800128 self.ipsec_select_backend()
Klement Sekera31da2e32018-06-24 22:49:55 +0200129
130 def tearDown(self):
131 super(TemplateIpsec, self).tearDown()
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800132
133 for i in self.interfaces:
134 i.admin_down()
135 i.unconfig_ip4()
136 i.unconfig_ip6()
137
Klement Sekera31da2e32018-06-24 22:49:55 +0200138 if not self.vpp_dead:
139 self.vapi.cli("show hardware")
140
Klement Sekera31da2e32018-06-24 22:49:55 +0200141 def gen_encrypt_pkts(self, sa, sw_intf, src, dst, count=1):
142 return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
143 sa.encrypt(IP(src=src, dst=dst) / ICMP() / self.payload)
144 for i in range(count)]
145
Klement Sekera611864f2018-09-26 11:19:00 +0200146 def gen_encrypt_pkts6(self, sa, sw_intf, src, dst, count=1):
147 return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
148 sa.encrypt(IPv6(src=src, dst=dst) /
149 ICMPv6EchoRequest(id=0, seq=1, data=self.payload))
150 for i in range(count)]
151
Klement Sekera31da2e32018-06-24 22:49:55 +0200152 def gen_pkts(self, sw_intf, src, dst, count=1):
153 return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
154 IP(src=src, dst=dst) / ICMP() / self.payload
155 for i in range(count)]
156
Klement Sekera611864f2018-09-26 11:19:00 +0200157 def gen_pkts6(self, sw_intf, src, dst, count=1):
158 return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
159 IPv6(src=src, dst=dst) /
160 ICMPv6EchoRequest(id=0, seq=1, data=self.payload)
161 for i in range(count)]
162
163 def configure_sa_tun(self, params):
164 ip_class_by_addr_type = {socket.AF_INET: IP, socket.AF_INET6: IPv6}
165 scapy_tun_sa = SecurityAssociation(
166 self.encryption_type, spi=params.vpp_tun_spi,
167 crypt_algo=params.crypt_algo, crypt_key=params.crypt_key,
168 auth_algo=params.auth_algo, auth_key=params.auth_key,
169 tunnel_header=ip_class_by_addr_type[params.addr_type](
170 src=self.tun_if.remote_addr[params.addr_type],
171 dst=self.tun_if.local_addr[params.addr_type]))
172 vpp_tun_sa = SecurityAssociation(
173 self.encryption_type, spi=params.scapy_tun_spi,
174 crypt_algo=params.crypt_algo, crypt_key=params.crypt_key,
175 auth_algo=params.auth_algo, auth_key=params.auth_key,
176 tunnel_header=ip_class_by_addr_type[params.addr_type](
177 dst=self.tun_if.remote_addr[params.addr_type],
178 src=self.tun_if.local_addr[params.addr_type]))
Klement Sekera31da2e32018-06-24 22:49:55 +0200179 return vpp_tun_sa, scapy_tun_sa
180
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800181 def configure_sa_tra(self, params):
182 params.scapy_tra_sa = SecurityAssociation(self.encryption_type,
Neale Rannsde847272018-11-28 01:38:34 -0800183 spi=params.vpp_tra_spi,
184 crypt_algo=params.crypt_algo,
185 crypt_key=params.crypt_key,
186 auth_algo=params.auth_algo,
187 auth_key=params.auth_key)
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800188 params.vpp_tra_sa = SecurityAssociation(self.encryption_type,
Neale Rannsde847272018-11-28 01:38:34 -0800189 spi=params.scapy_tra_spi,
190 crypt_algo=params.crypt_algo,
191 crypt_key=params.crypt_key,
192 auth_algo=params.auth_algo,
193 auth_key=params.auth_key)
Klement Sekera31da2e32018-06-24 22:49:55 +0200194
195
196class IpsecTcpTests(object):
197 def test_tcp_checksum(self):
198 """ verify checksum correctness for vpp generated packets """
199 self.vapi.cli("test http server")
Klement Sekera611864f2018-09-26 11:19:00 +0200200 p = self.params[socket.AF_INET]
201 vpp_tun_sa, scapy_tun_sa = self.configure_sa_tun(p)
Klement Sekera31da2e32018-06-24 22:49:55 +0200202 send = (Ether(src=self.tun_if.remote_mac, dst=self.tun_if.local_mac) /
Klement Sekera611864f2018-09-26 11:19:00 +0200203 scapy_tun_sa.encrypt(IP(src=p.remote_tun_if_host,
Klement Sekera31da2e32018-06-24 22:49:55 +0200204 dst=self.tun_if.local_ip4) /
205 TCP(flags='S', dport=80)))
206 self.logger.debug(ppp("Sending packet:", send))
Klement Sekera611864f2018-09-26 11:19:00 +0200207 recv = self.send_and_expect(self.tun_if, [send], self.tun_if)
Klement Sekera31da2e32018-06-24 22:49:55 +0200208 recv = recv[0]
209 decrypted = vpp_tun_sa.decrypt(recv[IP])
210 self.assert_packet_checksums_valid(decrypted)
211
212
213class IpsecTraTests(object):
Neale Rannsde847272018-11-28 01:38:34 -0800214 def test_tra_anti_replay(self, count=1):
215 """ ipsec v4 transport anti-reply test """
216 p = self.params[socket.AF_INET]
217
218 # fire in a packet with seq number 1
219 pkt = (Ether(src=self.tra_if.remote_mac,
220 dst=self.tra_if.local_mac) /
221 p.scapy_tra_sa.encrypt(IP(src=self.tra_if.remote_ip4,
222 dst=self.tra_if.local_ip4) /
223 ICMP(),
224 seq_num=1))
225 recv_pkts = self.send_and_expect(self.tra_if, [pkt], self.tra_if)
226
227 # now move the window over to 235
228 pkt = (Ether(src=self.tra_if.remote_mac,
229 dst=self.tra_if.local_mac) /
230 p.scapy_tra_sa.encrypt(IP(src=self.tra_if.remote_ip4,
231 dst=self.tra_if.local_ip4) /
232 ICMP(),
233 seq_num=235))
234 recv_pkts = self.send_and_expect(self.tra_if, [pkt], self.tra_if)
235
236 # the window size is 64 packets
237 # in window are still accepted
238 pkt = (Ether(src=self.tra_if.remote_mac,
239 dst=self.tra_if.local_mac) /
240 p.scapy_tra_sa.encrypt(IP(src=self.tra_if.remote_ip4,
241 dst=self.tra_if.local_ip4) /
242 ICMP(),
243 seq_num=172))
244 recv_pkts = self.send_and_expect(self.tra_if, [pkt], self.tra_if)
245
246 # out of window are dropped
247 pkt = (Ether(src=self.tra_if.remote_mac,
248 dst=self.tra_if.local_mac) /
249 p.scapy_tra_sa.encrypt(IP(src=self.tra_if.remote_ip4,
250 dst=self.tra_if.local_ip4) /
251 ICMP(),
252 seq_num=17))
253 self.send_and_assert_no_replies(self.tra_if, pkt * 17)
254
Klement Sekera14d7e902018-12-10 13:46:09 +0100255 self.assert_packet_counter_equal(
256 '/err/%s/SA replayed packet' % self.tra4_decrypt_node_name, 17)
Neale Rannsde847272018-11-28 01:38:34 -0800257
258 # a packet that does not decrypt does not move the window forward
259 bogus_sa = SecurityAssociation(self.encryption_type,
260 p.vpp_tra_spi)
261 pkt = (Ether(src=self.tra_if.remote_mac,
262 dst=self.tra_if.local_mac) /
263 bogus_sa.encrypt(IP(src=self.tra_if.remote_ip4,
264 dst=self.tra_if.local_ip4) /
265 ICMP(),
266 seq_num=350))
267 self.send_and_assert_no_replies(self.tra_if, pkt * 17)
268
Klement Sekera14d7e902018-12-10 13:46:09 +0100269 self.assert_packet_counter_equal(
270 '/err/%s/Integrity check failed' % self.tra4_decrypt_node_name, 17)
Neale Rannsde847272018-11-28 01:38:34 -0800271
272 # which we can determine since this packet is still in the window
273 pkt = (Ether(src=self.tra_if.remote_mac,
274 dst=self.tra_if.local_mac) /
275 p.scapy_tra_sa.encrypt(IP(src=self.tra_if.remote_ip4,
276 dst=self.tra_if.local_ip4) /
277 ICMP(),
278 seq_num=234))
Klement Sekera14d7e902018-12-10 13:46:09 +0100279 self.send_and_expect(self.tra_if, [pkt], self.tra_if)
Neale Rannsde847272018-11-28 01:38:34 -0800280
281 # move the security-associations seq number on to the last we used
282 p.scapy_tra_sa.seq_num = 351
283 p.vpp_tra_sa.seq_num = 351
284
Klement Sekera31da2e32018-06-24 22:49:55 +0200285 def test_tra_basic(self, count=1):
286 """ ipsec v4 transport basic test """
Klement Sekera10d066e2018-11-13 11:12:57 +0100287 self.vapi.cli("clear errors")
Klement Sekera31da2e32018-06-24 22:49:55 +0200288 try:
Klement Sekera611864f2018-09-26 11:19:00 +0200289 p = self.params[socket.AF_INET]
Neale Rannsde847272018-11-28 01:38:34 -0800290 send_pkts = self.gen_encrypt_pkts(p.scapy_tra_sa, self.tra_if,
Klement Sekera31da2e32018-06-24 22:49:55 +0200291 src=self.tra_if.remote_ip4,
292 dst=self.tra_if.local_ip4,
293 count=count)
294 recv_pkts = self.send_and_expect(self.tra_if, send_pkts,
Klement Sekera611864f2018-09-26 11:19:00 +0200295 self.tra_if)
Neale Rannsde847272018-11-28 01:38:34 -0800296 for rx in recv_pkts:
Klement Sekera611864f2018-09-26 11:19:00 +0200297 try:
Neale Rannsde847272018-11-28 01:38:34 -0800298 decrypted = p.vpp_tra_sa.decrypt(rx[IP])
Klement Sekera611864f2018-09-26 11:19:00 +0200299 self.assert_packet_checksums_valid(decrypted)
300 except:
Neale Rannsde847272018-11-28 01:38:34 -0800301 self.logger.debug(ppp("Unexpected packet:", rx))
Klement Sekera611864f2018-09-26 11:19:00 +0200302 raise
Klement Sekera31da2e32018-06-24 22:49:55 +0200303 finally:
304 self.logger.info(self.vapi.ppcli("show error"))
305 self.logger.info(self.vapi.ppcli("show ipsec"))
306
Klement Sekera10d066e2018-11-13 11:12:57 +0100307 self.assert_packet_counter_equal(self.tra4_encrypt_node_name, count)
308 self.assert_packet_counter_equal(self.tra4_decrypt_node_name, count)
309
Klement Sekera31da2e32018-06-24 22:49:55 +0200310 def test_tra_burst(self):
311 """ ipsec v4 transport burst test """
Klement Sekera611864f2018-09-26 11:19:00 +0200312 self.test_tra_basic(count=257)
313
314 def test_tra_basic6(self, count=1):
315 """ ipsec v6 transport basic test """
Klement Sekera10d066e2018-11-13 11:12:57 +0100316 self.vapi.cli("clear errors")
Klement Sekera31da2e32018-06-24 22:49:55 +0200317 try:
Klement Sekera611864f2018-09-26 11:19:00 +0200318 p = self.params[socket.AF_INET6]
Neale Rannsde847272018-11-28 01:38:34 -0800319 send_pkts = self.gen_encrypt_pkts6(p.scapy_tra_sa, self.tra_if,
Klement Sekera611864f2018-09-26 11:19:00 +0200320 src=self.tra_if.remote_ip6,
321 dst=self.tra_if.local_ip6,
322 count=count)
323 recv_pkts = self.send_and_expect(self.tra_if, send_pkts,
324 self.tra_if)
Neale Rannsde847272018-11-28 01:38:34 -0800325 for rx in recv_pkts:
Klement Sekera611864f2018-09-26 11:19:00 +0200326 try:
Neale Rannsde847272018-11-28 01:38:34 -0800327 decrypted = p.vpp_tra_sa.decrypt(rx[IPv6])
Klement Sekera611864f2018-09-26 11:19:00 +0200328 self.assert_packet_checksums_valid(decrypted)
329 except:
Neale Rannsde847272018-11-28 01:38:34 -0800330 self.logger.debug(ppp("Unexpected packet:", rx))
Klement Sekera611864f2018-09-26 11:19:00 +0200331 raise
Klement Sekera31da2e32018-06-24 22:49:55 +0200332 finally:
333 self.logger.info(self.vapi.ppcli("show error"))
334 self.logger.info(self.vapi.ppcli("show ipsec"))
335
Klement Sekera10d066e2018-11-13 11:12:57 +0100336 self.assert_packet_counter_equal(self.tra6_encrypt_node_name, count)
337 self.assert_packet_counter_equal(self.tra6_decrypt_node_name, count)
338
Klement Sekera611864f2018-09-26 11:19:00 +0200339 def test_tra_burst6(self):
340 """ ipsec v6 transport burst test """
341 self.test_tra_basic6(count=257)
Klement Sekera31da2e32018-06-24 22:49:55 +0200342
Klement Sekera611864f2018-09-26 11:19:00 +0200343
344class IpsecTun4Tests(object):
345 def test_tun_basic44(self, count=1):
Klement Sekera31da2e32018-06-24 22:49:55 +0200346 """ ipsec 4o4 tunnel basic test """
Klement Sekera10d066e2018-11-13 11:12:57 +0100347 self.vapi.cli("clear errors")
Klement Sekera31da2e32018-06-24 22:49:55 +0200348 try:
Klement Sekera611864f2018-09-26 11:19:00 +0200349 p = self.params[socket.AF_INET]
350 vpp_tun_sa, scapy_tun_sa = self.configure_sa_tun(p)
Klement Sekera31da2e32018-06-24 22:49:55 +0200351 send_pkts = self.gen_encrypt_pkts(scapy_tun_sa, self.tun_if,
Klement Sekera611864f2018-09-26 11:19:00 +0200352 src=p.remote_tun_if_host,
Klement Sekera31da2e32018-06-24 22:49:55 +0200353 dst=self.pg1.remote_ip4,
354 count=count)
Klement Sekera611864f2018-09-26 11:19:00 +0200355 recv_pkts = self.send_and_expect(self.tun_if, send_pkts, self.pg1)
Klement Sekera31da2e32018-06-24 22:49:55 +0200356 for recv_pkt in recv_pkts:
Klement Sekera611864f2018-09-26 11:19:00 +0200357 self.assert_equal(recv_pkt[IP].src, p.remote_tun_if_host)
Klement Sekera31da2e32018-06-24 22:49:55 +0200358 self.assert_equal(recv_pkt[IP].dst, self.pg1.remote_ip4)
359 self.assert_packet_checksums_valid(recv_pkt)
360 send_pkts = self.gen_pkts(self.pg1, src=self.pg1.remote_ip4,
Klement Sekera611864f2018-09-26 11:19:00 +0200361 dst=p.remote_tun_if_host, count=count)
362 recv_pkts = self.send_and_expect(self.pg1, send_pkts, self.tun_if)
Klement Sekera31da2e32018-06-24 22:49:55 +0200363 for recv_pkt in recv_pkts:
Klement Sekera611864f2018-09-26 11:19:00 +0200364 try:
365 decrypt_pkt = vpp_tun_sa.decrypt(recv_pkt[IP])
366 if not decrypt_pkt.haslayer(IP):
367 decrypt_pkt = IP(decrypt_pkt[Raw].load)
368 self.assert_equal(decrypt_pkt.src, self.pg1.remote_ip4)
369 self.assert_equal(decrypt_pkt.dst, p.remote_tun_if_host)
370 self.assert_packet_checksums_valid(decrypt_pkt)
371 except:
372 self.logger.debug(ppp("Unexpected packet:", recv_pkt))
373 try:
374 self.logger.debug(
375 ppp("Decrypted packet:", decrypt_pkt))
376 except:
377 pass
378 raise
Klement Sekera31da2e32018-06-24 22:49:55 +0200379 finally:
380 self.logger.info(self.vapi.ppcli("show error"))
381 self.logger.info(self.vapi.ppcli("show ipsec"))
382
Klement Sekera10d066e2018-11-13 11:12:57 +0100383 self.assert_packet_counter_equal(self.tun4_encrypt_node_name, count)
384 self.assert_packet_counter_equal(self.tun4_decrypt_node_name, count)
385
Klement Sekera611864f2018-09-26 11:19:00 +0200386 def test_tun_burst44(self):
Klement Sekera31da2e32018-06-24 22:49:55 +0200387 """ ipsec 4o4 tunnel burst test """
Klement Sekera611864f2018-09-26 11:19:00 +0200388 self.test_tun_basic44(count=257)
389
390
391class IpsecTun6Tests(object):
392 def test_tun_basic66(self, count=1):
393 """ ipsec 6o6 tunnel basic test """
Klement Sekera10d066e2018-11-13 11:12:57 +0100394 self.vapi.cli("clear errors")
Klement Sekera31da2e32018-06-24 22:49:55 +0200395 try:
Klement Sekera611864f2018-09-26 11:19:00 +0200396 p = self.params[socket.AF_INET6]
397 vpp_tun_sa, scapy_tun_sa = self.configure_sa_tun(p)
398 send_pkts = self.gen_encrypt_pkts6(scapy_tun_sa, self.tun_if,
399 src=p.remote_tun_if_host,
400 dst=self.pg1.remote_ip6,
401 count=count)
402 recv_pkts = self.send_and_expect(self.tun_if, send_pkts, self.pg1)
403 for recv_pkt in recv_pkts:
404 self.assert_equal(recv_pkt[IPv6].src, p.remote_tun_if_host)
405 self.assert_equal(recv_pkt[IPv6].dst, self.pg1.remote_ip6)
406 self.assert_packet_checksums_valid(recv_pkt)
407 send_pkts = self.gen_pkts6(self.pg1, src=self.pg1.remote_ip6,
408 dst=p.remote_tun_if_host,
409 count=count)
410 recv_pkts = self.send_and_expect(self.pg1, send_pkts, self.tun_if)
411 for recv_pkt in recv_pkts:
412 try:
413 decrypt_pkt = vpp_tun_sa.decrypt(recv_pkt[IPv6])
414 if not decrypt_pkt.haslayer(IPv6):
415 decrypt_pkt = IPv6(decrypt_pkt[Raw].load)
416 self.assert_equal(decrypt_pkt.src, self.pg1.remote_ip6)
417 self.assert_equal(decrypt_pkt.dst, p.remote_tun_if_host)
418 self.assert_packet_checksums_valid(decrypt_pkt)
419 except:
420 self.logger.debug(ppp("Unexpected packet:", recv_pkt))
421 try:
422 self.logger.debug(
423 ppp("Decrypted packet:", decrypt_pkt))
424 except:
425 pass
426 raise
Klement Sekera31da2e32018-06-24 22:49:55 +0200427 finally:
428 self.logger.info(self.vapi.ppcli("show error"))
429 self.logger.info(self.vapi.ppcli("show ipsec"))
430
Klement Sekera10d066e2018-11-13 11:12:57 +0100431 self.assert_packet_counter_equal(self.tun6_encrypt_node_name, count)
432 self.assert_packet_counter_equal(self.tun6_decrypt_node_name, count)
433
Klement Sekera611864f2018-09-26 11:19:00 +0200434 def test_tun_burst66(self):
435 """ ipsec 6o6 tunnel burst test """
436 self.test_tun_basic66(count=257)
437
438
439class IpsecTunTests(IpsecTun4Tests, IpsecTun6Tests):
440 pass
441
Klement Sekera31da2e32018-06-24 22:49:55 +0200442
443if __name__ == '__main__':
444 unittest.main(testRunner=VppTestRunner)