Revert "API: Cleanup APIs interface.api"
[vpp.git] / extras / vom / vom / l3_binding_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/l3_binding_cmds.hpp"
17
18 DEFINE_VAPI_MSG_IDS_IP_API_JSON;
19
20 namespace VOM {
21 namespace l3_binding_cmds {
22 bind_cmd::bind_cmd(HW::item<bool>& item,
23                    const handle_t& itf,
24                    const route::prefix_t& pfx)
25   : rpc_cmd(item)
26   , m_itf(itf)
27   , m_pfx(pfx)
28 {
29 }
30
31 bool
32 bind_cmd::operator==(const bind_cmd& other) const
33 {
34   return ((m_itf == other.m_itf) && (m_pfx == other.m_pfx));
35 }
36
37 rc_t
38 bind_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.sw_if_index = m_itf.value();
44   payload.is_add = 1;
45   payload.del_all = 0;
46
47   m_pfx.to_vpp(&payload.is_ipv6, payload.address, &payload.address_length);
48
49   VAPI_CALL(req.execute());
50
51   return (wait());
52 }
53
54 std::string
55 bind_cmd::to_string() const
56 {
57   std::ostringstream s;
58   s << "L3-bind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
59     << " pfx:" << m_pfx.to_string();
60
61   return (s.str());
62 }
63
64 unbind_cmd::unbind_cmd(HW::item<bool>& item,
65                        const handle_t& itf,
66                        const route::prefix_t& pfx)
67   : rpc_cmd(item)
68   , m_itf(itf)
69   , m_pfx(pfx)
70 {
71 }
72
73 bool
74 unbind_cmd::operator==(const unbind_cmd& other) const
75 {
76   return ((m_itf == other.m_itf) && (m_pfx == other.m_pfx));
77 }
78
79 rc_t
80 unbind_cmd::issue(connection& con)
81 {
82   msg_t req(con.ctx(), std::ref(*this));
83
84   auto& payload = req.get_request().get_payload();
85   payload.sw_if_index = m_itf.value();
86   payload.is_add = 0;
87   payload.del_all = 0;
88
89   m_pfx.to_vpp(&payload.is_ipv6, payload.address, &payload.address_length);
90
91   VAPI_CALL(req.execute());
92
93   wait();
94   m_hw_item.set(rc_t::NOOP);
95
96   return rc_t::OK;
97 }
98
99 std::string
100 unbind_cmd::to_string() const
101 {
102   std::ostringstream s;
103   s << "L3-unbind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
104     << " pfx:" << m_pfx.to_string();
105
106   return (s.str());
107 }
108
109 dump_v4_cmd::dump_v4_cmd(const handle_t& hdl)
110   : m_itf(hdl)
111 {
112 }
113
114 dump_v4_cmd::dump_v4_cmd(const dump_v4_cmd& d)
115   : m_itf(d.m_itf)
116 {
117 }
118
119 bool
120 dump_v4_cmd::operator==(const dump_v4_cmd& other) const
121 {
122   return (true);
123 }
124
125 rc_t
126 dump_v4_cmd::issue(connection& con)
127 {
128   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
129
130   auto& payload = m_dump->get_request().get_payload();
131   payload.sw_if_index = m_itf.value();
132   payload.is_ipv6 = 0;
133
134   VAPI_CALL(m_dump->execute());
135
136   wait();
137
138   return rc_t::OK;
139 }
140
141 std::string
142 dump_v4_cmd::to_string() const
143 {
144   return ("L3-binding-dump");
145 }
146
147 }; // namespace l3_binding_cmds
148 }; // namespace VOM
149
150 /*
151  * fd.io coding-style-patch-verification: ON
152  *
153  * Local Variables:
154  * eval: (c-set-style "mozilla")
155  * End:
156  */