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, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 11 | integ_alg, local_integ_key, remote_integ_key, salt=0, |
| 12 | is_ip6=False): |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 13 | 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 Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 22 | self.salt = salt |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 23 | 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 Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 29 | |
| 30 | def add_vpp_config(self): |
| 31 | r = self.test.vapi.ipsec_tunnel_if_add_del( |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 32 | 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 Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 35 | self.integ_alg, self.local_integ_key, self.remote_integ_key, |
| 36 | salt=self.salt) |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 37 | 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 Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 43 | 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 Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 48 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 49 | def object_id(self): |
| 50 | return "ipsec-tun-if-%d" % self._sw_if_index |
Neale Ranns | f05e732 | 2019-03-29 20:23:58 +0000 | [diff] [blame] | 51 | |
| 52 | |
| 53 | class 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 |