blob: 0a546d3c1b06348ddd7c1b821d8cff1ee422c6bd [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
16#include "vom/arp_proxy_config.hpp"
17
18#include <vapi/vpe.api.vapi.hpp>
19
20namespace VOM {
21arp_proxy_config::config_cmd::config_cmd(
22 HW::item<bool>& item,
23 const boost::asio::ip::address_v4& low,
24 const boost::asio::ip::address_v4& high)
25 : rpc_cmd(item)
26 , m_low(low)
27 , m_high(high)
28{
29}
30
31bool
32arp_proxy_config::config_cmd::operator==(const config_cmd& o) const
33{
34 return ((m_low == o.m_low) && (m_high == o.m_high));
35}
36
37rc_t
38arp_proxy_config::config_cmd::issue(connection& con)
39{
40 msg_t req(con.ctx(), std::ref(*this));
41
42 auto& payload = req.get_request().get_payload();
43 payload.is_add = 1;
44
45 std::copy_n(std::begin(m_low.to_bytes()), m_low.to_bytes().size(),
46 payload.low_address);
47 std::copy_n(std::begin(m_high.to_bytes()), m_high.to_bytes().size(),
48 payload.hi_address);
49
50 VAPI_CALL(req.execute());
51
52 m_hw_item.set(wait());
53
54 return (rc_t::OK);
55}
56
57std::string
58arp_proxy_config::config_cmd::to_string() const
59{
60 std::ostringstream s;
61 s << "ARP-proxy-config: " << m_hw_item.to_string()
62 << " low:" << m_low.to_string() << " high:" << m_high.to_string();
63
64 return (s.str());
65}
66
67arp_proxy_config::unconfig_cmd::unconfig_cmd(
68 HW::item<bool>& item,
69 const boost::asio::ip::address_v4& low,
70 const boost::asio::ip::address_v4& high)
71 : rpc_cmd(item)
72 , m_low(low)
73 , m_high(high)
74{
75}
76
77bool
78arp_proxy_config::unconfig_cmd::operator==(const unconfig_cmd& o) const
79{
80 return ((m_low == o.m_low) && (m_high == o.m_high));
81}
82
83rc_t
84arp_proxy_config::unconfig_cmd::issue(connection& con)
85{
86 msg_t req(con.ctx(), std::ref(*this));
87
88 auto& payload = req.get_request().get_payload();
89 payload.is_add = 0;
90
91 std::copy_n(std::begin(m_low.to_bytes()), m_low.to_bytes().size(),
92 payload.low_address);
93 std::copy_n(std::begin(m_high.to_bytes()), m_high.to_bytes().size(),
94 payload.hi_address);
95
96 VAPI_CALL(req.execute());
97
98 wait();
99 m_hw_item.set(rc_t::NOOP);
100
101 return (rc_t::OK);
102}
103
104std::string
105arp_proxy_config::unconfig_cmd::to_string() const
106{
107 std::ostringstream s;
108 s << "ARP-proxy-unconfig: " << m_hw_item.to_string()
109 << " low:" << m_low.to_string() << " high:" << m_high.to_string();
110
111 return (s.str());
112}
113}
114/*
115 * fd.io coding-style-patch-verification: ON
116 *
117 * Local Variables:
118 * eval: (c-set-style "mozilla")
119 * End:
120 */