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