blob: caec8d431c54472f3d3eb5108d16dec32cadd840 [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
Klement Sekerabf613952019-01-29 11:38:08 +01009from vpp_ipsec import VppIpsecSA, VppIpsecSpd, VppIpsecSpdEntry,\
10 VppIpsecSpdItfBinding
Neale Ranns311124e2019-01-24 04:52:25 -080011from vpp_ip_route import VppIpRoute, VppRoutePath
12from vpp_ip import DpoProto
Neale Ranns17dcec02019-01-09 21:22:20 -080013from vpp_papi import VppEnum
“mystarrocks”23f0c452017-12-11 07:11:51 -080014
15
Klement Sekera31da2e32018-06-24 22:49:55 +020016class TemplateIpsecAh(TemplateIpsec):
“mystarrocks”23f0c452017-12-11 07:11:51 -080017 """
18 Basic test for IPSEC using AH transport and Tunnel mode
19
“mystarrocks”23f0c452017-12-11 07:11:51 -080020 TRANSPORT MODE:
21
22 --- encrypt ---
23 |pg2| <-------> |VPP|
24 --- decrypt ---
25
26 TUNNEL MODE:
27
28 --- encrypt --- plain ---
Klement Sekera84c62042018-05-11 11:06:09 +020029 |pg0| <------- |VPP| <------ |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -080030 --- --- ---
31
32 --- decrypt --- plain ---
Klement Sekera84c62042018-05-11 11:06:09 +020033 |pg0| -------> |VPP| ------> |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -080034 --- --- ---
“mystarrocks”23f0c452017-12-11 07:11:51 -080035 """
36
Neale Ranns8e4a89b2019-01-23 08:16:17 -080037 def setUp(self):
38 super(TemplateIpsecAh, self).setUp()
“mystarrocks”23f0c452017-12-11 07:11:51 -080039
Neale Ranns8e4a89b2019-01-23 08:16:17 -080040 self.encryption_type = AH
41 self.tun_if = self.pg0
42 self.tra_if = self.pg2
43 self.logger.info(self.vapi.ppcli("show int addr"))
Neale Ranns311124e2019-01-24 04:52:25 -080044
45 self.tra_spd = VppIpsecSpd(self, self.tra_spd_id)
46 self.tra_spd.add_vpp_config()
47 VppIpsecSpdItfBinding(self, self.tra_spd,
48 self.tra_if).add_vpp_config()
49 self.tun_spd = VppIpsecSpd(self, self.tun_spd_id)
50 self.tun_spd.add_vpp_config()
51 VppIpsecSpdItfBinding(self, self.tun_spd,
52 self.tun_if).add_vpp_config()
53
Neale Ranns8e4a89b2019-01-23 08:16:17 -080054 for _, p in self.params.items():
55 self.config_ah_tra(p)
56 self.configure_sa_tra(p)
57 self.logger.info(self.vapi.ppcli("show ipsec"))
58 for _, p in self.params.items():
59 self.config_ah_tun(p)
60 self.logger.info(self.vapi.ppcli("show ipsec"))
61 for _, p in self.params.items():
Neale Ranns311124e2019-01-24 04:52:25 -080062 d = DpoProto.DPO_PROTO_IP6 if p.is_ipv6 else DpoProto.DPO_PROTO_IP4
63 VppIpRoute(self, p.remote_tun_if_host, p.addr_len,
64 [VppRoutePath(self.tun_if.remote_addr[p.addr_type],
65 0xffffffff,
66 proto=d)],
67 is_ip6=p.is_ipv6).add_vpp_config()
“mystarrocks”23f0c452017-12-11 07:11:51 -080068
69 def tearDown(self):
Klement Sekera31da2e32018-06-24 22:49:55 +020070 super(TemplateIpsecAh, self).tearDown()
“mystarrocks”23f0c452017-12-11 07:11:51 -080071 if not self.vpp_dead:
72 self.vapi.cli("show hardware")
73
Neale Ranns311124e2019-01-24 04:52:25 -080074 def config_ah_tun(self, params):
75 addr_type = params.addr_type
76 scapy_tun_sa_id = params.scapy_tun_sa_id
77 scapy_tun_spi = params.scapy_tun_spi
78 vpp_tun_sa_id = params.vpp_tun_sa_id
79 vpp_tun_spi = params.vpp_tun_spi
80 auth_algo_vpp_id = params.auth_algo_vpp_id
81 auth_key = params.auth_key
82 crypt_algo_vpp_id = params.crypt_algo_vpp_id
83 crypt_key = params.crypt_key
84 remote_tun_if_host = params.remote_tun_if_host
85 addr_any = params.addr_any
86 addr_bcast = params.addr_bcast
Neale Ranns17dcec02019-01-09 21:22:20 -080087 e = VppEnum.vl_api_ipsec_spd_action_t
88
Neale Ranns311124e2019-01-24 04:52:25 -080089 VppIpsecSA(self, scapy_tun_sa_id, scapy_tun_spi,
90 auth_algo_vpp_id, auth_key,
91 crypt_algo_vpp_id, crypt_key,
92 self.vpp_ah_protocol,
93 self.tun_if.local_addr[addr_type],
94 self.tun_if.remote_addr[addr_type]).add_vpp_config()
95 VppIpsecSA(self, vpp_tun_sa_id, vpp_tun_spi,
96 auth_algo_vpp_id, auth_key,
97 crypt_algo_vpp_id, crypt_key,
98 self.vpp_ah_protocol,
99 self.tun_if.remote_addr[addr_type],
100 self.tun_if.local_addr[addr_type]).add_vpp_config()
101
102 VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
103 addr_any, addr_bcast,
104 addr_any, addr_bcast,
105 socket.IPPROTO_AH).add_vpp_config()
106 VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
107 addr_any, addr_bcast,
108 addr_any, addr_bcast,
109 socket.IPPROTO_AH,
110 is_outbound=0).add_vpp_config()
111
112 VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
113 remote_tun_if_host,
114 remote_tun_if_host,
115 self.pg1.remote_addr[addr_type],
116 self.pg1.remote_addr[addr_type],
Neale Ranns17dcec02019-01-09 21:22:20 -0800117 0, priority=10,
118 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
Neale Ranns311124e2019-01-24 04:52:25 -0800119 is_outbound=0).add_vpp_config()
120 VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
121 self.pg1.remote_addr[addr_type],
122 self.pg1.remote_addr[addr_type],
123 remote_tun_if_host,
124 remote_tun_if_host,
Neale Ranns17dcec02019-01-09 21:22:20 -0800125 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
126 priority=10).add_vpp_config()
Neale Ranns311124e2019-01-24 04:52:25 -0800127
128 VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
129 remote_tun_if_host,
130 remote_tun_if_host,
131 self.pg0.local_addr[addr_type],
132 self.pg0.local_addr[addr_type],
Neale Ranns17dcec02019-01-09 21:22:20 -0800133 0, priority=20,
134 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
Neale Ranns311124e2019-01-24 04:52:25 -0800135 is_outbound=0).add_vpp_config()
136 VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
137 self.pg0.local_addr[addr_type],
138 self.pg0.local_addr[addr_type],
139 remote_tun_if_host,
140 remote_tun_if_host,
Neale Ranns17dcec02019-01-09 21:22:20 -0800141 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
142 priority=20).add_vpp_config()
Neale Ranns311124e2019-01-24 04:52:25 -0800143
144 def config_ah_tra(self, params):
145 addr_type = params.addr_type
146 scapy_tra_sa_id = params.scapy_tra_sa_id
147 scapy_tra_spi = params.scapy_tra_spi
148 vpp_tra_sa_id = params.vpp_tra_sa_id
149 vpp_tra_spi = params.vpp_tra_spi
150 auth_algo_vpp_id = params.auth_algo_vpp_id
151 auth_key = params.auth_key
152 crypt_algo_vpp_id = params.crypt_algo_vpp_id
153 crypt_key = params.crypt_key
154 addr_any = params.addr_any
155 addr_bcast = params.addr_bcast
Neale Ranns17dcec02019-01-09 21:22:20 -0800156 flags = (VppEnum.vl_api_ipsec_sad_flags_t.
157 IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY)
158 e = VppEnum.vl_api_ipsec_spd_action_t
Neale Ranns311124e2019-01-24 04:52:25 -0800159
160 VppIpsecSA(self, scapy_tra_sa_id, scapy_tra_spi,
161 auth_algo_vpp_id, auth_key,
162 crypt_algo_vpp_id, crypt_key,
163 self.vpp_ah_protocol,
Neale Ranns17dcec02019-01-09 21:22:20 -0800164 flags=flags).add_vpp_config()
Neale Ranns311124e2019-01-24 04:52:25 -0800165 VppIpsecSA(self, vpp_tra_sa_id, vpp_tra_spi,
166 auth_algo_vpp_id, auth_key,
167 crypt_algo_vpp_id, crypt_key,
168 self.vpp_ah_protocol,
Neale Ranns17dcec02019-01-09 21:22:20 -0800169 flags=flags).add_vpp_config()
Neale Ranns311124e2019-01-24 04:52:25 -0800170
171 VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
172 addr_any, addr_bcast,
173 addr_any, addr_bcast,
174 socket.IPPROTO_AH).add_vpp_config()
175 VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id,
176 addr_any, addr_bcast,
177 addr_any, addr_bcast,
178 socket.IPPROTO_AH,
179 is_outbound=0).add_vpp_config()
180
181 VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
182 self.tra_if.local_addr[addr_type],
183 self.tra_if.local_addr[addr_type],
184 self.tra_if.remote_addr[addr_type],
185 self.tra_if.remote_addr[addr_type],
Neale Ranns17dcec02019-01-09 21:22:20 -0800186 0, priority=10,
187 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
Neale Ranns311124e2019-01-24 04:52:25 -0800188 is_outbound=0).add_vpp_config()
189 VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id,
190 self.tra_if.local_addr[addr_type],
191 self.tra_if.local_addr[addr_type],
192 self.tra_if.remote_addr[addr_type],
193 self.tra_if.remote_addr[addr_type],
Neale Ranns17dcec02019-01-09 21:22:20 -0800194 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
195 priority=10).add_vpp_config()
Neale Ranns311124e2019-01-24 04:52:25 -0800196
“mystarrocks”23f0c452017-12-11 07:11:51 -0800197
Klement Sekera31da2e32018-06-24 22:49:55 +0200198class TestIpsecAh1(TemplateIpsecAh, IpsecTraTests, IpsecTunTests):
199 """ Ipsec AH - TUN & TRA tests """
Klement Sekerab4d30532018-11-08 13:00:02 +0100200 tra4_encrypt_node_name = "ah4-encrypt"
201 tra4_decrypt_node_name = "ah4-decrypt"
202 tra6_encrypt_node_name = "ah6-encrypt"
203 tra6_decrypt_node_name = "ah6-decrypt"
204 tun4_encrypt_node_name = "ah4-encrypt"
205 tun4_decrypt_node_name = "ah4-decrypt"
206 tun6_encrypt_node_name = "ah6-encrypt"
207 tun6_decrypt_node_name = "ah6-decrypt"
“mystarrocks”23f0c452017-12-11 07:11:51 -0800208
“mystarrocks”23f0c452017-12-11 07:11:51 -0800209
Klement Sekera31da2e32018-06-24 22:49:55 +0200210class TestIpsecAh2(TemplateIpsecAh, IpsecTcpTests):
211 """ Ipsec AH - TCP tests """
212 pass
“mystarrocks”23f0c452017-12-11 07:11:51 -0800213
214
215if __name__ == '__main__':
216 unittest.main(testRunner=VppTestRunner)