FD.io VPP  v18.07.1-19-g511ce25
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 #include "vom/prefix.hpp"
20 
21 namespace VOM {
22 singular_db<arp_proxy_config::key_t, arp_proxy_config> arp_proxy_config::m_db;
23 
24 arp_proxy_config::event_handler arp_proxy_config::m_evh;
25 
26 arp_proxy_config::arp_proxy_config(const boost::asio::ip::address_v4& low,
27  const boost::asio::ip::address_v4& high)
28  : m_low(low)
29  , m_high(high)
30  , m_config(true)
31 {
32 }
33 
35  : m_low(o.m_low)
36  , m_high(o.m_high)
37  , m_config(o.m_config)
38 {
39 }
40 
42 {
43  sweep();
44 
45  // not in the DB anymore.
46  m_db.release(std::make_pair(m_low, m_high), this);
47 }
48 
49 void
50 arp_proxy_config::sweep()
51 {
52  if (m_config) {
54  new arp_proxy_config_cmds::unconfig_cmd(m_config, m_low, m_high));
55  }
56  HW::write();
57 }
58 
59 void
60 arp_proxy_config::dump(std::ostream& os)
61 {
62  db_dump(m_db, os);
63 }
64 
65 void
66 arp_proxy_config::replay()
67 {
68  if (m_config) {
69  HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
70  }
71 }
72 
73 std::string
75 {
76  std::ostringstream s;
77  s << "ARP-proxy:"
78  << " low:" << m_low.to_string() << " high:" << m_high.to_string();
79 
80  return (s.str());
81 }
82 
83 void
84 arp_proxy_config::update(const arp_proxy_config& desired)
85 {
86  if (!m_config) {
87  HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
88  }
89 }
90 
91 std::shared_ptr<arp_proxy_config>
92 arp_proxy_config::find_or_add(const arp_proxy_config& temp)
93 {
94  return (m_db.find_or_add(std::make_pair(temp.m_low, temp.m_high), temp));
95 }
96 
97 std::shared_ptr<arp_proxy_config>
99 {
100  return find_or_add(*this);
101 }
102 
104 {
105  OM::register_listener(this);
106  inspect::register_handler({ "arp-proxy-config" }, "ARP Proxy configurations",
107  this);
108 }
109 
110 void
111 arp_proxy_config::event_handler::handle_replay()
112 {
113  m_db.replay();
114 }
115 
116 void
117 arp_proxy_config::event_handler::handle_populate(const client_db::key_t& key)
118 {
119  std::shared_ptr<arp_proxy_config_cmds::dump_cmd> cmd =
120  std::make_shared<arp_proxy_config_cmds::dump_cmd>();
121 
122  HW::enqueue(cmd);
123  HW::write();
124 
125  for (auto& record : *cmd) {
126  auto& payload = record.get_payload();
127 
128  boost::asio::ip::address lo = from_bytes(0, payload.proxy.low_address);
129  boost::asio::ip::address hi = from_bytes(0, payload.proxy.hi_address);
130 
131  arp_proxy_config ap(lo.to_v4(), hi.to_v4());
132  OM::commit(key, ap);
133  }
134 }
135 
137 arp_proxy_config::event_handler::order() const
138 {
139  return (dependency_t::GLOBAL);
140 }
141 
142 void
144 {
145  db_dump(m_db, os);
146 }
147 
148 std::ostream&
149 operator<<(std::ostream& os, const arp_proxy_config::key_t& key)
150 {
151  os << "[" << key.first << ", " << key.second << "]";
152 
153  return (os);
154 }
155 }
156 /*
157  * fd.io coding-style-patch-verification: ON
158  *
159  * Local Variables:
160  * eval: (c-set-style "mozilla")
161  * End:
162  */
vmrglw vmrglh hi
typedef address
Definition: ip_types.api:35
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.
lo
~arp_proxy_config()
Destructor.
boost::asio::ip::address from_bytes(uint8_t is_ip6, uint8_t *bytes)
Convert a VPP byte stinrg into a boost addresss.
Definition: prefix.cpp:193
std::string to_string() const
convert to string format for debug purposes
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
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
A representation of a method call to VPP.
Definition: cmd.hpp:32
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