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