FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
l2_xconnect.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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_L2_XCONNECT_H__
17 #define __VOM_L2_XCONNECT_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 Class representing the cross connnect of an L2 interface with another
29  * l2 interface
30  */
31 class l2_xconnect : public object_base
32 {
33 public:
34  /**
35  * Key type for an L2 xconnect in the singular DB
36  */
37  typedef std::pair<interface::key_t, interface::key_t> key_t;
38 
39  /**
40  * Construct a new object matching the desried state
41  */
42  l2_xconnect(const interface& east_itf, const interface& west_itf);
43 
44  /**
45  * Copy Constructor
46  */
47  l2_xconnect(const l2_xconnect& o);
48 
49  /**
50  * Destructor
51  */
52  ~l2_xconnect();
53 
54  /**
55  * Return the xconnect's key
56  */
57  const key_t key() const;
58 
59  /**
60  * Comparison operator - for UT
61  */
62  bool operator==(const l2_xconnect& l) const;
63 
64  /**
65  * Return the 'singular instance' of the L2 config that matches this
66  * object
67  */
68  std::shared_ptr<l2_xconnect> singular() const;
69 
70  /**
71  * convert to string format for debug purposes
72  */
73  std::string to_string() const;
74 
75  /**
76  * Dump all l2_xconnects into the stream provided
77  */
78  static void dump(std::ostream& os);
79 
80  /**
81  * Static function to find the bridge_domain in the model
82  */
83  static std::shared_ptr<l2_xconnect> find(const key_t& key);
84 
85 private:
86  /**
87  * Class definition for listeners to OM events
88  */
90  {
91  public:
92  event_handler();
93  virtual ~event_handler() = default;
94 
95  /**
96  * Handle a populate event
97  */
98  void handle_populate(const client_db::key_t& key);
99 
100  /**
101  * Handle a replay event
102  */
103  void handle_replay();
104 
105  /**
106  * Show the object in the Singular DB
107  */
108  void show(std::ostream& os);
109 
110  /**
111  * Get the sortable Id of the listener
112  */
113  dependency_t order() const;
114  };
115 
116  /**
117  * event_handler to register with OM
118  */
119  static event_handler m_evh;
120 
121  /**
122  * Enque commands to the VPP command Q for the update
123  */
124  void update(const l2_xconnect& obj);
125 
126  /**
127  * Find or Add the singular instance in the DB
128  */
129  static std::shared_ptr<l2_xconnect> find_or_add(const l2_xconnect& temp);
130 
131  /*
132  * It's the OM class that calls singular()
133  */
134  friend class OM;
135 
136  /**
137  * It's the singular_db class that calls replay()
138  */
139  friend class singular_db<key_t, l2_xconnect>;
140 
141  /**
142  * Sweep/reap the object if still stale
143  */
144  void sweep(void);
145 
146  /**
147  * replay the object to create it in hardware
148  */
149  void replay(void);
150 
151  /**
152  * A reference counting pointer the interface that this L2 layer
153  * represents. By holding the reference here, we can guarantee that
154  * this object will outlive the interface
155  */
156  const std::shared_ptr<interface> m_east_itf;
157 
158  /**
159  * A reference counting pointer the Bridge-Domain that this L2
160  * interface is bound to. By holding the reference here, we can
161  * guarantee that this object will outlive the BD.
162  */
163  const std::shared_ptr<interface> m_west_itf;
164 
165  /**
166  * HW configuration for the xconnect. The bool representing the
167  * do/don't bind.
168  */
169  HW::item<bool> m_xconnect_east;
170 
171  /**
172  * HW configuration for the xconnect. The bool representing the
173  * do/don't bind.
174  */
175  HW::item<bool> m_xconnect_west;
176 
177  /**
178  * A map of all L2 interfaces key against the interface's handle_t
179  */
181 };
182 
183 std::ostream& operator<<(std::ostream& os, const l2_xconnect::key_t& key);
184 };
185 
186 /*
187  * fd.io coding-style-patch-verification: ON
188  *
189  * Local Variables:
190  * eval: (c-set-style "mozilla")
191  * End:
192  */
193 
194 #endif
static std::shared_ptr< l2_xconnect > find(const key_t &key)
Static function to find the bridge_domain in the model.
Definition: l2_xconnect.cpp:62
const 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
A Class representing the cross connnect of an L2 interface with another l2 interface.
Definition: l2_xconnect.hpp:31
std::shared_ptr< l2_xconnect > singular() const
Return the &#39;singular instance&#39; of the L2 config that matches this object.
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
static void dump(std::ostream &os)
Dump all l2_xconnects into the stream provided.
A representation of an interface in VPP.
Definition: interface.hpp:41
Class definition for listeners to OM events.
Definition: om.hpp:284
inspect command handler Handler
Definition: inspect.hpp:54
bool operator==(const l2_xconnect &l) const
Comparison operator - for UT.
Definition: l2_xconnect.cpp:56
void event_handler(void *tls_async)
Definition: tls_async.c:340
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
l2_xconnect(const interface &east_itf, const interface &west_itf)
Construct a new object matching the desried state.
Definition: l2_xconnect.cpp:31
std::pair< interface::key_t, interface::key_t > key_t
Key type for an L2 xconnect in the singular DB.
Definition: l2_xconnect.hpp:37
The interface to writing objects into VPP OM.
Definition: om.hpp:140
~l2_xconnect()
Destructor.
Definition: l2_xconnect.cpp:95
std::string to_string() const
convert to string format for debug purposes
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
const key_t key() const
Return the xconnect&#39;s key.
Definition: l2_xconnect.cpp:48