blob: 91293c3d28c1e87c782fa2c161413264bce5bd91 [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 Ranns39f99732016-11-28 16:10:59 +000014 self._sw_if_index = 0
15 super(VppGreInterface, self).__init__(test)
Neale Ranns177bbdc2016-11-15 09:46:51 +000016 self._test = test
17 self.t_src = src_ip
18 self.t_dst = dst_ip
19 self.t_outer_fib = outer_fib_id
John Loa43ccae2018-02-13 17:15:23 -050020 self.t_type = type
21 self.t_session = session
Neale Ranns177bbdc2016-11-15 09:46:51 +000022
23 def add_vpp_config(self):
24 s = socket.inet_pton(socket.AF_INET, self.t_src)
25 d = socket.inet_pton(socket.AF_INET, self.t_dst)
26 r = self.test.vapi.gre_tunnel_add_del(s, d,
27 outer_fib_id=self.t_outer_fib,
John Loa43ccae2018-02-13 17:15:23 -050028 tunnel_type=self.t_type,
29 session_id=self.t_session)
Neale Ranns177bbdc2016-11-15 09:46:51 +000030 self._sw_if_index = r.sw_if_index
Neale Ranns39f99732016-11-28 16:10:59 +000031 self.generate_remote_hosts()
Klement Sekera75e7d132017-09-20 08:26:30 +020032 self._test.registry.register(self, self._test.logger)
Neale Ranns177bbdc2016-11-15 09:46:51 +000033
34 def remove_vpp_config(self):
35 s = socket.inet_pton(socket.AF_INET, self.t_src)
36 d = socket.inet_pton(socket.AF_INET, self.t_dst)
37 self.unconfig()
Klement Sekera75e7d132017-09-20 08:26:30 +020038 self.test.vapi.gre_tunnel_add_del(s, d,
39 outer_fib_id=self.t_outer_fib,
John Loa43ccae2018-02-13 17:15:23 -050040 tunnel_type=self.t_type,
41 session_id=self.t_session,
Klement Sekera75e7d132017-09-20 08:26:30 +020042 is_add=0)
43
44 def __str__(self):
45 return self.object_id()
46
47 def object_id(self):
48 return "gre-%d" % self._sw_if_index
Ciara Loftus7eac9162016-09-30 15:47:03 +010049
50
51class VppGre6Interface(VppInterface):
52 """
53 VPP GRE IPv6 interface
54 """
55
John Loa43ccae2018-02-13 17:15:23 -050056 def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0,
57 session=0):
Neale Ranns33ce60d2017-12-14 08:51:32 -080058 """ Create VPP GRE interface """
Ciara Loftus7eac9162016-09-30 15:47:03 +010059 self._sw_if_index = 0
60 super(VppGre6Interface, self).__init__(test)
61 self._test = test
62 self.t_src = src_ip
63 self.t_dst = dst_ip
64 self.t_outer_fib = outer_fib_id
John Loa43ccae2018-02-13 17:15:23 -050065 self.t_type = type
66 self.t_session = session
Ciara Loftus7eac9162016-09-30 15:47:03 +010067
68 def add_vpp_config(self):
69 s = socket.inet_pton(socket.AF_INET6, self.t_src)
70 d = socket.inet_pton(socket.AF_INET6, self.t_dst)
71 r = self.test.vapi.gre_tunnel_add_del(s, d,
72 outer_fib_id=self.t_outer_fib,
John Loa43ccae2018-02-13 17:15:23 -050073 tunnel_type=self.t_type,
74 session_id=self.t_session,
Ciara Loftus7eac9162016-09-30 15:47:03 +010075 is_ip6=1)
76 self._sw_if_index = r.sw_if_index
77 self.generate_remote_hosts()
Klement Sekera75e7d132017-09-20 08:26:30 +020078 self._test.registry.register(self, self._test.logger)
Ciara Loftus7eac9162016-09-30 15:47:03 +010079
80 def remove_vpp_config(self):
81 s = socket.inet_pton(socket.AF_INET6, self.t_src)
82 d = socket.inet_pton(socket.AF_INET6, self.t_dst)
83 self.unconfig()
Klement Sekera75e7d132017-09-20 08:26:30 +020084 self.test.vapi.gre_tunnel_add_del(s, d,
85 outer_fib_id=self.t_outer_fib,
John Loa43ccae2018-02-13 17:15:23 -050086 tunnel_type=self.t_type,
87 session_id=self.t_session,
Klement Sekera75e7d132017-09-20 08:26:30 +020088 is_add=0,
89 is_ip6=1)
90
91 def __str__(self):
92 return self.object_id()
93
94 def object_id(self):
95 return "gre-%d" % self._sw_if_index