blob: cf7fad5d90d3ba8723bc804d047d4612cb7609f1 [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
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
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070016#include "vom/arp_proxy_config_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070017
18namespace VOM {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070019namespace arp_proxy_config_cmds {
20
21config_cmd::config_cmd(HW::item<bool>& item,
22 const boost::asio::ip::address_v4& low,
23 const boost::asio::ip::address_v4& high)
Neale Ranns812ed392017-10-16 04:20:13 -070024 : rpc_cmd(item)
25 , m_low(low)
26 , m_high(high)
27{
28}
29
30bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070031config_cmd::operator==(const config_cmd& o) const
Neale Ranns812ed392017-10-16 04:20:13 -070032{
33 return ((m_low == o.m_low) && (m_high == o.m_high));
34}
35
36rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070037config_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070038{
39 msg_t req(con.ctx(), std::ref(*this));
40
41 auto& payload = req.get_request().get_payload();
42 payload.is_add = 1;
43
44 std::copy_n(std::begin(m_low.to_bytes()), m_low.to_bytes().size(),
45 payload.low_address);
46 std::copy_n(std::begin(m_high.to_bytes()), m_high.to_bytes().size(),
47 payload.hi_address);
48
49 VAPI_CALL(req.execute());
50
51 m_hw_item.set(wait());
52
53 return (rc_t::OK);
54}
55
56std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070057config_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -070058{
59 std::ostringstream s;
60 s << "ARP-proxy-config: " << m_hw_item.to_string()
61 << " low:" << m_low.to_string() << " high:" << m_high.to_string();
62
63 return (s.str());
64}
65
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070066unconfig_cmd::unconfig_cmd(HW::item<bool>& item,
67 const boost::asio::ip::address_v4& low,
68 const boost::asio::ip::address_v4& high)
Neale Ranns812ed392017-10-16 04:20:13 -070069 : rpc_cmd(item)
70 , m_low(low)
71 , m_high(high)
72{
73}
74
75bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070076unconfig_cmd::operator==(const unconfig_cmd& o) const
Neale Ranns812ed392017-10-16 04:20:13 -070077{
78 return ((m_low == o.m_low) && (m_high == o.m_high));
79}
80
81rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070082unconfig_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070083{
84 msg_t req(con.ctx(), std::ref(*this));
85
86 auto& payload = req.get_request().get_payload();
87 payload.is_add = 0;
88
89 std::copy_n(std::begin(m_low.to_bytes()), m_low.to_bytes().size(),
90 payload.low_address);
91 std::copy_n(std::begin(m_high.to_bytes()), m_high.to_bytes().size(),
92 payload.hi_address);
93
94 VAPI_CALL(req.execute());
95
96 wait();
97 m_hw_item.set(rc_t::NOOP);
98
99 return (rc_t::OK);
100}
101
102std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700103unconfig_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700104{
105 std::ostringstream s;
106 s << "ARP-proxy-unconfig: " << m_hw_item.to_string()
107 << " low:" << m_low.to_string() << " high:" << m_high.to_string();
108
109 return (s.str());
110}
111}
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700112}
113
Neale Ranns812ed392017-10-16 04:20:13 -0700114/*
115 * fd.io coding-style-patch-verification: ON
116 *
117 * Local Variables:
118 * eval: (c-set-style "mozilla")
119 * End:
120 */