FD.io VPP  v18.11-rc0-18-g2a3fb1a
Vector Packet Processing
dhcp_client_cmds.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
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 
16 #ifndef __VOM_DHCP_CLIENT_CMDS_H__
17 #define __VOM_DHCP_CLIENT_CMDS_H__
18 
19 #include "vom/dhcp_client.hpp"
20 #include "vom/dump_cmd.hpp"
21 #include "vom/event_cmd.hpp"
22 
23 #include <vapi/dhcp.api.vapi.hpp>
24 #include <vapi/vpe.api.vapi.hpp>
25 
26 namespace VOM {
27 namespace dhcp_client_cmds {
28 
29 /**
30  * A command class that binds the DHCP config to the interface
31  */
32 class bind_cmd : public rpc_cmd<HW::item<bool>, vapi::Dhcp_client_config>
33 {
34 public:
35  /**
36  * Constructor
37  */
39  const handle_t& itf,
40  const std::string& hostname,
41  const l2_address_t& client_id,
42  bool set_braodcast_flag = false);
43 
44  /**
45  * Issue the command to VPP/HW
46  */
47  rc_t issue(connection& con);
48  /**
49  * convert to string format for debug purposes
50  */
51  std::string to_string() const;
52 
53  /**
54  * Comparison operator - only used for UT
55  */
56  bool operator==(const bind_cmd& i) const;
57 
58 private:
59  /**
60  * Reference to the HW::item of the interface to bind
61  */
62  const handle_t& m_itf;
63 
64  /**
65  * The DHCP client's hostname
66  */
67  const std::string m_hostname;
68 
69  /**
70  * The DHCP client's ID
71  */
72  const l2_address_t m_client_id;
73 
74  /**
75  * Flag to control the setting the of DHCP discover's broadcast flag
76  */
77  const bool m_set_broadcast_flag;
78 };
79 
80 /**
81  * A cmd class that Unbinds Dhcp Config from an interface
82  */
83 class unbind_cmd : public rpc_cmd<HW::item<bool>, vapi::Dhcp_client_config>
84 {
85 public:
86  /**
87  * Constructor
88  */
90  const handle_t& itf,
91  const std::string& hostname);
92 
93  /**
94  * Issue the command to VPP/HW
95  */
96  rc_t issue(connection& con);
97  /**
98  * convert to string format for debug purposes
99  */
100  std::string to_string() const;
101 
102  /**
103  * Comparison operator - only used for UT
104  */
105  bool operator==(const unbind_cmd& i) const;
106 
107 private:
108  /**
109  * Reference to the HW::item of the interface to unbind
110  */
111  const handle_t& m_itf;
112 
113  /**
114  * The DHCP client's hostname
115  */
116  const std::string m_hostname;
117 };
118 
119 /**
120  * A functor class represents our desire to recieve interface events
121  */
122 class events_cmd : public event_cmd<vapi::Control_ping, vapi::Dhcp_compl_event>
123 {
124 public:
125  /**
126  * Constructor
127  */
129  ~events_cmd();
130 
131  /**
132  * Issue the command to VPP/HW - subscribe to DHCP events
133  */
134  rc_t issue(connection& con);
135 
136  /**
137  * Retire the command - unsubscribe
138  */
139  void retire(connection& con);
140  /**
141  * convert to string format for debug purposes
142  */
143  std::string to_string() const;
144 
145  /**
146  * Comparison operator - only used for UT
147  */
148  bool operator==(const events_cmd& i) const;
149 
150  /**
151  * called in the VAPI RX thread when data is available.
152  */
153  void notify();
154 
155 private:
156  void succeeded() {}
157  /**
158  * The listner of this command
159  */
160  dhcp_client::event_listener& m_listener;
161 };
162 
163 /**
164  * A cmd class that Dumps all the DHCP clients
165  */
166 class dump_cmd : public VOM::dump_cmd<vapi::Dhcp_client_dump>
167 {
168 public:
169  /**
170  * Constructor
171  */
172  dump_cmd();
173  dump_cmd(const dump_cmd& d);
174 
175  /**
176  * Issue the command to VPP/HW
177  */
178  rc_t issue(connection& con);
179  /**
180  * convert to string format for debug purposes
181  */
182  std::string to_string() const;
183 
184  /**
185  * Comparison operator - only used for UT
186  */
187  bool operator==(const dump_cmd& i) const;
188 
189 private:
190  /**
191  * HW reutrn code
192  */
194 };
195 
196 }; // namespace dhcp_client_cmds
197 }; // namespace VOM
198 
199 /*
200  * fd.io coding-style-patch-verification: ON
201  *
202  * Local Variables:
203  * eval: (c-set-style "mozilla")
204  * End:
205  */
206 
207 #endif
A functor class represents our desire to recieve interface events.
int i
Error codes that VPP will return during a HW write.
Definition: types.hpp:84
virtual void retire(connection &con)
Retire/cancel a long running command.
Definition: rpc_cmd.hpp:126
A class that listens to DHCP Events.
Definition: dhcp_client.hpp:83
Type def of a L2 address as read from VPP.
Definition: types.hpp:334
bool operator==(const bind_cmd &i) const
Comparison operator - only used for UT.
A representation of the connection to VPP.
Definition: connection.hpp:33
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:38
virtual void succeeded()
Called by the HW Command Q when it is disabled to indicate the command can be considered successful w...
Definition: rpc_cmd.hpp:101
std::string to_string() const
convert to string format for debug purposes
bind_cmd(HW::item< bool > &item, const handle_t &itf, const std::string &hostname, const l2_address_t &client_id, bool set_braodcast_flag=false)
Constructor.
A type declaration of an interface handle in VPP.
Definition: types.hpp:228
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
An Event command base class.
Definition: event_cmd.hpp:39
rc_t issue(connection &con)
Issue the command to VPP/HW.
A base class for VPP dump commands.
Definition: dump_cmd.hpp:43
A cmd class that Unbinds Dhcp Config from an interface.
A command class that binds the DHCP config to the interface.
A cmd class that Dumps all the DHCP clients.
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:64