blob: e832bfa2a27721ff85c8d1748cf71614673f4df1 [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)
48 cls.logger.info(cls.vapi.ppcli("show ipsec"))
49 for _, p in cls.params.items():
50 cls.config_ah_tun(p)
51 cls.logger.info(cls.vapi.ppcli("show ipsec"))
52 for _, p in cls.params.items():
53 src = socket.inet_pton(p.addr_type, p.remote_tun_if_host)
54 cls.vapi.ip_add_del_route(src, p.addr_len,
55 cls.tun_if.remote_addr_n[p.addr_type],
56 is_ipv6=p.is_ipv6)
57
58 @classmethod
59 def config_ah_tun(cls, params):
60 addr_type = params.addr_type
61 is_ipv6 = params.is_ipv6
62 scapy_tun_sa_id = params.scapy_tun_sa_id
63 scapy_tun_spi = params.scapy_tun_spi
64 vpp_tun_sa_id = params.vpp_tun_sa_id
65 vpp_tun_spi = params.vpp_tun_spi
66 auth_algo_vpp_id = params.auth_algo_vpp_id
67 auth_key = params.auth_key
68 crypt_algo_vpp_id = params.crypt_algo_vpp_id
69 crypt_key = params.crypt_key
70 remote_tun_if_host = params.remote_tun_if_host
71 addr_any = params.addr_any
72 addr_bcast = params.addr_bcast
73 cls.vapi.ipsec_sad_add_del_entry(scapy_tun_sa_id, scapy_tun_spi,
74 auth_algo_vpp_id, auth_key,
75 crypt_algo_vpp_id, crypt_key,
76 cls.vpp_ah_protocol,
77 cls.tun_if.local_addr_n[addr_type],
78 cls.tun_if.remote_addr_n[addr_type],
79 is_tunnel=1, is_tunnel_ipv6=is_ipv6)
80 cls.vapi.ipsec_sad_add_del_entry(vpp_tun_sa_id, vpp_tun_spi,
81 auth_algo_vpp_id, auth_key,
82 crypt_algo_vpp_id, crypt_key,
83 cls.vpp_ah_protocol,
84 cls.tun_if.remote_addr_n[addr_type],
85 cls.tun_if.local_addr_n[addr_type],
86 is_tunnel=1, is_tunnel_ipv6=is_ipv6)
87 l_startaddr = r_startaddr = socket.inet_pton(addr_type, addr_any)
88 l_stopaddr = r_stopaddr = socket.inet_pton(addr_type, addr_bcast)
89 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, vpp_tun_sa_id,
Klement Sekera31da2e32018-06-24 22:49:55 +020090 l_startaddr, l_stopaddr, r_startaddr,
Klement Sekera611864f2018-09-26 11:19:00 +020091 r_stopaddr, is_ipv6=is_ipv6,
Klement Sekera84c62042018-05-11 11:06:09 +020092 protocol=socket.IPPROTO_AH)
Klement Sekera611864f2018-09-26 11:19:00 +020093 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, vpp_tun_sa_id,
Klement Sekera31da2e32018-06-24 22:49:55 +020094 l_startaddr, l_stopaddr, r_startaddr,
95 r_stopaddr, is_outbound=0,
Klement Sekera611864f2018-09-26 11:19:00 +020096 is_ipv6=is_ipv6,
Klement Sekera31da2e32018-06-24 22:49:55 +020097 protocol=socket.IPPROTO_AH)
Klement Sekera611864f2018-09-26 11:19:00 +020098 l_startaddr = l_stopaddr = socket.inet_pton(addr_type,
99 remote_tun_if_host)
100 r_startaddr = r_stopaddr = cls.pg1.remote_addr_n[addr_type]
101 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, vpp_tun_sa_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200102 l_startaddr, l_stopaddr, r_startaddr,
103 r_stopaddr, priority=10, policy=3,
Klement Sekera611864f2018-09-26 11:19:00 +0200104 is_outbound=0, is_ipv6=is_ipv6)
105 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, scapy_tun_sa_id,
106 r_startaddr, r_stopaddr, l_startaddr,
107 l_stopaddr, priority=10, policy=3,
108 is_ipv6=is_ipv6)
109 r_startaddr = r_stopaddr = cls.pg0.local_addr_n[addr_type]
110 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, vpp_tun_sa_id,
111 l_startaddr, l_stopaddr, r_startaddr,
112 r_stopaddr, priority=20, policy=3,
113 is_outbound=0, is_ipv6=is_ipv6)
114 cls.vapi.ipsec_spd_add_del_entry(cls.tun_spd_id, scapy_tun_sa_id,
115 r_startaddr, r_stopaddr, l_startaddr,
116 l_stopaddr, priority=20, policy=3,
117 is_ipv6=is_ipv6)
118
119 @classmethod
120 def config_ah_tra(cls, params):
121 addr_type = params.addr_type
122 is_ipv6 = params.is_ipv6
123 scapy_tra_sa_id = params.scapy_tra_sa_id
124 scapy_tra_spi = params.scapy_tra_spi
125 vpp_tra_sa_id = params.vpp_tra_sa_id
126 vpp_tra_spi = params.vpp_tra_spi
127 auth_algo_vpp_id = params.auth_algo_vpp_id
128 auth_key = params.auth_key
129 crypt_algo_vpp_id = params.crypt_algo_vpp_id
130 crypt_key = params.crypt_key
131 addr_any = params.addr_any
132 addr_bcast = params.addr_bcast
133 cls.vapi.ipsec_sad_add_del_entry(scapy_tra_sa_id, scapy_tra_spi,
134 auth_algo_vpp_id, auth_key,
135 crypt_algo_vpp_id, crypt_key,
136 cls.vpp_ah_protocol, is_tunnel=0,
137 is_tunnel_ipv6=0)
138 cls.vapi.ipsec_sad_add_del_entry(vpp_tra_sa_id, vpp_tra_spi,
139 auth_algo_vpp_id, auth_key,
140 crypt_algo_vpp_id, crypt_key,
141 cls.vpp_ah_protocol, is_tunnel=0,
142 is_tunnel_ipv6=0)
143 l_startaddr = r_startaddr = socket.inet_pton(addr_type, addr_any)
144 l_stopaddr = r_stopaddr = socket.inet_pton(addr_type, addr_bcast)
145 cls.vapi.ipsec_spd_add_del_entry(cls.tra_spd_id, vpp_tra_sa_id,
146 l_startaddr, l_stopaddr, r_startaddr,
147 r_stopaddr, is_ipv6=is_ipv6,
148 protocol=socket.IPPROTO_AH)
149 cls.vapi.ipsec_spd_add_del_entry(cls.tra_spd_id, scapy_tra_sa_id,
150 l_startaddr, l_stopaddr, r_startaddr,
151 r_stopaddr, is_outbound=0,
152 is_ipv6=is_ipv6,
153 protocol=socket.IPPROTO_AH)
154 l_startaddr = l_stopaddr = cls.tra_if.local_addr_n[addr_type]
155 r_startaddr = r_stopaddr = cls.tra_if.remote_addr_n[addr_type]
156 cls.vapi.ipsec_spd_add_del_entry(cls.tra_spd_id, vpp_tra_sa_id,
157 l_startaddr, l_stopaddr, r_startaddr,
158 r_stopaddr, priority=10, policy=3,
159 is_outbound=0, is_ipv6=is_ipv6)
160 cls.vapi.ipsec_spd_add_del_entry(cls.tra_spd_id, scapy_tra_sa_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200161 l_startaddr, l_stopaddr, r_startaddr,
162 r_stopaddr, priority=10,
Klement Sekera611864f2018-09-26 11:19:00 +0200163 policy=3, is_ipv6=is_ipv6)
“mystarrocks”23f0c452017-12-11 07:11:51 -0800164
165 def tearDown(self):
Klement Sekera31da2e32018-06-24 22:49:55 +0200166 super(TemplateIpsecAh, self).tearDown()
“mystarrocks”23f0c452017-12-11 07:11:51 -0800167 if not self.vpp_dead:
168 self.vapi.cli("show hardware")
169
“mystarrocks”23f0c452017-12-11 07:11:51 -0800170
Klement Sekera31da2e32018-06-24 22:49:55 +0200171class TestIpsecAh1(TemplateIpsecAh, IpsecTraTests, IpsecTunTests):
172 """ Ipsec AH - TUN & TRA tests """
Klement Sekerab4d30532018-11-08 13:00:02 +0100173 tra4_encrypt_node_name = "ah4-encrypt"
174 tra4_decrypt_node_name = "ah4-decrypt"
175 tra6_encrypt_node_name = "ah6-encrypt"
176 tra6_decrypt_node_name = "ah6-decrypt"
177 tun4_encrypt_node_name = "ah4-encrypt"
178 tun4_decrypt_node_name = "ah4-decrypt"
179 tun6_encrypt_node_name = "ah6-encrypt"
180 tun6_decrypt_node_name = "ah6-decrypt"
“mystarrocks”23f0c452017-12-11 07:11:51 -0800181
“mystarrocks”23f0c452017-12-11 07:11:51 -0800182
Klement Sekera31da2e32018-06-24 22:49:55 +0200183class TestIpsecAh2(TemplateIpsecAh, IpsecTcpTests):
184 """ Ipsec AH - TCP tests """
185 pass
“mystarrocks”23f0c452017-12-11 07:11:51 -0800186
187
188if __name__ == '__main__':
189 unittest.main(testRunner=VppTestRunner)