import socket
import copy
-from scapy.layers.ipsec import ESP
-from scapy.layers.l2 import Ether, Raw, GRE
+from scapy.layers.ipsec import SecurityAssociation, ESP
+from scapy.layers.l2 import Ether, GRE, Dot1Q
+from scapy.packet import Raw
from scapy.layers.inet import IP, UDP
from scapy.layers.inet6 import IPv6
from framework import VppTestRunner
from template_ipsec import TemplateIpsec, IpsecTun4Tests, IpsecTun6Tests, \
- IpsecTun4, IpsecTun6, IpsecTcpTests, config_tun_params
+ IpsecTun4, IpsecTun6, IpsecTcpTests, mk_scapy_crypt_key, \
+ IpsecTun6HandoffTests, IpsecTun4HandoffTests, config_tun_params
from vpp_ipsec_tun_interface import VppIpsecTunInterface
from vpp_gre_interface import VppGreInterface
from vpp_ipip_tun_interface import VppIpIpTunInterface
from vpp_ip_route import VppIpRoute, VppRoutePath, DpoProto
from vpp_ipsec import VppIpsecSA, VppIpsecTunProtect
from vpp_l2 import VppBridgeDomain, VppBridgeDomainPort
+from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint
from util import ppp
from vpp_papi import VppEnum
+def config_tun_params(p, encryption_type, tun_if):
+ ip_class_by_addr_type = {socket.AF_INET: IP, socket.AF_INET6: IPv6}
+ esn_en = bool(p.flags & (VppEnum.vl_api_ipsec_sad_flags_t.
+ IPSEC_API_SAD_FLAG_USE_ESN))
+ crypt_key = mk_scapy_crypt_key(p)
+ p.tun_dst = tun_if.remote_ip
+ p.tun_src = tun_if.local_ip
+ p.scapy_tun_sa = SecurityAssociation(
+ encryption_type, spi=p.vpp_tun_spi,
+ crypt_algo=p.crypt_algo,
+ crypt_key=crypt_key,
+ auth_algo=p.auth_algo, auth_key=p.auth_key,
+ tunnel_header=ip_class_by_addr_type[p.addr_type](
+ src=p.tun_dst,
+ dst=p.tun_src),
+ nat_t_header=p.nat_header,
+ esn_en=esn_en)
+ p.vpp_tun_sa = SecurityAssociation(
+ encryption_type, spi=p.scapy_tun_spi,
+ crypt_algo=p.crypt_algo,
+ crypt_key=crypt_key,
+ auth_algo=p.auth_algo, auth_key=p.auth_key,
+ tunnel_header=ip_class_by_addr_type[p.addr_type](
+ dst=p.tun_dst,
+ src=p.tun_src),
+ nat_t_header=p.nat_header,
+ esn_en=esn_en)
+
+
+def config_tra_params(p, encryption_type, tun_if):
+ ip_class_by_addr_type = {socket.AF_INET: IP, socket.AF_INET6: IPv6}
+ esn_en = bool(p.flags & (VppEnum.vl_api_ipsec_sad_flags_t.
+ IPSEC_API_SAD_FLAG_USE_ESN))
+ crypt_key = mk_scapy_crypt_key(p)
+ p.tun_dst = tun_if.remote_ip
+ p.tun_src = tun_if.local_ip
+ p.scapy_tun_sa = SecurityAssociation(
+ encryption_type, spi=p.vpp_tun_spi,
+ crypt_algo=p.crypt_algo,
+ crypt_key=crypt_key,
+ auth_algo=p.auth_algo, auth_key=p.auth_key,
+ esn_en=esn_en)
+ p.vpp_tun_sa = SecurityAssociation(
+ encryption_type, spi=p.scapy_tun_spi,
+ crypt_algo=p.crypt_algo,
+ crypt_key=crypt_key,
+ auth_algo=p.auth_algo, auth_key=p.auth_key,
+ esn_en=esn_en)
+
+
class TemplateIpsec4TunIfEsp(TemplateIpsec):
""" IPsec tunnel interface tests """
p.tun_if.admin_up()
p.tun_if.config_ip4()
p.tun_if.config_ip6()
+ config_tun_params(p, self.encryption_type, p.tun_if)
r = VppIpRoute(self, p.remote_tun_if_host, 32,
[VppRoutePath(p.tun_if.remote_ip4,
""" IPsec UDP tunnel interface tests """
tun4_encrypt_node_name = "esp4-encrypt-tun"
- tun4_decrypt_node_name = "esp4-decrypt"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
encryption_type = ESP
@classmethod
p.tun_if.admin_up()
p.tun_if.config_ip4()
p.tun_if.config_ip6()
+ config_tun_params(p, self.encryption_type, p.tun_if)
r = VppIpRoute(self, p.remote_tun_if_host, 32,
[VppRoutePath(p.tun_if.remote_ip4,
class TestIpsec4TunIfEsp1(TemplateIpsec4TunIfEsp, IpsecTun4Tests):
""" Ipsec ESP - TUN tests """
tun4_encrypt_node_name = "esp4-encrypt-tun"
- tun4_decrypt_node_name = "esp4-decrypt"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
def test_tun_basic64(self):
""" ipsec 6o4 tunnel basic test """
- self.tun4_encrypt_node_name = "esp6-encrypt-tun"
+ self.tun4_encrypt_node_name = "esp4-encrypt-tun"
self.verify_tun_64(self.params[socket.AF_INET], count=1)
def test_tun_burst64(self):
""" ipsec 6o4 tunnel basic test """
- self.tun4_encrypt_node_name = "esp6-encrypt-tun"
+ self.tun4_encrypt_node_name = "esp4-encrypt-tun"
self.verify_tun_64(self.params[socket.AF_INET], count=257)
class TestIpsec4TunIfEspUdp(TemplateIpsec4TunIfEspUdp, IpsecTun4Tests):
""" Ipsec ESP UDP tests """
- tun4_input_node = "ipsec4-if-input"
+ tun4_input_node = "ipsec4-tun-input"
def test_keepalive(self):
""" IPSEC NAT Keepalive """
self.tun_if = self.pg0
p = self.ipv6_params
- tun_if = VppIpsecTunInterface(self, self.pg0, p.vpp_tun_spi,
- p.scapy_tun_spi, p.crypt_algo_vpp_id,
- p.crypt_key, p.crypt_key,
- p.auth_algo_vpp_id, p.auth_key,
- p.auth_key, is_ip6=True)
- tun_if.add_vpp_config()
- tun_if.admin_up()
- tun_if.config_ip6()
- tun_if.config_ip4()
+ p.tun_if = VppIpsecTunInterface(self, self.pg0, p.vpp_tun_spi,
+ p.scapy_tun_spi, p.crypt_algo_vpp_id,
+ p.crypt_key, p.crypt_key,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.auth_key, is_ip6=True)
+ p.tun_if.add_vpp_config()
+ p.tun_if.admin_up()
+ p.tun_if.config_ip6()
+ p.tun_if.config_ip4()
+ config_tun_params(p, self.encryption_type, p.tun_if)
r = VppIpRoute(self, p.remote_tun_if_host, 128,
- [VppRoutePath(tun_if.remote_ip6,
+ [VppRoutePath(p.tun_if.remote_ip6,
0xffffffff,
proto=DpoProto.DPO_PROTO_IP6)])
r.add_vpp_config()
r = VppIpRoute(self, p.remote_tun_if_host4, 32,
- [VppRoutePath(tun_if.remote_ip4,
+ [VppRoutePath(p.tun_if.remote_ip4,
0xffffffff)])
r.add_vpp_config()
super(TemplateIpsec6TunIfEsp, self).tearDown()
-class TestIpsec6TunIfEsp1(TemplateIpsec6TunIfEsp, IpsecTun6Tests):
+class TestIpsec6TunIfEsp1(TemplateIpsec6TunIfEsp,
+ IpsecTun6Tests):
""" Ipsec ESP - TUN tests """
tun6_encrypt_node_name = "esp6-encrypt-tun"
- tun6_decrypt_node_name = "esp6-decrypt"
+ tun6_decrypt_node_name = "esp6-decrypt-tun"
def test_tun_basic46(self):
""" ipsec 4o6 tunnel basic test """
- self.tun6_encrypt_node_name = "esp4-encrypt-tun"
+ self.tun6_encrypt_node_name = "esp6-encrypt-tun"
self.verify_tun_46(self.params[socket.AF_INET6], count=1)
def test_tun_burst46(self):
""" ipsec 4o6 tunnel burst test """
- self.tun6_encrypt_node_name = "esp4-encrypt-tun"
+ self.tun6_encrypt_node_name = "esp6-encrypt-tun"
self.verify_tun_46(self.params[socket.AF_INET6], count=257)
+class TestIpsec6TunIfEspHandoff(TemplateIpsec6TunIfEsp,
+ IpsecTun6HandoffTests):
+ """ Ipsec ESP 6 Handoff tests """
+ tun6_encrypt_node_name = "esp6-encrypt-tun"
+ tun6_decrypt_node_name = "esp6-decrypt-tun"
+
+
+class TestIpsec4TunIfEspHandoff(TemplateIpsec4TunIfEsp,
+ IpsecTun4HandoffTests):
+ """ Ipsec ESP 4 Handoff tests """
+ tun4_encrypt_node_name = "esp4-encrypt-tun"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
+
+
class TestIpsec4MultiTunIfEsp(TemplateIpsec, IpsecTun4):
""" IPsec IPv4 Multi Tunnel interface """
encryption_type = ESP
tun4_encrypt_node_name = "esp4-encrypt-tun"
- tun4_decrypt_node_name = "esp4-decrypt"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
def setUp(self):
super(TestIpsec4MultiTunIfEsp, self).setUp()
self.tun_if = self.pg0
self.multi_params = []
+ self.pg0.generate_remote_hosts(10)
+ self.pg0.configure_ipv4_neighbors()
for ii in range(10):
p = copy.copy(self.ipv4_params)
p.scapy_tra_spi = p.scapy_tra_spi + ii
p.vpp_tra_sa_id = p.vpp_tra_sa_id + ii
p.vpp_tra_spi = p.vpp_tra_spi + ii
-
- config_tun_params(p, self.encryption_type, self.tun_if)
- self.multi_params.append(p)
+ p.tun_dst = self.pg0.remote_hosts[ii].ip4
p.tun_if = VppIpsecTunInterface(self, self.pg0, p.vpp_tun_spi,
p.scapy_tun_spi,
p.crypt_algo_vpp_id,
p.crypt_key, p.crypt_key,
p.auth_algo_vpp_id, p.auth_key,
- p.auth_key)
+ p.auth_key,
+ dst=p.tun_dst)
p.tun_if.add_vpp_config()
p.tun_if.admin_up()
p.tun_if.config_ip4()
+ config_tun_params(p, self.encryption_type, p.tun_if)
+ self.multi_params.append(p)
VppIpRoute(self, p.remote_tun_if_host, 32,
[VppRoutePath(p.tun_if.remote_ip4,
c = p.tun_if.get_tx_stats()
self.assertEqual(c['packets'], 127)
+ def test_tun_rr_44(self):
+ """ Round-robin packets acrros multiple interface """
+ tx = []
+ for p in self.multi_params:
+ tx = tx + self.gen_encrypt_pkts(p.scapy_tun_sa, self.tun_if,
+ src=p.remote_tun_if_host,
+ dst=self.pg1.remote_ip4)
+ rxs = self.send_and_expect(self.tun_if, tx, self.pg1)
+
+ for rx, p in zip(rxs, self.multi_params):
+ self.verify_decrypted(p, [rx])
+
+ tx = []
+ for p in self.multi_params:
+ tx = tx + self.gen_pkts(self.pg1, src=self.pg1.remote_ip4,
+ dst=p.remote_tun_if_host)
+ rxs = self.send_and_expect(self.pg1, tx, self.tun_if)
+
+ for rx, p in zip(rxs, self.multi_params):
+ self.verify_encrypted(p, p.vpp_tun_sa, [rx])
+
class TestIpsec4TunIfEspAll(TemplateIpsec, IpsecTun4):
""" IPsec IPv4 Tunnel interface all Algos """
encryption_type = ESP
tun4_encrypt_node_name = "esp4-encrypt-tun"
- tun4_decrypt_node_name = "esp4-decrypt"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
def config_network(self, p):
- config_tun_params(p, self.encryption_type, self.tun_if)
p.tun_if = VppIpsecTunInterface(self, self.pg0, p.vpp_tun_spi,
p.scapy_tun_spi,
p.tun_if.add_vpp_config()
p.tun_if.admin_up()
p.tun_if.config_ip4()
+ config_tun_params(p, self.encryption_type, p.tun_if)
self.logger.info(self.vapi.cli("sh ipsec sa 0"))
self.logger.info(self.vapi.cli("sh ipsec sa 1"))
#
# change the key and the SPI
#
- p.crypt_key = 'X' + p.crypt_key[1:]
+ p.crypt_key = b'X' + p.crypt_key[1:]
p.scapy_tun_spi += 1
p.scapy_tun_sa_id += 1
p.vpp_tun_spi += 1
p.tun_if.local_spi = p.vpp_tun_spi
p.tun_if.remote_spi = p.scapy_tun_spi
- config_tun_params(p, self.encryption_type, self.tun_if)
+ config_tun_params(p, self.encryption_type, p.tun_if)
p.tun_sa_in = VppIpsecSA(self,
p.scapy_tun_sa_id,
p.crypt_algo_vpp_id,
p.crypt_key,
self.vpp_esp_protocol,
- self.tun_if.local_addr[p.addr_type],
- self.tun_if.remote_addr[p.addr_type],
flags=p.flags,
salt=p.salt)
p.tun_sa_out = VppIpsecSA(self,
p.crypt_algo_vpp_id,
p.crypt_key,
self.vpp_esp_protocol,
- self.tun_if.remote_addr[p.addr_type],
- self.tun_if.local_addr[p.addr_type],
flags=p.flags,
salt=p.salt)
p.tun_sa_in.add_vpp_config()
IPSEC_API_INTEG_ALG_NONE),
'scapy-crypto': "AES-GCM",
'scapy-integ': "NULL",
- 'key': "JPjyOWBeVEQiMe7h",
+ 'key': b"JPjyOWBeVEQiMe7h",
'salt': 3333},
{'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
IPSEC_API_CRYPTO_ALG_AES_GCM_192),
IPSEC_API_INTEG_ALG_NONE),
'scapy-crypto': "AES-GCM",
'scapy-integ': "NULL",
- 'key': "JPjyOWBeVEQiMe7hJPjyOWBe",
+ 'key': b"JPjyOWBeVEQiMe7hJPjyOWBe",
'salt': 0},
{'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
IPSEC_API_CRYPTO_ALG_AES_GCM_256),
IPSEC_API_INTEG_ALG_NONE),
'scapy-crypto': "AES-GCM",
'scapy-integ': "NULL",
- 'key': "JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h",
+ 'key': b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h",
'salt': 9999},
{'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
IPSEC_API_CRYPTO_ALG_AES_CBC_128),
'scapy-crypto': "AES-CBC",
'scapy-integ': "HMAC-SHA1-96",
'salt': 0,
- 'key': "JPjyOWBeVEQiMe7h"},
+ 'key': b"JPjyOWBeVEQiMe7h"},
{'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
IPSEC_API_CRYPTO_ALG_AES_CBC_192),
'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
'scapy-crypto': "AES-CBC",
'scapy-integ': "HMAC-SHA1-96",
'salt': 0,
- 'key': "JPjyOWBeVEQiMe7hJPjyOWBe"},
+ 'key': b"JPjyOWBeVEQiMe7hJPjyOWBe"},
{'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
IPSEC_API_CRYPTO_ALG_AES_CBC_256),
'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
'scapy-crypto': "AES-CBC",
'scapy-integ': "HMAC-SHA1-96",
'salt': 0,
- 'key': "JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"},
+ 'key': b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"},
{'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
IPSEC_API_CRYPTO_ALG_NONE),
'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
'scapy-crypto': "NULL",
'scapy-integ': "HMAC-SHA1-96",
'salt': 0,
- 'key': "JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"}]
+ 'key': b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"}]
for engine in engines:
self.vapi.cli("set crypto handler all %s" % engine)
p.tun_sa_in.remove_vpp_config()
+class TestIpsec4TunIfEspNoAlgo(TemplateIpsec, IpsecTun4):
+ """ IPsec IPv4 Tunnel interface all Algos """
+
+ encryption_type = ESP
+ tun4_encrypt_node_name = "esp4-encrypt-tun"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
+
+ def config_network(self, p):
+
+ p.auth_algo_vpp_id = (VppEnum.vl_api_ipsec_integ_alg_t.
+ IPSEC_API_INTEG_ALG_NONE)
+ p.auth_algo = 'NULL'
+ p.auth_key = []
+
+ p.crypt_algo_vpp_id = (VppEnum.vl_api_ipsec_crypto_alg_t.
+ IPSEC_API_CRYPTO_ALG_NONE)
+ p.crypt_algo = 'NULL'
+ p.crypt_key = []
+
+ p.tun_if = VppIpsecTunInterface(self, self.pg0, p.vpp_tun_spi,
+ p.scapy_tun_spi,
+ p.crypt_algo_vpp_id,
+ p.crypt_key, p.crypt_key,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.auth_key,
+ salt=p.salt)
+ p.tun_if.add_vpp_config()
+ p.tun_if.admin_up()
+ p.tun_if.config_ip4()
+ config_tun_params(p, self.encryption_type, p.tun_if)
+ self.logger.info(self.vapi.cli("sh ipsec sa 0"))
+ self.logger.info(self.vapi.cli("sh ipsec sa 1"))
+
+ p.route = VppIpRoute(self, p.remote_tun_if_host, 32,
+ [VppRoutePath(p.tun_if.remote_ip4,
+ 0xffffffff)])
+ p.route.add_vpp_config()
+
+ def unconfig_network(self, p):
+ p.tun_if.unconfig_ip4()
+ p.tun_if.remove_vpp_config()
+ p.route.remove_vpp_config()
+
+ def setUp(self):
+ super(TestIpsec4TunIfEspNoAlgo, self).setUp()
+
+ self.tun_if = self.pg0
+
+ def tearDown(self):
+ super(TestIpsec4TunIfEspNoAlgo, self).tearDown()
+
+ def test_tun_44(self):
+ p = self.ipv4_params
+
+ self.config_network(p)
+
+ tx = self.gen_pkts(self.pg1, src=self.pg1.remote_ip4,
+ dst=p.remote_tun_if_host)
+ self.send_and_assert_no_replies(self.pg1, tx)
+
+ self.unconfig_network(p)
+
+
class TestIpsec6MultiTunIfEsp(TemplateIpsec, IpsecTun6):
""" IPsec IPv6 Multi Tunnel interface """
encryption_type = ESP
tun6_encrypt_node_name = "esp6-encrypt-tun"
- tun6_decrypt_node_name = "esp6-decrypt"
+ tun6_decrypt_node_name = "esp6-decrypt-tun"
def setUp(self):
super(TestIpsec6MultiTunIfEsp, self).setUp()
self.tun_if = self.pg0
self.multi_params = []
+ self.pg0.generate_remote_hosts(10)
+ self.pg0.configure_ipv6_neighbors()
for ii in range(10):
p = copy.copy(self.ipv6_params)
p.vpp_tra_sa_id = p.vpp_tra_sa_id + ii
p.vpp_tra_spi = p.vpp_tra_spi + ii
- config_tun_params(p, self.encryption_type, self.tun_if)
- self.multi_params.append(p)
+ p.tun_if = VppIpsecTunInterface(self, self.pg0, p.vpp_tun_spi,
+ p.scapy_tun_spi,
+ p.crypt_algo_vpp_id,
+ p.crypt_key, p.crypt_key,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.auth_key, is_ip6=True,
+ dst=self.pg0.remote_hosts[ii].ip6)
+ p.tun_if.add_vpp_config()
+ p.tun_if.admin_up()
+ p.tun_if.config_ip6()
+ config_tun_params(p, self.encryption_type, p.tun_if)
+ self.multi_params.append(p)
+
+ r = VppIpRoute(self, p.remote_tun_if_host, 128,
+ [VppRoutePath(p.tun_if.remote_ip6,
+ 0xffffffff,
+ proto=DpoProto.DPO_PROTO_IP6)])
+ r.add_vpp_config()
+
+ def tearDown(self):
+ super(TestIpsec6MultiTunIfEsp, self).tearDown()
+
+ def test_tun_66(self):
+ """Multiple IPSEC tunnel interfaces """
+ for p in self.multi_params:
+ self.verify_tun_66(p, count=127)
+ c = p.tun_if.get_rx_stats()
+ self.assertEqual(c['packets'], 127)
+ c = p.tun_if.get_tx_stats()
+ self.assertEqual(c['packets'], 127)
+
+
+class TestIpsecGreTebIfEsp(TemplateIpsec,
+ IpsecTun4Tests):
+ """ Ipsec GRE TEB ESP - TUN tests """
+ tun4_encrypt_node_name = "esp4-encrypt-tun"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
+ encryption_type = ESP
+ omac = "00:11:22:33:44:55"
+
+ def gen_encrypt_pkts(self, sa, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ sa.encrypt(IP(src=self.pg0.remote_ip4,
+ dst=self.pg0.local_ip4) /
+ GRE() /
+ Ether(dst=self.omac) /
+ IP(src="1.1.1.1", dst="1.1.1.2") /
+ UDP(sport=1144, dport=2233) /
+ Raw(b'X' * payload_size))
+ for i in range(count)]
+
+ def gen_pkts(self, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(dst=self.omac) /
+ IP(src="1.1.1.1", dst="1.1.1.2") /
+ UDP(sport=1144, dport=2233) /
+ Raw(b'X' * payload_size)
+ for i in range(count)]
+
+ def verify_decrypted(self, p, rxs):
+ for rx in rxs:
+ self.assert_equal(rx[Ether].dst, self.omac)
+ self.assert_equal(rx[IP].dst, "1.1.1.2")
+
+ def verify_encrypted(self, p, sa, rxs):
+ for rx in rxs:
+ try:
+ pkt = sa.decrypt(rx[IP])
+ if not pkt.haslayer(IP):
+ pkt = IP(pkt[Raw].load)
+ self.assert_packet_checksums_valid(pkt)
+ self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
+ self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
+ self.assertTrue(pkt.haslayer(GRE))
+ e = pkt[Ether]
+ self.assertEqual(e[Ether].dst, self.omac)
+ self.assertEqual(e[IP].dst, "1.1.1.2")
+ except (IndexError, AssertionError):
+ self.logger.debug(ppp("Unexpected packet:", rx))
+ try:
+ self.logger.debug(ppp("Decrypted packet:", pkt))
+ except:
+ pass
+ raise
+
+ def setUp(self):
+ super(TestIpsecGreTebIfEsp, self).setUp()
+
+ self.tun_if = self.pg0
+
+ p = self.ipv4_params
+
+ bd1 = VppBridgeDomain(self, 1)
+ bd1.add_vpp_config()
+
+ p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol,
+ self.pg0.local_ip4,
+ self.pg0.remote_ip4)
+ p.tun_sa_out.add_vpp_config()
+
+ p.tun_sa_in = VppIpsecSA(self, p.vpp_tun_sa_id, p.vpp_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol,
+ self.pg0.remote_ip4,
+ self.pg0.local_ip4)
+ p.tun_sa_in.add_vpp_config()
+
+ p.tun_if = VppGreInterface(self,
+ self.pg0.local_ip4,
+ self.pg0.remote_ip4,
+ type=(VppEnum.vl_api_gre_tunnel_type_t.
+ GRE_API_TUNNEL_TYPE_TEB))
+ p.tun_if.add_vpp_config()
+
+ p.tun_protect = VppIpsecTunProtect(self,
+ p.tun_if,
+ p.tun_sa_out,
+ [p.tun_sa_in])
+
+ p.tun_protect.add_vpp_config()
+
+ p.tun_if.admin_up()
+ p.tun_if.config_ip4()
+ config_tun_params(p, self.encryption_type, p.tun_if)
+
+ VppBridgeDomainPort(self, bd1, p.tun_if).add_vpp_config()
+ VppBridgeDomainPort(self, bd1, self.pg1).add_vpp_config()
+
+ self.vapi.cli("clear ipsec sa")
+
+ def tearDown(self):
+ p = self.ipv4_params
+ p.tun_if.unconfig_ip4()
+ super(TestIpsecGreTebIfEsp, self).tearDown()
+
+
+class TestIpsecGreTebVlanIfEsp(TemplateIpsec,
+ IpsecTun4Tests):
+ """ Ipsec GRE TEB ESP - TUN tests """
+ tun4_encrypt_node_name = "esp4-encrypt-tun"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
+ encryption_type = ESP
+ omac = "00:11:22:33:44:55"
+
+ def gen_encrypt_pkts(self, sa, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ sa.encrypt(IP(src=self.pg0.remote_ip4,
+ dst=self.pg0.local_ip4) /
+ GRE() /
+ Ether(dst=self.omac) /
+ IP(src="1.1.1.1", dst="1.1.1.2") /
+ UDP(sport=1144, dport=2233) /
+ Raw(b'X' * payload_size))
+ for i in range(count)]
+
+ def gen_pkts(self, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(dst=self.omac) /
+ Dot1Q(vlan=11) /
+ IP(src="1.1.1.1", dst="1.1.1.2") /
+ UDP(sport=1144, dport=2233) /
+ Raw(b'X' * payload_size)
+ for i in range(count)]
+
+ def verify_decrypted(self, p, rxs):
+ for rx in rxs:
+ self.assert_equal(rx[Ether].dst, self.omac)
+ self.assert_equal(rx[Dot1Q].vlan, 11)
+ self.assert_equal(rx[IP].dst, "1.1.1.2")
+
+ def verify_encrypted(self, p, sa, rxs):
+ for rx in rxs:
+ try:
+ pkt = sa.decrypt(rx[IP])
+ if not pkt.haslayer(IP):
+ pkt = IP(pkt[Raw].load)
+ self.assert_packet_checksums_valid(pkt)
+ self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
+ self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
+ self.assertTrue(pkt.haslayer(GRE))
+ e = pkt[Ether]
+ self.assertEqual(e[Ether].dst, self.omac)
+ self.assertFalse(e.haslayer(Dot1Q))
+ self.assertEqual(e[IP].dst, "1.1.1.2")
+ except (IndexError, AssertionError):
+ self.logger.debug(ppp("Unexpected packet:", rx))
+ try:
+ self.logger.debug(ppp("Decrypted packet:", pkt))
+ except:
+ pass
+ raise
+
+ def setUp(self):
+ super(TestIpsecGreTebVlanIfEsp, self).setUp()
+
+ self.tun_if = self.pg0
+
+ p = self.ipv4_params
+
+ bd1 = VppBridgeDomain(self, 1)
+ bd1.add_vpp_config()
+
+ self.pg1_11 = VppDot1QSubint(self, self.pg1, 11)
+ self.vapi.l2_interface_vlan_tag_rewrite(
+ sw_if_index=self.pg1_11.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1,
+ push_dot1q=11)
+ self.pg1_11.admin_up()
+
+ p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol,
+ self.pg0.local_ip4,
+ self.pg0.remote_ip4)
+ p.tun_sa_out.add_vpp_config()
+
+ p.tun_sa_in = VppIpsecSA(self, p.vpp_tun_sa_id, p.vpp_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol,
+ self.pg0.remote_ip4,
+ self.pg0.local_ip4)
+ p.tun_sa_in.add_vpp_config()
+
+ p.tun_if = VppGreInterface(self,
+ self.pg0.local_ip4,
+ self.pg0.remote_ip4,
+ type=(VppEnum.vl_api_gre_tunnel_type_t.
+ GRE_API_TUNNEL_TYPE_TEB))
+ p.tun_if.add_vpp_config()
+
+ p.tun_protect = VppIpsecTunProtect(self,
+ p.tun_if,
+ p.tun_sa_out,
+ [p.tun_sa_in])
+
+ p.tun_protect.add_vpp_config()
+
+ p.tun_if.admin_up()
+ p.tun_if.config_ip4()
+ config_tun_params(p, self.encryption_type, p.tun_if)
+
+ VppBridgeDomainPort(self, bd1, p.tun_if).add_vpp_config()
+ VppBridgeDomainPort(self, bd1, self.pg1_11).add_vpp_config()
+
+ self.vapi.cli("clear ipsec sa")
+
+ def tearDown(self):
+ p = self.ipv4_params
+ p.tun_if.unconfig_ip4()
+ super(TestIpsecGreTebVlanIfEsp, self).tearDown()
+ self.pg1_11.admin_down()
+ self.pg1_11.remove_vpp_config()
+
+
+class TestIpsecGreTebIfEspTra(TemplateIpsec,
+ IpsecTun4Tests):
+ """ Ipsec GRE TEB ESP - Tra tests """
+ tun4_encrypt_node_name = "esp4-encrypt-tun"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
+ encryption_type = ESP
+ omac = "00:11:22:33:44:55"
+
+ def gen_encrypt_pkts(self, sa, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ sa.encrypt(IP(src=self.pg0.remote_ip4,
+ dst=self.pg0.local_ip4) /
+ GRE() /
+ Ether(dst=self.omac) /
+ IP(src="1.1.1.1", dst="1.1.1.2") /
+ UDP(sport=1144, dport=2233) /
+ Raw(b'X' * payload_size))
+ for i in range(count)]
+
+ def gen_pkts(self, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(dst=self.omac) /
+ IP(src="1.1.1.1", dst="1.1.1.2") /
+ UDP(sport=1144, dport=2233) /
+ Raw(b'X' * payload_size)
+ for i in range(count)]
+
+ def verify_decrypted(self, p, rxs):
+ for rx in rxs:
+ self.assert_equal(rx[Ether].dst, self.omac)
+ self.assert_equal(rx[IP].dst, "1.1.1.2")
+
+ def verify_encrypted(self, p, sa, rxs):
+ for rx in rxs:
+ try:
+ pkt = sa.decrypt(rx[IP])
+ if not pkt.haslayer(IP):
+ pkt = IP(pkt[Raw].load)
+ self.assert_packet_checksums_valid(pkt)
+ self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
+ self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
+ self.assertTrue(pkt.haslayer(GRE))
+ e = pkt[Ether]
+ self.assertEqual(e[Ether].dst, self.omac)
+ self.assertEqual(e[IP].dst, "1.1.1.2")
+ except (IndexError, AssertionError):
+ self.logger.debug(ppp("Unexpected packet:", rx))
+ try:
+ self.logger.debug(ppp("Decrypted packet:", pkt))
+ except:
+ pass
+ raise
+
+ def setUp(self):
+ super(TestIpsecGreTebIfEspTra, self).setUp()
+
+ self.tun_if = self.pg0
+
+ p = self.ipv4_params
+
+ bd1 = VppBridgeDomain(self, 1)
+ bd1.add_vpp_config()
+
+ p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol)
+ p.tun_sa_out.add_vpp_config()
+
+ p.tun_sa_in = VppIpsecSA(self, p.vpp_tun_sa_id, p.vpp_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol)
+ p.tun_sa_in.add_vpp_config()
+
+ p.tun_if = VppGreInterface(self,
+ self.pg0.local_ip4,
+ self.pg0.remote_ip4,
+ type=(VppEnum.vl_api_gre_tunnel_type_t.
+ GRE_API_TUNNEL_TYPE_TEB))
+ p.tun_if.add_vpp_config()
+
+ p.tun_protect = VppIpsecTunProtect(self,
+ p.tun_if,
+ p.tun_sa_out,
+ [p.tun_sa_in])
+
+ p.tun_protect.add_vpp_config()
- p.tun_if = VppIpsecTunInterface(self, self.pg0, p.vpp_tun_spi,
- p.scapy_tun_spi,
- p.crypt_algo_vpp_id,
- p.crypt_key, p.crypt_key,
- p.auth_algo_vpp_id, p.auth_key,
- p.auth_key, is_ip6=True)
- p.tun_if.add_vpp_config()
- p.tun_if.admin_up()
- p.tun_if.config_ip6()
+ p.tun_if.admin_up()
+ p.tun_if.config_ip4()
+ config_tra_params(p, self.encryption_type, p.tun_if)
- r = VppIpRoute(self, p.remote_tun_if_host, 128,
- [VppRoutePath(p.tun_if.remote_ip6,
- 0xffffffff,
- proto=DpoProto.DPO_PROTO_IP6)])
- r.add_vpp_config()
+ VppBridgeDomainPort(self, bd1, p.tun_if).add_vpp_config()
+ VppBridgeDomainPort(self, bd1, self.pg1).add_vpp_config()
- def tearDown(self):
- super(TestIpsec6MultiTunIfEsp, self).tearDown()
+ self.vapi.cli("clear ipsec sa")
- def test_tun_66(self):
- """Multiple IPSEC tunnel interfaces """
- for p in self.multi_params:
- self.verify_tun_66(p, count=127)
- c = p.tun_if.get_rx_stats()
- self.assertEqual(c['packets'], 127)
- c = p.tun_if.get_tx_stats()
- self.assertEqual(c['packets'], 127)
+ def tearDown(self):
+ p = self.ipv4_params
+ p.tun_if.unconfig_ip4()
+ super(TestIpsecGreTebIfEspTra, self).tearDown()
-class TestIpsecGreTebIfEsp(TemplateIpsec,
- IpsecTun4Tests):
- """ Ipsec GRE TEB ESP - TUN tests """
+class TestIpsecGreIfEsp(TemplateIpsec,
+ IpsecTun4Tests):
+ """ Ipsec GRE ESP - TUN tests """
tun4_encrypt_node_name = "esp4-encrypt-tun"
tun4_decrypt_node_name = "esp4-decrypt-tun"
encryption_type = ESP
- omac = "00:11:22:33:44:55"
def gen_encrypt_pkts(self, sa, sw_intf, src, dst, count=1,
payload_size=100):
sa.encrypt(IP(src=self.pg0.remote_ip4,
dst=self.pg0.local_ip4) /
GRE() /
- Ether(dst=self.omac) /
- IP(src="1.1.1.1", dst="1.1.1.2") /
+ IP(src=self.pg1.local_ip4,
+ dst=self.pg1.remote_ip4) /
UDP(sport=1144, dport=2233) /
- Raw('X' * payload_size))
+ Raw(b'X' * payload_size))
for i in range(count)]
def gen_pkts(self, sw_intf, src, dst, count=1,
payload_size=100):
- return [Ether(dst=self.omac) /
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
IP(src="1.1.1.1", dst="1.1.1.2") /
UDP(sport=1144, dport=2233) /
- Raw('X' * payload_size)
+ Raw(b'X' * payload_size)
for i in range(count)]
def verify_decrypted(self, p, rxs):
for rx in rxs:
- self.assert_equal(rx[Ether].dst, self.omac)
- self.assert_equal(rx[IP].dst, "1.1.1.2")
+ self.assert_equal(rx[Ether].dst, self.pg1.remote_mac)
+ self.assert_equal(rx[IP].dst, self.pg1.remote_ip4)
def verify_encrypted(self, p, sa, rxs):
for rx in rxs:
self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
self.assertTrue(pkt.haslayer(GRE))
- e = pkt[Ether]
- self.assertEqual(e[Ether].dst, self.omac)
+ e = pkt[GRE]
self.assertEqual(e[IP].dst, "1.1.1.2")
except (IndexError, AssertionError):
self.logger.debug(ppp("Unexpected packet:", rx))
raise
def setUp(self):
- super(TestIpsecGreTebIfEsp, self).setUp()
+ super(TestIpsecGreIfEsp, self).setUp()
self.tun_if = self.pg0
self.pg0.local_ip4)
p.tun_sa_in.add_vpp_config()
- self.tun = VppGreInterface(self,
+ p.tun_if = VppGreInterface(self,
self.pg0.local_ip4,
- self.pg0.remote_ip4,
- type=(VppEnum.vl_api_gre_tunnel_type_t.
- GRE_API_TUNNEL_TYPE_TEB))
- self.tun.add_vpp_config()
+ self.pg0.remote_ip4)
+ p.tun_if.add_vpp_config()
p.tun_protect = VppIpsecTunProtect(self,
- self.tun,
+ p.tun_if,
p.tun_sa_out,
[p.tun_sa_in])
-
p.tun_protect.add_vpp_config()
- self.tun.admin_up()
- self.tun.config_ip4()
-
- VppBridgeDomainPort(self, bd1, self.tun).add_vpp_config()
- VppBridgeDomainPort(self, bd1, self.pg1).add_vpp_config()
+ p.tun_if.admin_up()
+ p.tun_if.config_ip4()
+ config_tun_params(p, self.encryption_type, p.tun_if)
- self.vapi.cli("clear ipsec sa")
+ VppIpRoute(self, "1.1.1.2", 32,
+ [VppRoutePath(p.tun_if.remote_ip4,
+ 0xffffffff)]).add_vpp_config()
def tearDown(self):
- self.tun.unconfig_ip4()
- super(TestIpsecGreTebIfEsp, self).tearDown()
+ p = self.ipv4_params
+ p.tun_if.unconfig_ip4()
+ super(TestIpsecGreIfEsp, self).tearDown()
-class TestIpsecGreIfEsp(TemplateIpsec,
- IpsecTun4Tests):
- """ Ipsec GRE ESP - TUN tests """
+class TestIpsecGreIfEspTra(TemplateIpsec,
+ IpsecTun4Tests):
+ """ Ipsec GRE ESP - TRA tests """
tun4_encrypt_node_name = "esp4-encrypt-tun"
tun4_decrypt_node_name = "esp4-decrypt-tun"
encryption_type = ESP
IP(src=self.pg1.local_ip4,
dst=self.pg1.remote_ip4) /
UDP(sport=1144, dport=2233) /
- Raw('X' * payload_size))
+ Raw(b'X' * payload_size))
+ for i in range(count)]
+
+ def gen_encrypt_non_ip_pkts(self, sa, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ sa.encrypt(IP(src=self.pg0.remote_ip4,
+ dst=self.pg0.local_ip4) /
+ GRE() /
+ UDP(sport=1144, dport=2233) /
+ Raw(b'X' * payload_size))
for i in range(count)]
def gen_pkts(self, sw_intf, src, dst, count=1,
return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
IP(src="1.1.1.1", dst="1.1.1.2") /
UDP(sport=1144, dport=2233) /
- Raw('X' * payload_size)
+ Raw(b'X' * payload_size)
for i in range(count)]
def verify_decrypted(self, p, rxs):
if not pkt.haslayer(IP):
pkt = IP(pkt[Raw].load)
self.assert_packet_checksums_valid(pkt)
- self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
- self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
self.assertTrue(pkt.haslayer(GRE))
e = pkt[GRE]
self.assertEqual(e[IP].dst, "1.1.1.2")
raise
def setUp(self):
- super(TestIpsecGreIfEsp, self).setUp()
+ super(TestIpsecGreIfEspTra, self).setUp()
self.tun_if = self.pg0
p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
p.auth_algo_vpp_id, p.auth_key,
p.crypt_algo_vpp_id, p.crypt_key,
- self.vpp_esp_protocol,
- self.pg0.local_ip4,
- self.pg0.remote_ip4)
+ self.vpp_esp_protocol)
p.tun_sa_out.add_vpp_config()
p.tun_sa_in = VppIpsecSA(self, p.vpp_tun_sa_id, p.vpp_tun_spi,
p.auth_algo_vpp_id, p.auth_key,
p.crypt_algo_vpp_id, p.crypt_key,
- self.vpp_esp_protocol,
- self.pg0.remote_ip4,
- self.pg0.local_ip4)
+ self.vpp_esp_protocol)
p.tun_sa_in.add_vpp_config()
- self.tun = VppGreInterface(self,
+ p.tun_if = VppGreInterface(self,
self.pg0.local_ip4,
self.pg0.remote_ip4)
- self.tun.add_vpp_config()
+ p.tun_if.add_vpp_config()
p.tun_protect = VppIpsecTunProtect(self,
- self.tun,
+ p.tun_if,
p.tun_sa_out,
[p.tun_sa_in])
p.tun_protect.add_vpp_config()
- self.tun.admin_up()
- self.tun.config_ip4()
+ p.tun_if.admin_up()
+ p.tun_if.config_ip4()
+ config_tra_params(p, self.encryption_type, p.tun_if)
VppIpRoute(self, "1.1.1.2", 32,
- [VppRoutePath(self.tun.remote_ip4,
+ [VppRoutePath(p.tun_if.remote_ip4,
0xffffffff)]).add_vpp_config()
def tearDown(self):
- self.tun.unconfig_ip4()
- super(TestIpsecGreIfEsp, self).tearDown()
+ p = self.ipv4_params
+ p.tun_if.unconfig_ip4()
+ super(TestIpsecGreIfEspTra, self).tearDown()
+
+ def test_gre_non_ip(self):
+ p = self.ipv4_params
+ tx = self.gen_encrypt_non_ip_pkts(p.scapy_tun_sa, self.tun_if,
+ src=p.remote_tun_if_host,
+ dst=self.pg1.remote_ip6)
+ self.send_and_assert_no_replies(self.tun_if, tx)
+ node_name = ('/err/%s/unsupported payload' %
+ self.tun4_decrypt_node_name)
+ self.assertEqual(1, self.statistics.get_err_counter(node_name))
+
+
+class TestIpsecGre6IfEspTra(TemplateIpsec,
+ IpsecTun6Tests):
+ """ Ipsec GRE ESP - TRA tests """
+ tun6_encrypt_node_name = "esp6-encrypt-tun"
+ tun6_decrypt_node_name = "esp6-decrypt-tun"
+ encryption_type = ESP
+
+ def gen_encrypt_pkts6(self, sa, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ sa.encrypt(IPv6(src=self.pg0.remote_ip6,
+ dst=self.pg0.local_ip6) /
+ GRE() /
+ IPv6(src=self.pg1.local_ip6,
+ dst=self.pg1.remote_ip6) /
+ UDP(sport=1144, dport=2233) /
+ Raw(b'X' * payload_size))
+ for i in range(count)]
+
+ def gen_pkts6(self, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ IPv6(src="1::1", dst="1::2") /
+ UDP(sport=1144, dport=2233) /
+ Raw(b'X' * payload_size)
+ for i in range(count)]
+
+ def verify_decrypted6(self, p, rxs):
+ for rx in rxs:
+ self.assert_equal(rx[Ether].dst, self.pg1.remote_mac)
+ self.assert_equal(rx[IPv6].dst, self.pg1.remote_ip6)
+
+ def verify_encrypted6(self, p, sa, rxs):
+ for rx in rxs:
+ try:
+ pkt = sa.decrypt(rx[IPv6])
+ if not pkt.haslayer(IPv6):
+ pkt = IPv6(pkt[Raw].load)
+ self.assert_packet_checksums_valid(pkt)
+ self.assertTrue(pkt.haslayer(GRE))
+ e = pkt[GRE]
+ self.assertEqual(e[IPv6].dst, "1::2")
+ except (IndexError, AssertionError):
+ self.logger.debug(ppp("Unexpected packet:", rx))
+ try:
+ self.logger.debug(ppp("Decrypted packet:", pkt))
+ except:
+ pass
+ raise
+
+ def setUp(self):
+ super(TestIpsecGre6IfEspTra, self).setUp()
+
+ self.tun_if = self.pg0
+
+ p = self.ipv6_params
+
+ bd1 = VppBridgeDomain(self, 1)
+ bd1.add_vpp_config()
+
+ p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol)
+ p.tun_sa_out.add_vpp_config()
+
+ p.tun_sa_in = VppIpsecSA(self, p.vpp_tun_sa_id, p.vpp_tun_spi,
+ p.auth_algo_vpp_id, p.auth_key,
+ p.crypt_algo_vpp_id, p.crypt_key,
+ self.vpp_esp_protocol)
+ p.tun_sa_in.add_vpp_config()
+
+ p.tun_if = VppGreInterface(self,
+ self.pg0.local_ip6,
+ self.pg0.remote_ip6)
+ p.tun_if.add_vpp_config()
+
+ p.tun_protect = VppIpsecTunProtect(self,
+ p.tun_if,
+ p.tun_sa_out,
+ [p.tun_sa_in])
+ p.tun_protect.add_vpp_config()
+
+ p.tun_if.admin_up()
+ p.tun_if.config_ip6()
+ config_tra_params(p, self.encryption_type, p.tun_if)
+
+ r = VppIpRoute(self, "1::2", 128,
+ [VppRoutePath(p.tun_if.remote_ip6,
+ 0xffffffff,
+ proto=DpoProto.DPO_PROTO_IP6)])
+ r.add_vpp_config()
+
+ def tearDown(self):
+ p = self.ipv6_params
+ p.tun_if.unconfig_ip6()
+ super(TestIpsecGre6IfEspTra, self).tearDown()
class TemplateIpsec4TunProtect(object):
tun4_input_node = "ipsec4-tun-input"
def config_sa_tra(self, p):
- config_tun_params(p, self.encryption_type, self.tun_if)
+ config_tun_params(p, self.encryption_type, p.tun_if)
p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
p.auth_algo_vpp_id, p.auth_key,
p.tun_sa_in.add_vpp_config()
def config_sa_tun(self, p):
- config_tun_params(p, self.encryption_type, self.tun_if)
+ config_tun_params(p, self.encryption_type, p.tun_if)
p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
p.auth_algo_vpp_id, p.auth_key,
p.crypt_algo_vpp_id, p.crypt_key,
self.vpp_esp_protocol,
- self.tun_if.remote_addr[p.addr_type],
self.tun_if.local_addr[p.addr_type],
+ self.tun_if.remote_addr[p.addr_type],
flags=p.flags)
p.tun_sa_out.add_vpp_config()
# rekey - create new SAs and update the tunnel protection
np = copy.copy(p)
- np.crypt_key = 'X' + p.crypt_key[1:]
+ np.crypt_key = b'X' + p.crypt_key[1:]
np.scapy_tun_spi += 100
np.scapy_tun_sa_id += 1
np.vpp_tun_spi += 100
dst=sw_intf.local_ip4) /
IP(src=src, dst=dst) /
UDP(sport=1144, dport=2233) /
- Raw('X' * payload_size))
+ Raw(b'X' * payload_size))
for i in range(count)]
def gen_pkts(self, sw_intf, src, dst, count=1,
return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
IP(src=src, dst=dst) /
UDP(sport=1144, dport=2233) /
- Raw('X' * payload_size)
+ Raw(b'X' * payload_size)
for i in range(count)]
def verify_decrypted(self, p, rxs):
# rekey - create new SAs and update the tunnel protection
np = copy.copy(p)
- np.crypt_key = 'X' + p.crypt_key[1:]
+ np.crypt_key = b'X' + p.crypt_key[1:]
np.scapy_tun_spi += 100
np.scapy_tun_sa_id += 1
np.vpp_tun_spi += 100
self.unconfig_network(p)
+class TestIpsec4TunProtectTunDrop(TemplateIpsec,
+ TemplateIpsec4TunProtect,
+ IpsecTun4):
+ """ IPsec IPv4 Tunnel protect - tunnel mode - drop"""
+
+ encryption_type = ESP
+ tun4_encrypt_node_name = "esp4-encrypt-tun"
+ tun4_decrypt_node_name = "esp4-decrypt-tun"
+
+ def setUp(self):
+ super(TestIpsec4TunProtectTunDrop, self).setUp()
+
+ self.tun_if = self.pg0
+
+ def tearDown(self):
+ super(TestIpsec4TunProtectTunDrop, self).tearDown()
+
+ def gen_encrypt_pkts(self, sa, sw_intf, src, dst, count=1,
+ payload_size=100):
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ sa.encrypt(IP(src=sw_intf.remote_ip4,
+ dst="5.5.5.5") /
+ IP(src=src, dst=dst) /
+ UDP(sport=1144, dport=2233) /
+ Raw(b'X' * payload_size))
+ for i in range(count)]
+
+ def test_tun_drop_44(self):
+ """IPSEC tunnel protect bogus tunnel header """
+
+ p = self.ipv4_params
+
+ self.config_network(p)
+ self.config_sa_tun(p)
+ self.config_protect(p)
+
+ tx = self.gen_encrypt_pkts(p.scapy_tun_sa, self.tun_if,
+ src=p.remote_tun_if_host,
+ dst=self.pg1.remote_ip4,
+ count=63)
+ self.send_and_assert_no_replies(self.tun_if, tx)
+
+ # teardown
+ self.unconfig_protect(p)
+ self.unconfig_sa(p)
+ self.unconfig_network(p)
+
+
class TemplateIpsec6TunProtect(object):
""" IPsec IPv6 Tunnel protect """
def config_sa_tra(self, p):
- config_tun_params(p, self.encryption_type, self.tun_if)
+ config_tun_params(p, self.encryption_type, p.tun_if)
p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
p.auth_algo_vpp_id, p.auth_key,
p.tun_sa_in.add_vpp_config()
def config_sa_tun(self, p):
- config_tun_params(p, self.encryption_type, self.tun_if)
+ config_tun_params(p, self.encryption_type, p.tun_if)
p.tun_sa_out = VppIpsecSA(self, p.scapy_tun_sa_id, p.scapy_tun_spi,
p.auth_algo_vpp_id, p.auth_key,
p.crypt_algo_vpp_id, p.crypt_key,
self.vpp_esp_protocol,
- self.tun_if.remote_addr[p.addr_type],
- self.tun_if.local_addr[p.addr_type])
+ self.tun_if.local_addr[p.addr_type],
+ self.tun_if.remote_addr[p.addr_type])
p.tun_sa_out.add_vpp_config()
p.tun_sa_in = VppIpsecSA(self, p.vpp_tun_sa_id, p.vpp_tun_spi,
super(TestIpsec6TunProtect, self).tearDown()
def test_tun_66(self):
- """IPSEC tunnel protect"""
+ """IPSEC tunnel protect 6o6"""
p = self.ipv6_params
# rekey - create new SAs and update the tunnel protection
np = copy.copy(p)
- np.crypt_key = 'X' + p.crypt_key[1:]
+ np.crypt_key = b'X' + p.crypt_key[1:]
np.scapy_tun_spi += 100
np.scapy_tun_sa_id += 1
np.vpp_tun_spi += 100
c = p.tun_if.get_tx_stats()
self.assertEqual(c['packets'], 254)
+ # bounce the interface state
+ p.tun_if.admin_down()
+ self.verify_drop_tun_66(np, count=127)
+ node = ('/err/ipsec6-tun-input/%s' %
+ 'ipsec packets received on disabled interface')
+ self.assertEqual(127, self.statistics.get_err_counter(node))
+ p.tun_if.admin_up()
+ self.verify_tun_66(np, count=127)
+
# 3 phase rekey
# 1) add two input SAs [old, new]
# 2) swap output SA to [new]
# 3) use only [new] input SA
np3 = copy.copy(np)
- np3.crypt_key = 'Z' + p.crypt_key[1:]
+ np3.crypt_key = b'Z' + p.crypt_key[1:]
np3.scapy_tun_spi += 100
np3.scapy_tun_sa_id += 1
np3.vpp_tun_spi += 100
self.verify_drop_tun_66(np, count=127)
c = p.tun_if.get_rx_stats()
- self.assertEqual(c['packets'], 127*7)
+ self.assertEqual(c['packets'], 127*9)
c = p.tun_if.get_tx_stats()
- self.assertEqual(c['packets'], 127*7)
+ self.assertEqual(c['packets'], 127*8)
self.unconfig_sa(np)
# teardown
self.unconfig_network(p)
def test_tun_46(self):
- """IPSEC tunnel protect"""
+ """IPSEC tunnel protect 4o6"""
p = self.ipv6_params
dst=sw_intf.local_ip6) /
IPv6(src=src, dst=dst) /
UDP(sport=1166, dport=2233) /
- Raw('X' * payload_size))
+ Raw(b'X' * payload_size))
for i in range(count)]
def gen_pkts6(self, sw_intf, src, dst, count=1,
return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
IPv6(src=src, dst=dst) /
UDP(sport=1166, dport=2233) /
- Raw('X' * payload_size)
+ Raw(b'X' * payload_size)
for i in range(count)]
def verify_decrypted6(self, p, rxs):
# rekey - create new SAs and update the tunnel protection
np = copy.copy(p)
- np.crypt_key = 'X' + p.crypt_key[1:]
+ np.crypt_key = b'X' + p.crypt_key[1:]
np.scapy_tun_spi += 100
np.scapy_tun_sa_id += 1
np.vpp_tun_spi += 100
self.unconfig_network(p)
+class TestIpsec6TunProtectTunDrop(TemplateIpsec,
+ TemplateIpsec6TunProtect,
+ IpsecTun6):
+ """ IPsec IPv6 Tunnel protect - tunnel mode - drop"""
+
+ encryption_type = ESP
+ tun6_encrypt_node_name = "esp6-encrypt-tun"
+ tun6_decrypt_node_name = "esp6-decrypt-tun"
+
+ def setUp(self):
+ super(TestIpsec6TunProtectTunDrop, self).setUp()
+
+ self.tun_if = self.pg0
+
+ def tearDown(self):
+ super(TestIpsec6TunProtectTunDrop, self).tearDown()
+
+ def gen_encrypt_pkts5(self, sa, sw_intf, src, dst, count=1,
+ payload_size=100):
+ # the IP destination of the revelaed packet does not match
+ # that assigned to the tunnel
+ return [Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) /
+ sa.encrypt(IPv6(src=sw_intf.remote_ip6,
+ dst="5::5") /
+ IPv6(src=src, dst=dst) /
+ UDP(sport=1144, dport=2233) /
+ Raw(b'X' * payload_size))
+ for i in range(count)]
+
+ def test_tun_drop_66(self):
+ """IPSEC 6 tunnel protect bogus tunnel header """
+
+ p = self.ipv6_params
+
+ self.config_network(p)
+ self.config_sa_tun(p)
+ self.config_protect(p)
+
+ tx = self.gen_encrypt_pkts6(p.scapy_tun_sa, self.tun_if,
+ src=p.remote_tun_if_host,
+ dst=self.pg1.remote_ip6,
+ count=63)
+ self.send_and_assert_no_replies(self.tun_if, tx)
+
+ self.unconfig_protect(p)
+ self.unconfig_sa(p)
+ self.unconfig_network(p)
+
+
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)