Steven Luong | c4b5d10 | 2024-07-30 13:44:01 -0700 | [diff] [blame^] | 1 | from ipaddress import IPv4Network |
| 2 | |
| 3 | from vpp_object import VppObject |
| 4 | from vpp_papi import VppEnum |
| 5 | from vpp_ip import INVALID_INDEX |
| 6 | from vpp_papi_provider import UnexpectedApiReturnValueError |
| 7 | |
| 8 | |
| 9 | class SessionSdl: |
| 10 | """Session SDL""" |
| 11 | |
| 12 | def __init__( |
| 13 | self, |
| 14 | lcl, |
| 15 | action_index, |
| 16 | tag, |
| 17 | ): |
| 18 | |
| 19 | self.action_index = action_index |
| 20 | self.lcl = lcl |
| 21 | self.tag = tag |
| 22 | |
| 23 | def encode(self): |
| 24 | return { |
| 25 | "lcl": self.lcl, |
| 26 | "action_index": self.action_index, |
| 27 | "tag": self.tag, |
| 28 | } |
| 29 | |
| 30 | |
| 31 | class VppSessionSdl(VppObject): |
| 32 | """VPP Session SDL""" |
| 33 | |
| 34 | def __init__(self, test, rules, is_add, appns_index): |
| 35 | self._test = test |
| 36 | self._rules = rules |
| 37 | self.is_add = is_add |
| 38 | self.appns_index = appns_index |
| 39 | |
| 40 | @property |
| 41 | def rules(self): |
| 42 | return self._rules |
| 43 | |
| 44 | @property |
| 45 | def count(self): |
| 46 | return len(self._rules) |
| 47 | |
| 48 | def encode_rules(self): |
| 49 | rules = [] |
| 50 | for rule in self._rules: |
| 51 | rules.append(rule.encode()) |
| 52 | return rules |
| 53 | |
| 54 | def add_vpp_config(self, expect_error=False): |
| 55 | try: |
| 56 | reply = self._test.vapi.session_sdl_add_del( |
| 57 | is_add=self.is_add, |
| 58 | appns_index=self.appns_index, |
| 59 | count=self.count, |
| 60 | r=self.encode_rules(), |
| 61 | ) |
| 62 | self._test.registry.register(self, self._test.logger) |
| 63 | if expect_error: |
| 64 | self._test.fail("Unexpected api reply") |
| 65 | return self |
| 66 | except UnexpectedApiReturnValueError: |
| 67 | if not expect_error: |
| 68 | self._test.fail("Unexpected api reply") |
| 69 | return None |
| 70 | |
| 71 | def query_vpp_config(self): |
| 72 | pass |
| 73 | |
| 74 | def remove_vpp_config(self, expect_error=False): |
| 75 | pass |