fib: fib api updates
[vpp.git] / extras / vom / vom / neighbour_cmds.cpp
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/neighbour_cmds.hpp"
17 #include "vom/api_types.hpp"
18
19 namespace VOM {
20 namespace neighbour_cmds {
21 create_cmd::create_cmd(HW::item<handle_t>& item,
22                        handle_t itf,
23                        const mac_address_t& mac,
24                        const boost::asio::ip::address& ip_addr,
25                        const neighbour::flags_t& flags)
26   : srpc_cmd(item)
27   , m_itf(itf)
28   , m_mac(mac)
29   , m_ip_addr(ip_addr)
30   , m_flags(flags)
31 {
32 }
33
34 bool
35 create_cmd::operator==(const create_cmd& other) const
36 {
37   return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
38           (m_itf == other.m_itf) && (m_flags == other.m_flags));
39 }
40
41 rc_t
42 create_cmd::issue(connection& con)
43 {
44   msg_t req(con.ctx(), std::ref(*this));
45
46   auto& payload = req.get_request().get_payload();
47   payload.is_add = 1;
48   payload.neighbor.sw_if_index = m_itf.value();
49
50   to_api(m_mac, payload.neighbor.mac_address);
51   to_api(m_ip_addr, payload.neighbor.ip_address);
52   payload.neighbor.flags = to_api(m_flags);
53
54   VAPI_CALL(req.execute());
55
56   return (wait());
57 }
58
59 std::string
60 create_cmd::to_string() const
61 {
62   std::ostringstream s;
63   s << "nieghbour-create: " << m_hw_item.to_string()
64     << " itf:" << m_itf.to_string() << " mac:" << m_mac.to_string()
65     << " ip:" << m_ip_addr.to_string();
66
67   return (s.str());
68 }
69
70 delete_cmd::delete_cmd(HW::item<handle_t>& item,
71                        handle_t itf,
72                        const mac_address_t& mac,
73                        const boost::asio::ip::address& ip_addr,
74                        const neighbour::flags_t& flags)
75   : srpc_cmd(item)
76   , m_itf(itf)
77   , m_mac(mac)
78   , m_ip_addr(ip_addr)
79   , m_flags(flags)
80 {
81 }
82
83 bool
84 delete_cmd::operator==(const delete_cmd& other) const
85 {
86   return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
87           (m_itf == other.m_itf));
88 }
89
90 rc_t
91 delete_cmd::issue(connection& con)
92 {
93   msg_t req(con.ctx(), std::ref(*this));
94
95   auto& payload = req.get_request().get_payload();
96   payload.is_add = 0;
97   payload.neighbor.sw_if_index = m_itf.value();
98
99   to_api(m_mac, payload.neighbor.mac_address);
100   to_api(m_ip_addr, payload.neighbor.ip_address);
101   payload.neighbor.flags = to_api(m_flags);
102
103   VAPI_CALL(req.execute());
104
105   wait();
106   m_hw_item.set(rc_t::NOOP);
107
108   return rc_t::OK;
109 }
110
111 std::string
112 delete_cmd::to_string() const
113 {
114   std::ostringstream s;
115   s << "neighbour-delete: " << m_hw_item.to_string()
116     << " itf:" << m_itf.to_string() << " mac:" << m_mac.to_string()
117     << " ip:" << m_ip_addr.to_string();
118
119   return (s.str());
120 }
121
122 dump_cmd::dump_cmd(const handle_t& hdl, const l3_proto_t& proto)
123   : m_itf(hdl)
124   , m_proto(proto)
125 {
126 }
127
128 dump_cmd::dump_cmd(const dump_cmd& d)
129   : m_itf(d.m_itf)
130   , m_proto(d.m_proto)
131 {
132 }
133
134 bool
135 dump_cmd::operator==(const dump_cmd& other) const
136 {
137   return (true);
138 }
139
140 rc_t
141 dump_cmd::issue(connection& con)
142 {
143   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
144
145   auto& payload = m_dump->get_request().get_payload();
146   payload.sw_if_index = m_itf.value();
147   payload.is_ipv6 = m_proto.is_ipv6();
148
149   VAPI_CALL(m_dump->execute());
150
151   wait();
152
153   return rc_t::OK;
154 }
155
156 std::string
157 dump_cmd::to_string() const
158 {
159   std::ostringstream s;
160
161   s << "neighbour-dump: " << m_itf.to_string() << " " << m_proto.to_string();
162
163   return (s.str());
164 }
165 } // namespace neighbour_cmds
166 } // namespace vom
167
168 /*
169  * fd.io coding-style-patch-verification: ON
170  *
171  * Local Variables:
172  * eval: (c-set-style "mozilla")
173  * End:
174  */