FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
ip_punt_redirect.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_IP_PUNT_REDIRECT_H__
17 #define __VOM_IP_PUNT_REDIRECT_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 IP punt_redirect configuration on an interface
29  */
31 {
32 public:
33  /**
34  * Construct a new object matching the desried state
35  *
36  * @param rx_itf - The interface from where the punt traffic should come.
37  * @param tx_itf - The interface to which traffic should be redirected.
38  * @param addr - The next hop ip address to redirect the traffic.
39  */
40  ip_punt_redirect(const interface& rx_itf,
41  const interface& tx_itf,
43 
44  /**
45  * Construct a new object matching the desried state
46  *
47  * @param tx_itf - The interface to which traffic should be redirected.
48  * @param addr - The next hop ip address to redirect the traffic.
49  */
50  ip_punt_redirect(const interface& tx_itf,
52 
53  /**
54  * Copy Constructor
55  */
57 
58  /**
59  * Destructor
60  */
62 
63  /**
64  * Return the 'singular instance' of the ip_punt_redirect that matches this
65  * object
66  */
67  std::shared_ptr<ip_punt_redirect> singular() const;
68 
69  /**
70  * convert to string format for debug purposes
71  */
72  std::string to_string() const;
73 
74  /**
75  * Dump all ip_punt_redirects into the stream provided
76  */
77  static void dump(std::ostream& os);
78 
79  /**
80  * The key type for ip_punt_redirects
81  */
83 
84  /**
85  * return the object's key
86  */
87  const key_t key() const;
88 
89  /**
90  * Find an singular instance in the DB for the interface passed
91  */
92  static std::shared_ptr<ip_punt_redirect> find(const interface& i);
93 
94 private:
95  /**
96  * Class definition for listeners to OM events
97  */
99  {
100  public:
101  event_handler();
102  virtual ~event_handler() = default;
103 
104  /**
105  * Handle a populate event
106  */
107  void handle_populate(const client_db::key_t& key);
108 
109  /**
110  * Handle a replay event
111  */
112  void handle_replay();
113 
114  /**
115  * Show the object in the Singular DB
116  */
117  void show(std::ostream& os);
118 
119  /**
120  * Get the sortable Id of the listener
121  */
122  dependency_t order() const;
123  };
124 
125  /**
126  * event_handler to register with OM
127  */
128  static event_handler m_evh;
129 
130  /**
131  * Enquue commonds to the VPP command Q for the update
132  */
133  void update(const ip_punt_redirect& obj);
134 
135  /**
136  * Find or add the singular instance in the DB
137  */
138  static std::shared_ptr<ip_punt_redirect> find_or_add(
139  const ip_punt_redirect& temp);
140 
141  /*
142  * It's the VPPHW class that updates the objects in HW
143  */
144  friend class OM;
145 
146  /**
147  * It's the singular_db class that calls replay
148  */
150 
151  /**
152  * Sweep/reap the object if still stale
153  */
154  void sweep(void);
155 
156  /**
157  * replay the object to create it in hardware
158  */
159  void replay(void);
160 
161  /**
162  * A reference counting pointer the interface that requires an address.
163  */
164  const std::shared_ptr<interface> m_rx_itf;
165  /**
166  * A reference counting pointer the interface that has an address.
167  */
168  const std::shared_ptr<interface> m_tx_itf;
169 
170  /**
171  * host Ip Prefix to redirect traffic to
172  */
173  const boost::asio::ip::address m_addr;
174 
175  /**
176  * HW configuration for the binding. The bool representing the
177  * do/don't bind.
178  */
179  HW::item<bool> m_config;
180 
181  /**
182  * A map of all ip punt redirect keyed against a combination of the interface.
183  */
185 };
186 };
187 
188 /*
189  * fd.io coding-style-patch-verification: OFF
190  *
191  * Local Variables:
192  * eval: (c-set-style "mozilla")
193  * End:
194  */
195 
196 #endif
VOM::HW::item< bool >
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::inspect::command_handler
inspect command handler Handler
Definition: inspect.hpp:54
VOM::ip_punt_redirect
A representation of IP punt_redirect configuration on an interface.
Definition: ip_punt_redirect.hpp:30
VOM::ip_punt_redirect::key_t
interface::key_t key_t
The key type for ip_punt_redirects.
Definition: ip_punt_redirect.hpp:82
VOM::OM::listener
Class definition for listeners to OM events.
Definition: om.hpp:284
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
VOM::ip_punt_redirect::find
static std::shared_ptr< ip_punt_redirect > find(const interface &i)
Find an singular instance in the DB for the interface passed.
VOM::ip_punt_redirect::key
const key_t key() const
return the object's key
Definition: ip_punt_redirect.cpp:63
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
hw.hpp
VOM::ip_punt_redirect::ip_punt_redirect
ip_punt_redirect(const interface &rx_itf, const interface &tx_itf, const boost::asio::ip::address &addr)
Construct a new object matching the desried state.
Definition: ip_punt_redirect.cpp:29
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
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
address
manual_print typedef address
Definition: ip_types.api:96
VOM::ip_punt_redirect::singular
std::shared_ptr< ip_punt_redirect > singular() const
Return the 'singular instance' of the ip_punt_redirect that matches this object.
Definition: ip_punt_redirect.cpp:126
inspect.hpp
singular_db.hpp
interface.hpp
VOM::ip_punt_redirect::~ip_punt_redirect
~ip_punt_redirect()
Destructor.
Definition: ip_punt_redirect.cpp:54
VOM::singular_db
A Database to store the unique 'singular' instances of a single object type.
Definition: singular_db.hpp:33
VOM::ip_punt_redirect::dump
static void dump(std::ostream &os)
Dump all ip_punt_redirects into the stream provided.
Definition: ip_punt_redirect.cpp:83
VOM::interface::key_t
std::string key_t
The key for interface's key.
Definition: interface.hpp:56
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::ip_punt_redirect::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: ip_punt_redirect.cpp:99
string
const char *const string
Definition: cJSON.h:172