Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1 | |
| 2 | from vpp_interface import VppInterface |
| 3 | import socket |
| 4 | |
| 5 | |
| 6 | class VppGreInterface(VppInterface): |
| 7 | """ |
| 8 | VPP GRE interface |
| 9 | """ |
| 10 | |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 11 | def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0, |
| 12 | session=0): |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 13 | """ Create VPP GRE interface """ |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 14 | self._test = test |
| 15 | self.t_src = src_ip |
| 16 | self.t_dst = dst_ip |
| 17 | self.t_outer_fib = outer_fib_id |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 18 | self.t_type = type |
| 19 | self.t_session = session |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 20 | |
| 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 Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 26 | tunnel_type=self.t_type, |
| 27 | session_id=self.t_session) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 28 | self._sw_if_index = r.sw_if_index |
Neale Ranns | 39f9973 | 2016-11-28 16:10:59 +0000 | [diff] [blame] | 29 | self.generate_remote_hosts() |
Klement Sekera | c798bc5 | 2018-05-23 20:22:20 +0200 | [diff] [blame] | 30 | self.test.registry.register(self, self.test.logger) |
| 31 | super(VppGreInterface, self).__init__(self.test) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 32 | |
| 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 Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 37 | self.test.vapi.gre_tunnel_add_del(s, d, |
| 38 | outer_fib_id=self.t_outer_fib, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 39 | tunnel_type=self.t_type, |
| 40 | session_id=self.t_session, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 41 | is_add=0) |
| 42 | |
| 43 | def __str__(self): |
| 44 | return self.object_id() |
| 45 | |
| 46 | def object_id(self): |
Klement Sekera | c798bc5 | 2018-05-23 20:22:20 +0200 | [diff] [blame] | 47 | return "gre-%d" % self.sw_if_index |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 48 | |
| 49 | |
| 50 | class VppGre6Interface(VppInterface): |
| 51 | """ |
| 52 | VPP GRE IPv6 interface |
| 53 | """ |
| 54 | |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 55 | def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0, |
| 56 | session=0): |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 57 | """ Create VPP GRE interface """ |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 58 | self._test = test |
| 59 | self.t_src = src_ip |
| 60 | self.t_dst = dst_ip |
| 61 | self.t_outer_fib = outer_fib_id |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 62 | self.t_type = type |
| 63 | self.t_session = session |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 64 | |
| 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 Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 70 | tunnel_type=self.t_type, |
| 71 | session_id=self.t_session, |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 72 | is_ip6=1) |
| 73 | self._sw_if_index = r.sw_if_index |
| 74 | self.generate_remote_hosts() |
Klement Sekera | c798bc5 | 2018-05-23 20:22:20 +0200 | [diff] [blame] | 75 | self.test.registry.register(self, self.test.logger) |
| 76 | super(VppGre6Interface, self).__init__(self.test) |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 77 | |
| 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 Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 82 | self.test.vapi.gre_tunnel_add_del(s, d, |
| 83 | outer_fib_id=self.t_outer_fib, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 84 | tunnel_type=self.t_type, |
| 85 | session_id=self.t_session, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 86 | 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 |