FD.io VPP  v18.07.1-13-g909ba93
Vector Packet Processing
ip_unnumbered.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/ip_unnumbered.hpp"
19 
20 namespace VOM {
21 /**
22  * A DB of all LLDP configs
23  */
24 singular_db<ip_unnumbered::key_t, ip_unnumbered> ip_unnumbered::m_db;
25 
26 ip_unnumbered::event_handler ip_unnumbered::m_evh;
27 
29  : m_itf(itf.singular())
30  , m_l3_itf(l3_itf.singular())
31 {
32 }
33 
35  : m_itf(o.m_itf)
36  , m_l3_itf(o.m_l3_itf)
37  , m_config(o.m_config)
38 {
39 }
40 
42 {
43  sweep();
44 
45  // not in the DB anymore.
46  m_db.release(m_itf->key(), this);
47 }
48 
49 void
50 ip_unnumbered::sweep()
51 {
52  if (m_config) {
53  HW::enqueue(new ip_unnumbered_cmds::unconfig_cmd(m_config, m_itf->handle(),
54  m_l3_itf->handle()));
55  }
56  HW::write();
57 }
58 
59 void
60 ip_unnumbered::dump(std::ostream& os)
61 {
62  db_dump(m_db, os);
63 }
64 
65 void
66 ip_unnumbered::replay()
67 {
68  if (m_config) {
69  HW::enqueue(new ip_unnumbered_cmds::config_cmd(m_config, m_itf->handle(),
70  m_l3_itf->handle()));
71  }
72 }
73 
74 std::string
76 {
77  std::ostringstream s;
78  s << "IP Unnumbered-config:"
79  << " itf:" << m_itf->to_string() << " l3-itf:" << m_l3_itf->to_string();
80 
81  return (s.str());
82 }
83 
84 void
85 ip_unnumbered::update(const ip_unnumbered& desired)
86 {
87  if (!m_config) {
88  HW::enqueue(new ip_unnumbered_cmds::config_cmd(m_config, m_itf->handle(),
89  m_l3_itf->handle()));
90  }
91 }
92 
93 std::shared_ptr<ip_unnumbered>
94 ip_unnumbered::find_or_add(const ip_unnumbered& temp)
95 {
96  return (m_db.find_or_add(temp.m_itf->key(), temp));
97 }
98 
99 std::shared_ptr<ip_unnumbered>
101 {
102  return find_or_add(*this);
103 }
104 
106 {
107  OM::register_listener(this);
108  inspect::register_handler({ "ip-un" }, "IP unnumbered configurations", this);
109 }
110 
111 void
112 ip_unnumbered::event_handler::handle_replay()
113 {
114  m_db.replay();
115 }
116 
117 void
118 ip_unnumbered::event_handler::handle_populate(const client_db::key_t& key)
119 {
120  std::shared_ptr<ip_unnumbered_cmds::dump_cmd> cmd =
121  std::make_shared<ip_unnumbered_cmds::dump_cmd>();
122 
123  HW::enqueue(cmd);
124  HW::write();
125 
126  for (auto& ip_record : *cmd) {
127  auto& payload = ip_record.get_payload();
128 
129  VOM_LOG(log_level_t::DEBUG) << "ip-unnumbered dump: "
130  << " itf: " << payload.sw_if_index
131  << " ip: " << payload.ip_sw_if_index;
132 
133  std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
134  std::shared_ptr<interface> ip_itf = interface::find(payload.ip_sw_if_index);
135 
136  if (itf && ip_itf) {
137  ip_unnumbered ipun(*itf, *ip_itf);
138  OM::commit(key, ipun);
139  }
140  }
141 }
142 
144 ip_unnumbered::event_handler::order() const
145 {
146  return (dependency_t::BINDING);
147 }
148 
149 void
150 ip_unnumbered::event_handler::show(std::ostream& os)
151 {
152  db_dump(m_db, os);
153 }
154 }
155 
156 /*
157  * fd.io coding-style-patch-verification: ON
158  *
159  * Local Variables:
160  * eval: (c-set-style "mozilla")
161  * End:
162  */
A command class that configures the IP unnumbered.
std::string to_string() const
convert to string format for debug purposes
#define VOM_LOG(lvl)
Definition: logger.hpp:181
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
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:461
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
static const log_level_t DEBUG
Definition: logger.hpp:32
A cmd class that Unconfigs L3 Config from an interface.
std::shared_ptr< ip_unnumbered > singular() const
Return the &#39;singular instance&#39; of the L3-Config that matches this object.
~ip_unnumbered()
Destructor.
A representation of IP unnumbered configuration on an interface.
A representation of an interface in VPP.
Definition: interface.hpp:41
static void dump(std::ostream &os)
Dump all ip_unnumbereds into the stream provided.
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:311
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:194
ip_unnumbered(const interface &itf, const interface &l3_itf)
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 a method call to VPP.
Definition: cmd.hpp:32
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