24233d9e44396ac0e0d18ce8f3ebd53d57c300ca
[vpp.git] / extras / vom / vom / route_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 <sstream>
17
18 #include <vom/route_api_types.hpp>
19 #include <vom/route_cmds.hpp>
20
21 namespace VOM {
22 namespace route {
23 namespace ip_route_cmds {
24
25 update_cmd::update_cmd(HW::item<bool>& item,
26                        table_id_t id,
27                        const prefix_t& prefix,
28                        const path& path)
29   : rpc_cmd(item)
30   , m_id(id)
31   , m_prefix(prefix)
32   , m_path(path)
33 {
34 }
35
36 bool
37 update_cmd::operator==(const update_cmd& other) const
38 {
39   return ((m_prefix == other.m_prefix) && (m_id == other.m_id) &&
40           (m_path == other.m_path));
41 }
42
43 rc_t
44 update_cmd::issue(connection& con)
45 {
46   msg_t req(con.ctx(), 0, std::ref(*this));
47
48   auto& payload = req.get_request().get_payload();
49
50   payload.table_id = m_id;
51   payload.is_add = 1;
52   payload.is_multipath = 1;
53
54   m_prefix.to_vpp(&payload.is_ipv6, payload.dst_address,
55                   &payload.dst_address_length);
56   to_vpp(m_path, payload);
57
58   VAPI_CALL(req.execute());
59
60   return (wait());
61 }
62
63 std::string
64 update_cmd::to_string() const
65 {
66   std::ostringstream s;
67   s << "ip-route-create: " << m_hw_item.to_string() << " table-id:" << m_id
68     << " prefix:" << m_prefix.to_string() << " paths:" << m_path.to_string();
69
70   return (s.str());
71 }
72
73 delete_cmd::delete_cmd(HW::item<bool>& item,
74                        table_id_t id,
75                        const prefix_t& prefix,
76                        const path& path)
77   : rpc_cmd(item)
78   , m_id(id)
79   , m_prefix(prefix)
80   , m_path(path)
81 {
82 }
83
84 bool
85 delete_cmd::operator==(const delete_cmd& other) const
86 {
87   return ((m_prefix == other.m_prefix) && (m_id == other.m_id) &&
88           (m_path == other.m_path));
89 }
90
91 rc_t
92 delete_cmd::issue(connection& con)
93 {
94   msg_t req(con.ctx(), 0, std::ref(*this));
95
96   auto& payload = req.get_request().get_payload();
97   payload.table_id = m_id;
98   payload.is_add = 0;
99
100   m_prefix.to_vpp(&payload.is_ipv6, payload.dst_address,
101                   &payload.dst_address_length);
102   to_vpp(m_path, payload);
103
104   VAPI_CALL(req.execute());
105
106   wait();
107   m_hw_item.set(rc_t::NOOP);
108
109   return rc_t::OK;
110 }
111
112 std::string
113 delete_cmd::to_string() const
114 {
115   std::ostringstream s;
116   s << "ip-route-delete: " << m_hw_item.to_string() << " id:" << m_id
117     << " prefix:" << m_prefix.to_string() << " paths:" << m_path.to_string();
118
119   return (s.str());
120 }
121
122 dump_v4_cmd::dump_v4_cmd()
123 {
124 }
125
126 bool
127 dump_v4_cmd::operator==(const dump_v4_cmd& other) const
128 {
129   return (true);
130 }
131
132 rc_t
133 dump_v4_cmd::issue(connection& con)
134 {
135   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
136
137   VAPI_CALL(m_dump->execute());
138
139   wait();
140
141   return rc_t::OK;
142 }
143
144 std::string
145 dump_v4_cmd::to_string() const
146 {
147   return ("ip-route-v4-dump");
148 }
149
150 dump_v6_cmd::dump_v6_cmd()
151 {
152 }
153
154 bool
155 dump_v6_cmd::operator==(const dump_v6_cmd& other) const
156 {
157   return (true);
158 }
159
160 rc_t
161 dump_v6_cmd::issue(connection& con)
162 {
163   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
164
165   VAPI_CALL(m_dump->execute());
166
167   wait();
168
169   return rc_t::OK;
170 }
171
172 std::string
173 dump_v6_cmd::to_string() const
174 {
175   return ("ip-route-v6-dump");
176 }
177 } // namespace ip_route_cmds
178 } // namespace route
179 } // namespace vom
180   /*
181    * fd.io coding-style-patch-verification: ON
182    *
183    * Local Variables:
184    * eval: (c-set-style "mozilla")
185    * End:
186    */