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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __VOM_L3_BINDING_H__
17 #define __VOM_L3_BINDING_H__
20 #include "vom/inspect.hpp"
21 #include "vom/interface.hpp"
22 #include "vom/object_base.hpp"
24 #include "vom/singular_db.hpp"
28 * A representation of L3 configuration on an interface
30 class l3_binding : public object_base
34 * Construct a new object matching the desried state
36 l3_binding(const interface& itf, const route::prefix_t& pfx);
41 l3_binding(const l3_binding& o);
49 * The key type for l3_bindings
51 typedef std::pair<interface::key_type, route::prefix_t> key_type_t;
56 typedef singular_db<key_type_t, l3_binding>::const_iterator const_iterator_t;
58 static const_iterator_t cbegin();
59 static const_iterator_t cend();
62 * Return the 'singular instance' of the L3-Config that matches this
65 std::shared_ptr<l3_binding> singular() const;
68 * convert to string format for debug purposes
70 std::string to_string() const;
73 * Return the prefix associated with this L3 binding
75 const route::prefix_t& prefix() const;
78 * Return the interface associated with this L3 binding
80 const interface& itf() const;
83 * Dump all l3_bindings into the stream provided
85 static void dump(std::ostream& os);
88 * Find an singular instance in the DB for the interface passed
90 static std::deque<std::shared_ptr<l3_binding>> find(const interface& i);
94 * Class definition for listeners to OM events
96 class event_handler : public OM::listener, public inspect::command_handler
100 virtual ~event_handler() = default;
103 * Handle a populate event
105 void handle_populate(const client_db::key_t& key);
108 * Handle a replay event
110 void handle_replay();
113 * Show the object in the Singular DB
115 void show(std::ostream& os);
118 * Get the sortable Id of the listener
120 dependency_t order() const;
124 * event_handler to register with OM
126 static event_handler m_evh;
129 * Enquue commonds to the VPP command Q for the update
131 void update(const l3_binding& obj);
134 * Find or add the singular instance in the DB
136 static std::shared_ptr<l3_binding> find_or_add(const l3_binding& temp);
139 * It's the VPPHW class that updates the objects in HW
144 e* It's the singular_db class that calls replay()
146 friend class singular_db<key_type_t, l3_binding>;
149 * Sweep/reap the object if still stale
154 * replay the object to create it in hardware
158 friend class interface;
161 * A reference counting pointer the interface that this L3 layer
162 * represents. By holding the reference here, we can guarantee that
163 * this object will outlive the interface
165 const std::shared_ptr<interface> m_itf;
168 * The prefix for this L3 configuration
170 const route::prefix_t m_pfx;
173 * HW configuration for the binding. The bool representing the
176 HW::item<bool> m_binding;
179 * A map of all L3 configs keyed against a combination of the interface
182 static singular_db<key_type_t, l3_binding> m_db;
186 * Ostream output for the key
188 std::ostream& operator<<(std::ostream& os, const l3_binding::key_type_t& key);
192 * fd.io coding-style-patch-verification: ON
195 * eval: (c-set-style "mozilla")