FD.io VPP  v18.10-32-g1161dda
Vector Packet Processing
ip_punt_redirect.cpp
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 #include "vom/ip_punt_redirect.hpp"
19 
20 namespace VOM {
21 /**
22  * A DB of all IP Punt configs
23  */
24 singular_db<ip_punt_redirect::key_t, ip_punt_redirect> ip_punt_redirect::m_db;
25 
26 ip_punt_redirect::event_handler ip_punt_redirect::m_evh;
27 
29  const interface& tx_itf,
31  : m_rx_itf(rx_itf.singular())
32  , m_tx_itf(tx_itf.singular())
33  , m_addr(addr)
34 {
35 }
36 
38  : m_rx_itf(o.m_rx_itf)
39  , m_tx_itf(o.m_tx_itf)
40  , m_addr(o.m_addr)
41  , m_config(o.m_config)
42 {
43 }
44 
46 {
47  sweep();
48 
49  // not in the DB anymore.
50  m_db.release(m_rx_itf->key(), this);
51 }
52 
53 void
54 ip_punt_redirect::sweep()
55 {
56  if (m_config) {
58  m_config, m_rx_itf->handle(), m_tx_itf->handle(), m_addr));
59  }
60  HW::write();
61 }
62 
63 void
64 ip_punt_redirect::dump(std::ostream& os)
65 {
66  db_dump(m_db, os);
67 }
68 
69 void
70 ip_punt_redirect::replay()
71 {
72  if (m_config) {
74  m_config, m_rx_itf->handle(), m_tx_itf->handle(), m_addr));
75  }
76 }
77 
78 std::string
80 {
81  std::ostringstream s;
82  s << "IP-punt-redirect-config:"
83  << " rx-itf:" << m_rx_itf->to_string()
84  << " tx-itf:" << m_tx_itf->to_string() << " next-hop:" << m_addr;
85 
86  return (s.str());
87 }
88 
89 void
90 ip_punt_redirect::update(const ip_punt_redirect& desired)
91 {
92  if (!m_config) {
94  m_config, m_rx_itf->handle(), m_tx_itf->handle(), m_addr));
95  }
96 }
97 
98 std::shared_ptr<ip_punt_redirect>
99 ip_punt_redirect::find_or_add(const ip_punt_redirect& temp)
100 {
101  return (m_db.find_or_add(temp.m_rx_itf->key(), temp));
102 }
103 
104 std::shared_ptr<ip_punt_redirect>
106 {
107  return find_or_add(*this);
108 }
109 
111 {
112  OM::register_listener(this);
113  inspect::register_handler({ "ip-punt-redirect" },
114  "IP punt redirect configurations", this);
115 }
116 
117 void
118 ip_punt_redirect::event_handler::handle_replay()
119 {
120  m_db.replay();
121 }
122 
123 void
124 ip_punt_redirect::event_handler::handle_populate(const client_db::key_t& key)
125 {
126 }
127 
129 ip_punt_redirect::event_handler::order() const
130 {
131  return (dependency_t::BINDING);
132 }
133 
134 void
136 {
137  db_dump(m_db, os);
138 }
139 }
140 
141 /*
142  * fd.io coding-style-patch-verification: ON
143  *
144  * Local Variables:
145  * eval: (c-set-style "mozilla")
146  * End:
147  */
std::string to_string() const
convert to string format for debug purposes
typedef address
Definition: ip_types.api:35
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
A command class that configures the IP punt_redirect.
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:236
vhost_vring_addr_t addr
Definition: vhost_user.h:121
A cmd class that Unconfigs Ip punt redirect.
static void dump(std::ostream &os)
Dump all ip_punt_redirects into the stream provided.
~ip_punt_redirect()
Destructor.
A representation of an interface in VPP.
Definition: interface.hpp:41
void event_handler(void *tls_async)
Definition: tls_async.c:339
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::shared_ptr< ip_punt_redirect > singular() const
Return the &#39;singular instance&#39; of the ip_punt_redirect that matches this object.
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:194
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.
Then L2/objects that bind to interfaces, BD, ACLS, etc.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of IP punt_redirect configuration on an interface.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127