Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1 | |
| 2 | from vpp_interface import VppInterface |
| 3 | import socket |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 4 | from vpp_papi import VppEnum |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 5 | |
| 6 | |
| 7 | class VppGreInterface(VppInterface): |
| 8 | """ |
| 9 | VPP GRE interface |
| 10 | """ |
| 11 | |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 12 | def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=None, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 13 | session=0): |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 14 | """ Create VPP GRE interface """ |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 15 | super(VppGreInterface, self).__init__(test) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 16 | self.t_src = src_ip |
| 17 | self.t_dst = dst_ip |
| 18 | self.t_outer_fib = outer_fib_id |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 19 | self.t_session = session |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 20 | self.t_type = type |
| 21 | if not self.t_type: |
| 22 | self.t_type = (VppEnum.vl_api_gre_tunnel_type_t. |
| 23 | GRE_API_TUNNEL_TYPE_L3) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 24 | |
| 25 | def add_vpp_config(self): |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 26 | r = self.test.vapi.gre_tunnel_add_del(self.t_src, |
| 27 | self.t_dst, |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 28 | outer_fib_id=self.t_outer_fib, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 29 | tunnel_type=self.t_type, |
| 30 | session_id=self.t_session) |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 31 | self.set_sw_if_index(r.sw_if_index) |
Neale Ranns | 39f9973 | 2016-11-28 16:10:59 +0000 | [diff] [blame] | 32 | self.generate_remote_hosts() |
Klement Sekera | c798bc5 | 2018-05-23 20:22:20 +0200 | [diff] [blame] | 33 | self.test.registry.register(self, self.test.logger) |
Neale Ranns | adb17a8 | 2019-08-04 02:41:57 -0700 | [diff] [blame] | 34 | return self |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 35 | |
| 36 | def remove_vpp_config(self): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 37 | self.unconfig() |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 38 | self.test.vapi.gre_tunnel_add_del(self.t_src, |
| 39 | self.t_dst, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 40 | outer_fib_id=self.t_outer_fib, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 41 | tunnel_type=self.t_type, |
| 42 | session_id=self.t_session, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 43 | is_add=0) |
| 44 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 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 | |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 48 | def query_vpp_config(self): |
| 49 | return (self.test.vapi.gre_tunnel_dump( |
| 50 | sw_if_index=self._sw_if_index)) |