blob: 0c5610013acb93be023e68e9bba032877e4a0197 [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_BINDING_H__
17#define __VOM_LLDP_BINDING_H__
18
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 {
27/**
28 * A representation of LLDP client configuration on an interface
29 */
30class lldp_binding : public object_base
31{
32public:
33 /**
Neale Rannsfd920602017-11-23 12:15:00 -080034 * Typedef for the key of a LLDP binding
35 */
36 typedef interface::key_t key_t;
37
38 /**
Neale Ranns812ed392017-10-16 04:20:13 -070039 * Construct a new object matching the desried state
40 */
41 lldp_binding(const interface& itf, const std::string& hostname);
42
43 /**
44 * Copy Constructor
45 */
46 lldp_binding(const lldp_binding& o);
Neale Rannsfd920602017-11-23 12:15:00 -080047
Neale Ranns812ed392017-10-16 04:20:13 -070048 /**
49 * Destructor
50 */
51 ~lldp_binding();
52
53 /**
Neale Rannsfd920602017-11-23 12:15:00 -080054 * Comparison operator
55 */
56 bool operator==(const lldp_binding& b) const;
57
58 /**
59 * Return this object's key
60 */
61 const key_t& key() const;
62
63 /**
Neale Ranns812ed392017-10-16 04:20:13 -070064 * Return the 'singular' of the LLDP binding that matches this object
65 */
66 std::shared_ptr<lldp_binding> singular() const;
67
68 /**
69 * convert to string format for debug purposes
70 */
71 std::string to_string() const;
72
73 /**
74 * Dump all LLDP bindings into the stream provided
75 */
76 static void dump(std::ostream& os);
77
Neale Rannsfd920602017-11-23 12:15:00 -080078 /**
79 * Find or add LLDP binding based on its key
80 */
81 static std::shared_ptr<lldp_binding> find(const key_t& k);
82
Neale Ranns812ed392017-10-16 04:20:13 -070083private:
84 /**
85 * Class definition for listeners to OM events
86 */
87 class event_handler : public OM::listener, public inspect::command_handler
88 {
89 public:
90 event_handler();
91 virtual ~event_handler() = default;
92
93 /**
94 * Handle a populate event
95 */
96 void handle_populate(const client_db::key_t& key);
97
98 /**
99 * Handle a replay event
100 */
101 void handle_replay();
102
103 /**
104 * Show the object in the Singular DB
105 */
106 void show(std::ostream& os);
107
108 /**
109 * Get the sortable Id of the listener
110 */
111 dependency_t order() const;
112 };
113
114 /**
115 * event_handler to register with OM
116 */
117 static event_handler m_evh;
118
119 /**
120 * Enquue commonds to the VPP command Q for the update
121 */
122 void update(const lldp_binding& obj);
123
124 /**
125 * Find or add LLDP binding to the OM
126 */
127 static std::shared_ptr<lldp_binding> find_or_add(const lldp_binding& temp);
128
129 /*
130 * It's the OM class that calls singular()
131 */
132 friend class OM;
133
134 /**
135 * It's the singular_db class that calls replay()
136 */
Neale Rannsfd920602017-11-23 12:15:00 -0800137 friend class singular_db<key_t, lldp_binding>;
Neale Ranns812ed392017-10-16 04:20:13 -0700138
139 /**
140 * Sweep/reap the object if still stale
141 */
142 void sweep(void);
143
144 /**
145 * replay the object to create it in hardware
146 */
147 void replay(void);
148
149 /**
150 * A reference counting pointer to the interface on which LLDP config
151 * resides. By holding the reference here, we can guarantee that
152 * this object will outlive the interface
153 */
154 const std::shared_ptr<interface> m_itf;
155
156 /**
157 * The port-description in the LLDP configuration
158 */
159 const std::string m_port_desc;
160
161 /**
162 * HW configuration 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 bindings keyed against the interface.
169 */
Neale Rannsfd920602017-11-23 12:15:00 -0800170 static singular_db<key_t, lldp_binding> m_db;
Neale Ranns812ed392017-10-16 04:20:13 -0700171};
172};
173
174/*
175 * fd.io coding-style-patch-verification: ON
176 *
177 * Local Variables:
178 * eval: (c-set-style "mozilla")
179 * End:
180 */
181
182#endif