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