FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
interface_span.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_INTERFACE_SPAN_H__
17 #define __VOM_INTERFACE_SPAN_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 interface span configuration
29  */
31 {
32 public:
33  /**
34  * The state of the interface - rx/tx or both to be mirrored
35  */
36  struct state_t : enum_base<state_t>
37  {
38  /**
39  * DISABLED state
40  */
41  const static state_t DISABLED;
42  /**
43  * RX enable state
44  */
45  const static state_t RX_ENABLED;
46  /**
47  * TX enable state
48  */
49  const static state_t TX_ENABLED;
50  /**
51  * TX and RX enable state
52  */
53  const static state_t TX_RX_ENABLED;
54 
55  /**
56  * Convert VPP's numerical value to enum type
57  */
58  static state_t from_int(uint8_t val);
59 
60  private:
61  /**
62  * Private constructor taking the value and the string name
63  */
64  state_t(int v, const std::string& s);
65  };
66 
67  /**
68  * Construct a new object matching the desried state
69  *
70  * @param itf_from - The interface to be mirrored
71  * @param itf_to - The interface where the traffic is mirrored
72  */
73  interface_span(const interface& itf_from,
74  const interface& itf_to,
75  state_t state);
76 
77  /**
78  * Copy Constructor
79  */
81 
82  /**
83  * Destructor
84  */
86 
87  /**
88  * Return the 'singular instance' of the interface_span that matches
89  * this object
90  */
91  std::shared_ptr<interface_span> singular() const;
92 
93  /**
94  * convert to string format for debug purposes
95  */
96  std::string to_string() const;
97 
98  /**
99  * Dump all interface_spans into the stream provided
100  */
101  static void dump(std::ostream& os);
102 
103  /**
104  * The key type for interface_spans
105  */
106  typedef std::pair<interface::key_t, interface::key_t> key_t;
107 
108  /**
109  * Find a singular instance in the DB for the interface passed
110  */
111  static std::shared_ptr<interface_span> find(const interface& i);
112 
113 private:
114  /**
115  * Class definition for listeners to OM events
116  */
117  class event_handler : public OM::listener, public inspect::command_handler
118  {
119  public:
120  event_handler();
121  virtual ~event_handler() = default;
122 
123  /**
124  * Handle a populate event
125  */
126  void handle_populate(const client_db::key_t& key);
127 
128  /**
129  * Handle a replay event
130  */
131  void handle_replay();
132 
133  /**
134  * Show the object in the Singular DB
135  */
136  void show(std::ostream& os);
137 
138  /**
139  * Get the sortable Id of the listener
140  */
141  dependency_t order() const;
142  };
143 
144  /**
145  * event_handler to register with OM
146  */
147  static event_handler m_evh;
148 
149  /**
150  * Enquue commonds to the VPP command Q for the update
151  */
152  void update(const interface_span& obj);
153 
154  /**
155  * Find or add the singular instance in the DB
156  */
157  static std::shared_ptr<interface_span> find_or_add(
158  const interface_span& temp);
159 
160  /*
161  * It's the VPPHW class that updates the objects in HW
162  */
163  friend class OM;
164 
165  /**
166  e* It's the singular_db class that calls replay()
167  */
168  friend class singular_db<key_t, interface_span>;
169 
170  /**
171  * Sweep/reap the object if still stale
172  */
173  void sweep(void);
174 
175  /**
176  * replay the object to create it in hardware
177  */
178  void replay(void);
179 
180  /**
181  * A reference counting pointer the interface to be mirrored
182  */
183  const std::shared_ptr<interface> m_itf_from;
184  /**
185  * A reference counting pointer the interface where the traffic is
186  * mirrored
187  */
188  const std::shared_ptr<interface> m_itf_to;
189 
190  /**
191  * the state (rx, tx or both) of the interface to be mirrored
192  */
193  const state_t m_state;
194 
195  /**
196  * HW configuration for the binding. The bool representing the
197  * do/don't bind.
198  */
199  HW::item<bool> m_config;
200 
201  /**
202  * A map of all interface span keyed against the interface to be
203  * mirrored.
204  */
206 };
207 
208 /**
209  * Ostream output for the key
210  */
211 std::ostream& operator<<(std::ostream& os, const interface_span::key_t& key);
212 };
213 
214 /*
215  * fd.io coding-style-patch-verification: ON
216  *
217  * Local Variables:
218  * eval: (c-set-style "mozilla")
219  * End:
220  */
221 
222 #endif
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
A template base class for all enum types.
Definition: enum_base.hpp:30
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
static const state_t TX_ENABLED
TX enable state.
static const state_t TX_RX_ENABLED
TX and RX enable state.
std::shared_ptr< interface_span > singular() const
Return the &#39;singular instance&#39; of the interface_span that matches this object.
static std::shared_ptr< interface_span > find(const interface &i)
Find a singular instance in the DB for the interface passed.
#define v
Definition: acl.c:341
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:32
static const state_t DISABLED
DISABLED state.
static void dump(std::ostream &os)
Dump all interface_spans 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
std::pair< interface::key_t, interface::key_t > key_t
The key type for interface_spans.
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
The interface to writing objects into VPP OM.
Definition: om.hpp:140
vhost_vring_state_t state
Definition: vhost-user.h:82
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
~interface_span()
Destructor.
static state_t from_int(uint8_t val)
Convert VPP&#39;s numerical value to enum type.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
interface_span(const interface &itf_from, const interface &itf_to, state_t state)
Construct a new object matching the desried state.
static const state_t RX_ENABLED
RX enable state.
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
A representation of interface span configuration.
The state of the interface - rx/tx or both to be mirrored.