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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __VOM_INTERFACE_SPAN_H__
17 #define __VOM_INTERFACE_SPAN_H__
20 #include "vom/inspect.hpp"
21 #include "vom/interface.hpp"
22 #include "vom/object_base.hpp"
24 #include "vom/singular_db.hpp"
28 * A representation of interface span configuration
30 class interface_span : public object_base
34 * The state of the interface - rx/tx or both to be mirrored
36 struct state_t : enum_base<state_t>
41 const static state_t DISABLED;
45 const static state_t RX_ENABLED;
49 const static state_t TX_ENABLED;
51 * TX and RX enable state
53 const static state_t TX_RX_ENABLED;
56 * Convert VPP's numerical value to enum type
58 static state_t from_int(uint8_t val);
62 * Private constructor taking the value and the string name
64 state_t(int v, const std::string& s);
68 * Construct a new object matching the desried state
70 * @param itf_from - The interface to be mirrored
71 * @param itf_to - The interface where the traffic is mirrored
73 interface_span(const interface& itf_from,
74 const interface& itf_to,
80 interface_span(const interface_span& o);
88 * Return the 'singular instance' of the interface_span that matches
91 std::shared_ptr<interface_span> singular() const;
94 * convert to string format for debug purposes
96 std::string to_string() const;
99 * Dump all interface_spans into the stream provided
101 static void dump(std::ostream& os);
104 * The key type for interface_spans
106 typedef std::pair<interface::key_t, interface::key_t> key_t;
109 * Find a singular instance in the DB for the interface passed
111 static std::shared_ptr<interface_span> find(const interface& i);
115 * Class definition for listeners to OM events
117 class event_handler : public OM::listener, public inspect::command_handler
121 virtual ~event_handler() = default;
124 * Handle a populate event
126 void handle_populate(const client_db::key_t& key);
129 * Handle a replay event
131 void handle_replay();
134 * Show the object in the Singular DB
136 void show(std::ostream& os);
139 * Get the sortable Id of the listener
141 dependency_t order() const;
145 * event_handler to register with OM
147 static event_handler m_evh;
150 * Enquue commonds to the VPP command Q for the update
152 void update(const interface_span& obj);
155 * Find or add the singular instance in the DB
157 static std::shared_ptr<interface_span> find_or_add(
158 const interface_span& temp);
161 * It's the VPPHW class that updates the objects in HW
166 e* It's the singular_db class that calls replay()
168 friend class singular_db<key_t, interface_span>;
171 * Sweep/reap the object if still stale
176 * replay the object to create it in hardware
181 * A reference counting pointer the interface to be mirrored
183 const std::shared_ptr<interface> m_itf_from;
185 * A reference counting pointer the interface where the traffic is
188 const std::shared_ptr<interface> m_itf_to;
191 * the state (rx, tx or both) of the interface to be mirrored
193 const state_t m_state;
196 * HW configuration for the binding. The bool representing the
199 HW::item<bool> m_config;
202 * A map of all interface span keyed against the interface to be
205 static singular_db<key_t, interface_span> m_db;
209 * Ostream output for the key
211 std::ostream& operator<<(std::ostream& os, const interface_span::key_t& key);
215 * fd.io coding-style-patch-verification: ON
218 * eval: (c-set-style "mozilla")