DHCP Client Dump
[vpp.git] / extras / vom / vom / dhcp_client_cmds.hpp
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>, rc_t, vapi::Dhcp_client_config>
33 {
34 public:
35   /**
36    * Constructor
37    */
38   bind_cmd(HW::item<bool>& item,
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
84   : public rpc_cmd<HW::item<bool>, rc_t, vapi::Dhcp_client_config>
85 {
86 public:
87   /**
88    * Constructor
89    */
90   unbind_cmd(HW::item<bool>& item,
91              const handle_t& itf,
92              const std::string& hostname);
93
94   /**
95    * Issue the command to VPP/HW
96    */
97   rc_t issue(connection& con);
98   /**
99    * convert to string format for debug purposes
100    */
101   std::string to_string() const;
102
103   /**
104    * Comparison operator - only used for UT
105    */
106   bool operator==(const unbind_cmd& i) const;
107
108 private:
109   /**
110    * Reference to the HW::item of the interface to unbind
111    */
112   const handle_t& m_itf;
113
114   /**
115    * The DHCP client's hostname
116    */
117   const std::string m_hostname;
118 };
119
120 /**
121  * A functor class represents our desire to recieve interface events
122  */
123 class events_cmd : public event_cmd<vapi::Control_ping, vapi::Dhcp_compl_event>
124 {
125 public:
126   /**
127    * Constructor
128    */
129   events_cmd(dhcp_client::event_listener& el);
130   ~events_cmd();
131
132   /**
133    * Issue the command to VPP/HW - subscribe to DHCP events
134    */
135   rc_t issue(connection& con);
136
137   /**
138    * Retire the command - unsubscribe
139    */
140   void retire(connection& con);
141   /**
142    * convert to string format for debug purposes
143    */
144   std::string to_string() const;
145
146   /**
147    * Comparison operator - only used for UT
148    */
149   bool operator==(const events_cmd& i) const;
150
151   /**
152    * called in the VAPI RX thread when data is available.
153    */
154   void notify();
155
156 private:
157   void succeeded() {}
158   /**
159    * The listner of this command
160    */
161   dhcp_client::event_listener& m_listener;
162 };
163
164 /**
165  * A cmd class that Dumps all the DHCP clients
166  */
167 class dump_cmd : public VOM::dump_cmd<vapi::Dhcp_client_dump>
168 {
169 public:
170   /**
171    * Constructor
172    */
173   dump_cmd();
174   dump_cmd(const dump_cmd& d);
175
176   /**
177    * Issue the command to VPP/HW
178    */
179   rc_t issue(connection& con);
180   /**
181    * convert to string format for debug purposes
182    */
183   std::string to_string() const;
184
185   /**
186    * Comparison operator - only used for UT
187    */
188   bool operator==(const dump_cmd& i) const;
189
190 private:
191   /**
192    * HW reutrn code
193    */
194   HW::item<bool> item;
195 };
196
197 }; // namespace dhcp_client_cmds
198 }; // namespace VOM
199
200 /*
201  * fd.io coding-style-patch-verification: ON
202  *
203  * Local Variables:
204  * eval: (c-set-style "mozilla")
205  * End:
206  */
207
208 #endif