blob: 21080cad3d63635f4ca54aa24b617cee97fb4e7d [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
Neale Ranns2ac885c2019-03-20 18:24:43 +00007from template_ipsec import TemplateIpsec, IpsecTra46Tests, IpsecTun46Tests, \
8 config_tun_params, config_tra_params
Klement Sekera31da2e32018-06-24 22:49:55 +02009from template_ipsec import IpsecTcpTests
Klement Sekerabf613952019-01-29 11:38:08 +010010from vpp_ipsec import VppIpsecSA, VppIpsecSpd, VppIpsecSpdEntry,\
11 VppIpsecSpdItfBinding
Neale Ranns311124e2019-01-24 04:52:25 -080012from vpp_ip_route import VppIpRoute, VppRoutePath
13from vpp_ip import DpoProto
Neale Ranns17dcec02019-01-09 21:22:20 -080014from vpp_papi import VppEnum
“mystarrocks”23f0c452017-12-11 07:11:51 -080015
16
Klement Sekera31da2e32018-06-24 22:49:55 +020017class TemplateIpsecAh(TemplateIpsec):
“mystarrocks”23f0c452017-12-11 07:11:51 -080018 """
19 Basic test for IPSEC using AH transport and Tunnel mode
20
“mystarrocks”23f0c452017-12-11 07:11:51 -080021 TRANSPORT MODE:
22
23 --- encrypt ---
24 |pg2| <-------> |VPP|
25 --- decrypt ---
26
27 TUNNEL MODE:
28
29 --- encrypt --- plain ---
Klement Sekera84c62042018-05-11 11:06:09 +020030 |pg0| <------- |VPP| <------ |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -080031 --- --- ---
32
33 --- decrypt --- plain ---
Klement Sekera84c62042018-05-11 11:06:09 +020034 |pg0| -------> |VPP| ------> |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -080035 --- --- ---
“mystarrocks”23f0c452017-12-11 07:11:51 -080036 """
37
Neale Ranns8e4a89b2019-01-23 08:16:17 -080038 def setUp(self):
39 super(TemplateIpsecAh, self).setUp()
“mystarrocks”23f0c452017-12-11 07:11:51 -080040
Neale Ranns8e4a89b2019-01-23 08:16:17 -080041 self.encryption_type = AH
42 self.tun_if = self.pg0
43 self.tra_if = self.pg2
44 self.logger.info(self.vapi.ppcli("show int addr"))
Neale Ranns311124e2019-01-24 04:52:25 -080045
46 self.tra_spd = VppIpsecSpd(self, self.tra_spd_id)
47 self.tra_spd.add_vpp_config()
48 VppIpsecSpdItfBinding(self, self.tra_spd,
49 self.tra_if).add_vpp_config()
50 self.tun_spd = VppIpsecSpd(self, self.tun_spd_id)
51 self.tun_spd.add_vpp_config()
52 VppIpsecSpdItfBinding(self, self.tun_spd,
53 self.tun_if).add_vpp_config()
54
Neale Ranns8e4a89b2019-01-23 08:16:17 -080055 for _, p in self.params.items():
56 self.config_ah_tra(p)
Neale Ranns2ac885c2019-03-20 18:24:43 +000057 config_tra_params(p, self.encryption_type)
Neale Ranns8e4a89b2019-01-23 08:16:17 -080058 self.logger.info(self.vapi.ppcli("show ipsec"))
59 for _, p in self.params.items():
60 self.config_ah_tun(p)
61 self.logger.info(self.vapi.ppcli("show ipsec"))
62 for _, p in self.params.items():
Neale Ranns311124e2019-01-24 04:52:25 -080063 d = DpoProto.DPO_PROTO_IP6 if p.is_ipv6 else DpoProto.DPO_PROTO_IP4
64 VppIpRoute(self, p.remote_tun_if_host, p.addr_len,
65 [VppRoutePath(self.tun_if.remote_addr[p.addr_type],
66 0xffffffff,
67 proto=d)],
68 is_ip6=p.is_ipv6).add_vpp_config()
“mystarrocks”23f0c452017-12-11 07:11:51 -080069
70 def tearDown(self):
Klement Sekera31da2e32018-06-24 22:49:55 +020071 super(TemplateIpsecAh, self).tearDown()
“mystarrocks”23f0c452017-12-11 07:11:51 -080072 if not self.vpp_dead:
73 self.vapi.cli("show hardware")
74
Neale Ranns311124e2019-01-24 04:52:25 -080075 def config_ah_tun(self, params):
76 addr_type = params.addr_type
77 scapy_tun_sa_id = params.scapy_tun_sa_id
78 scapy_tun_spi = params.scapy_tun_spi
79 vpp_tun_sa_id = params.vpp_tun_sa_id
80 vpp_tun_spi = params.vpp_tun_spi
81 auth_algo_vpp_id = params.auth_algo_vpp_id
82 auth_key = params.auth_key
83 crypt_algo_vpp_id = params.crypt_algo_vpp_id
84 crypt_key = params.crypt_key
85 remote_tun_if_host = params.remote_tun_if_host
86 addr_any = params.addr_any
87 addr_bcast = params.addr_bcast
Neale Ranns17dcec02019-01-09 21:22:20 -080088 e = VppEnum.vl_api_ipsec_spd_action_t
89
Neale Rannseba31ec2019-02-17 18:04:27 +000090 params.tun_sa_in = VppIpsecSA(self, scapy_tun_sa_id, scapy_tun_spi,
91 auth_algo_vpp_id, auth_key,
92 crypt_algo_vpp_id, crypt_key,
93 self.vpp_ah_protocol,
94 self.tun_if.local_addr[addr_type],
95 self.tun_if.remote_addr[addr_type])
96 params.tun_sa_in.add_vpp_config()
97 params.tun_sa_out = VppIpsecSA(self, vpp_tun_sa_id, vpp_tun_spi,
98 auth_algo_vpp_id, auth_key,
99 crypt_algo_vpp_id, crypt_key,
100 self.vpp_ah_protocol,
101 self.tun_if.remote_addr[addr_type],
102 self.tun_if.local_addr[addr_type])
103 params.tun_sa_out.add_vpp_config()
Neale Ranns311124e2019-01-24 04:52:25 -0800104
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800105 params.spd_policy_in_any = VppIpsecSpdEntry(self, self.tun_spd,
106 vpp_tun_sa_id,
107 addr_any, addr_bcast,
108 addr_any, addr_bcast,
109 socket.IPPROTO_AH)
110 params.spd_policy_in_any.add_vpp_config()
111 params.spd_policy_out_any = VppIpsecSpdEntry(self, self.tun_spd,
112 vpp_tun_sa_id,
113 addr_any, addr_bcast,
114 addr_any, addr_bcast,
115 socket.IPPROTO_AH,
116 is_outbound=0)
117 params.spd_policy_out_any.add_vpp_config()
Neale Ranns311124e2019-01-24 04:52:25 -0800118
119 VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
120 remote_tun_if_host,
121 remote_tun_if_host,
122 self.pg1.remote_addr[addr_type],
123 self.pg1.remote_addr[addr_type],
Neale Ranns17dcec02019-01-09 21:22:20 -0800124 0, priority=10,
125 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
Neale Ranns311124e2019-01-24 04:52:25 -0800126 is_outbound=0).add_vpp_config()
127 VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
128 self.pg1.remote_addr[addr_type],
129 self.pg1.remote_addr[addr_type],
130 remote_tun_if_host,
131 remote_tun_if_host,
Neale Ranns17dcec02019-01-09 21:22:20 -0800132 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
133 priority=10).add_vpp_config()
Neale Ranns311124e2019-01-24 04:52:25 -0800134
135 VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
136 remote_tun_if_host,
137 remote_tun_if_host,
138 self.pg0.local_addr[addr_type],
139 self.pg0.local_addr[addr_type],
Neale Ranns17dcec02019-01-09 21:22:20 -0800140 0, priority=20,
141 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
Neale Ranns311124e2019-01-24 04:52:25 -0800142 is_outbound=0).add_vpp_config()
143 VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
144 self.pg0.local_addr[addr_type],
145 self.pg0.local_addr[addr_type],
146 remote_tun_if_host,
147 remote_tun_if_host,
Neale Ranns17dcec02019-01-09 21:22:20 -0800148 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
149 priority=20).add_vpp_config()
Neale Ranns311124e2019-01-24 04:52:25 -0800150
151 def config_ah_tra(self, params):
152 addr_type = params.addr_type
153 scapy_tra_sa_id = params.scapy_tra_sa_id
154 scapy_tra_spi = params.scapy_tra_spi
155 vpp_tra_sa_id = params.vpp_tra_sa_id
156 vpp_tra_spi = params.vpp_tra_spi
157 auth_algo_vpp_id = params.auth_algo_vpp_id
158 auth_key = params.auth_key
159 crypt_algo_vpp_id = params.crypt_algo_vpp_id
160 crypt_key = params.crypt_key
161 addr_any = params.addr_any
162 addr_bcast = params.addr_bcast
Neale Ranns17dcec02019-01-09 21:22:20 -0800163 flags = (VppEnum.vl_api_ipsec_sad_flags_t.
164 IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY)
165 e = VppEnum.vl_api_ipsec_spd_action_t
Neale Ranns311124e2019-01-24 04:52:25 -0800166
Neale Rannseba31ec2019-02-17 18:04:27 +0000167 params.tra_sa_in = VppIpsecSA(self, scapy_tra_sa_id, scapy_tra_spi,
168 auth_algo_vpp_id, auth_key,
169 crypt_algo_vpp_id, crypt_key,
170 self.vpp_ah_protocol,
171 flags=flags)
172 params.tra_sa_in.add_vpp_config()
173 params.tra_sa_out = VppIpsecSA(self, vpp_tra_sa_id, vpp_tra_spi,
174 auth_algo_vpp_id, auth_key,
175 crypt_algo_vpp_id, crypt_key,
176 self.vpp_ah_protocol,
177 flags=flags)
178 params.tra_sa_out.add_vpp_config()
Neale Ranns311124e2019-01-24 04:52:25 -0800179
180 VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
181 addr_any, addr_bcast,
182 addr_any, addr_bcast,
183 socket.IPPROTO_AH).add_vpp_config()
184 VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id,
185 addr_any, addr_bcast,
186 addr_any, addr_bcast,
187 socket.IPPROTO_AH,
188 is_outbound=0).add_vpp_config()
189
190 VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
191 self.tra_if.local_addr[addr_type],
192 self.tra_if.local_addr[addr_type],
193 self.tra_if.remote_addr[addr_type],
194 self.tra_if.remote_addr[addr_type],
Neale Ranns17dcec02019-01-09 21:22:20 -0800195 0, priority=10,
196 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
Neale Ranns311124e2019-01-24 04:52:25 -0800197 is_outbound=0).add_vpp_config()
198 VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id,
199 self.tra_if.local_addr[addr_type],
200 self.tra_if.local_addr[addr_type],
201 self.tra_if.remote_addr[addr_type],
202 self.tra_if.remote_addr[addr_type],
Neale Ranns17dcec02019-01-09 21:22:20 -0800203 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
204 priority=10).add_vpp_config()
Neale Ranns311124e2019-01-24 04:52:25 -0800205
“mystarrocks”23f0c452017-12-11 07:11:51 -0800206
Neale Ranns53f526b2019-02-25 14:32:02 +0000207class TestIpsecAh1(TemplateIpsecAh, IpsecTra46Tests, IpsecTun46Tests):
Klement Sekera31da2e32018-06-24 22:49:55 +0200208 """ Ipsec AH - TUN & TRA tests """
Klement Sekerab4d30532018-11-08 13:00:02 +0100209 tra4_encrypt_node_name = "ah4-encrypt"
210 tra4_decrypt_node_name = "ah4-decrypt"
211 tra6_encrypt_node_name = "ah6-encrypt"
212 tra6_decrypt_node_name = "ah6-decrypt"
213 tun4_encrypt_node_name = "ah4-encrypt"
214 tun4_decrypt_node_name = "ah4-decrypt"
215 tun6_encrypt_node_name = "ah6-encrypt"
216 tun6_decrypt_node_name = "ah6-decrypt"
“mystarrocks”23f0c452017-12-11 07:11:51 -0800217
“mystarrocks”23f0c452017-12-11 07:11:51 -0800218
Klement Sekera31da2e32018-06-24 22:49:55 +0200219class TestIpsecAh2(TemplateIpsecAh, IpsecTcpTests):
220 """ Ipsec AH - TCP tests """
221 pass
“mystarrocks”23f0c452017-12-11 07:11:51 -0800222
223
224if __name__ == '__main__':
225 unittest.main(testRunner=VppTestRunner)