FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
l3_binding.hpp
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 #ifndef __VOM_L3_BINDING_H__
17 #define __VOM_L3_BINDING_H__
18 
19 #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"
24 #include "vom/singular_db.hpp"
25 
26 namespace VOM {
27 /**
28  * A representation of L3 configuration on an interface
29  */
30 class l3_binding : public object_base
31 {
32 public:
33  /**
34  * The key type for l3_bindings
35  */
36  typedef std::pair<interface::key_t, route::prefix_t> key_t;
37 
38  /**
39  * Construct a new object matching the desried state
40  */
41  l3_binding(const interface& itf, const route::prefix_t& pfx);
42 
43  /**
44  * Copy Constructor
45  */
46  l3_binding(const l3_binding& o);
47 
48  /**
49  * Destructor
50  */
51  ~l3_binding();
52 
53  /**
54  * Comparison operator
55  */
56  bool operator==(const l3_binding& l) const;
57 
58  /**
59  * Get the object's key
60  */
61  const key_t key() const;
62 
63  /**
64  * The iterator type
65  */
67 
68  static const_iterator_t cbegin();
69  static const_iterator_t cend();
70 
71  /**
72  * Return the 'singular instance' of the L3-Config that matches this
73  * object
74  */
75  std::shared_ptr<l3_binding> singular() const;
76 
77  /**
78  * convert to string format for debug purposes
79  */
80  std::string to_string() const;
81 
82  /**
83  * Return the prefix associated with this L3 binding
84  */
85  const route::prefix_t& prefix() const;
86 
87  /**
88  * Return the interface associated with this L3 binding
89  */
90  const interface& itf() const;
91 
92  /**
93  * Dump all l3_bindings into the stream provided
94  */
95  static void dump(std::ostream& os);
96 
97  /**
98  * Find a binding from its key
99  */
100  static std::shared_ptr<l3_binding> find(const key_t& k);
101 
102 private:
103  /**
104  * Class definition for listeners to OM events
105  */
107  {
108  public:
109  event_handler();
110  virtual ~event_handler() = default;
111 
112  /**
113  * Handle a populate event
114  */
115  void handle_populate(const client_db::key_t& key);
116 
117  /**
118  * Handle a replay event
119  */
120  void handle_replay();
121 
122  /**
123  * Show the object in the Singular DB
124  */
125  void show(std::ostream& os);
126 
127  /**
128  * Get the sortable Id of the listener
129  */
130  dependency_t order() const;
131  };
132 
133  /**
134  * event_handler to register with OM
135  */
136  static event_handler m_evh;
137 
138  /**
139  * Enquue commonds to the VPP command Q for the update
140  */
141  void update(const l3_binding& obj);
142 
143  /**
144  * Find or add the singular instance in the DB
145  */
146  static std::shared_ptr<l3_binding> find_or_add(const l3_binding& temp);
147 
148  /*
149  * It's the VPPHW class that updates the objects in HW
150  */
151  friend class OM;
152 
153  /**
154  e* It's the singular_db class that calls replay()
155  */
156  friend class singular_db<key_t, l3_binding>;
157 
158  /**
159  * Sweep/reap the object if still stale
160  */
161  void sweep(void);
162 
163  /**
164  * replay the object to create it in hardware
165  */
166  void replay(void);
167 
168  friend class interface;
169 
170  /**
171  * A reference counting pointer the interface that this L3 layer
172  * represents. By holding the reference here, we can guarantee that
173  * this object will outlive the interface
174  */
175  const std::shared_ptr<interface> m_itf;
176 
177  /**
178  * The prefix for this L3 configuration
179  */
180  const route::prefix_t m_pfx;
181 
182  /**
183  * HW configuration for the binding. The bool representing the
184  * do/don't bind.
185  */
186  HW::item<bool> m_binding;
187 
188  /**
189  * A map of all L3 configs keyed against a combination of the interface
190  * and subnet's keys.
191  */
192  static singular_db<key_t, l3_binding> m_db;
193 };
194 
195 /**
196  * Ostream output for the key
197  */
198 std::ostream& operator<<(std::ostream& os, const l3_binding::key_t& key);
199 };
200 
201 /*
202  * fd.io coding-style-patch-verification: OFF
203  *
204  * Local Variables:
205  * eval: (c-set-style "mozilla")
206  * End:
207  */
208 
209 #endif
VOM::route::prefix_t
A prefix defintion.
Definition: prefix.hpp:131
VOM::HW::item< bool >
VOM::l3_binding::operator==
bool operator==(const l3_binding &l) const
Comparison operator.
Definition: l3_binding.cpp:51
VOM::l3_binding::cbegin
static const_iterator_t cbegin()
Definition: l3_binding.cpp:94
VOM::l3_binding::find
static std::shared_ptr< l3_binding > find(const key_t &k)
Find a binding from its key.
Definition: l3_binding.cpp:136
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
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
om.hpp
VOM::l3_binding::cend
static const_iterator_t cend()
Definition: l3_binding.cpp:100
VOM::OM
The interface to writing objects into VPP OM.
Definition: om.hpp:140
VOM::inspect::command_handler
inspect command handler Handler
Definition: inspect.hpp:54
VOM::l3_binding::itf
const interface & itf() const
Return the interface associated with this L3 binding.
Definition: l3_binding.cpp:88
VOM::OM::listener
Class definition for listeners to OM events.
Definition: om.hpp:284
VOM::singular_db::const_iterator
std::map< KEY, std::weak_ptr< OBJ > >::const_iterator const_iterator
Iterator.
Definition: singular_db.hpp:45
key
typedef key
Definition: ipsec_types.api:88
VOM::l3_binding::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: l3_binding.cpp:106
VOM::l3_binding::key
const key_t key() const
Get the object's key.
Definition: l3_binding.cpp:57
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
hw.hpp
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::l3_binding::dump
static void dump(std::ostream &os)
Dump all l3_bindings into the stream provided.
Definition: l3_binding.cpp:148
VOM::l3_binding::key_t
std::pair< interface::key_t, route::prefix_t > key_t
The key type for l3_bindings.
Definition: l3_binding.hpp:36
VOM::operator<<
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Definition: acl_binding.cpp:201
VOM::l3_binding::l3_binding
l3_binding(const interface &itf, const route::prefix_t &pfx)
Construct a new object matching the desried state.
Definition: l3_binding.cpp:28
inspect.hpp
singular_db.hpp
interface.hpp
VOM::l3_binding::singular
std::shared_ptr< l3_binding > singular() const
Return the 'singular instance' of the L3-Config that matches this object.
Definition: l3_binding.cpp:142
VOM::singular_db
A Database to store the unique 'singular' instances of a single object type.
Definition: singular_db.hpp:33
VOM::l3_binding::const_iterator_t
singular_db< key_t, l3_binding >::const_iterator const_iterator_t
The iterator type.
Definition: l3_binding.hpp:66
show
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
VOM::l3_binding::~l3_binding
~l3_binding()
Destructor.
Definition: l3_binding.cpp:42
event_handler
void event_handler(void *tls_async)
Definition: tls_async.c:334
VOM::l3_binding
A representation of L3 configuration on an interface.
Definition: l3_binding.hpp:30
VOM::object_base
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
object_base.hpp
VOM::l3_binding::prefix
const route::prefix_t & prefix() const
Return the prefix associated with this L3 binding.
Definition: l3_binding.cpp:82
string
const char *const string
Definition: cJSON.h:172