blob: 770292e80b8cff10dae2ab377a1ce96e44ea83a0 [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,
Neale Rannse5b94dd2019-12-31 05:13:14 +000013 type=None, mode=None, flags=0,
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 Rannse5b94dd2019-12-31 05:13:14 +000021 self.t_flags = flags
Neale Ranns5a8844b2019-04-16 07:15:35 +000022 self.t_type = type
23 if not self.t_type:
24 self.t_type = (VppEnum.vl_api_gre_tunnel_type_t.
25 GRE_API_TUNNEL_TYPE_L3)
Neale Ranns5f8f6172019-04-18 10:23:56 +000026 self.t_mode = mode
27 if not self.t_mode:
Neale Ranns59ff9182019-12-29 23:55:18 +000028 self.t_mode = (VppEnum.vl_api_tunnel_mode_t.
29 TUNNEL_API_MODE_P2P)
Neale Ranns177bbdc2016-11-15 09:46:51 +000030
31 def add_vpp_config(self):
Neale Ranns5f8f6172019-04-18 10:23:56 +000032 r = self.test.vapi.gre_tunnel_add_del(
Neale Rannse5b94dd2019-12-31 05:13:14 +000033 is_add=1,
34 tunnel={
35 'src': self.t_src,
36 'dst': self.t_dst,
37 'outer_table_id': self.t_outer_table,
38 'instance': 0xffffffff,
39 'type': self.t_type,
40 'mode': self.t_mode,
41 'flags': self.t_flags,
42 'session_id': self.t_session})
Klement Sekerab9ef2732018-06-24 22:49:33 +020043 self.set_sw_if_index(r.sw_if_index)
Neale Ranns39f99732016-11-28 16:10:59 +000044 self.generate_remote_hosts()
Klement Sekerac798bc52018-05-23 20:22:20 +020045 self.test.registry.register(self, self.test.logger)
Neale Rannsadb17a82019-08-04 02:41:57 -070046 return self
Neale Ranns177bbdc2016-11-15 09:46:51 +000047
48 def remove_vpp_config(self):
Neale Ranns177bbdc2016-11-15 09:46:51 +000049 self.unconfig()
Neale Rannse5b94dd2019-12-31 05:13:14 +000050 self.test.vapi.gre_tunnel_add_del(
51 is_add=0,
52 tunnel={
53 'src': self.t_src,
54 'dst': self.t_dst,
55 'outer_table_id': self.t_outer_table,
56 'instance': 0xffffffff,
57 'type': self.t_type,
58 'mode': self.t_mode,
59 'flags': self.t_flags,
60 'session_id': self.t_session})
Klement Sekera75e7d132017-09-20 08:26:30 +020061
Klement Sekera75e7d132017-09-20 08:26:30 +020062 def object_id(self):
Klement Sekerac798bc52018-05-23 20:22:20 +020063 return "gre-%d" % self.sw_if_index
Ciara Loftus7eac9162016-09-30 15:47:03 +010064
Neale Ranns5a8844b2019-04-16 07:15:35 +000065 def query_vpp_config(self):
66 return (self.test.vapi.gre_tunnel_dump(
67 sw_if_index=self._sw_if_index))
Neale Ranns12989b52019-09-26 16:20:19 +000068
69 @property
70 def remote_ip(self):
71 return self.t_dst
72
73 @property
74 def local_ip(self):
75 return self.t_src