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 | 39f9973 | 2016-11-28 16:10:59 +0000 | [diff] [blame] | 14 | self._sw_if_index = 0 |
| 15 | super(VppGreInterface, self).__init__(test) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 16 | self._test = test |
| 17 | self.t_src = src_ip |
| 18 | self.t_dst = dst_ip |
| 19 | self.t_outer_fib = outer_fib_id |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame^] | 20 | self.t_type = type |
| 21 | self.t_session = session |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 22 | |
| 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 Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame^] | 28 | tunnel_type=self.t_type, |
| 29 | session_id=self.t_session) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 30 | self._sw_if_index = r.sw_if_index |
Neale Ranns | 39f9973 | 2016-11-28 16:10:59 +0000 | [diff] [blame] | 31 | self.generate_remote_hosts() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 32 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 33 | |
| 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 Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 38 | self.test.vapi.gre_tunnel_add_del(s, d, |
| 39 | outer_fib_id=self.t_outer_fib, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame^] | 40 | tunnel_type=self.t_type, |
| 41 | session_id=self.t_session, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 42 | 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 Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 49 | |
| 50 | |
| 51 | class VppGre6Interface(VppInterface): |
| 52 | """ |
| 53 | VPP GRE IPv6 interface |
| 54 | """ |
| 55 | |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame^] | 56 | def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0, |
| 57 | session=0): |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 58 | """ Create VPP GRE interface """ |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 59 | 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 Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame^] | 65 | self.t_type = type |
| 66 | self.t_session = session |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 67 | |
| 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 Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame^] | 73 | tunnel_type=self.t_type, |
| 74 | session_id=self.t_session, |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 75 | is_ip6=1) |
| 76 | self._sw_if_index = r.sw_if_index |
| 77 | self.generate_remote_hosts() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 78 | self._test.registry.register(self, self._test.logger) |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 79 | |
| 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 Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 84 | self.test.vapi.gre_tunnel_add_del(s, d, |
| 85 | outer_fib_id=self.t_outer_fib, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame^] | 86 | tunnel_type=self.t_type, |
| 87 | session_id=self.t_session, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 88 | 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 |