blob: 905c3832532ac7491305079ed11b8640e36e7043 [file] [log] [blame]
Neale Ranns177bbdc2016-11-15 09:46:51 +00001
2from vpp_interface import VppInterface
3import socket
Neale Ranns5a8844b2019-04-16 07:15:35 +00004from vpp_papi import VppEnum
Neale Ranns177bbdc2016-11-15 09:46:51 +00005
6
7class VppGreInterface(VppInterface):
8 """
9 VPP GRE interface
10 """
11
Neale Ranns5f8f6172019-04-18 10:23:56 +000012 def __init__(self, test, src_ip, dst_ip, outer_table_id=0,
13 type=None, mode=None,
John Loa43ccae2018-02-13 17:15:23 -050014 session=0):
Neale Ranns33ce60d2017-12-14 08:51:32 -080015 """ Create VPP GRE interface """
Klement Sekerab9ef2732018-06-24 22:49:33 +020016 super(VppGreInterface, self).__init__(test)
Neale Ranns177bbdc2016-11-15 09:46:51 +000017 self.t_src = src_ip
18 self.t_dst = dst_ip
Neale Ranns5f8f6172019-04-18 10:23:56 +000019 self.t_outer_table = outer_table_id
John Loa43ccae2018-02-13 17:15:23 -050020 self.t_session = session
Neale Ranns5a8844b2019-04-16 07:15:35 +000021 self.t_type = type
22 if not self.t_type:
23 self.t_type = (VppEnum.vl_api_gre_tunnel_type_t.
24 GRE_API_TUNNEL_TYPE_L3)
Neale Ranns5f8f6172019-04-18 10:23:56 +000025 self.t_mode = mode
26 if not self.t_mode:
27 self.t_mode = (VppEnum.vl_api_gre_tunnel_mode_t.
28 GRE_API_TUNNEL_MODE_P2P)
Neale Ranns177bbdc2016-11-15 09:46:51 +000029
30 def add_vpp_config(self):
Neale Ranns5f8f6172019-04-18 10:23:56 +000031 r = self.test.vapi.gre_tunnel_add_del(
32 self.t_src,
33 self.t_dst,
34 outer_table_id=self.t_outer_table,
35 type=self.t_type,
36 mode=self.t_mode,
37 session_id=self.t_session)
Klement Sekerab9ef2732018-06-24 22:49:33 +020038 self.set_sw_if_index(r.sw_if_index)
Neale Ranns39f99732016-11-28 16:10:59 +000039 self.generate_remote_hosts()
Klement Sekerac798bc52018-05-23 20:22:20 +020040 self.test.registry.register(self, self.test.logger)
Neale Rannsadb17a82019-08-04 02:41:57 -070041 return self
Neale Ranns177bbdc2016-11-15 09:46:51 +000042
43 def remove_vpp_config(self):
Neale Ranns177bbdc2016-11-15 09:46:51 +000044 self.unconfig()
Neale Ranns5a8844b2019-04-16 07:15:35 +000045 self.test.vapi.gre_tunnel_add_del(self.t_src,
46 self.t_dst,
Neale Ranns5f8f6172019-04-18 10:23:56 +000047 outer_table_id=self.t_outer_table,
48 type=self.t_type,
49 mode=self.t_mode,
John Loa43ccae2018-02-13 17:15:23 -050050 session_id=self.t_session,
Klement Sekera75e7d132017-09-20 08:26:30 +020051 is_add=0)
52
Klement Sekera75e7d132017-09-20 08:26:30 +020053 def object_id(self):
Klement Sekerac798bc52018-05-23 20:22:20 +020054 return "gre-%d" % self.sw_if_index
Ciara Loftus7eac9162016-09-30 15:47:03 +010055
Neale Ranns5a8844b2019-04-16 07:15:35 +000056 def query_vpp_config(self):
57 return (self.test.vapi.gre_tunnel_dump(
58 sw_if_index=self._sw_if_index))
Neale Ranns12989b52019-09-26 16:20:19 +000059
60 @property
61 def remote_ip(self):
62 return self.t_dst
63
64 @property
65 def local_ip(self):
66 return self.t_src