blob: 1a41244a0c5faa5186f73e7a4f043938eef88009 [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,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040011 integ_alg, local_integ_key, remote_integ_key, is_ip6=False):
Klement Sekera31da2e32018-06-24 22:49:55 +020012 super(VppIpsecTunInterface, self).__init__(test, parent_if)
13 self.local_spi = local_spi
14 self.remote_spi = remote_spi
15 self.crypto_alg = crypto_alg
16 self.local_crypto_key = local_crypto_key
17 self.remote_crypto_key = remote_crypto_key
18 self.integ_alg = integ_alg
19 self.local_integ_key = local_integ_key
20 self.remote_integ_key = remote_integ_key
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040021 if is_ip6:
22 self.local_ip = self.parent_if.local_ip6
23 self.remote_ip = self.parent_if.remote_ip6
24 else:
25 self.local_ip = self.parent_if.local_ip4
26 self.remote_ip = self.parent_if.remote_ip4
Klement Sekera31da2e32018-06-24 22:49:55 +020027
28 def add_vpp_config(self):
29 r = self.test.vapi.ipsec_tunnel_if_add_del(
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040030 self.local_ip, self.remote_ip,
31 self.remote_spi, self.local_spi,
32 self.crypto_alg, self.local_crypto_key, self.remote_crypto_key,
33 self.integ_alg, self.local_integ_key, self.remote_integ_key)
Klement Sekera31da2e32018-06-24 22:49:55 +020034 self.set_sw_if_index(r.sw_if_index)
35 self.generate_remote_hosts()
36 self.test.registry.register(self, self.test.logger)
37
38 def remove_vpp_config(self):
39 self.test.vapi.ipsec_tunnel_if_add_del(
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040040 self.local_ip, self.remote_ip,
41 self.remote_spi, self.local_spi,
42 self.crypto_alg, self.local_crypto_key, self.remote_crypto_key,
43 self.integ_alg, self.local_integ_key, self.remote_integ_key,
44 is_add=0)
Klement Sekera31da2e32018-06-24 22:49:55 +020045
Klement Sekera31da2e32018-06-24 22:49:55 +020046 def object_id(self):
47 return "ipsec-tun-if-%d" % self._sw_if_index
Neale Rannsf05e7322019-03-29 20:23:58 +000048
49
50class VppIpsecGRETunInterface(VppTunnelInterface):
51 """
52 VPP IPsec GRE Tunnel interface
53 this creates headers
54 IP / ESP / IP / GRE / payload
55 i.e. it's GRE over IPSEC, rather than IPSEC over GRE.
56 """
57
58 def __init__(self, test, parent_if, sa_out, sa_in):
59 super(VppIpsecGRETunInterface, self).__init__(test, parent_if)
60 self.sa_in = sa_in
61 self.sa_out = sa_out
62
63 def add_vpp_config(self):
64 r = self.test.vapi.ipsec_gre_tunnel_add_del(
65 self.parent_if.local_ip4n,
66 self.parent_if.remote_ip4n,
67 self.sa_out,
68 self.sa_in)
69 self.set_sw_if_index(r.sw_if_index)
70 self.generate_remote_hosts()
71 self.test.registry.register(self, self.test.logger)
72
73 def remove_vpp_config(self):
74 self.test.vapi.ipsec_gre_tunnel_add_del(
75 self.parent_if.local_ip4n,
76 self.parent_if.remote_ip4n,
77 self.sa_out,
78 self.sa_in,
79 is_add=0)
80
81 def query_vpp_config(self):
82 ts = self.test.vapi.ipsec_gre_tunnel_dump(sw_if_index=0xffffffff)
83 for t in ts:
84 if t.tunnel.sw_if_index == self._sw_if_index:
85 return True
86 return False
87
88 def __str__(self):
89 return self.object_id()
90
91 def object_id(self):
92 return "ipsec-gre-tun-if-%d" % self._sw_if_index