blob: eb07df2ecd7975dd84933d4dcc121581a35dbe57 [file] [log] [blame]
Jakub Grajciar103ba6b2019-10-01 11:30:56 +02001from vpp_object import VppObject
2
3
4class VppDHCPProxy(VppObject):
Jakub Grajciar103ba6b2019-10-01 11:30:56 +02005 def __init__(
6 self,
7 test,
8 dhcp_server,
9 dhcp_src_address,
10 rx_vrf_id=0,
11 server_vrf_id=0,
12 ):
13 self._test = test
14 self._rx_vrf_id = rx_vrf_id
15 self._server_vrf_id = server_vrf_id
16 self._dhcp_server = dhcp_server
17 self._dhcp_src_address = dhcp_src_address
18
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020019 def set_proxy(self, dhcp_server, dhcp_src_address, rx_vrf_id=0, server_vrf_id=0):
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020020 if self.query_vpp_config():
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020021 raise Exception("Vpp config present")
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020022 self._rx_vrf_id = rx_vrf_id
23 self._server_vrf_id = server_vrf_id
24 self._dhcp_server = dhcp_server
25 self._dhcp_src_address = dhcp_src_address
26
27 def add_vpp_config(self):
28 self._test.vapi.dhcp_proxy_config(
Neale Ranns02bfd642019-10-07 00:39:28 -070029 is_add=1,
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020030 rx_vrf_id=self._rx_vrf_id,
31 server_vrf_id=self._server_vrf_id,
32 dhcp_server=self._dhcp_server,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020033 dhcp_src_address=self._dhcp_src_address,
34 )
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020035 self._test.registry.register(self, self._test.logger)
36
37 def remove_vpp_config(self):
38 self._test.vapi.dhcp_proxy_config(
39 rx_vrf_id=self._rx_vrf_id,
40 server_vrf_id=self._server_vrf_id,
41 dhcp_server=self._dhcp_server,
42 dhcp_src_address=self._dhcp_src_address,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020043 is_add=0,
44 )
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020045
46 def get_vpp_dump(self):
47 dump = self._test.vapi.dhcp_proxy_dump()
48 for entry in dump:
49 if entry.rx_vrf_id == self._rx_vrf_id:
50 return entry
51
52 def query_vpp_config(self):
53 dump = self.get_vpp_dump()
54 return True if dump else False
55
56 def object_id(self):
57 return "dhcp-proxy-%d" % self._rx_vrf_id
58
59
60class VppDHCPClient(VppObject):
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020061 def __init__(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020062 self,
63 test,
64 sw_if_index,
65 hostname,
66 id=None,
67 want_dhcp_event=False,
68 set_broadcast_flag=True,
69 dscp=None,
70 pid=None,
71 ):
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020072 self._test = test
73 self._sw_if_index = sw_if_index
74 self._hostname = hostname
75 self._id = id
76 self._want_dhcp_event = want_dhcp_event
77 self._set_broadcast_flag = set_broadcast_flag
78 self._dscp = dscp
79 self._pid = pid
80
81 def set_client(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020082 self,
83 sw_if_index,
84 hostname,
85 id=None,
86 want_dhcp_event=False,
87 set_broadcast_flag=True,
88 dscp=None,
89 pid=None,
90 ):
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020091 if self.query_vpp_config():
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020092 raise Exception("Vpp config present")
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020093 self._sw_if_index = sw_if_index
94 self._hostname = hostname
95 self._id = id
96 self._want_dhcp_event = want_dhcp_event
97 self._set_broadcast_flag = set_broadcast_flag
98 self._dscp = dscp
99 self._pid = pid
100
101 def add_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200102 id = self._id.encode("ascii") if self._id else None
103 client = {
104 "sw_if_index": self._sw_if_index,
105 "hostname": self._hostname,
106 "id": id,
107 "want_dhcp_event": self._want_dhcp_event,
108 "set_broadcast_flag": self._set_broadcast_flag,
109 "dscp": self._dscp,
110 "pid": self._pid,
111 }
Neale Ranns02bfd642019-10-07 00:39:28 -0700112 self._test.vapi.dhcp_client_config(is_add=1, client=client)
Jakub Grajciar103ba6b2019-10-01 11:30:56 +0200113 self._test.registry.register(self, self._test.logger)
114
115 def remove_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200116 client = client = {"sw_if_index": self._sw_if_index, "hostname": self._hostname}
Jakub Grajciar103ba6b2019-10-01 11:30:56 +0200117 self._test.vapi.dhcp_client_config(client=client, is_add=0)
118
119 def get_vpp_dump(self):
120 dump = self._test.vapi.dhcp_client_dump()
121 for entry in dump:
122 if entry.client.sw_if_index == self._sw_if_index:
123 return entry
124
125 def query_vpp_config(self):
126 dump = self.get_vpp_dump()
127 return True if dump else False
128
129 def object_id(self):
130 return "dhcp-client-%s/%d" % (self._hostname, self._sw_if_index)