Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 1 | from vpp_tunnel_interface import VppTunnelInterface |
| 2 | from ipaddress import ip_address |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 3 | from vpp_papi import VppEnum |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 4 | |
| 5 | |
| 6 | class VppIpIpTunInterface(VppTunnelInterface): |
| 7 | """ |
| 8 | VPP IP-IP Tunnel interface |
| 9 | """ |
| 10 | |
Neale Ranns | 9534696 | 2019-11-25 13:04:44 +0000 | [diff] [blame] | 11 | def __init__(self, test, parent_if, src, dst, |
| 12 | table_id=0, dscp=0x0, |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 13 | flags=0, mode=None): |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 14 | super(VppIpIpTunInterface, self).__init__(test, parent_if) |
| 15 | self.src = src |
| 16 | self.dst = dst |
Neale Ranns | 9534696 | 2019-11-25 13:04:44 +0000 | [diff] [blame] | 17 | self.table_id = table_id |
| 18 | self.dscp = dscp |
| 19 | self.flags = flags |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 20 | self.mode = mode |
| 21 | if not self.mode: |
| 22 | self.mode = (VppEnum.vl_api_tunnel_mode_t. |
| 23 | TUNNEL_API_MODE_P2P) |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 24 | |
| 25 | def add_vpp_config(self): |
| 26 | r = self.test.vapi.ipip_add_tunnel( |
| 27 | tunnel={ |
| 28 | 'src': self.src, |
| 29 | 'dst': self.dst, |
Neale Ranns | 9534696 | 2019-11-25 13:04:44 +0000 | [diff] [blame] | 30 | 'table_id': self.table_id, |
| 31 | 'flags': self.flags, |
| 32 | 'dscp': self.dscp, |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 33 | 'instance': 0xffffffff, |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 34 | 'mode': self.mode, |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 35 | }) |
| 36 | self.set_sw_if_index(r.sw_if_index) |
Neale Ranns | 89d939e | 2021-06-07 09:34:07 +0000 | [diff] [blame] | 37 | r = self.test.vapi.ipip_tunnel_dump( |
| 38 | sw_if_index=self.sw_if_index) |
| 39 | self.instance = r[0].tunnel.instance |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 40 | self.test.registry.register(self, self.test.logger) |
Neale Ranns | 9534696 | 2019-11-25 13:04:44 +0000 | [diff] [blame] | 41 | return self |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 42 | |
| 43 | def remove_vpp_config(self): |
| 44 | self.test.vapi.ipip_del_tunnel(sw_if_index=self._sw_if_index) |
| 45 | |
| 46 | def query_vpp_config(self): |
| 47 | ts = self.test.vapi.ipip_tunnel_dump(sw_if_index=0xffffffff) |
| 48 | for t in ts: |
| 49 | if t.tunnel.sw_if_index == self._sw_if_index: |
| 50 | return True |
| 51 | return False |
| 52 | |
| 53 | def __str__(self): |
| 54 | return self.object_id() |
| 55 | |
| 56 | def object_id(self): |
Neale Ranns | 89d939e | 2021-06-07 09:34:07 +0000 | [diff] [blame] | 57 | return "ipip%d" % self.instance |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 58 | |
| 59 | @property |
| 60 | def remote_ip(self): |
| 61 | return self.dst |
| 62 | |
| 63 | @property |
| 64 | def local_ip(self): |
| 65 | return self.src |