Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1 | from vpp_object import VppObject |
| 2 | |
| 3 | |
| 4 | class VppDHCPProxy(VppObject): |
| 5 | |
| 6 | def __init__( |
| 7 | self, |
| 8 | test, |
| 9 | dhcp_server, |
| 10 | dhcp_src_address, |
| 11 | rx_vrf_id=0, |
| 12 | server_vrf_id=0, |
| 13 | ): |
| 14 | self._test = test |
| 15 | self._rx_vrf_id = rx_vrf_id |
| 16 | self._server_vrf_id = server_vrf_id |
| 17 | self._dhcp_server = dhcp_server |
| 18 | self._dhcp_src_address = dhcp_src_address |
| 19 | |
| 20 | def set_proxy( |
| 21 | self, |
| 22 | dhcp_server, |
| 23 | dhcp_src_address, |
| 24 | rx_vrf_id=0, |
| 25 | server_vrf_id=0): |
| 26 | if self.query_vpp_config(): |
| 27 | raise Exception('Vpp config present') |
| 28 | self._rx_vrf_id = rx_vrf_id |
| 29 | self._server_vrf_id = server_vrf_id |
| 30 | self._dhcp_server = dhcp_server |
| 31 | self._dhcp_src_address = dhcp_src_address |
| 32 | |
| 33 | def add_vpp_config(self): |
| 34 | self._test.vapi.dhcp_proxy_config( |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 35 | is_add=1, |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 36 | rx_vrf_id=self._rx_vrf_id, |
| 37 | server_vrf_id=self._server_vrf_id, |
| 38 | dhcp_server=self._dhcp_server, |
| 39 | dhcp_src_address=self._dhcp_src_address) |
| 40 | self._test.registry.register(self, self._test.logger) |
| 41 | |
| 42 | def remove_vpp_config(self): |
| 43 | self._test.vapi.dhcp_proxy_config( |
| 44 | rx_vrf_id=self._rx_vrf_id, |
| 45 | server_vrf_id=self._server_vrf_id, |
| 46 | dhcp_server=self._dhcp_server, |
| 47 | dhcp_src_address=self._dhcp_src_address, |
| 48 | is_add=0) |
| 49 | |
| 50 | def get_vpp_dump(self): |
| 51 | dump = self._test.vapi.dhcp_proxy_dump() |
| 52 | for entry in dump: |
| 53 | if entry.rx_vrf_id == self._rx_vrf_id: |
| 54 | return entry |
| 55 | |
| 56 | def query_vpp_config(self): |
| 57 | dump = self.get_vpp_dump() |
| 58 | return True if dump else False |
| 59 | |
| 60 | def object_id(self): |
| 61 | return "dhcp-proxy-%d" % self._rx_vrf_id |
| 62 | |
| 63 | |
| 64 | class VppDHCPClient(VppObject): |
| 65 | |
| 66 | def __init__( |
| 67 | self, |
| 68 | test, |
| 69 | sw_if_index, |
| 70 | hostname, |
| 71 | id=None, |
| 72 | want_dhcp_event=False, |
| 73 | set_broadcast_flag=True, |
| 74 | dscp=None, |
| 75 | pid=None): |
| 76 | self._test = test |
| 77 | self._sw_if_index = sw_if_index |
| 78 | self._hostname = hostname |
| 79 | self._id = id |
| 80 | self._want_dhcp_event = want_dhcp_event |
| 81 | self._set_broadcast_flag = set_broadcast_flag |
| 82 | self._dscp = dscp |
| 83 | self._pid = pid |
| 84 | |
| 85 | def set_client( |
| 86 | self, |
| 87 | sw_if_index, |
| 88 | hostname, |
| 89 | id=None, |
| 90 | want_dhcp_event=False, |
| 91 | set_broadcast_flag=True, |
| 92 | dscp=None, |
| 93 | pid=None): |
| 94 | if self.query_vpp_config(): |
| 95 | raise Exception('Vpp config present') |
| 96 | self._sw_if_index = sw_if_index |
| 97 | self._hostname = hostname |
| 98 | self._id = id |
| 99 | self._want_dhcp_event = want_dhcp_event |
| 100 | self._set_broadcast_flag = set_broadcast_flag |
| 101 | self._dscp = dscp |
| 102 | self._pid = pid |
| 103 | |
| 104 | def add_vpp_config(self): |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 105 | id = self._id.encode('ascii') if self._id else None |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 106 | client = {'sw_if_index': self._sw_if_index, 'hostname': self._hostname, |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 107 | 'id': id, |
| 108 | 'want_dhcp_event': self._want_dhcp_event, |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 109 | 'set_broadcast_flag': self._set_broadcast_flag, |
| 110 | 'dscp': self._dscp, 'pid': self._pid} |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 111 | self._test.vapi.dhcp_client_config(is_add=1, client=client) |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 112 | self._test.registry.register(self, self._test.logger) |
| 113 | |
| 114 | def remove_vpp_config(self): |
| 115 | client = client = { |
| 116 | 'sw_if_index': self._sw_if_index, |
| 117 | 'hostname': self._hostname} |
| 118 | self._test.vapi.dhcp_client_config(client=client, is_add=0) |
| 119 | |
| 120 | def get_vpp_dump(self): |
| 121 | dump = self._test.vapi.dhcp_client_dump() |
| 122 | for entry in dump: |
| 123 | if entry.client.sw_if_index == self._sw_if_index: |
| 124 | return entry |
| 125 | |
| 126 | def query_vpp_config(self): |
| 127 | dump = self.get_vpp_dump() |
| 128 | return True if dump else False |
| 129 | |
| 130 | def object_id(self): |
| 131 | return "dhcp-client-%s/%d" % (self._hostname, self._sw_if_index) |