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