FD.io VPP  v18.01-8-g0eacf49
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"
18 
19 namespace VOM {
20 singular_db<arp_proxy_config::key_t, arp_proxy_config> arp_proxy_config::m_db;
21 
22 arp_proxy_config::event_handler arp_proxy_config::m_evh;
23 
24 arp_proxy_config::arp_proxy_config(const boost::asio::ip::address_v4& low,
25  const boost::asio::ip::address_v4& high)
26  : m_low(low)
27  , m_high(high)
28  , m_config(true)
29 {
30 }
31 
33  : m_low(o.m_low)
34  , m_high(o.m_high)
35  , m_config(o.m_config)
36 {
37 }
38 
40 {
41  sweep();
42 
43  // not in the DB anymore.
44  m_db.release(std::make_pair(m_low, m_high), this);
45 }
46 
47 void
48 arp_proxy_config::sweep()
49 {
50  if (m_config) {
52  new arp_proxy_config_cmds::unconfig_cmd(m_config, m_low, m_high));
53  }
54  HW::write();
55 }
56 
57 void
58 arp_proxy_config::dump(std::ostream& os)
59 {
60  m_db.dump(os);
61 }
62 
63 void
64 arp_proxy_config::replay()
65 {
66  if (m_config) {
67  HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
68  }
69 }
70 
71 std::string
73 {
74  std::ostringstream s;
75  s << "ARP-proxy:"
76  << " low:" << m_low.to_string() << " high:" << m_high.to_string();
77 
78  return (s.str());
79 }
80 
81 void
82 arp_proxy_config::update(const arp_proxy_config& desired)
83 {
84  if (!m_config) {
85  HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
86  }
87 }
88 
89 std::shared_ptr<arp_proxy_config>
90 arp_proxy_config::find_or_add(const arp_proxy_config& temp)
91 {
92  return (m_db.find_or_add(std::make_pair(temp.m_low, temp.m_high), temp));
93 }
94 
95 std::shared_ptr<arp_proxy_config>
97 {
98  return find_or_add(*this);
99 }
100 
101 arp_proxy_config::event_handler::event_handler()
102 {
103  OM::register_listener(this);
104  inspect::register_handler({ "arp-proxy" }, "ARP Proxy configurations", this);
105 }
106 
107 void
108 arp_proxy_config::event_handler::handle_replay()
109 {
110  m_db.replay();
111 }
112 
113 void
114 arp_proxy_config::event_handler::handle_populate(const client_db::key_t& key)
115 {
116  // VPP provides no dump for ARP proxy.
117 }
118 
120 arp_proxy_config::event_handler::order() const
121 {
122  return (dependency_t::GLOBAL);
123 }
124 
125 void
127 {
128  m_db.dump(os);
129 }
130 
131 std::ostream&
132 operator<<(std::ostream& os, const arp_proxy_config::key_t& key)
133 {
134  os << "[" << key.first << ", " << key.second << "]";
135 
136  return (os);
137 }
138 }
139 /*
140  * fd.io coding-style-patch-verification: ON
141  *
142  * Local Variables:
143  * eval: (c-set-style "mozilla")
144  * End:
145  */
static void dump(std::ostream &os)
Dump all LLDP configs into the stream provided.
Global Configuration has no dependency.
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 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
std::shared_ptr< arp_proxy_config > singular() const
Return the &#39;singular&#39; of the LLDP config that matches this object.
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:225
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.
~arp_proxy_config()
Destructor.
std::string to_string() const
convert to string format for debug purposes
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:189
A representation of LLDP client configuration on an interface.
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
A cmd class that Unconfigs ArpProxy Config from an interface.
A command class that adds the ARP Proxy config.
std::pair< boost::asio::ip::address_v4, boost::asio::ip::address_v4 > key_t
Key type.
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:124