blob: a1470587e94545490e587abd5f9ecca3aa992193 [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#ifndef __VOM_L3_BINDING_H__
17#define __VOM_L3_BINDING_H__
18
Neale Ranns812ed392017-10-16 04:20:13 -070019#include "vom/hw.hpp"
20#include "vom/inspect.hpp"
21#include "vom/interface.hpp"
22#include "vom/object_base.hpp"
23#include "vom/om.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070024#include "vom/singular_db.hpp"
25
Neale Ranns812ed392017-10-16 04:20:13 -070026namespace VOM {
27/**
28 * A representation of L3 configuration on an interface
29 */
30class l3_binding : public object_base
31{
32public:
33 /**
34 * Construct a new object matching the desried state
35 */
36 l3_binding(const interface& itf, const route::prefix_t& pfx);
37
38 /**
39 * Copy Constructor
40 */
41 l3_binding(const l3_binding& o);
42
43 /**
44 * Destructor
45 */
46 ~l3_binding();
47
48 /**
Neale Ranns352ea0c2017-11-14 11:04:28 -080049 * The key type for l3_bindings
50 */
51 typedef std::pair<interface::key_type, route::prefix_t> key_type_t;
52
53 /**
54 * The iterator type
55 */
56 typedef singular_db<key_type_t, l3_binding>::const_iterator const_iterator_t;
57
58 static const_iterator_t cbegin();
59 static const_iterator_t cend();
60
61 /**
Neale Ranns812ed392017-10-16 04:20:13 -070062 * Return the 'singular instance' of the L3-Config that matches this
63 * object
64 */
65 std::shared_ptr<l3_binding> singular() const;
66
67 /**
68 * convert to string format for debug purposes
69 */
70 std::string to_string() const;
71
72 /**
Neale Ranns352ea0c2017-11-14 11:04:28 -080073 * Return the prefix associated with this L3 binding
Neale Ranns812ed392017-10-16 04:20:13 -070074 */
75 const route::prefix_t& prefix() const;
76
77 /**
Neale Ranns352ea0c2017-11-14 11:04:28 -080078 * Return the interface associated with this L3 binding
79 */
80 const interface& itf() const;
81
82 /**
Neale Ranns812ed392017-10-16 04:20:13 -070083 * Dump all l3_bindings into the stream provided
84 */
85 static void dump(std::ostream& os);
86
87 /**
Neale Ranns812ed392017-10-16 04:20:13 -070088 * Find an singular instance in the DB for the interface passed
89 */
90 static std::deque<std::shared_ptr<l3_binding>> find(const interface& i);
91
Neale Ranns812ed392017-10-16 04:20:13 -070092private:
93 /**
94 * Class definition for listeners to OM events
95 */
96 class event_handler : public OM::listener, public inspect::command_handler
97 {
98 public:
99 event_handler();
100 virtual ~event_handler() = default;
101
102 /**
103 * Handle a populate event
104 */
105 void handle_populate(const client_db::key_t& key);
106
107 /**
108 * Handle a replay event
109 */
110 void handle_replay();
111
112 /**
113 * Show the object in the Singular DB
114 */
115 void show(std::ostream& os);
116
117 /**
118 * Get the sortable Id of the listener
119 */
120 dependency_t order() const;
121 };
122
123 /**
124 * event_handler to register with OM
125 */
126 static event_handler m_evh;
127
128 /**
129 * Enquue commonds to the VPP command Q for the update
130 */
131 void update(const l3_binding& obj);
132
133 /**
134 * Find or add the singular instance in the DB
135 */
136 static std::shared_ptr<l3_binding> find_or_add(const l3_binding& temp);
137
138 /*
139 * It's the VPPHW class that updates the objects in HW
140 */
141 friend class OM;
142
143 /**
144 e* It's the singular_db class that calls replay()
145 */
146 friend class singular_db<key_type_t, l3_binding>;
147
148 /**
149 * Sweep/reap the object if still stale
150 */
151 void sweep(void);
152
153 /**
154 * replay the object to create it in hardware
155 */
156 void replay(void);
157
Neale Ranns352ea0c2017-11-14 11:04:28 -0800158 friend class interface;
159
Neale Ranns812ed392017-10-16 04:20:13 -0700160 /**
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
164 */
165 const std::shared_ptr<interface> m_itf;
166
167 /**
168 * The prefix for this L3 configuration
169 */
Neale Ranns8ac4ce82017-11-17 05:08:55 -0800170 const route::prefix_t m_pfx;
Neale Ranns812ed392017-10-16 04:20:13 -0700171
172 /**
173 * HW configuration for the binding. The bool representing the
174 * do/don't bind.
175 */
176 HW::item<bool> m_binding;
177
178 /**
179 * A map of all L3 configs keyed against a combination of the interface
180 * and subnet's keys.
181 */
182 static singular_db<key_type_t, l3_binding> m_db;
183};
184
185/**
186 * Ostream output for the key
187 */
188std::ostream& operator<<(std::ostream& os, const l3_binding::key_type_t& key);
189};
190
191/*
192 * fd.io coding-style-patch-verification: ON
193 *
194 * Local Variables:
195 * eval: (c-set-style "mozilla")
196 * End:
197 */
198
199#endif