FD.io VPP  v19.08-23-g4b943d6
Vector Packet Processing
pipe.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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_PIPE_H__
17 #define __VOM_PIPE_H__
18 
19 #include "vom/interface.hpp"
20 
21 namespace VOM {
22 /**
23  * A Pipe interface.
24  * A pipe is composed for 3 'interfaces'.
25  * 1) the 'parent' interface - this is used as the 'key' for the pipe
26  * 2) the two 'ends' of the pipe - these are used to RX/TX packets
27  * form/to. The ends are retreivable using the east()/west() functions.
28  * The east and west end are exactly equivalent, they are merely
29  * named differently for logical purposes.
30  */
31 class pipe : public interface
32 {
33 public:
34  typedef std::pair<handle_t, handle_t> handle_pair_t;
35 
36  /**
37  * Construct a new object matching the desried state
38  */
39  pipe(uint32_t instance, admin_state_t state);
40 
41  /**
42  * Destructor
43  */
44  ~pipe();
45 
46  /**
47  * Copy Constructor
48  */
49  pipe(const pipe& o);
50 
51  /**
52  * comparison operator - for UT
53  */
54  bool operator==(const pipe& s) const;
55 
56  /**
57  * Return the matching 'singular instance' of the sub-interface
58  */
59  std::shared_ptr<pipe> singular() const;
60 
61  /**
62  * Find a subinterface from its key
63  */
64  static std::shared_ptr<pipe> find(const key_t& k);
65 
66  /**
67  * The interface that is the east end of the pipe
68  */
69  std::shared_ptr<interface> east();
70 
71  /**
72  * The interface that is the west end of the pipe.
73  * The east and west end are exactly equivalent, they are merely
74  * named differently for logical purposes.
75  */
76  std::shared_ptr<interface> west();
77 
78  virtual std::string to_string(void) const;
79 
80  void set_ends(const handle_pair_t& p);
81 
82 private:
83  /**
84  * The interface type that forms the ends of the pipe
85  */
86  class pipe_end : public interface
87  {
88  public:
89  pipe_end(const pipe& p, uint8_t id);
90 
91  private:
92  virtual std::queue<cmd*>& mk_create_cmd(std::queue<cmd*>& cmds);
93  virtual std::queue<cmd*>& mk_delete_cmd(std::queue<cmd*>& cmds);
94 
95  std::shared_ptr<pipe> m_pipe;
96  };
97 
98  /**
99 *Class definition for listeners to OM events
100 */
102  {
103  public:
104  event_handler();
105  virtual ~event_handler() = default;
106 
107  /**
108  * Handle a populate event
109  */
110  void handle_populate(const client_db::key_t& key);
111 
112  /**
113  * Handle a replay event
114  */
115  void handle_replay();
116 
117  /**
118  * Show the object in the Singular DB
119  */
120  void show(std::ostream& os);
121 
122  /**
123  * Get the sortable Id of the listener
124  */
125  dependency_t order() const;
126  };
127  static event_handler m_evh;
128 
129  /**
130  * Return the matching 'instance' of the pipe
131  * over-ride from the base class
132  */
133  std::shared_ptr<interface> singular_i() const;
134 
135  /**
136  * Virtual functions to construct an interface create commands.
137  */
138  virtual std::queue<cmd*>& mk_create_cmd(std::queue<cmd*>& cmds);
139 
140  /**
141  * Virtual functions to construct an interface delete commands.
142  */
143  virtual std::queue<cmd*>& mk_delete_cmd(std::queue<cmd*>& cmds);
144 
145  /**
146  * the handles that are set during the create command
147  */
148  HW::item<handle_pair_t> m_hdl_pair;
149 
150  /**
151  * The ends of the pipe
152  */
153  std::shared_ptr<interface> m_ends[2];
154 
155  /**
156  * Instance number
157  */
158  uint32_t m_instance;
159 };
160 
161 }; // namespace VOM
162 
163 /*
164  * fd.io coding-style-patch-verification: ON
165  *
166  * Local Variables:
167  * eval: (c-set-style "mozilla")
168  * End:
169  */
170 
171 #endif
A Pipe interface.
Definition: pipe.hpp:31
bool operator==(const pipe &s) const
comparison operator - for UT
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 std::string to_string(void) const
convert to string format for debug purposes
Definition: pipe.cpp:59
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
std::shared_ptr< pipe > singular() const
Return the matching &#39;singular instance&#39; of the sub-interface.
Definition: pipe.cpp:87
~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
Class definition for listeners to OM events.
Definition: om.hpp:284
inspect command handler Handler
Definition: inspect.hpp:54
void event_handler(void *tls_async)
Definition: tls_async.c:340
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
std::pair< handle_t, handle_t > handle_pair_t
Definition: pipe.hpp:34
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
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
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
std::string key_t
The key for interface&#39;s key.
Definition: interface.hpp:56
const key_t & key() const
Return the interface type.
Definition: interface.cpp:277