FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
arp_proxy_binding.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 
19 
20 namespace VOM {
21 
22 /**
23  * A DB of all ARP proxy bindings configs
24  */
25 singular_db<interface::key_t, arp_proxy_binding> arp_proxy_binding::m_db;
26 
27 arp_proxy_binding::event_handler arp_proxy_binding::m_evh;
28 
30  : m_itf(itf.singular())
31  , m_binding(true)
32 {
33 }
34 
36  : m_itf(o.m_itf)
37  , m_binding(o.m_binding)
38 {
39 }
40 
42 {
43  sweep();
44  m_db.release(m_itf->key(), this);
45 }
46 
47 void
48 arp_proxy_binding::sweep()
49 {
50  if (m_binding) {
52  new arp_proxy_binding_cmds::unbind_cmd(m_binding, m_itf->handle()));
53  }
54  HW::write();
55 }
56 
57 void
58 arp_proxy_binding::dump(std::ostream& os)
59 {
60  db_dump(m_db, os);
61 }
62 
63 void
64 arp_proxy_binding::replay()
65 {
66  if (m_binding) {
68  new arp_proxy_binding_cmds::bind_cmd(m_binding, m_itf->handle()));
69  }
70 }
71 
74 {
75  std::ostringstream s;
76  s << "ArpProxy-binding: " << m_itf->to_string();
77 
78  return (s.str());
79 }
80 
81 void
82 arp_proxy_binding::update(const arp_proxy_binding& desired)
83 {
84  /*
85  * the desired state is always that the interface should be created
86  */
87  if (!m_binding) {
89  new arp_proxy_binding_cmds::bind_cmd(m_binding, m_itf->handle()));
90  }
91 }
92 
93 std::shared_ptr<arp_proxy_binding>
94 arp_proxy_binding::find_or_add(const arp_proxy_binding& temp)
95 {
96  return (m_db.find_or_add(temp.m_itf->key(), temp));
97 }
98 
99 std::shared_ptr<arp_proxy_binding>
101 {
102  return find_or_add(*this);
103 }
104 
106 {
107  OM::register_listener(this);
108  inspect::register_handler({ "arp-proxy-binding" }, "ARP proxy bindings",
109  this);
110 }
111 
112 void
113 arp_proxy_binding::event_handler::handle_replay()
114 {
115  m_db.replay();
116 }
117 
118 void
119 arp_proxy_binding::event_handler::handle_populate(const client_db::key_t& key)
120 {
121  std::shared_ptr<arp_proxy_binding_cmds::dump_cmd> cmd =
122  std::make_shared<arp_proxy_binding_cmds::dump_cmd>();
123 
124  HW::enqueue(cmd);
125  HW::write();
126 
127  for (auto& record : *cmd) {
128  auto& payload = record.get_payload();
129 
130  std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
131 
132  if (itf) {
133  arp_proxy_binding ab(*itf);
134  OM::commit(key, ab);
135  } else {
136  VOM_LOG(log_level_t::ERROR) << "arp-proxy-binding dump:"
137  << " itf:" << payload.sw_if_index;
138  }
139  }
140 }
141 
143 arp_proxy_binding::event_handler::order() const
144 {
145  return (dependency_t::BINDING);
146 }
147 
148 void
150 {
151  db_dump(m_db, os);
152 }
153 }
154 /*
155  * fd.io coding-style-patch-verification: OFF
156  *
157  * Local Variables:
158  * eval: (c-set-style "mozilla")
159  * End:
160  */
VOM::arp_proxy_binding
A representation of LLDP client configuration on an interface.
Definition: arp_proxy_binding.hpp:31
VOM::HW::write
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
VOM::OM::commit
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
VOM::arp_proxy_binding_cmds::bind_cmd
A command class that binds the LLDP config to the interface.
Definition: arp_proxy_binding_cmds.hpp:29
arp_proxy_binding_cmds.hpp
VOM_LOG
#define VOM_LOG(lvl)
Definition: logger.hpp:181
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::inspect::register_handler
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
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
VOM::arp_proxy_binding::dump
static void dump(std::ostream &os)
Dump all LLDP bindings into the stream provided.
Definition: arp_proxy_binding.cpp:58
key
typedef key
Definition: ipsec_types.api:91
arp_proxy_binding.hpp
VOM::db_dump
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
Definition: singular_db_funcs.hpp:35
VOM::arp_proxy_binding::singular
std::shared_ptr< arp_proxy_binding > singular() const
Return the 'singular' of the LLDP binding that matches this object.
Definition: arp_proxy_binding.cpp:100
VOM::OM::register_listener
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
VOM::arp_proxy_binding::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: arp_proxy_binding.cpp:73
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
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
VOM::HW::enqueue
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
singular_db_funcs.hpp
true
#define true
Definition: cJSON.c:65
VOM::arp_proxy_binding_cmds::unbind_cmd
A cmd class that Unbinds ArpProxy Config from an interface.
Definition: arp_proxy_binding_cmds.hpp:62
VOM::dependency_t::BINDING
@ BINDING
Then L2/objects that bind to interfaces, BD, ACLS, etc.
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::arp_proxy_binding::~arp_proxy_binding
~arp_proxy_binding()
Destructor.
Definition: arp_proxy_binding.cpp:41
VOM::arp_proxy_binding::arp_proxy_binding
arp_proxy_binding(const interface &itf)
Construct a new object matching the desried state.
Definition: arp_proxy_binding.cpp:29
VOM::log_level_t::ERROR
const static log_level_t ERROR
Definition: logger.hpp:29
VOM::interface::find
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:538
string
const char *const string
Definition: cJSON.h:172