Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1 | from vpp_tunnel_interface import VppTunnelInterface |
| 2 | |
| 3 | |
| 4 | class 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 Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 11 | integ_alg, local_integ_key, remote_integ_key, is_ip6=False): |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 12 | 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 Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 21 | 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 Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 27 | |
| 28 | def add_vpp_config(self): |
| 29 | r = self.test.vapi.ipsec_tunnel_if_add_del( |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 30 | 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 Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 34 | 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 Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 40 | 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 Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 45 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 46 | def object_id(self): |
| 47 | return "ipsec-tun-if-%d" % self._sw_if_index |
Neale Ranns | f05e732 | 2019-03-29 20:23:58 +0000 | [diff] [blame] | 48 | |
| 49 | |
| 50 | class 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 |