blob: 259767653bdca50cbaf1109852b43fc398780edf [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
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020011 def __init__(
12 self, test, parent_if, src, dst, table_id=0, dscp=0x0, flags=0, mode=None
13 ):
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:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020022 self.mode = VppEnum.vl_api_tunnel_mode_t.TUNNEL_API_MODE_P2P
Neale Rannsc87b66c2019-02-07 07:26:12 -080023
24 def add_vpp_config(self):
25 r = self.test.vapi.ipip_add_tunnel(
26 tunnel={
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020027 "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 Rannsc87b66c2019-02-07 07:26:12 -080036 self.set_sw_if_index(r.sw_if_index)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020037 r = self.test.vapi.ipip_tunnel_dump(sw_if_index=self.sw_if_index)
Neale Ranns89d939e2021-06-07 09:34:07 +000038 self.instance = r[0].tunnel.instance
Neale Rannsc87b66c2019-02-07 07:26:12 -080039 self.test.registry.register(self, self.test.logger)
Neale Ranns95346962019-11-25 13:04:44 +000040 return self
Neale Rannsc87b66c2019-02-07 07:26:12 -080041
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 Sekerad9b0c6f2022-04-26 19:02:15 +020046 ts = self.test.vapi.ipip_tunnel_dump(sw_if_index=0xFFFFFFFF)
Neale Rannsc87b66c2019-02-07 07:26:12 -080047 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 Ranns89d939e2021-06-07 09:34:07 +000056 return "ipip%d" % self.instance
Neale Ranns12989b52019-09-26 16:20:19 +000057
58 @property
59 def remote_ip(self):
60 return self.dst
61
62 @property
63 def local_ip(self):
64 return self.src