gre: migrate old MULTIARCH macros to VLIB_NODE_FN
[vpp.git] / extras / vom / vom / gbp_global.cpp
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/gbp_global.hpp"
17 #include "vom/gbp_global_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
19
20 namespace VOM {
21 /**
22  * A DB of all GBP configs
23  */
24 singular_db<std::string, gbp_global> gbp_global::m_db;
25
26 gbp_global::event_handler gbp_global::m_evh;
27
28 gbp_global::gbp_global(const std::string& system_name,
29                        uint32_t remote_ep_retention)
30   : m_system_name(system_name)
31   , m_remote_ep_retention(remote_ep_retention)
32 {
33 }
34
35 gbp_global::gbp_global(const gbp_global& o)
36   : m_system_name(o.m_system_name)
37   , m_remote_ep_retention(o.m_remote_ep_retention)
38 {
39 }
40
41 gbp_global::~gbp_global()
42 {
43   sweep();
44   m_db.release(m_system_name, this);
45 }
46
47 const gbp_global::key_t&
48 gbp_global::key() const
49 {
50   return (m_system_name);
51 }
52
53 bool
54 gbp_global::operator==(const gbp_global& l) const
55 {
56   return ((key() == l.key()) &&
57           (m_remote_ep_retention == l.m_remote_ep_retention));
58 }
59
60 void
61 gbp_global::sweep()
62 {
63   // no means to remove this in VPP
64 }
65
66 void
67 gbp_global::dump(std::ostream& os)
68 {
69   db_dump(m_db, os);
70 }
71
72 void
73 gbp_global::replay()
74 {
75   if (m_binding) {
76     HW::enqueue(
77       new gbp_global_cmds::config_cmd(m_binding, m_remote_ep_retention));
78   }
79 }
80
81 std::string
82 gbp_global::to_string() const
83 {
84   std::ostringstream s;
85   s << "GBP-global:"
86     << " remote-EP-retention:" << m_remote_ep_retention;
87
88   return (s.str());
89 }
90
91 void
92 gbp_global::update(const gbp_global& desired)
93 {
94   if (!m_binding) {
95     HW::enqueue(
96       new gbp_global_cmds::config_cmd(m_binding, m_remote_ep_retention));
97   }
98 }
99
100 std::shared_ptr<gbp_global>
101 gbp_global::find_or_add(const gbp_global& temp)
102 {
103   return (m_db.find_or_add(temp.key(), temp));
104 }
105
106 std::shared_ptr<gbp_global>
107 gbp_global::find(const key_t& k)
108 {
109   return (m_db.find(k));
110 }
111
112 std::shared_ptr<gbp_global>
113 gbp_global::singular() const
114 {
115   return find_or_add(*this);
116 }
117
118 gbp_global::event_handler::event_handler()
119 {
120   OM::register_listener(this);
121   inspect::register_handler({ "gbp-global" }, "GBP global configurations",
122                             this);
123 }
124
125 void
126 gbp_global::event_handler::handle_replay()
127 {
128   m_db.replay();
129 }
130
131 void
132 gbp_global::event_handler::handle_populate(const client_db::key_t& key)
133 {
134 }
135
136 dependency_t
137 gbp_global::event_handler::order() const
138 {
139   return (dependency_t::GLOBAL);
140 }
141
142 void
143 gbp_global::event_handler::show(std::ostream& os)
144 {
145   db_dump(m_db, os);
146 }
147 }
148
149 /*
150  * fd.io coding-style-patch-verification: ON
151  *
152  * Local Variables:
153  * eval: (c-set-style "mozilla")
154  * End:
155  */