blob: f64a3c8a2e2a36b0d81fdf639e83c4f97aaab2d7 [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -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
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070016#ifndef __VOM_DHCP_CONFIG_H__
17#define __VOM_DHCP_CONFIG_H__
Neale Ranns812ed392017-10-16 04:20:13 -070018
Neale Ranns812ed392017-10-16 04:20:13 -070019#include "vom/hw.hpp"
20#include "vom/inspect.hpp"
21#include "vom/interface.hpp"
22#include "vom/object_base.hpp"
23#include "vom/om.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070024#include "vom/singular_db.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070025
26namespace VOM {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070027namespace dhcp_config_cmds {
28class events_cmd;
29};
Neale Ranns812ed392017-10-16 04:20:13 -070030/**
31 * A representation of DHCP client configuration on an interface
32 */
33class dhcp_config : public object_base
34{
35public:
36 /**
37 * Construct a new object matching the desried state
38 */
39 dhcp_config(const interface& itf, const std::string& hostname);
40
41 /**
42 * Construct a new object matching the desried state
43 */
44 dhcp_config(const interface& itf,
45 const std::string& hostname,
46 const l2_address_t& client_id);
47
48 /**
49 * Copy Constructor
50 */
51 dhcp_config(const dhcp_config& o);
52
53 /**
54 * Destructor
55 */
56 ~dhcp_config();
57
58 /**
59 * Return the 'singular' of the DHCP config that matches this object
60 */
61 std::shared_ptr<dhcp_config> singular() const;
62
63 /**
64 * convert to string format for debug purposes
65 */
66 std::string to_string() const;
67
68 /**
69 * Dump all DHCP configs into the stream provided
70 */
71 static void dump(std::ostream& os);
72
73 /**
Neale Ranns812ed392017-10-16 04:20:13 -070074 * A class that listens to DHCP Events
75 */
76 class event_listener
77 {
78 public:
79 /**
80 * Constructor
81 */
82 event_listener();
83
84 /**
85 * listener's virtual function invoked when a DHCP event is
86 * available to read
87 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070088 virtual void handle_dhcp_event(dhcp_config_cmds::events_cmd* cmd) = 0;
Neale Ranns812ed392017-10-16 04:20:13 -070089
90 /**
91 * Return the HW::item associated with this command
92 */
93 HW::item<bool>& status();
94
95 protected:
96 /**
97 * The HW::item associated with this command
98 */
99 HW::item<bool> m_status;
100 };
101
Neale Ranns812ed392017-10-16 04:20:13 -0700102private:
103 /**
104 * Class definition for listeners to OM events
105 */
106 class event_handler : public OM::listener, public inspect::command_handler
107 {
108 public:
109 event_handler();
110 virtual ~event_handler() = default;
111
112 /**
113 * Handle a populate event
114 */
115 void handle_populate(const client_db::key_t& key);
116
117 /**
118 * Handle a replay event
119 */
120 void handle_replay();
121
122 /**
123 * Show the object in the Singular DB
124 */
125 void show(std::ostream& os);
126
127 /**
128 * Get the sortable Id of the listener
129 */
130 dependency_t order() const;
131 };
132
133 /**
134 * event_handler to register with OM
135 */
136 static event_handler m_evh;
137
138 /**
139 * Enquue commonds to the VPP command Q for the update
140 */
141 void update(const dhcp_config& obj);
142
143 /**
144 * Find or add DHCP config to the OM
145 */
146 static std::shared_ptr<dhcp_config> find_or_add(const dhcp_config& temp);
147
148 /*
149 * It's the OM class that calls singular()
150 */
151 friend class OM;
152
153 /**
154 * It's the singular_db class that calls replay()
155 */
156 friend class singular_db<interface::key_type, dhcp_config>;
157
158 /**
159 * Sweep/reap the object if still stale
160 */
161 void sweep(void);
162
163 /**
164 * replay the object to create it in hardware
165 */
166 void replay(void);
167
168 /**
169 * A reference counting pointer to the interface on which DHCP config
170 * resides. By holding the reference here, we can guarantee that
171 * this object will outlive the interface
172 */
173 const std::shared_ptr<interface> m_itf;
174
175 /**
176 * The hostname in the DHCP configuration
177 */
178 const std::string m_hostname;
179
180 /**
181 * The option-61 client_id in the DHCP configuration
182 */
183 const l2_address_t m_client_id;
184
185 /**
186 * HW configuration for the binding. The bool representing the
187 * do/don't bind.
188 */
189 HW::item<bool> m_binding;
190
191 /**
192 * A map of all Dhcp configs keyed against the interface.
193 */
194 static singular_db<interface::key_type, dhcp_config> m_db;
195};
196};
197
198/*
199 * fd.io coding-style-patch-verification: ON
200 *
201 * Local Variables:
202 * eval: (c-set-style "mozilla")
203 * End:
204 */
205
206#endif