blob: 928cd53c1f10fcd014868837f77137afa8a5546e [file] [log] [blame]
“mystarrocks”23f0c452017-12-11 07:11:51 -08001import socket
Klement Sekera28fb03f2018-04-17 11:36:55 +02002import unittest
“mystarrocks”23f0c452017-12-11 07:11:51 -08003
Klement Sekera31da2e32018-06-24 22:49:55 +02004from scapy.layers.ipsec import AH
“mystarrocks”23f0c452017-12-11 07:11:51 -08005
Klement Sekera31da2e32018-06-24 22:49:55 +02006from framework import VppTestRunner
7from template_ipsec import TemplateIpsec, IpsecTraTests, IpsecTunTests
8from template_ipsec import IpsecTcpTests
“mystarrocks”23f0c452017-12-11 07:11:51 -08009
10
Klement Sekera31da2e32018-06-24 22:49:55 +020011class TemplateIpsecAh(TemplateIpsec):
“mystarrocks”23f0c452017-12-11 07:11:51 -080012 """
13 Basic test for IPSEC using AH transport and Tunnel mode
14
“mystarrocks”23f0c452017-12-11 07:11:51 -080015 TRANSPORT MODE:
16
17 --- encrypt ---
18 |pg2| <-------> |VPP|
19 --- decrypt ---
20
21 TUNNEL MODE:
22
23 --- encrypt --- plain ---
Klement Sekera84c62042018-05-11 11:06:09 +020024 |pg0| <------- |VPP| <------ |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -080025 --- --- ---
26
27 --- decrypt --- plain ---
Klement Sekera84c62042018-05-11 11:06:09 +020028 |pg0| -------> |VPP| ------> |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -080029 --- --- ---
“mystarrocks”23f0c452017-12-11 07:11:51 -080030 """
31
Klement Sekera31da2e32018-06-24 22:49:55 +020032 encryption_type = AH
“mystarrocks”23f0c452017-12-11 07:11:51 -080033
34 @classmethod
35 def setUpClass(cls):
Klement Sekera31da2e32018-06-24 22:49:55 +020036 super(TemplateIpsecAh, cls).setUpClass()
37 cls.tun_if = cls.pg0
38 cls.tra_if = cls.pg2
39 cls.logger.info(cls.vapi.ppcli("show int addr"))
Klement Sekera31da2e32018-06-24 22:49:55 +020040 cls.vapi.ipsec_spd_add_del(cls.tun_spd_id)
41 cls.vapi.ipsec_interface_add_del_spd(cls.tun_spd_id,
42 cls.tun_if.sw_if_index)
Klement Sekera31da2e32018-06-24 22:49:55 +020043 cls.vapi.ipsec_spd_add_del(cls.tra_spd_id)
44 cls.vapi.ipsec_interface_add_del_spd(cls.tra_spd_id,
45 cls.tra_if.sw_if_index)
Klement Sekera611864f2018-09-26 11:19:00 +020046 for _, p in cls.params.items():
47 cls.config_ah_tra(p)
Neale Rannsde847272018-11-28 01:38:34 -080048 cls.configure_sa_tra(p)
Klement Sekera611864f2018-09-26 11:19:00 +020049 cls.logger.info(cls.vapi.ppcli("show ipsec"))
50 for _, p in cls.params.items():
51 cls.config_ah_tun(p)
52 cls.logger.info(cls.vapi.ppcli("show ipsec"))
53 for _, p in cls.params.items():
54 src = socket.inet_pton(p.addr_type, p.remote_tun_if_host)
55 cls.vapi.ip_add_del_route(src, p.addr_len,
56 cls.tun_if.remote_addr_n[p.addr_type],
57 is_ipv6=p.is_ipv6)
58
59 @classmethod
60 def config_ah_tun(cls, params):
61 addr_type = params.addr_type
62 is_ipv6 = params.is_ipv6
63 scapy_tun_sa_id = params.scapy_tun_sa_id
64 scapy_tun_spi = params.scapy_tun_spi
65 vpp_tun_sa_id = params.vpp_tun_sa_id
66 vpp_tun_spi = params.vpp_tun_spi
67 auth_algo_vpp_id = params.auth_algo_vpp_id
68 auth_key = params.auth_key
69 crypt_algo_vpp_id = params.crypt_algo_vpp_id
70 crypt_key = params.crypt_key
71 remote_tun_if_host = params.remote_tun_if_host
72 addr_any = params.addr_any
73 addr_bcast = params.addr_bcast
74 cls.vapi.ipsec_sad_add_del_entry(scapy_tun_sa_id, scapy_tun_spi,
75 auth_algo_vpp_id, auth_key,
76 crypt_algo_vpp_id, crypt_key,
77 cls.vpp_ah_protocol,
78 cls.tun_if.local_addr_n[addr_type],
79 cls.tun_if.remote_addr_n[addr_type],
80 is_tunnel=1, is_tunnel_ipv6=is_ipv6)
81 cls.vapi.ipsec_sad_add_del_entry(vpp_tun_sa_id, vpp_tun_spi,
82 auth_algo_vpp_id, auth_key,
83 crypt_algo_vpp_id, crypt_key,
84 cls.vpp_ah_protocol,
85 cls.tun_if.remote_addr_n[addr_type],
86 cls.tun_if.local_addr_n[addr_type],
87 is_tunnel=1, is_tunnel_ipv6=is_ipv6)
88 l_startaddr = r_startaddr = socket.inet_pton(addr_type, addr_any)
89 l_stopaddr = r_stopaddr = socket.inet_pton(addr_type, addr_bcast)
90 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, vpp_tun_sa_id,
Klement Sekera31da2e32018-06-24 22:49:55 +020091 l_startaddr, l_stopaddr, r_startaddr,
Klement Sekera611864f2018-09-26 11:19:00 +020092 r_stopaddr, is_ipv6=is_ipv6,
Klement Sekera84c62042018-05-11 11:06:09 +020093 protocol=socket.IPPROTO_AH)
Klement Sekera611864f2018-09-26 11:19:00 +020094 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, vpp_tun_sa_id,
Klement Sekera31da2e32018-06-24 22:49:55 +020095 l_startaddr, l_stopaddr, r_startaddr,
96 r_stopaddr, is_outbound=0,
Klement Sekera611864f2018-09-26 11:19:00 +020097 is_ipv6=is_ipv6,
Klement Sekera31da2e32018-06-24 22:49:55 +020098 protocol=socket.IPPROTO_AH)
Klement Sekera611864f2018-09-26 11:19:00 +020099 l_startaddr = l_stopaddr = socket.inet_pton(addr_type,
100 remote_tun_if_host)
101 r_startaddr = r_stopaddr = cls.pg1.remote_addr_n[addr_type]
102 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, vpp_tun_sa_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200103 l_startaddr, l_stopaddr, r_startaddr,
104 r_stopaddr, priority=10, policy=3,
Klement Sekera611864f2018-09-26 11:19:00 +0200105 is_outbound=0, is_ipv6=is_ipv6)
106 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, scapy_tun_sa_id,
107 r_startaddr, r_stopaddr, l_startaddr,
108 l_stopaddr, priority=10, policy=3,
109 is_ipv6=is_ipv6)
110 r_startaddr = r_stopaddr = cls.pg0.local_addr_n[addr_type]
111 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, vpp_tun_sa_id,
112 l_startaddr, l_stopaddr, r_startaddr,
113 r_stopaddr, priority=20, policy=3,
114 is_outbound=0, is_ipv6=is_ipv6)
115 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, scapy_tun_sa_id,
116 r_startaddr, r_stopaddr, l_startaddr,
117 l_stopaddr, priority=20, policy=3,
118 is_ipv6=is_ipv6)
119
120 @classmethod
121 def config_ah_tra(cls, params):
122 addr_type = params.addr_type
123 is_ipv6 = params.is_ipv6
124 scapy_tra_sa_id = params.scapy_tra_sa_id
125 scapy_tra_spi = params.scapy_tra_spi
126 vpp_tra_sa_id = params.vpp_tra_sa_id
127 vpp_tra_spi = params.vpp_tra_spi
128 auth_algo_vpp_id = params.auth_algo_vpp_id
129 auth_key = params.auth_key
130 crypt_algo_vpp_id = params.crypt_algo_vpp_id
131 crypt_key = params.crypt_key
132 addr_any = params.addr_any
133 addr_bcast = params.addr_bcast
134 cls.vapi.ipsec_sad_add_del_entry(scapy_tra_sa_id, scapy_tra_spi,
135 auth_algo_vpp_id, auth_key,
136 crypt_algo_vpp_id, crypt_key,
137 cls.vpp_ah_protocol, is_tunnel=0,
Neale Rannsde847272018-11-28 01:38:34 -0800138 is_tunnel_ipv6=0,
139 use_anti_replay=1)
Klement Sekera611864f2018-09-26 11:19:00 +0200140 cls.vapi.ipsec_sad_add_del_entry(vpp_tra_sa_id, vpp_tra_spi,
141 auth_algo_vpp_id, auth_key,
142 crypt_algo_vpp_id, crypt_key,
143 cls.vpp_ah_protocol, is_tunnel=0,
Neale Rannsde847272018-11-28 01:38:34 -0800144 is_tunnel_ipv6=0,
145 use_anti_replay=1)
Klement Sekera611864f2018-09-26 11:19:00 +0200146 l_startaddr = r_startaddr = socket.inet_pton(addr_type, addr_any)
147 l_stopaddr = r_stopaddr = socket.inet_pton(addr_type, addr_bcast)
148 cls.vapi.ipsec_spd_add_del_entry(cls.tra_spd_id, vpp_tra_sa_id,
149 l_startaddr, l_stopaddr, r_startaddr,
150 r_stopaddr, is_ipv6=is_ipv6,
151 protocol=socket.IPPROTO_AH)
152 cls.vapi.ipsec_spd_add_del_entry(cls.tra_spd_id, scapy_tra_sa_id,
153 l_startaddr, l_stopaddr, r_startaddr,
154 r_stopaddr, is_outbound=0,
155 is_ipv6=is_ipv6,
156 protocol=socket.IPPROTO_AH)
157 l_startaddr = l_stopaddr = cls.tra_if.local_addr_n[addr_type]
158 r_startaddr = r_stopaddr = cls.tra_if.remote_addr_n[addr_type]
159 cls.vapi.ipsec_spd_add_del_entry(cls.tra_spd_id, vpp_tra_sa_id,
160 l_startaddr, l_stopaddr, r_startaddr,
161 r_stopaddr, priority=10, policy=3,
162 is_outbound=0, is_ipv6=is_ipv6)
163 cls.vapi.ipsec_spd_add_del_entry(cls.tra_spd_id, scapy_tra_sa_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200164 l_startaddr, l_stopaddr, r_startaddr,
165 r_stopaddr, priority=10,
Klement Sekera611864f2018-09-26 11:19:00 +0200166 policy=3, is_ipv6=is_ipv6)
“mystarrocks”23f0c452017-12-11 07:11:51 -0800167
168 def tearDown(self):
Klement Sekera31da2e32018-06-24 22:49:55 +0200169 super(TemplateIpsecAh, self).tearDown()
“mystarrocks”23f0c452017-12-11 07:11:51 -0800170 if not self.vpp_dead:
171 self.vapi.cli("show hardware")
172
“mystarrocks”23f0c452017-12-11 07:11:51 -0800173
Klement Sekera31da2e32018-06-24 22:49:55 +0200174class TestIpsecAh1(TemplateIpsecAh, IpsecTraTests, IpsecTunTests):
175 """ Ipsec AH - TUN & TRA tests """
Klement Sekerab4d30532018-11-08 13:00:02 +0100176 tra4_encrypt_node_name = "ah4-encrypt"
177 tra4_decrypt_node_name = "ah4-decrypt"
178 tra6_encrypt_node_name = "ah6-encrypt"
179 tra6_decrypt_node_name = "ah6-decrypt"
180 tun4_encrypt_node_name = "ah4-encrypt"
181 tun4_decrypt_node_name = "ah4-decrypt"
182 tun6_encrypt_node_name = "ah6-encrypt"
183 tun6_decrypt_node_name = "ah6-decrypt"
“mystarrocks”23f0c452017-12-11 07:11:51 -0800184
“mystarrocks”23f0c452017-12-11 07:11:51 -0800185
Klement Sekera31da2e32018-06-24 22:49:55 +0200186class TestIpsecAh2(TemplateIpsecAh, IpsecTcpTests):
187 """ Ipsec AH - TCP tests """
188 pass
“mystarrocks”23f0c452017-12-11 07:11:51 -0800189
190
191if __name__ == '__main__':
192 unittest.main(testRunner=VppTestRunner)