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 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 11 | def __init__( |
| 12 | self, test, parent_if, src, dst, table_id=0, dscp=0x0, flags=0, mode=None |
| 13 | ): |
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: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 22 | self.mode = VppEnum.vl_api_tunnel_mode_t.TUNNEL_API_MODE_P2P |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 23 | |
| 24 | def add_vpp_config(self): |
| 25 | r = self.test.vapi.ipip_add_tunnel( |
| 26 | tunnel={ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 27 | "src": self.src, |
| 28 | "dst": self.dst, |
| 29 | "table_id": self.table_id, |
| 30 | "flags": self.flags, |
| 31 | "dscp": self.dscp, |
| 32 | "instance": 0xFFFFFFFF, |
| 33 | "mode": self.mode, |
| 34 | } |
| 35 | ) |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 36 | self.set_sw_if_index(r.sw_if_index) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 37 | r = self.test.vapi.ipip_tunnel_dump(sw_if_index=self.sw_if_index) |
Neale Ranns | 89d939e | 2021-06-07 09:34:07 +0000 | [diff] [blame] | 38 | self.instance = r[0].tunnel.instance |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 39 | self.test.registry.register(self, self.test.logger) |
Neale Ranns | 9534696 | 2019-11-25 13:04:44 +0000 | [diff] [blame] | 40 | return self |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 41 | |
| 42 | def remove_vpp_config(self): |
| 43 | self.test.vapi.ipip_del_tunnel(sw_if_index=self._sw_if_index) |
| 44 | |
| 45 | def query_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 46 | ts = self.test.vapi.ipip_tunnel_dump(sw_if_index=0xFFFFFFFF) |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 47 | for t in ts: |
| 48 | if t.tunnel.sw_if_index == self._sw_if_index: |
| 49 | return True |
| 50 | return False |
| 51 | |
| 52 | def __str__(self): |
| 53 | return self.object_id() |
| 54 | |
| 55 | def object_id(self): |
Neale Ranns | 89d939e | 2021-06-07 09:34:07 +0000 | [diff] [blame] | 56 | return "ipip%d" % self.instance |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 57 | |
| 58 | @property |
| 59 | def remote_ip(self): |
| 60 | return self.dst |
| 61 | |
| 62 | @property |
| 63 | def local_ip(self): |
| 64 | return self.src |