blob: bc689b321f06d954139ee3f2a805552982204d43 [file] [log] [blame]
Klement Sekera31da2e32018-06-24 22:49:55 +02001from vpp_tunnel_interface import VppTunnelInterface
2
3
4class VppIpsecTunInterface(VppTunnelInterface):
5 """
6 VPP IPsec Tunnel interface
7 """
8
9 def __init__(self, test, parent_if, local_spi,
10 remote_spi, crypto_alg, local_crypto_key, remote_crypto_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +000011 integ_alg, local_integ_key, remote_integ_key, salt=0,
12 is_ip6=False):
Klement Sekera31da2e32018-06-24 22:49:55 +020013 super(VppIpsecTunInterface, self).__init__(test, parent_if)
14 self.local_spi = local_spi
15 self.remote_spi = remote_spi
16 self.crypto_alg = crypto_alg
17 self.local_crypto_key = local_crypto_key
18 self.remote_crypto_key = remote_crypto_key
19 self.integ_alg = integ_alg
20 self.local_integ_key = local_integ_key
21 self.remote_integ_key = remote_integ_key
Neale Ranns80f6fd52019-04-16 02:41:34 +000022 self.salt = salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040023 if is_ip6:
24 self.local_ip = self.parent_if.local_ip6
25 self.remote_ip = self.parent_if.remote_ip6
26 else:
27 self.local_ip = self.parent_if.local_ip4
28 self.remote_ip = self.parent_if.remote_ip4
Klement Sekera31da2e32018-06-24 22:49:55 +020029
30 def add_vpp_config(self):
31 r = self.test.vapi.ipsec_tunnel_if_add_del(
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040032 self.local_ip, self.remote_ip,
33 self.remote_spi, self.local_spi,
34 self.crypto_alg, self.local_crypto_key, self.remote_crypto_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +000035 self.integ_alg, self.local_integ_key, self.remote_integ_key,
36 salt=self.salt)
Klement Sekera31da2e32018-06-24 22:49:55 +020037 self.set_sw_if_index(r.sw_if_index)
38 self.generate_remote_hosts()
39 self.test.registry.register(self, self.test.logger)
40
41 def remove_vpp_config(self):
42 self.test.vapi.ipsec_tunnel_if_add_del(
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040043 self.local_ip, self.remote_ip,
44 self.remote_spi, self.local_spi,
45 self.crypto_alg, self.local_crypto_key, self.remote_crypto_key,
46 self.integ_alg, self.local_integ_key, self.remote_integ_key,
47 is_add=0)
Klement Sekera31da2e32018-06-24 22:49:55 +020048
Klement Sekera31da2e32018-06-24 22:49:55 +020049 def object_id(self):
50 return "ipsec-tun-if-%d" % self._sw_if_index
Neale Rannsf05e7322019-03-29 20:23:58 +000051
52
53class VppIpsecGRETunInterface(VppTunnelInterface):
54 """
55 VPP IPsec GRE Tunnel interface
56 this creates headers
57 IP / ESP / IP / GRE / payload
58 i.e. it's GRE over IPSEC, rather than IPSEC over GRE.
59 """
60
61 def __init__(self, test, parent_if, sa_out, sa_in):
62 super(VppIpsecGRETunInterface, self).__init__(test, parent_if)
63 self.sa_in = sa_in
64 self.sa_out = sa_out
65
66 def add_vpp_config(self):
67 r = self.test.vapi.ipsec_gre_tunnel_add_del(
68 self.parent_if.local_ip4n,
69 self.parent_if.remote_ip4n,
70 self.sa_out,
71 self.sa_in)
72 self.set_sw_if_index(r.sw_if_index)
73 self.generate_remote_hosts()
74 self.test.registry.register(self, self.test.logger)
75
76 def remove_vpp_config(self):
77 self.test.vapi.ipsec_gre_tunnel_add_del(
78 self.parent_if.local_ip4n,
79 self.parent_if.remote_ip4n,
80 self.sa_out,
81 self.sa_in,
82 is_add=0)
83
84 def query_vpp_config(self):
85 ts = self.test.vapi.ipsec_gre_tunnel_dump(sw_if_index=0xffffffff)
86 for t in ts:
87 if t.tunnel.sw_if_index == self._sw_if_index:
88 return True
89 return False
90
91 def __str__(self):
92 return self.object_id()
93
94 def object_id(self):
95 return "ipsec-gre-tun-if-%d" % self._sw_if_index