FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
interface_span.cpp
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 #include "vom/interface_span.hpp"
18 
19 namespace VOM {
20 /**
21  * A DB of all interface_span config
22  */
23 singular_db<interface_span::key_t, interface_span> interface_span::m_db;
24 
25 interface_span::event_handler interface_span::m_evh;
26 
28  const interface& itf_to,
30  : m_itf_from(itf_from.singular())
31  , m_itf_to(itf_to.singular())
32  , m_state(state)
33  , m_config(true)
34 {
35 }
36 
38  : m_itf_from(o.m_itf_from)
39  , m_itf_to(o.m_itf_to)
40  , m_state(o.m_state)
41  , m_config(o.m_config)
42 {
43 }
44 
46 {
47  sweep();
48 
49  // not in the DB anymore.
50  m_db.release(make_pair(m_itf_from->key(), m_itf_to->key()), this);
51 }
52 
53 void
54 interface_span::sweep()
55 {
56  if (m_config) {
58  m_config, m_itf_from->handle(), m_itf_to->handle()));
59  }
60  HW::write();
61 }
62 
63 void
64 interface_span::dump(std::ostream& os)
65 {
66  m_db.dump(os);
67 }
68 
69 void
70 interface_span::replay()
71 {
72  if (m_config) {
74  m_config, m_itf_from->handle(), m_itf_to->handle(), m_state));
75  }
76 }
77 
78 std::string
80 {
81  std::ostringstream s;
82  s << "Itf Span-config:"
83  << " itf-from:" << m_itf_from->to_string()
84  << " itf-to:" << m_itf_to->to_string() << " state:" << m_state.to_string();
85 
86  return (s.str());
87 }
88 
89 void
90 interface_span::update(const interface_span& desired)
91 {
92  if (!m_config) {
94  m_config, m_itf_from->handle(), m_itf_to->handle(), m_state));
95  }
96 }
97 
98 std::ostream&
99 operator<<(std::ostream& os, const interface_span::key_t& key)
100 {
101  os << "[" << key.first << ", " << key.second << "]";
102 
103  return (os);
104 }
105 
106 std::shared_ptr<interface_span>
107 interface_span::find_or_add(const interface_span& temp)
108 {
109  return (m_db.find_or_add(
110  make_pair(temp.m_itf_from->key(), temp.m_itf_to->key()), temp));
111 }
112 
113 std::shared_ptr<interface_span>
115 {
116  return find_or_add(*this);
117 }
118 
119 interface_span::event_handler::event_handler()
120 {
121  OM::register_listener(this);
122  inspect::register_handler({ "itf-span" }, "interface span configurations",
123  this);
124 }
125 
126 void
127 interface_span::event_handler::handle_replay()
128 {
129  m_db.replay();
130 }
131 
132 void
133 interface_span::event_handler::handle_populate(const client_db::key_t& key)
134 {
135  std::shared_ptr<interface_span_cmds::dump_cmd> cmd =
136  std::make_shared<interface_span_cmds::dump_cmd>();
137 
138  HW::enqueue(cmd);
139  HW::write();
140 
141  for (auto& record : *cmd) {
142  auto& payload = record.get_payload();
143 
144  std::shared_ptr<interface> itf_from =
145  interface::find(payload.sw_if_index_from);
146  std::shared_ptr<interface> itf_to = interface::find(payload.sw_if_index_to);
147 
148  interface_span itf_span(*itf_from, *itf_to,
149  state_t::from_int(payload.state));
150 
151  VOM_LOG(log_level_t::DEBUG) << "span-dump: " << itf_from->to_string()
152  << itf_to->to_string()
153  << state_t::from_int(payload.state).to_string();
154 
155  /*
156  * Write each of the discovered interfaces into the OM,
157  * but disable the HW Command q whilst we do, so that no
158  * commands are sent to VPP
159  */
160  OM::commit(key, itf_span);
161  }
162 }
163 
165 interface_span::event_handler::order() const
166 {
167  return (dependency_t::BINDING);
168 }
169 
170 void
171 interface_span::event_handler::show(std::ostream& os)
172 {
173  m_db.dump(os);
174 }
175 
178  "rx-enable");
180  "tx-enable");
182  3,
183  "tx-rx-enable");
184 
185 interface_span::state_t::state_t(int v, const std::string& s)
187 {
188 }
189 
192 {
193  switch (i) {
194  case 0:
196  break;
197  case 1:
199  break;
200  case 2:
202  break;
203  case 3:
204  default:
205  break;
206  }
207 
209 }
210 }
211 
212 /*
213  * fd.io coding-style-patch-verification: ON
214  *
215  * Local Variables:
216  * eval: (c-set-style "mozilla")
217  * End:
218  */
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
#define VOM_LOG(lvl)
Definition: logger.hpp:181
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 std::shared_ptr< interface > find(const handle_t &h)
The the singular instance of the interface in the DB by handle.
Definition: interface.cpp:402
static void register_handler(const std::vector< std::string > &cmds, const std::string &help, command_handler *ch)
Register a command handler for inspection.
Definition: inspect.cpp:85
static const state_t TX_ENABLED
TX enable state.
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:225
static const log_level_t DEBUG
Definition: logger.hpp:32
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.
A command class that configures the interface span.
A cmd class that Unconfigs interface span.
std::string to_string() const
convert to string format for debug purposes
#define v
Definition: acl.c:341
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
std::pair< interface::key_t, interface::key_t > key_t
The key type for interface_spans.
static rc_t commit(const client_db::key_t &key, const OBJ &obj)
Make the State in VPP reflect the expressed desired state.
Definition: om.hpp:202
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
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:189
vhost_vring_state_t state
Definition: vhost-user.h:82
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Then L2/objects that bind to interfaces, BD, ACLS, etc.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
~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.
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:124
The state of the interface - rx/tx or both to be mirrored.