FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
pipe.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/pipe.hpp"
18 #include "vom/pipe_cmds.hpp"
20 
21 namespace VOM {
22 
23 typedef enum end_t_ {
24  EAST = 0,
26 } end_t;
27 #define N_ENDS (WEST + 1)
28 
29 pipe::event_handler pipe::m_evh;
30 
31 static const std::string
33 {
34  return ("pipe" + std::to_string(instance));
35 }
36 
37 /**
38  * Construct a new object matching the desried state
39  */
41  : interface(pipe_mk_name(instance), type_t::PIPE, state)
42  , m_instance(instance)
43 {
44 }
45 
47 {
48  sweep();
49  release();
50 }
51 
52 pipe::pipe(const pipe& o)
53  : interface(o)
54  , m_instance(o.m_instance)
55 {
56 }
57 
58 std::string
59 pipe::to_string(void) const
60 {
61  std::ostringstream s;
62 
63  s << "[pipe: " << interface::to_string() << " instance:" << m_instance
64  << " ends:[" << m_hdl_pair.rc().to_string() << " "
65  << m_hdl_pair.data().first << ", " << m_hdl_pair.data().second << "]]";
66 
67  return (s.str());
68 }
69 
70 std::queue<cmd*>&
71 pipe::mk_create_cmd(std::queue<cmd*>& q)
72 {
73  q.push(new pipe_cmds::create_cmd(m_hdl, m_name, m_instance, m_hdl_pair));
74 
75  return (q);
76 }
77 
78 std::queue<cmd*>&
79 pipe::mk_delete_cmd(std::queue<cmd*>& q)
80 {
81  q.push(new pipe_cmds::delete_cmd(m_hdl, m_hdl_pair));
82 
83  return (q);
84 }
85 
86 std::shared_ptr<pipe>
88 {
89  return std::dynamic_pointer_cast<pipe>(singular_i());
90 }
91 
92 std::shared_ptr<interface>
93 pipe::singular_i() const
94 {
95  return m_db.find_or_add(key(), *this);
96 }
97 
98 std::shared_ptr<pipe>
99 pipe::find(const key_t& k)
100 {
101  return std::dynamic_pointer_cast<pipe>(m_db.find(k));
102 }
103 
104 std::shared_ptr<interface>
106 {
107  if (!m_ends[WEST]) {
108  if (rc_t::OK == m_hdl_pair.rc()) {
109  m_ends[WEST] = pipe_end(*this, WEST).singular();
110  m_ends[WEST]->set(m_hdl_pair.data().first);
111  }
112  }
113 
114  return (m_ends[WEST]);
115 }
116 
117 std::shared_ptr<interface>
119 {
120  if (!m_ends[EAST]) {
121  if (rc_t::OK == m_hdl_pair.rc()) {
122  m_ends[EAST] = pipe_end(*this, EAST).singular();
123  m_ends[EAST]->set(m_hdl_pair.data().first);
124  }
125  }
126 
127  return (m_ends[EAST]);
128 }
129 
130 pipe::pipe_end::pipe_end(const pipe& p, uint8_t id)
131  : interface(p.name() + "." + std::to_string(id),
134  , m_pipe(p.singular())
135 {
136 }
137 
138 std::queue<cmd*>&
139 pipe::pipe_end::mk_create_cmd(std::queue<cmd*>& q)
140 {
141  return (q);
142 }
143 
144 std::queue<cmd*>&
145 pipe::pipe_end::mk_delete_cmd(std::queue<cmd*>& q)
146 {
147  return (q);
148 }
149 
150 void
152 {
153  if (handle_t::INVALID != p.first && handle_t::INVALID != p.second) {
154  m_hdl_pair = { p, rc_t::OK };
155  } else {
156  m_hdl_pair = { p, rc_t::INVALID };
157  }
158 }
159 
161 {
162  OM::register_listener(this);
163  inspect::register_handler({ "pipe" }, "pipes", this);
164 }
165 
166 void
167 pipe::event_handler::handle_replay()
168 {
169  // m_db.replay();
170 }
171 
172 void
173 pipe::event_handler::handle_populate(const client_db::key_t& key)
174 {
175  std::shared_ptr<pipe_cmds::dump_cmd> cmd =
176  std::make_shared<pipe_cmds::dump_cmd>();
177 
178  HW::enqueue(cmd);
179  HW::write();
180 
181  for (auto& record : *cmd) {
182  std::shared_ptr<pipe> sp;
183 
184  sp = interface_factory::new_pipe_interface(record.get_payload());
185 
186  VOM_LOG(log_level_t::DEBUG) << " pipe-dump: " << sp->to_string();
187  OM::commit(key, *sp);
188  }
189 }
190 
192 pipe::event_handler::order() const
193 {
195 }
196 
197 void
198 pipe::event_handler::show(std::ostream& os)
199 {
200  db_dump(m_db, os);
201 }
202 
203 }; // namespace VOM
204 
205 /*
206  * fd.io coding-style-patch-verification: ON
207  *
208  * Local Variables:
209  * eval: (c-set-style "mozilla")
210  * End:
211  */
void release()
release/remove an interface form the singular store
Definition: interface.cpp:240
A Pipe interface.
Definition: pipe.hpp:31
A cmd class that Delete an interface.
Definition: pipe_cmds.hpp:67
interface(const std::string &name, type_t type, admin_state_t state, const std::string &tag="")
Construct a new object matching the desried state.
Definition: interface.cpp:51
#define VOM_LOG(lvl)
Definition: logger.hpp:181
end_t_
Definition: pipe.cpp:23
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
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
pipe(uint32_t instance, admin_state_t state)
Construct a new object matching the desried state.
Definition: pipe.cpp:40
virtual interfaces - those that depend on some real interface
HW::item< handle_t > m_hdl
The SW interface handle VPP has asigned to the interface.
Definition: interface.hpp:540
static std::shared_ptr< pipe > new_pipe_interface(const vapi_payload_pipe_details &payload)
virtual void sweep(void)
Sweep/reap the object if still stale.
Definition: interface.cpp:182
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 rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
static const log_level_t DEBUG
Definition: logger.hpp:32
virtual std::string to_string(void) const
convert to string format for debug purposes
Definition: interface.cpp:247
static const handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
enum VOM::end_t_ end_t
T & data()
Return the data read/written.
Definition: hw.hpp:109
virtual std::string to_string(void) const
convert to string format for debug purposes
Definition: pipe.cpp:59
static singular_db< key_t, interface > m_db
A map of all interfaces key against the interface&#39;s name.
Definition: interface.hpp:572
A functor class that creates an interface.
Definition: pipe_cmds.hpp:30
const std::string & name() const
Return the interface type.
Definition: interface.cpp:271
vhost_vring_state_t state
Definition: vhost_user.h:146
std::shared_ptr< interface > east()
The interface that is the east end of the pipe.
Definition: pipe.cpp:118
static const type_t PIPE_END
pipe-end type
Definition: interface.hpp:121
~pipe()
Destructor.
Definition: pipe.cpp:46
The admin state of the interface.
Definition: interface.hpp:138
A representation of an interface in VPP.
Definition: interface.hpp:41
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
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
void event_handler(void *tls_async)
Definition: tls_async.c:338
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 const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
std::pair< handle_t, handle_t > handle_pair_t
Definition: pipe.hpp:34
An interface type.
Definition: interface.hpp:67
static const rc_t INVALID
HW write reported invalid input.
Definition: types.hpp:114
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
static const admin_state_t UP
Admin UP state.
Definition: interface.hpp:147
A representation of a method call to VPP.
Definition: cmd.hpp:32
std::shared_ptr< pipe > singular() const
Return the matching &#39;singular instance&#39; of the sub-interface.
Definition: pipe.cpp:87
u32 instance
Definition: gre.api:48
std::shared_ptr< interface > west()
The interface that is the west end of the pipe.
Definition: pipe.cpp:105
static const std::string pipe_mk_name(uint32_t instance)
Definition: pipe.cpp:32
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
void set_ends(const handle_pair_t &p)
Definition: pipe.cpp:151
static std::shared_ptr< pipe > find(const key_t &k)
Find a subinterface from its key.
Definition: pipe.cpp:99
const key_t & key() const
Return the interface type.
Definition: interface.cpp:277
std::string key_t
The key for interface&#39;s key.
Definition: interface.hpp:56
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127