blob: a40e8531a6198de932e48fa09295e38cbe6c76bc [file] [log] [blame]
Neale Ranns177bbdc2016-11-15 09:46:51 +00001from vpp_interface import VppInterface
Neale Ranns5a8844b2019-04-16 07:15:35 +00002from vpp_papi import VppEnum
Neale Ranns177bbdc2016-11-15 09:46:51 +00003
4
5class VppGreInterface(VppInterface):
6 """
7 VPP GRE interface
8 """
9
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020010 def __init__(
11 self,
12 test,
13 src_ip,
14 dst_ip,
15 outer_table_id=0,
16 type=None,
17 mode=None,
18 flags=0,
19 session=0,
20 ):
21 """Create VPP GRE interface"""
Klement Sekerab9ef2732018-06-24 22:49:33 +020022 super(VppGreInterface, self).__init__(test)
Neale Ranns177bbdc2016-11-15 09:46:51 +000023 self.t_src = src_ip
24 self.t_dst = dst_ip
Neale Ranns5f8f6172019-04-18 10:23:56 +000025 self.t_outer_table = outer_table_id
John Loa43ccae2018-02-13 17:15:23 -050026 self.t_session = session
Neale Rannse5b94dd2019-12-31 05:13:14 +000027 self.t_flags = flags
Neale Ranns5a8844b2019-04-16 07:15:35 +000028 self.t_type = type
29 if not self.t_type:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020030 self.t_type = VppEnum.vl_api_gre_tunnel_type_t.GRE_API_TUNNEL_TYPE_L3
Neale Ranns5f8f6172019-04-18 10:23:56 +000031 self.t_mode = mode
32 if not self.t_mode:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020033 self.t_mode = VppEnum.vl_api_tunnel_mode_t.TUNNEL_API_MODE_P2P
Neale Ranns177bbdc2016-11-15 09:46:51 +000034
35 def add_vpp_config(self):
Neale Ranns5f8f6172019-04-18 10:23:56 +000036 r = self.test.vapi.gre_tunnel_add_del(
Neale Rannse5b94dd2019-12-31 05:13:14 +000037 is_add=1,
38 tunnel={
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020039 "src": self.t_src,
40 "dst": self.t_dst,
41 "outer_table_id": self.t_outer_table,
42 "instance": 0xFFFFFFFF,
43 "type": self.t_type,
44 "mode": self.t_mode,
45 "flags": self.t_flags,
46 "session_id": self.t_session,
47 },
48 )
Klement Sekerab9ef2732018-06-24 22:49:33 +020049 self.set_sw_if_index(r.sw_if_index)
Neale Ranns39f99732016-11-28 16:10:59 +000050 self.generate_remote_hosts()
Klement Sekerac798bc52018-05-23 20:22:20 +020051 self.test.registry.register(self, self.test.logger)
Neale Rannsadb17a82019-08-04 02:41:57 -070052 return self
Neale Ranns177bbdc2016-11-15 09:46:51 +000053
54 def remove_vpp_config(self):
Neale Ranns177bbdc2016-11-15 09:46:51 +000055 self.unconfig()
Neale Rannse5b94dd2019-12-31 05:13:14 +000056 self.test.vapi.gre_tunnel_add_del(
57 is_add=0,
58 tunnel={
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020059 "src": self.t_src,
60 "dst": self.t_dst,
61 "outer_table_id": self.t_outer_table,
62 "instance": 0xFFFFFFFF,
63 "type": self.t_type,
64 "mode": self.t_mode,
65 "flags": self.t_flags,
66 "session_id": self.t_session,
67 },
68 )
Klement Sekera75e7d132017-09-20 08:26:30 +020069
Klement Sekera75e7d132017-09-20 08:26:30 +020070 def object_id(self):
Klement Sekerac798bc52018-05-23 20:22:20 +020071 return "gre-%d" % self.sw_if_index
Ciara Loftus7eac9162016-09-30 15:47:03 +010072
Neale Ranns5a8844b2019-04-16 07:15:35 +000073 def query_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020074 return self.test.vapi.gre_tunnel_dump(sw_if_index=self._sw_if_index)
Neale Ranns12989b52019-09-26 16:20:19 +000075
76 @property
77 def remote_ip(self):
78 return self.t_dst
79
80 @property
81 def local_ip(self):
82 return self.t_src