blob: 3de3e5c455988ec95459f8d50747cc724e005685 [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 """
Neale Ranns177bbdc2016-11-15 09:46:51 +000014 self._test = test
15 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)
24 r = self.test.vapi.gre_tunnel_add_del(s, d,
25 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)
Neale Ranns177bbdc2016-11-15 09:46:51 +000028 self._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)
31 super(VppGreInterface, self).__init__(self.test)
Neale Ranns177bbdc2016-11-15 09:46:51 +000032
33 def remove_vpp_config(self):
34 s = socket.inet_pton(socket.AF_INET, self.t_src)
35 d = socket.inet_pton(socket.AF_INET, self.t_dst)
36 self.unconfig()
Klement Sekera75e7d132017-09-20 08:26:30 +020037 self.test.vapi.gre_tunnel_add_del(s, d,
38 outer_fib_id=self.t_outer_fib,
John Loa43ccae2018-02-13 17:15:23 -050039 tunnel_type=self.t_type,
40 session_id=self.t_session,
Klement Sekera75e7d132017-09-20 08:26:30 +020041 is_add=0)
42
43 def __str__(self):
44 return self.object_id()
45
46 def object_id(self):
Klement Sekerac798bc52018-05-23 20:22:20 +020047 return "gre-%d" % self.sw_if_index
Ciara Loftus7eac9162016-09-30 15:47:03 +010048
49
50class VppGre6Interface(VppInterface):
51 """
52 VPP GRE IPv6 interface
53 """
54
John Loa43ccae2018-02-13 17:15:23 -050055 def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0,
56 session=0):
Neale Ranns33ce60d2017-12-14 08:51:32 -080057 """ Create VPP GRE interface """
Ciara Loftus7eac9162016-09-30 15:47:03 +010058 self._test = test
59 self.t_src = src_ip
60 self.t_dst = dst_ip
61 self.t_outer_fib = outer_fib_id
John Loa43ccae2018-02-13 17:15:23 -050062 self.t_type = type
63 self.t_session = session
Ciara Loftus7eac9162016-09-30 15:47:03 +010064
65 def add_vpp_config(self):
66 s = socket.inet_pton(socket.AF_INET6, self.t_src)
67 d = socket.inet_pton(socket.AF_INET6, self.t_dst)
68 r = self.test.vapi.gre_tunnel_add_del(s, d,
69 outer_fib_id=self.t_outer_fib,
John Loa43ccae2018-02-13 17:15:23 -050070 tunnel_type=self.t_type,
71 session_id=self.t_session,
Ciara Loftus7eac9162016-09-30 15:47:03 +010072 is_ip6=1)
73 self._sw_if_index = r.sw_if_index
74 self.generate_remote_hosts()
Klement Sekerac798bc52018-05-23 20:22:20 +020075 self.test.registry.register(self, self.test.logger)
76 super(VppGre6Interface, self).__init__(self.test)
Ciara Loftus7eac9162016-09-30 15:47:03 +010077
78 def remove_vpp_config(self):
79 s = socket.inet_pton(socket.AF_INET6, self.t_src)
80 d = socket.inet_pton(socket.AF_INET6, self.t_dst)
81 self.unconfig()
Klement Sekera75e7d132017-09-20 08:26:30 +020082 self.test.vapi.gre_tunnel_add_del(s, d,
83 outer_fib_id=self.t_outer_fib,
John Loa43ccae2018-02-13 17:15:23 -050084 tunnel_type=self.t_type,
85 session_id=self.t_session,
Klement Sekera75e7d132017-09-20 08:26:30 +020086 is_add=0,
87 is_ip6=1)
88
89 def __str__(self):
90 return self.object_id()
91
92 def object_id(self):
93 return "gre-%d" % self._sw_if_index