blob: d6f4202cf1a190743645c96aeb9f07ebc39572b7 [file] [log] [blame]
Neale Ranns177bbdc2016-11-15 09:46:51 +00001
2from vpp_interface import VppInterface
3import socket
4
5
6class VppGreInterface(VppInterface):
7 """
8 VPP GRE interface
9 """
10
John Loa43ccae2018-02-13 17:15:23 -050011 def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0,
12 session=0):
Neale Ranns33ce60d2017-12-14 08:51:32 -080013 """ Create VPP GRE interface """
Klement Sekerab9ef2732018-06-24 22:49:33 +020014 super(VppGreInterface, self).__init__(test)
Neale Ranns177bbdc2016-11-15 09:46:51 +000015 self.t_src = src_ip
16 self.t_dst = dst_ip
17 self.t_outer_fib = outer_fib_id
John Loa43ccae2018-02-13 17:15:23 -050018 self.t_type = type
19 self.t_session = session
Neale Ranns177bbdc2016-11-15 09:46:51 +000020
21 def add_vpp_config(self):
22 s = socket.inet_pton(socket.AF_INET, self.t_src)
23 d = socket.inet_pton(socket.AF_INET, self.t_dst)
Ole Troane1ade682019-03-04 23:55:43 +010024 r = self.test.vapi.gre_add_del_tunnel(s, d,
Neale Ranns177bbdc2016-11-15 09:46:51 +000025 outer_fib_id=self.t_outer_fib,
John Loa43ccae2018-02-13 17:15:23 -050026 tunnel_type=self.t_type,
27 session_id=self.t_session)
Klement Sekerab9ef2732018-06-24 22:49:33 +020028 self.set_sw_if_index(r.sw_if_index)
Neale Ranns39f99732016-11-28 16:10:59 +000029 self.generate_remote_hosts()
Klement Sekerac798bc52018-05-23 20:22:20 +020030 self.test.registry.register(self, self.test.logger)
Neale Ranns177bbdc2016-11-15 09:46:51 +000031
32 def remove_vpp_config(self):
33 s = socket.inet_pton(socket.AF_INET, self.t_src)
34 d = socket.inet_pton(socket.AF_INET, self.t_dst)
35 self.unconfig()
Ole Troane1ade682019-03-04 23:55:43 +010036 self.test.vapi.gre_add_del_tunnel(s, d,
Klement Sekera75e7d132017-09-20 08:26:30 +020037 outer_fib_id=self.t_outer_fib,
John Loa43ccae2018-02-13 17:15:23 -050038 tunnel_type=self.t_type,
39 session_id=self.t_session,
Klement Sekera75e7d132017-09-20 08:26:30 +020040 is_add=0)
41
42 def __str__(self):
43 return self.object_id()
44
45 def object_id(self):
Klement Sekerac798bc52018-05-23 20:22:20 +020046 return "gre-%d" % self.sw_if_index
Ciara Loftus7eac9162016-09-30 15:47:03 +010047
48
49class VppGre6Interface(VppInterface):
50 """
51 VPP GRE IPv6 interface
52 """
53
John Loa43ccae2018-02-13 17:15:23 -050054 def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0,
55 session=0):
Neale Ranns33ce60d2017-12-14 08:51:32 -080056 """ Create VPP GRE interface """
Klement Sekerab9ef2732018-06-24 22:49:33 +020057 super(VppGre6Interface, self).__init__(test)
Ciara Loftus7eac9162016-09-30 15:47:03 +010058 self.t_src = src_ip
59 self.t_dst = dst_ip
60 self.t_outer_fib = outer_fib_id
John Loa43ccae2018-02-13 17:15:23 -050061 self.t_type = type
62 self.t_session = session
Ciara Loftus7eac9162016-09-30 15:47:03 +010063
64 def add_vpp_config(self):
65 s = socket.inet_pton(socket.AF_INET6, self.t_src)
66 d = socket.inet_pton(socket.AF_INET6, self.t_dst)
Ole Troane1ade682019-03-04 23:55:43 +010067 r = self.test.vapi.gre_add_del_tunnel(s, d,
Ciara Loftus7eac9162016-09-30 15:47:03 +010068 outer_fib_id=self.t_outer_fib,
John Loa43ccae2018-02-13 17:15:23 -050069 tunnel_type=self.t_type,
70 session_id=self.t_session,
Ciara Loftus7eac9162016-09-30 15:47:03 +010071 is_ip6=1)
Klement Sekerab9ef2732018-06-24 22:49:33 +020072 self.set_sw_if_index(r.sw_if_index)
Ciara Loftus7eac9162016-09-30 15:47:03 +010073 self.generate_remote_hosts()
Klement Sekerac798bc52018-05-23 20:22:20 +020074 self.test.registry.register(self, self.test.logger)
Ciara Loftus7eac9162016-09-30 15:47:03 +010075
76 def remove_vpp_config(self):
77 s = socket.inet_pton(socket.AF_INET6, self.t_src)
78 d = socket.inet_pton(socket.AF_INET6, self.t_dst)
79 self.unconfig()
Ole Troane1ade682019-03-04 23:55:43 +010080 self.test.vapi.gre_add_del_tunnel(s, d,
Klement Sekera75e7d132017-09-20 08:26:30 +020081 outer_fib_id=self.t_outer_fib,
John Loa43ccae2018-02-13 17:15:23 -050082 tunnel_type=self.t_type,
83 session_id=self.t_session,
Klement Sekera75e7d132017-09-20 08:26:30 +020084 is_add=0,
85 is_ip6=1)
86
87 def __str__(self):
88 return self.object_id()
89
90 def object_id(self):
91 return "gre-%d" % self._sw_if_index