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