FD.io VPP  v18.04-17-g3a0d853
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"
19 
20 namespace VOM {
21 singular_db<arp_proxy_config::key_t, arp_proxy_config> arp_proxy_config::m_db;
22 
23 arp_proxy_config::event_handler arp_proxy_config::m_evh;
24 
25 arp_proxy_config::arp_proxy_config(const boost::asio::ip::address_v4& low,
26  const boost::asio::ip::address_v4& high)
27  : m_low(low)
28  , m_high(high)
29  , m_config(true)
30 {
31 }
32 
34  : m_low(o.m_low)
35  , m_high(o.m_high)
36  , m_config(o.m_config)
37 {
38 }
39 
41 {
42  sweep();
43 
44  // not in the DB anymore.
45  m_db.release(std::make_pair(m_low, m_high), this);
46 }
47 
48 void
49 arp_proxy_config::sweep()
50 {
51  if (m_config) {
53  new arp_proxy_config_cmds::unconfig_cmd(m_config, m_low, m_high));
54  }
55  HW::write();
56 }
57 
58 void
59 arp_proxy_config::dump(std::ostream& os)
60 {
61  db_dump(m_db, os);
62 }
63 
64 void
65 arp_proxy_config::replay()
66 {
67  if (m_config) {
68  HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
69  }
70 }
71 
72 std::string
74 {
75  std::ostringstream s;
76  s << "ARP-proxy:"
77  << " low:" << m_low.to_string() << " high:" << m_high.to_string();
78 
79  return (s.str());
80 }
81 
82 void
83 arp_proxy_config::update(const arp_proxy_config& desired)
84 {
85  if (!m_config) {
86  HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
87  }
88 }
89 
90 std::shared_ptr<arp_proxy_config>
91 arp_proxy_config::find_or_add(const arp_proxy_config& temp)
92 {
93  return (m_db.find_or_add(std::make_pair(temp.m_low, temp.m_high), temp));
94 }
95 
96 std::shared_ptr<arp_proxy_config>
98 {
99  return find_or_add(*this);
100 }
101 
102 arp_proxy_config::event_handler::event_handler()
103 {
104  OM::register_listener(this);
105  inspect::register_handler({ "arp-proxy-config" }, "ARP Proxy configurations",
106  this);
107 }
108 
109 void
110 arp_proxy_config::event_handler::handle_replay()
111 {
112  m_db.replay();
113 }
114 
115 void
116 arp_proxy_config::event_handler::handle_populate(const client_db::key_t& key)
117 {
118  // VPP provides no dump for ARP proxy.
119 }
120 
122 arp_proxy_config::event_handler::order() const
123 {
124  return (dependency_t::GLOBAL);
125 }
126 
127 void
129 {
130  db_dump(m_db, os);
131 }
132 
133 std::ostream&
134 operator<<(std::ostream& os, const arp_proxy_config::key_t& key)
135 {
136  os << "[" << key.first << ", " << key.second << "]";
137 
138  return (os);
139 }
140 }
141 /*
142  * fd.io coding-style-patch-verification: ON
143  *
144  * Local Variables:
145  * eval: (c-set-style "mozilla")
146  * End:
147  */
static void dump(std::ostream &os)
Dump all LLDP configs into the stream provided.
Global Configuration has no dependency.
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 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:236
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:194
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:127