blob: 67cc1b5f1d8ae1de4158e1ee57906eb0f4cb789a [file] [log] [blame]
Neale Rannsc87b66c2019-02-07 07:26:12 -08001from vpp_tunnel_interface import VppTunnelInterface
2from ipaddress import ip_address
Neale Ranns14053c92019-12-29 23:55:18 +00003from vpp_papi import VppEnum
Neale Rannsc87b66c2019-02-07 07:26:12 -08004
5
6class VppIpIpTunInterface(VppTunnelInterface):
7 """
8 VPP IP-IP Tunnel interface
9 """
10
Neale Ranns95346962019-11-25 13:04:44 +000011 def __init__(self, test, parent_if, src, dst,
12 table_id=0, dscp=0x0,
Neale Ranns14053c92019-12-29 23:55:18 +000013 flags=0, mode=None):
Neale Rannsc87b66c2019-02-07 07:26:12 -080014 super(VppIpIpTunInterface, self).__init__(test, parent_if)
15 self.src = src
16 self.dst = dst
Neale Ranns95346962019-11-25 13:04:44 +000017 self.table_id = table_id
18 self.dscp = dscp
19 self.flags = flags
Neale Ranns14053c92019-12-29 23:55:18 +000020 self.mode = mode
21 if not self.mode:
22 self.mode = (VppEnum.vl_api_tunnel_mode_t.
23 TUNNEL_API_MODE_P2P)
Neale Rannsc87b66c2019-02-07 07:26:12 -080024
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 Ranns95346962019-11-25 13:04:44 +000030 'table_id': self.table_id,
31 'flags': self.flags,
32 'dscp': self.dscp,
Neale Rannsc87b66c2019-02-07 07:26:12 -080033 'instance': 0xffffffff,
Neale Ranns14053c92019-12-29 23:55:18 +000034 'mode': self.mode,
Neale Rannsc87b66c2019-02-07 07:26:12 -080035 })
36 self.set_sw_if_index(r.sw_if_index)
37 self.test.registry.register(self, self.test.logger)
Neale Ranns95346962019-11-25 13:04:44 +000038 return self
Neale Rannsc87b66c2019-02-07 07:26:12 -080039
40 def remove_vpp_config(self):
41 self.test.vapi.ipip_del_tunnel(sw_if_index=self._sw_if_index)
42
43 def query_vpp_config(self):
44 ts = self.test.vapi.ipip_tunnel_dump(sw_if_index=0xffffffff)
45 for t in ts:
46 if t.tunnel.sw_if_index == self._sw_if_index:
47 return True
48 return False
49
50 def __str__(self):
51 return self.object_id()
52
53 def object_id(self):
54 return "ipip-%d" % self._sw_if_index
Neale Ranns12989b52019-09-26 16:20:19 +000055
56 @property
57 def remote_ip(self):
58 return self.dst
59
60 @property
61 def local_ip(self):
62 return self.src