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 |
| 3 | |
| 4 | |
| 5 | class VppIpIpTunInterface(VppTunnelInterface): |
| 6 | """ |
| 7 | VPP IP-IP Tunnel interface |
| 8 | """ |
| 9 | |
Neale Ranns | 9534696 | 2019-11-25 13:04:44 +0000 | [diff] [blame] | 10 | def __init__(self, test, parent_if, src, dst, |
| 11 | table_id=0, dscp=0x0, |
| 12 | flags=0): |
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 | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 19 | |
| 20 | def add_vpp_config(self): |
| 21 | r = self.test.vapi.ipip_add_tunnel( |
| 22 | tunnel={ |
| 23 | 'src': self.src, |
| 24 | 'dst': self.dst, |
Neale Ranns | 9534696 | 2019-11-25 13:04:44 +0000 | [diff] [blame] | 25 | 'table_id': self.table_id, |
| 26 | 'flags': self.flags, |
| 27 | 'dscp': self.dscp, |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 28 | 'instance': 0xffffffff, |
| 29 | }) |
| 30 | self.set_sw_if_index(r.sw_if_index) |
| 31 | self.test.registry.register(self, self.test.logger) |
Neale Ranns | 9534696 | 2019-11-25 13:04:44 +0000 | [diff] [blame] | 32 | return self |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 33 | |
| 34 | def remove_vpp_config(self): |
| 35 | self.test.vapi.ipip_del_tunnel(sw_if_index=self._sw_if_index) |
| 36 | |
| 37 | def query_vpp_config(self): |
| 38 | ts = self.test.vapi.ipip_tunnel_dump(sw_if_index=0xffffffff) |
| 39 | for t in ts: |
| 40 | if t.tunnel.sw_if_index == self._sw_if_index: |
| 41 | return True |
| 42 | return False |
| 43 | |
| 44 | def __str__(self): |
| 45 | return self.object_id() |
| 46 | |
| 47 | def object_id(self): |
| 48 | return "ipip-%d" % self._sw_if_index |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 49 | |
| 50 | @property |
| 51 | def remote_ip(self): |
| 52 | return self.dst |
| 53 | |
| 54 | @property |
| 55 | def local_ip(self): |
| 56 | return self.src |