blob: 6517458d3d68366921ace3d56d26d5c876b5d7e1 [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)
Neale Ranns89d939e2021-06-07 09:34:07 +000037 r = self.test.vapi.ipip_tunnel_dump(
38 sw_if_index=self.sw_if_index)
39 self.instance = r[0].tunnel.instance
Neale Rannsc87b66c2019-02-07 07:26:12 -080040 self.test.registry.register(self, self.test.logger)
Neale Ranns95346962019-11-25 13:04:44 +000041 return self
Neale Rannsc87b66c2019-02-07 07:26:12 -080042
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 Ranns89d939e2021-06-07 09:34:07 +000057 return "ipip%d" % self.instance
Neale Ranns12989b52019-09-26 16:20:19 +000058
59 @property
60 def remote_ip(self):
61 return self.dst
62
63 @property
64 def local_ip(self):
65 return self.src