blob: 92526189d34fdae849d11ad4de305791b53d6f18 [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#include "vom/lldp_global.hpp"
17#include "vom/cmd.hpp"
18
19namespace VOM {
20/**
21 * A DB of all LLDP configs
22 */
23singular_db<std::string, lldp_global> lldp_global::m_db;
24
25lldp_global::event_handler lldp_global::m_evh;
26
27lldp_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
36lldp_global::lldp_global(const lldp_global& o)
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
43lldp_global::~lldp_global()
44{
45 sweep();
46
47 // not in the DB anymore.
48 m_db.release(m_system_name, this);
49}
50
51void
52lldp_global::sweep()
53{
54 // no means to remove this in VPP
55}
56
57void
58lldp_global::dump(std::ostream& os)
59{
60 m_db.dump(os);
61}
62
63void
64lldp_global::replay()
65{
66 if (m_binding) {
67 HW::enqueue(
68 new config_cmd(m_binding, m_system_name, m_tx_hold, m_tx_interval));
69 }
70}
71
72std::string
73lldp_global::to_string() const
74{
75 std::ostringstream s;
76 s << "LLDP-global:"
77 << " system_name:" << m_system_name << " tx-hold:" << m_tx_hold
78 << " tx-interval:" << m_tx_interval;
79
80 return (s.str());
81}
82
83void
84lldp_global::update(const lldp_global& desired)
85{
86 if (!m_binding) {
87 HW::enqueue(
88 new config_cmd(m_binding, m_system_name, m_tx_hold, m_tx_interval));
89 }
90}
91
92std::shared_ptr<lldp_global>
93lldp_global::find_or_add(const lldp_global& temp)
94{
95 return (m_db.find_or_add(temp.m_system_name, temp));
96}
97
98std::shared_ptr<lldp_global>
99lldp_global::singular() const
100{
101 return find_or_add(*this);
102}
103
104lldp_global::event_handler::event_handler()
105{
106 OM::register_listener(this);
107 inspect::register_handler({ "lldp-global" }, "LLDP global configurations",
108 this);
109}
110
111void
112lldp_global::event_handler::handle_replay()
113{
114 m_db.replay();
115}
116
117void
118lldp_global::event_handler::handle_populate(const client_db::key_t& key)
119{
120 // FIXME
121}
122
123dependency_t
124lldp_global::event_handler::order() const
125{
126 return (dependency_t::GLOBAL);
127}
128
129void
130lldp_global::event_handler::show(std::ostream& os)
131{
132 m_db.dump(os);
133}
134}
135
136/*
137 * fd.io coding-style-patch-verification: ON
138 *
139 * Local Variables:
140 * eval: (c-set-style "mozilla")
141 * End:
142 */