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 """ |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame^] | 14 | super(VppGreInterface, self).__init__(test) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 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) |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame^] | 28 | self.set_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) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 31 | |
| 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() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 36 | self.test.vapi.gre_tunnel_add_del(s, d, |
| 37 | outer_fib_id=self.t_outer_fib, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 38 | tunnel_type=self.t_type, |
| 39 | session_id=self.t_session, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 40 | is_add=0) |
| 41 | |
| 42 | def __str__(self): |
| 43 | return self.object_id() |
| 44 | |
| 45 | def object_id(self): |
Klement Sekera | c798bc5 | 2018-05-23 20:22:20 +0200 | [diff] [blame] | 46 | return "gre-%d" % self.sw_if_index |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 47 | |
| 48 | |
| 49 | class VppGre6Interface(VppInterface): |
| 50 | """ |
| 51 | VPP GRE IPv6 interface |
| 52 | """ |
| 53 | |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 54 | def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0, |
| 55 | session=0): |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 56 | """ Create VPP GRE interface """ |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame^] | 57 | super(VppGre6Interface, self).__init__(test) |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 58 | self.t_src = src_ip |
| 59 | self.t_dst = dst_ip |
| 60 | self.t_outer_fib = outer_fib_id |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 61 | self.t_type = type |
| 62 | self.t_session = session |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 63 | |
| 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) |
| 67 | r = self.test.vapi.gre_tunnel_add_del(s, d, |
| 68 | outer_fib_id=self.t_outer_fib, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 69 | tunnel_type=self.t_type, |
| 70 | session_id=self.t_session, |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 71 | is_ip6=1) |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame^] | 72 | self.set_sw_if_index(r.sw_if_index) |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 73 | self.generate_remote_hosts() |
Klement Sekera | c798bc5 | 2018-05-23 20:22:20 +0200 | [diff] [blame] | 74 | self.test.registry.register(self, self.test.logger) |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 75 | |
| 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() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 80 | self.test.vapi.gre_tunnel_add_del(s, d, |
| 81 | outer_fib_id=self.t_outer_fib, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 82 | tunnel_type=self.t_type, |
| 83 | session_id=self.t_session, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 84 | 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 |