Hongjun Ni | 3efcd0d | 2019-06-10 19:43:48 +0800 | [diff] [blame] | 1 | # Copyright (c) 2019. Vinci Consulting Corp. All Rights Reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import vpp_object |
| 16 | |
| 17 | |
| 18 | class VppLbVip(vpp_object.VppObject): |
Hongjun Ni | 3efcd0d | 2019-06-10 19:43:48 +0800 | [diff] [blame] | 19 | def __init__(self, test, pfx, sfx, port, protocol): |
| 20 | self._test = test |
| 21 | self.pfx = pfx |
| 22 | self.sfx = sfx |
| 23 | self.port = port |
| 24 | self.protocol = protocol |
| 25 | |
| 26 | def add_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 27 | self._test_vapi.lb_add_del_vip( |
| 28 | pfx=self.pfx, sfx=self.pfx, port=self.port, protocol=self.protocol |
| 29 | ) |
Hongjun Ni | 3efcd0d | 2019-06-10 19:43:48 +0800 | [diff] [blame] | 30 | |
| 31 | self._test.registry.register(self, self._test.logger) |
| 32 | |
| 33 | def remove_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 34 | self._test.vapi.lb_add_del_vip( |
| 35 | pfx=self.pfx, sfx=self.pfx, port=self.port, protocol=self.protocol, is_del=1 |
| 36 | ) |
Hongjun Ni | 3efcd0d | 2019-06-10 19:43:48 +0800 | [diff] [blame] | 37 | |
| 38 | def query_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 39 | details = self._test.vapi.lb_add_del_vip( |
| 40 | fx=self.pfx, sfx=self.pfx, port=self.port, protocol=self.protocol |
| 41 | ) |
Hongjun Ni | 3efcd0d | 2019-06-10 19:43:48 +0800 | [diff] [blame] | 42 | return True if self == details else False |
| 43 | |
| 44 | |
| 45 | class VppLbAs(vpp_object.VppObject): |
| 46 | def __init__(self, test, pfx, port, protocol, app_srv, is_del, is_flush): |
| 47 | self._test = test |
| 48 | # this is the vip |
| 49 | self.pfx = pfx |
| 50 | self.port = port |
| 51 | self.protocol = protocol |
| 52 | |
| 53 | self.app_srv = app_srv |
| 54 | self.is_del = is_del |
| 55 | self.is_flush = is_flush |
| 56 | |
| 57 | def add_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 58 | self._test_vapi.lb_add_del_as( |
| 59 | pfx=self.pfx, |
| 60 | port=self.port, |
| 61 | protocol=self.protocol, |
| 62 | app_srv=self.app_srv, |
| 63 | is_flush=self.is_flush, |
| 64 | ) |
Hongjun Ni | 3efcd0d | 2019-06-10 19:43:48 +0800 | [diff] [blame] | 65 | |
| 66 | self._test.registry.register(self, self._test.logger) |
| 67 | |
| 68 | def remove_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 69 | self._test.vapi.lb_add_del_as( |
| 70 | pfx=self.pfx, |
| 71 | port=self.port, |
| 72 | protocol=self.protocol, |
| 73 | app_srv=self.app_srv, |
| 74 | is_flush=self.is_flush, |
| 75 | is_del=1, |
| 76 | ) |
Hongjun Ni | 3efcd0d | 2019-06-10 19:43:48 +0800 | [diff] [blame] | 77 | |
| 78 | def query_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 79 | details = self._test.vapi.lb_as_dump( |
| 80 | pfx=self.pfx, port=self.port, protocol=self.protocol |
| 81 | ) |
Hongjun Ni | 3efcd0d | 2019-06-10 19:43:48 +0800 | [diff] [blame] | 82 | return True if self == details else False |