FD.io VPP  v21.10.1-2-g0a485f517
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  */
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  */
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: OFF
216  *
217  * Local Variables:
218  * eval: (c-set-style "mozilla")
219  * End:
220  */
221 
222 #endif
VOM::interface_span::state_t::RX_ENABLED
const static state_t RX_ENABLED
RX enable state.
Definition: interface_span.hpp:45
VOM::HW::item< bool >
VOM::interface_span::interface_span
interface_span(const interface &itf_from, const interface &itf_to, state_t state)
Construct a new object matching the desried state.
Definition: interface_span.cpp:28
VOM::interface_span::state_t::from_int
static state_t from_int(uint8_t val)
Convert VPP's numerical value to enum type.
Definition: interface_span.cpp:192
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::OM
The interface to writing objects into VPP OM.
Definition: om.hpp:140
VOM::interface_span::state_t::TX_ENABLED
const static state_t TX_ENABLED
TX enable state.
Definition: interface_span.hpp:49
VOM::inspect::command_handler
inspect command handler Handler
Definition: inspect.hpp:54
state
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
VOM::OM::listener
Class definition for listeners to OM events.
Definition: om.hpp:284
VOM::interface_span
A representation of interface span configuration.
Definition: interface_span.hpp:30
key
typedef key
Definition: ipsec_types.api:91
VOM::interface_span::state_t
The state of the interface - rx/tx or both to be mirrored.
Definition: interface_span.hpp:36
VOM::interface_span::state_t::DISABLED
const static state_t DISABLED
DISABLED state.
Definition: interface_span.hpp:41
VOM::interface_span::singular
std::shared_ptr< interface_span > singular() const
Return the 'singular instance' of the interface_span that matches this object.
Definition: interface_span.cpp:115
VOM::enum_base
A template base class for all enum types.
Definition: enum_base.hpp:30
VOM::interface_span::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: interface_span.cpp:80
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::interface_span::find
static std::shared_ptr< interface_span > find(const interface &i)
Find a singular instance in the DB for the interface passed.
VOM::operator<<
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Definition: acl_binding.cpp:201
VOM::interface_span::key_t
std::pair< interface::key_t, interface::key_t > key_t
The key type for interface_spans.
Definition: interface_span.hpp:106
inspect.hpp
singular_db.hpp
interface.hpp
VOM::interface_span::dump
static void dump(std::ostream &os)
Dump all interface_spans into the stream provided.
Definition: interface_span.cpp:65
VOM::singular_db
A Database to store the unique 'singular' instances of a single object type.
Definition: singular_db.hpp:33
i
int i
Definition: flowhash_template.h:376
VOM::interface_span::~interface_span
~interface_span()
Destructor.
Definition: interface_span.cpp:46
show
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
event_handler
void event_handler(void *tls_async)
Definition: tls_async.c:334
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::interface_span::state_t::TX_RX_ENABLED
const static state_t TX_RX_ENABLED
TX and RX enable state.
Definition: interface_span.hpp:53
string
const char *const string
Definition: cJSON.h:172