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