Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1 | from vpp_interface import VppInterface |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 2 | from vpp_papi import VppEnum |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 3 | |
| 4 | |
| 5 | class VppGreInterface(VppInterface): |
| 6 | """ |
| 7 | VPP GRE interface |
| 8 | """ |
| 9 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 10 | def __init__( |
| 11 | self, |
| 12 | test, |
| 13 | src_ip, |
| 14 | dst_ip, |
| 15 | outer_table_id=0, |
| 16 | type=None, |
| 17 | mode=None, |
| 18 | flags=0, |
| 19 | session=0, |
| 20 | ): |
| 21 | """Create VPP GRE interface""" |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 22 | super(VppGreInterface, self).__init__(test) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 23 | self.t_src = src_ip |
| 24 | self.t_dst = dst_ip |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 25 | self.t_outer_table = outer_table_id |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 26 | self.t_session = session |
Neale Ranns | e5b94dd | 2019-12-31 05:13:14 +0000 | [diff] [blame] | 27 | self.t_flags = flags |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 28 | self.t_type = type |
| 29 | if not self.t_type: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 30 | self.t_type = VppEnum.vl_api_gre_tunnel_type_t.GRE_API_TUNNEL_TYPE_L3 |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 31 | self.t_mode = mode |
| 32 | if not self.t_mode: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 33 | self.t_mode = VppEnum.vl_api_tunnel_mode_t.TUNNEL_API_MODE_P2P |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 34 | |
| 35 | def add_vpp_config(self): |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 36 | r = self.test.vapi.gre_tunnel_add_del( |
Neale Ranns | e5b94dd | 2019-12-31 05:13:14 +0000 | [diff] [blame] | 37 | is_add=1, |
| 38 | tunnel={ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 39 | "src": self.t_src, |
| 40 | "dst": self.t_dst, |
| 41 | "outer_table_id": self.t_outer_table, |
| 42 | "instance": 0xFFFFFFFF, |
| 43 | "type": self.t_type, |
| 44 | "mode": self.t_mode, |
| 45 | "flags": self.t_flags, |
| 46 | "session_id": self.t_session, |
| 47 | }, |
| 48 | ) |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 49 | self.set_sw_if_index(r.sw_if_index) |
Neale Ranns | 39f9973 | 2016-11-28 16:10:59 +0000 | [diff] [blame] | 50 | self.generate_remote_hosts() |
Klement Sekera | c798bc5 | 2018-05-23 20:22:20 +0200 | [diff] [blame] | 51 | self.test.registry.register(self, self.test.logger) |
Neale Ranns | adb17a8 | 2019-08-04 02:41:57 -0700 | [diff] [blame] | 52 | return self |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 53 | |
| 54 | def remove_vpp_config(self): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 55 | self.unconfig() |
Neale Ranns | e5b94dd | 2019-12-31 05:13:14 +0000 | [diff] [blame] | 56 | self.test.vapi.gre_tunnel_add_del( |
| 57 | is_add=0, |
| 58 | tunnel={ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 59 | "src": self.t_src, |
| 60 | "dst": self.t_dst, |
| 61 | "outer_table_id": self.t_outer_table, |
| 62 | "instance": 0xFFFFFFFF, |
| 63 | "type": self.t_type, |
| 64 | "mode": self.t_mode, |
| 65 | "flags": self.t_flags, |
| 66 | "session_id": self.t_session, |
| 67 | }, |
| 68 | ) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 69 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 70 | def object_id(self): |
Klement Sekera | c798bc5 | 2018-05-23 20:22:20 +0200 | [diff] [blame] | 71 | return "gre-%d" % self.sw_if_index |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 72 | |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 73 | def query_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 74 | return self.test.vapi.gre_tunnel_dump(sw_if_index=self._sw_if_index) |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 75 | |
| 76 | @property |
| 77 | def remote_ip(self): |
| 78 | return self.t_dst |
| 79 | |
| 80 | @property |
| 81 | def local_ip(self): |
| 82 | return self.t_src |