blob: f545a2828cc9aff7c66e9e6305e33a45b5c76205 [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
16#ifndef __VOM_LLDP_GLOBAL_H__
17#define __VOM_LLDP_GLOBAL_H__
18
Neale Ranns812ed392017-10-16 04:20:13 -070019#include "vom/hw.hpp"
20#include "vom/inspect.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070021#include "vom/object_base.hpp"
22#include "vom/om.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070023#include "vom/singular_db.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070024
25namespace VOM {
26/**
27 * A representation of LLDP global configuration
28 */
29class lldp_global : public object_base
30{
31public:
32 /**
Neale Rannsfd920602017-11-23 12:15:00 -080033 * The key for the global conifugration is the 'system' namse
34 */
35 typedef std::string key_t;
36
37 /**
Neale Ranns812ed392017-10-16 04:20:13 -070038 * Construct a new object matching the desried state
39 */
40 lldp_global(const std::string& system_name,
41 uint32_t tx_hold,
42 uint32_t tx_interval);
43
44 /**
45 * Copy Constructor
46 */
47 lldp_global(const lldp_global& o);
48
49 /**
50 * Destructor
51 */
52 ~lldp_global();
53
54 /**
Neale Rannsfd920602017-11-23 12:15:00 -080055 * Get this objects key
56 */
57 const key_t& key() const;
58
59 /**
60 * Comparison operator
61 */
62 bool operator==(const lldp_global& l) const;
63
64 /**
Neale Ranns812ed392017-10-16 04:20:13 -070065 * Return the 'singular' of the LLDP global that matches this object
66 */
67 std::shared_ptr<lldp_global> singular() const;
68
69 /**
70 * convert to string format for debug purposes
71 */
72 std::string to_string() const;
73
74 /**
75 * Dump all LLDP globals into the stream provided
76 */
77 static void dump(std::ostream& os);
78
79 /**
Neale Rannsfd920602017-11-23 12:15:00 -080080 * Find LLDP global config from its key
Neale Ranns812ed392017-10-16 04:20:13 -070081 */
Neale Rannsfd920602017-11-23 12:15:00 -080082 static std::shared_ptr<lldp_global> find(const key_t& k);
Neale Ranns812ed392017-10-16 04:20:13 -070083
84private:
85 /**
86 * Class definition for listeners to OM events
87 */
88 class event_handler : public OM::listener, public inspect::command_handler
89 {
90 public:
91 event_handler();
92 virtual ~event_handler() = default;
93
94 /**
95 * Handle a populate event
96 */
97 void handle_populate(const client_db::key_t& key);
98
99 /**
100 * Handle a replay event
101 */
102 void handle_replay();
103
104 /**
105 * Show the object in the Singular DB
106 */
107 void show(std::ostream& os);
108
109 /**
110 * Get the sortable Id of the listener
111 */
112 dependency_t order() const;
113 };
114
115 /**
116 * event_handler to register with OM
117 */
118 static event_handler m_evh;
119
120 /**
121 * Enquue commonds to the VPP command Q for the update
122 */
123 void update(const lldp_global& obj);
124
125 /**
126 * Find or add LLDP global to the OM
127 */
128 static std::shared_ptr<lldp_global> find_or_add(const lldp_global& temp);
129
130 /*
131 * It's the OM class that calls singular()
132 */
133 friend class OM;
134
135 /**
136 * It's the singular_db class that calls replay()
137 */
Neale Rannsfd920602017-11-23 12:15:00 -0800138 friend class singular_db<key_t, lldp_global>;
Neale Ranns812ed392017-10-16 04:20:13 -0700139
140 /**
141 * Sweep/reap the object if still stale
142 */
143 void sweep(void);
144
145 /**
146 * replay the object to create it in hardware
147 */
148 void replay(void);
149
150 /**
151 * The system name
152 */
153 const std::string m_system_name;
154
155 /**
156 * TX timer configs
157 */
158 uint32_t m_tx_hold;
159 uint32_t m_tx_interval;
160
161 /**
162 * HW globaluration for the binding. The bool representing the
163 * do/don't bind.
164 */
165 HW::item<bool> m_binding;
166
167 /**
168 * A map of all Lldp globals keyed against the system name.
169 * there needs to be some sort of key, that will do.
170 */
Neale Rannsfd920602017-11-23 12:15:00 -0800171 static singular_db<key_t, lldp_global> m_db;
Neale Ranns812ed392017-10-16 04:20:13 -0700172};
173};
174
175/*
176 * fd.io coding-style-patch-verification: ON
177 *
178 * Local Variables:
179 * eval: (c-set-style "mozilla")
180 * End:
181 */
182
183#endif