FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
lldp_global.cpp
Go to the documentation of this file.
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 #include "vom/lldp_global.hpp"
17 #include "vom/lldp_global_cmds.hpp"
18 
19 namespace VOM {
20 /**
21  * A DB of all LLDP configs
22  */
23 singular_db<std::string, lldp_global> lldp_global::m_db;
24 
25 lldp_global::event_handler lldp_global::m_evh;
26 
27 lldp_global::lldp_global(const std::string& system_name,
28  uint32_t tx_hold,
29  uint32_t tx_interval)
30  : m_system_name(system_name)
31  , m_tx_hold(tx_hold)
32  , m_tx_interval(tx_interval)
33 {
34 }
35 
37  : m_system_name(o.m_system_name)
38  , m_tx_hold(o.m_tx_hold)
39  , m_tx_interval(o.m_tx_interval)
40 {
41 }
42 
44 {
45  sweep();
46 
47  // not in the DB anymore.
48  m_db.release(m_system_name, this);
49 }
50 
51 const lldp_global::key_t&
53 {
54  return (m_system_name);
55 }
56 
57 bool
59 {
60  return ((key() == l.key()) && (m_tx_hold == l.m_tx_hold) &&
61  (m_tx_interval == l.m_tx_interval));
62 }
63 
64 void
65 lldp_global::sweep()
66 {
67  // no means to remove this in VPP
68 }
69 
70 void
71 lldp_global::dump(std::ostream& os)
72 {
73  m_db.dump(os);
74 }
75 
76 void
77 lldp_global::replay()
78 {
79  if (m_binding) {
80  HW::enqueue(new lldp_global_cmds::config_cmd(m_binding, m_system_name,
81  m_tx_hold, m_tx_interval));
82  }
83 }
84 
85 std::string
87 {
88  std::ostringstream s;
89  s << "LLDP-global:"
90  << " system_name:" << m_system_name << " tx-hold:" << m_tx_hold
91  << " tx-interval:" << m_tx_interval;
92 
93  return (s.str());
94 }
95 
96 void
97 lldp_global::update(const lldp_global& desired)
98 {
99  if (!m_binding) {
100  HW::enqueue(new lldp_global_cmds::config_cmd(m_binding, m_system_name,
101  m_tx_hold, m_tx_interval));
102  }
103 }
104 
105 std::shared_ptr<lldp_global>
106 lldp_global::find_or_add(const lldp_global& temp)
107 {
108  return (m_db.find_or_add(temp.key(), temp));
109 }
110 
111 std::shared_ptr<lldp_global>
113 {
114  return (m_db.find(k));
115 }
116 
117 std::shared_ptr<lldp_global>
119 {
120  return find_or_add(*this);
121 }
122 
123 lldp_global::event_handler::event_handler()
124 {
125  OM::register_listener(this);
126  inspect::register_handler({ "lldp-global" }, "LLDP global configurations",
127  this);
128 }
129 
130 void
131 lldp_global::event_handler::handle_replay()
132 {
133  m_db.replay();
134 }
135 
136 void
137 lldp_global::event_handler::handle_populate(const client_db::key_t& key)
138 {
139  // FIXME
140 }
141 
143 lldp_global::event_handler::order() const
144 {
145  return (dependency_t::GLOBAL);
146 }
147 
148 void
149 lldp_global::event_handler::show(std::ostream& os)
150 {
151  m_db.dump(os);
152 }
153 }
154 
155 /*
156  * fd.io coding-style-patch-verification: ON
157  *
158  * Local Variables:
159  * eval: (c-set-style "mozilla")
160  * End:
161  */
const key_t & key() const
Get this objects key.
Definition: lldp_global.cpp:52
Global Configuration has no dependency.
static void dump(std::ostream &os)
Dump all LLDP globals into the stream provided.
Definition: lldp_global.cpp:71
bool operator==(const lldp_global &l) const
Comparison operator.
Definition: lldp_global.cpp:58
std::shared_ptr< lldp_global > singular() const
Return the &#39;singular&#39; of the LLDP global that matches this object.
const std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
std::string key_t
The key for the global conifugration is the &#39;system&#39; namse.
Definition: lldp_global.hpp:35
static void register_handler(const std::vector< std::string > &cmds, const std::string &help, command_handler *ch)
Register a command handler for inspection.
Definition: inspect.cpp:85
std::string to_string() const
convert to string format for debug purposes
Definition: lldp_global.cpp:86
A representation of LLDP global configuration.
Definition: lldp_global.hpp:29
static std::shared_ptr< lldp_global > find(const key_t &k)
Find LLDP global config from its key.
lldp_global(const std::string &system_name, uint32_t tx_hold, uint32_t tx_interval)
Construct a new object matching the desried state.
Definition: lldp_global.cpp:27
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:189
A command class that binds the LLDP global to the interface.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
~lldp_global()
Destructor.
Definition: lldp_global.cpp:43
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:124