FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
arp_proxy_config.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/arp_proxy_config.hpp"
17 #include "vom/api_types.hpp"
19 #include "vom/prefix.hpp"
21 
22 namespace VOM {
23 singular_db<arp_proxy_config::key_t, arp_proxy_config> arp_proxy_config::m_db;
24 
25 arp_proxy_config::event_handler arp_proxy_config::m_evh;
26 
27 arp_proxy_config::arp_proxy_config(const boost::asio::ip::address_v4& low,
28  const boost::asio::ip::address_v4& high)
29  : m_low(low)
30  , m_high(high)
31  , m_config(true)
32 {
33 }
34 
36  : m_low(o.m_low)
37  , m_high(o.m_high)
38  , m_config(o.m_config)
39 {
40 }
41 
43 {
44  sweep();
45 
46  // not in the DB anymore.
47  m_db.release(std::make_pair(m_low, m_high), this);
48 }
49 
50 void
51 arp_proxy_config::sweep()
52 {
53  if (m_config) {
55  new arp_proxy_config_cmds::unconfig_cmd(m_config, m_low, m_high));
56  }
57  HW::write();
58 }
59 
60 void
61 arp_proxy_config::dump(std::ostream& os)
62 {
63  db_dump(m_db, os);
64 }
65 
66 void
67 arp_proxy_config::replay()
68 {
69  if (m_config) {
70  HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
71  }
72 }
73 
76 {
77  std::ostringstream s;
78  s << "ARP-proxy:"
79  << " low:" << m_low.to_string() << " high:" << m_high.to_string();
80 
81  return (s.str());
82 }
83 
84 void
85 arp_proxy_config::update(const arp_proxy_config& desired)
86 {
87  if (!m_config) {
88  HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
89  }
90 }
91 
92 std::shared_ptr<arp_proxy_config>
93 arp_proxy_config::find_or_add(const arp_proxy_config& temp)
94 {
95  return (m_db.find_or_add(std::make_pair(temp.m_low, temp.m_high), temp));
96 }
97 
98 std::shared_ptr<arp_proxy_config>
100 {
101  return find_or_add(*this);
102 }
103 
105 {
106  OM::register_listener(this);
107  inspect::register_handler({ "arp-proxy-config" }, "ARP Proxy configurations",
108  this);
109 }
110 
111 void
112 arp_proxy_config::event_handler::handle_replay()
113 {
114  m_db.replay();
115 }
116 
117 void
118 arp_proxy_config::event_handler::handle_populate(const client_db::key_t& key)
119 {
120  std::shared_ptr<arp_proxy_config_cmds::dump_cmd> cmd =
121  std::make_shared<arp_proxy_config_cmds::dump_cmd>();
122 
123  HW::enqueue(cmd);
124  HW::write();
125 
126  for (auto& record : *cmd) {
127  auto& payload = record.get_payload();
128 
129  boost::asio::ip::address lo = from_api(payload.proxy.low);
130  boost::asio::ip::address hi = from_api(payload.proxy.hi);
131 
132  arp_proxy_config ap(lo.to_v4(), hi.to_v4());
133  OM::commit(key, ap);
134  }
135 }
136 
138 arp_proxy_config::event_handler::order() const
139 {
140  return (dependency_t::GLOBAL);
141 }
142 
143 void
145 {
146  db_dump(m_db, os);
147 }
148 
149 std::ostream&
150 operator<<(std::ostream& os, const arp_proxy_config::key_t& key)
151 {
152  os << "[" << key.first << ", " << key.second << "]";
153 
154  return (os);
155 }
156 }
157 /*
158  * fd.io coding-style-patch-verification: OFF
159  *
160  * Local Variables:
161  * eval: (c-set-style "mozilla")
162  * End:
163  */
VOM::arp_proxy_config::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: arp_proxy_config.cpp:75
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
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_config::singular
std::shared_ptr< arp_proxy_config > singular() const
Return the 'singular' of the LLDP config that matches this object.
Definition: arp_proxy_config.cpp:99
VOM::arp_proxy_config::arp_proxy_config
arp_proxy_config(const boost::asio::ip::address_v4 &low, const boost::asio::ip::address_v4 &high)
Construct a new object matching the desried state.
Definition: arp_proxy_config.cpp:27
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
key
typedef key
Definition: ipsec_types.api:88
VOM::arp_proxy_config::dump
static void dump(std::ostream &os)
Dump all LLDP configs into the stream provided.
Definition: arp_proxy_config.cpp:61
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::OM::register_listener
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
VOM::arp_proxy_config
A representation of LLDP client configuration on an interface.
Definition: arp_proxy_config.hpp: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
low
vl_api_ip4_address_t low
Definition: arp.api:36
VOM::HW::enqueue
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
address
manual_print typedef address
Definition: ip_types.api:96
VOM::arp_proxy_config::key_t
std::pair< boost::asio::ip::address_v4, boost::asio::ip::address_v4 > key_t
Key type.
Definition: arp_proxy_config.hpp:36
VOM::operator<<
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Definition: acl_binding.cpp:201
VOM::arp_proxy_config_cmds::config_cmd
A command class that adds the ARP Proxy config.
Definition: arp_proxy_config_cmds.hpp:30
singular_db_funcs.hpp
true
#define true
Definition: cJSON.c:65
arp_proxy_config.hpp
VOM::arp_proxy_config::~arp_proxy_config
~arp_proxy_config()
Destructor.
Definition: arp_proxy_config.cpp:42
prefix.hpp
VOM::arp_proxy_config_cmds::unconfig_cmd
A cmd class that Unconfigs ArpProxy Config from an interface.
Definition: arp_proxy_config_cmds.hpp:65
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
arp_proxy_config_cmds.hpp
VOM::from_api
const neighbour::flags_t from_api(vapi_enum_ip_neighbor_flags f)
Definition: api_types.cpp:36
api_types.hpp
VOM::dependency_t::GLOBAL
@ GLOBAL
Global Configuration has no dependency.
lo
lo
Definition: vector_altivec.h:95
string
const char *const string
Definition: cJSON.h:172