blob: 863cf599b7484f5168c174055ba6e4576f643210 [file] [log] [blame]
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001/*
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_CONFIG_CMDS_H__
17#define __VOM_DHCP_CONFIG_CMDS_H__
18
19#include "vom/dhcp_config.hpp"
20#include "vom/event_cmd.hpp"
21
22#include <vapi/dhcp.api.vapi.hpp>
23#include <vapi/vpe.api.vapi.hpp>
24
25namespace VOM {
26namespace dhcp_config_cmds {
27
28/**
29 * A command class that binds the DHCP config to the interface
30 */
31class bind_cmd : public rpc_cmd<HW::item<bool>, rc_t, vapi::Dhcp_client_config>
32{
33public:
34 /**
35 * Constructor
36 */
37 bind_cmd(HW::item<bool>& item,
38 const handle_t& itf,
39 const std::string& hostname,
40 const l2_address_t& client_id);
41
42 /**
43 * Issue the command to VPP/HW
44 */
45 rc_t issue(connection& con);
46 /**
47 * convert to string format for debug purposes
48 */
49 std::string to_string() const;
50
51 /**
52 * Comparison operator - only used for UT
53 */
54 bool operator==(const bind_cmd& i) const;
55
56private:
57 /**
58 * Reference to the HW::item of the interface to bind
59 */
60 const handle_t& m_itf;
61
62 /**
63 * The DHCP client's hostname
64 */
65 const std::string m_hostname;
66
67 /**
68 * The DHCP client's ID
69 */
70 const l2_address_t m_client_id;
71};
72
73/**
74 * A cmd class that Unbinds Dhcp Config from an interface
75 */
76class unbind_cmd
77 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Dhcp_client_config>
78{
79public:
80 /**
81 * Constructor
82 */
83 unbind_cmd(HW::item<bool>& item,
84 const handle_t& itf,
85 const std::string& hostname);
86
87 /**
88 * Issue the command to VPP/HW
89 */
90 rc_t issue(connection& con);
91 /**
92 * convert to string format for debug purposes
93 */
94 std::string to_string() const;
95
96 /**
97 * Comparison operator - only used for UT
98 */
99 bool operator==(const unbind_cmd& i) const;
100
101private:
102 /**
103 * Reference to the HW::item of the interface to unbind
104 */
105 const handle_t& m_itf;
106
107 /**
108 * The DHCP client's hostname
109 */
110 const std::string m_hostname;
111};
112
113/**
114 * A functor class represents our desire to recieve interface events
115 */
116class events_cmd : public event_cmd<vapi::Control_ping, vapi::Dhcp_compl_event>
117{
118public:
119 /**
120 * Constructor
121 */
122 events_cmd(dhcp_config::event_listener& el);
123
124 /**
125 * Issue the command to VPP/HW - subscribe to DHCP events
126 */
127 rc_t issue(connection& con);
128
129 /**
130 * Retire the command - unsubscribe
131 */
132 void retire(connection& con);
133 /**
134 * convert to string format for debug purposes
135 */
136 std::string to_string() const;
137
138 /**
139 * Comparison operator - only used for UT
140 */
141 bool operator==(const events_cmd& i) const;
142
143 /**
144 * called in the VAPI RX thread when data is available.
145 */
146 void notify();
147
148private:
149 void succeeded() {}
150 /**
151 * The listner of this command
152 */
153 dhcp_config::event_listener& m_listener;
154};
155};
156};
157
158/*
159 * fd.io coding-style-patch-verification: ON
160 *
161 * Local Variables:
162 * eval: (c-set-style "mozilla")
163 * End:
164 */
165
166#endif