Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 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 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 16 | #include "vom/interface_cmds.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 17 | #include "vom/cmd.hpp" |
| 18 | |
| 19 | DEFINE_VAPI_MSG_IDS_VPE_API_JSON; |
| 20 | DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON; |
| 21 | DEFINE_VAPI_MSG_IDS_AF_PACKET_API_JSON; |
| 22 | DEFINE_VAPI_MSG_IDS_TAP_API_JSON; |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 23 | DEFINE_VAPI_MSG_IDS_VHOST_USER_API_JSON; |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 24 | DEFINE_VAPI_MSG_IDS_STATS_API_JSON; |
| 25 | |
| 26 | namespace VOM { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 27 | namespace interface_cmds { |
| 28 | loopback_create_cmd::loopback_create_cmd(HW::item<handle_t>& item, |
| 29 | const std::string& name) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 30 | : create_cmd(item, name) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 35 | loopback_create_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 36 | { |
| 37 | msg_t req(con.ctx(), std::ref(*this)); |
| 38 | |
| 39 | VAPI_CALL(req.execute()); |
| 40 | |
| 41 | m_hw_item = wait(); |
| 42 | |
| 43 | if (m_hw_item.rc() == rc_t::OK) { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 44 | insert_interface(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | return rc_t::OK; |
| 48 | } |
| 49 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 50 | loopback_create_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 51 | { |
| 52 | std::ostringstream s; |
| 53 | s << "loopback-itf-create: " << m_hw_item.to_string() << " name:" << m_name; |
| 54 | |
| 55 | return (s.str()); |
| 56 | } |
| 57 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 58 | af_packet_create_cmd::af_packet_create_cmd(HW::item<handle_t>& item, |
| 59 | const std::string& name) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 60 | : create_cmd(item, name) |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 65 | af_packet_create_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 66 | { |
| 67 | msg_t req(con.ctx(), std::ref(*this)); |
| 68 | |
| 69 | auto& payload = req.get_request().get_payload(); |
| 70 | |
| 71 | payload.use_random_hw_addr = 1; |
| 72 | memset(payload.host_if_name, 0, sizeof(payload.host_if_name)); |
| 73 | memcpy(payload.host_if_name, m_name.c_str(), |
| 74 | std::min(m_name.length(), sizeof(payload.host_if_name))); |
| 75 | |
| 76 | VAPI_CALL(req.execute()); |
| 77 | |
| 78 | m_hw_item = wait(); |
| 79 | |
| 80 | if (m_hw_item.rc() == rc_t::OK) { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 81 | insert_interface(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | return rc_t::OK; |
| 85 | } |
| 86 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 87 | af_packet_create_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 88 | { |
| 89 | std::ostringstream s; |
| 90 | s << "af-packet-itf-create: " << m_hw_item.to_string() << " name:" << m_name; |
| 91 | |
| 92 | return (s.str()); |
| 93 | } |
| 94 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 95 | tap_create_cmd::tap_create_cmd(HW::item<handle_t>& item, |
| 96 | const std::string& name) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 97 | : create_cmd(item, name) |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 102 | tap_create_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 103 | { |
| 104 | msg_t req(con.ctx(), std::ref(*this)); |
| 105 | |
| 106 | auto& payload = req.get_request().get_payload(); |
| 107 | |
| 108 | memset(payload.tap_name, 0, sizeof(payload.tap_name)); |
| 109 | memcpy(payload.tap_name, m_name.c_str(), |
| 110 | std::min(m_name.length(), sizeof(payload.tap_name))); |
| 111 | payload.use_random_mac = 1; |
| 112 | |
| 113 | VAPI_CALL(req.execute()); |
| 114 | |
| 115 | m_hw_item = wait(); |
| 116 | |
| 117 | if (m_hw_item.rc() == rc_t::OK) { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 118 | insert_interface(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | return rc_t::OK; |
| 122 | } |
| 123 | |
| 124 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 125 | tap_create_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 126 | { |
| 127 | std::ostringstream s; |
| 128 | s << "tap-intf-create: " << m_hw_item.to_string() << " name:" << m_name; |
| 129 | |
| 130 | return (s.str()); |
| 131 | } |
| 132 | |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 133 | vhost_create_cmd::vhost_create_cmd(HW::item<handle_t>& item, |
| 134 | const std::string& name, |
| 135 | const std::string& tag) |
| 136 | : create_cmd(item, name) |
| 137 | , m_tag(tag) |
| 138 | { |
| 139 | } |
| 140 | |
| 141 | rc_t |
| 142 | vhost_create_cmd::issue(connection& con) |
| 143 | { |
| 144 | msg_t req(con.ctx(), std::ref(*this)); |
| 145 | |
| 146 | auto& payload = req.get_request().get_payload(); |
| 147 | memset(payload.sock_filename, 0, sizeof(payload.sock_filename)); |
| 148 | memcpy(payload.sock_filename, m_name.c_str(), |
| 149 | std::min(m_name.length(), sizeof(payload.sock_filename))); |
| 150 | memset(payload.tag, 0, sizeof(payload.tag)); |
| 151 | |
| 152 | if (!m_tag.empty()) |
| 153 | memcpy(payload.tag, m_tag.c_str(), |
| 154 | std::min(m_tag.length(), sizeof(payload.tag))); |
| 155 | |
Mohsin Kazmi | c6a716b | 2018-03-22 16:07:05 +0100 | [diff] [blame] | 156 | payload.is_server = 0; |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 157 | payload.use_custom_mac = 0; |
| 158 | payload.renumber = 0; |
| 159 | |
| 160 | VAPI_CALL(req.execute()); |
| 161 | |
| 162 | m_hw_item = wait(); |
| 163 | |
Mohsin Kazmi | 3a758b0 | 2018-02-27 14:05:15 +0100 | [diff] [blame] | 164 | if (m_hw_item.rc() == rc_t::OK) { |
| 165 | insert_interface(); |
| 166 | } |
| 167 | |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 168 | return rc_t::OK; |
| 169 | } |
| 170 | |
| 171 | std::string |
| 172 | vhost_create_cmd::to_string() const |
| 173 | { |
| 174 | std::ostringstream s; |
| 175 | s << "vhost-intf-create: " << m_hw_item.to_string() << " name:" << m_name |
| 176 | << " tag:" << m_tag; |
| 177 | |
| 178 | return (s.str()); |
| 179 | } |
| 180 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 181 | loopback_delete_cmd::loopback_delete_cmd(HW::item<handle_t>& item) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 182 | : delete_cmd(item) |
| 183 | { |
| 184 | } |
| 185 | |
| 186 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 187 | loopback_delete_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 188 | { |
| 189 | msg_t req(con.ctx(), std::ref(*this)); |
| 190 | |
| 191 | auto& payload = req.get_request().get_payload(); |
| 192 | payload.sw_if_index = m_hw_item.data().value(); |
| 193 | |
| 194 | VAPI_CALL(req.execute()); |
| 195 | |
| 196 | wait(); |
| 197 | m_hw_item.set(rc_t::NOOP); |
| 198 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 199 | remove_interface(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 200 | return rc_t::OK; |
| 201 | } |
| 202 | |
| 203 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 204 | loopback_delete_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 205 | { |
| 206 | std::ostringstream s; |
| 207 | s << "loopback-itf-delete: " << m_hw_item.to_string(); |
| 208 | |
| 209 | return (s.str()); |
| 210 | } |
| 211 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 212 | af_packet_delete_cmd::af_packet_delete_cmd(HW::item<handle_t>& item, |
| 213 | const std::string& name) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 214 | : delete_cmd(item, name) |
| 215 | { |
| 216 | } |
| 217 | |
| 218 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 219 | af_packet_delete_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 220 | { |
| 221 | msg_t req(con.ctx(), std::ref(*this)); |
| 222 | |
| 223 | auto& payload = req.get_request().get_payload(); |
| 224 | memset(payload.host_if_name, 0, sizeof(payload.host_if_name)); |
| 225 | memcpy(payload.host_if_name, m_name.c_str(), |
| 226 | std::min(m_name.length(), sizeof(payload.host_if_name))); |
| 227 | |
| 228 | VAPI_CALL(req.execute()); |
| 229 | |
| 230 | wait(); |
| 231 | m_hw_item.set(rc_t::NOOP); |
| 232 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 233 | remove_interface(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 234 | return rc_t::OK; |
| 235 | } |
| 236 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 237 | af_packet_delete_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 238 | { |
| 239 | std::ostringstream s; |
| 240 | s << "af_packet-itf-delete: " << m_hw_item.to_string(); |
| 241 | |
| 242 | return (s.str()); |
| 243 | } |
| 244 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 245 | tap_delete_cmd::tap_delete_cmd(HW::item<handle_t>& item) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 246 | : delete_cmd(item) |
| 247 | { |
| 248 | } |
| 249 | |
| 250 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 251 | tap_delete_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 252 | { |
| 253 | // finally... call VPP |
| 254 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 255 | remove_interface(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 256 | return rc_t::OK; |
| 257 | } |
| 258 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 259 | tap_delete_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 260 | { |
| 261 | std::ostringstream s; |
| 262 | s << "tap-itf-delete: " << m_hw_item.to_string(); |
| 263 | |
| 264 | return (s.str()); |
| 265 | } |
| 266 | |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 267 | vhost_delete_cmd::vhost_delete_cmd(HW::item<handle_t>& item, |
| 268 | const std::string& name) |
| 269 | : delete_cmd(item, name) |
| 270 | { |
| 271 | } |
| 272 | |
| 273 | rc_t |
| 274 | vhost_delete_cmd::issue(connection& con) |
| 275 | { |
| 276 | msg_t req(con.ctx(), std::ref(*this)); |
| 277 | |
| 278 | auto& payload = req.get_request().get_payload(); |
| 279 | payload.sw_if_index = m_hw_item.data().value(); |
| 280 | |
| 281 | VAPI_CALL(req.execute()); |
| 282 | |
| 283 | wait(); |
Mohsin Kazmi | c6a716b | 2018-03-22 16:07:05 +0100 | [diff] [blame] | 284 | remove_interface(); |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 285 | |
| 286 | return rc_t::OK; |
| 287 | } |
| 288 | std::string |
| 289 | vhost_delete_cmd::to_string() const |
| 290 | { |
| 291 | std::ostringstream s; |
| 292 | s << "vhost-itf-delete: " << m_hw_item.to_string() << " name:" << m_name; |
| 293 | |
| 294 | return (s.str()); |
| 295 | } |
| 296 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 297 | state_change_cmd::state_change_cmd(HW::item<interface::admin_state_t>& state, |
| 298 | const HW::item<handle_t>& hdl) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 299 | : rpc_cmd(state) |
| 300 | , m_hdl(hdl) |
| 301 | { |
| 302 | } |
| 303 | |
| 304 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 305 | state_change_cmd::operator==(const state_change_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 306 | { |
| 307 | return ((m_hdl == other.m_hdl) && (m_hw_item == other.m_hw_item)); |
| 308 | } |
| 309 | |
| 310 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 311 | state_change_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 312 | { |
| 313 | msg_t req(con.ctx(), std::ref(*this)); |
| 314 | |
| 315 | auto& payload = req.get_request().get_payload(); |
| 316 | payload.sw_if_index = m_hdl.data().value(); |
| 317 | payload.admin_up_down = m_hw_item.data().value(); |
| 318 | |
| 319 | VAPI_CALL(req.execute()); |
| 320 | |
| 321 | m_hw_item.set(wait()); |
| 322 | |
| 323 | return rc_t::OK; |
| 324 | } |
| 325 | |
| 326 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 327 | state_change_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 328 | { |
| 329 | std::ostringstream s; |
| 330 | s << "itf-state-change: " << m_hw_item.to_string() |
| 331 | << " hdl:" << m_hdl.to_string(); |
| 332 | return (s.str()); |
| 333 | } |
| 334 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 335 | set_table_cmd::set_table_cmd(HW::item<route::table_id_t>& table, |
| 336 | const l3_proto_t& proto, |
| 337 | const HW::item<handle_t>& hdl) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 338 | : rpc_cmd(table) |
| 339 | , m_hdl(hdl) |
| 340 | , m_proto(proto) |
| 341 | { |
| 342 | } |
| 343 | |
| 344 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 345 | set_table_cmd::operator==(const set_table_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 346 | { |
| 347 | return ((m_hdl == other.m_hdl) && (m_proto == other.m_proto) && |
| 348 | (m_hw_item == other.m_hw_item)); |
| 349 | } |
| 350 | |
| 351 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 352 | set_table_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 353 | { |
| 354 | msg_t req(con.ctx(), std::ref(*this)); |
| 355 | |
| 356 | auto& payload = req.get_request().get_payload(); |
| 357 | payload.sw_if_index = m_hdl.data().value(); |
| 358 | payload.is_ipv6 = m_proto.is_ipv6(); |
| 359 | payload.vrf_id = m_hw_item.data(); |
| 360 | |
| 361 | VAPI_CALL(req.execute()); |
| 362 | |
| 363 | m_hw_item.set(wait()); |
| 364 | |
| 365 | return (rc_t::OK); |
| 366 | } |
| 367 | |
| 368 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 369 | set_table_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 370 | { |
| 371 | std::ostringstream s; |
| 372 | s << "itf-set-table: " << m_hw_item.to_string() |
| 373 | << " proto:" << m_proto.to_string() << " hdl:" << m_hdl.to_string(); |
| 374 | return (s.str()); |
| 375 | } |
| 376 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 377 | set_mac_cmd::set_mac_cmd(HW::item<l2_address_t>& mac, |
| 378 | const HW::item<handle_t>& hdl) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 379 | : rpc_cmd(mac) |
| 380 | , m_hdl(hdl) |
| 381 | { |
| 382 | } |
| 383 | |
| 384 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 385 | set_mac_cmd::operator==(const set_mac_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 386 | { |
| 387 | return ((m_hdl == other.m_hdl) && (m_hw_item == other.m_hw_item)); |
| 388 | } |
| 389 | |
| 390 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 391 | set_mac_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 392 | { |
| 393 | msg_t req(con.ctx(), std::ref(*this)); |
| 394 | |
| 395 | auto& payload = req.get_request().get_payload(); |
| 396 | payload.sw_if_index = m_hdl.data().value(); |
| 397 | m_hw_item.data().to_mac().to_bytes(payload.mac_address, |
| 398 | sizeof(payload.mac_address)); |
| 399 | |
| 400 | VAPI_CALL(req.execute()); |
| 401 | |
| 402 | m_hw_item.set(wait()); |
| 403 | |
| 404 | return (rc_t::OK); |
| 405 | } |
| 406 | |
| 407 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 408 | set_mac_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 409 | { |
| 410 | std::ostringstream s; |
| 411 | s << "itf-set-mac: " << m_hw_item.to_string() << " hdl:" << m_hdl.to_string(); |
| 412 | return (s.str()); |
| 413 | } |
| 414 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 415 | events_cmd::events_cmd(interface::event_listener& el) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 416 | : event_cmd(el.status()) |
| 417 | , m_listener(el) |
| 418 | { |
| 419 | } |
| 420 | |
| 421 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 422 | events_cmd::operator==(const events_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 423 | { |
| 424 | return (true); |
| 425 | } |
| 426 | |
| 427 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 428 | events_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 429 | { |
| 430 | /* |
| 431 | * First set the call back to handle the interface events |
| 432 | */ |
| 433 | m_reg.reset(new reg_t(con.ctx(), std::ref(*(static_cast<event_cmd*>(this))))); |
| 434 | |
| 435 | /* |
| 436 | * then send the request to enable them |
| 437 | */ |
| 438 | msg_t req(con.ctx(), std::ref(*(static_cast<rpc_cmd*>(this)))); |
| 439 | |
| 440 | auto& payload = req.get_request().get_payload(); |
| 441 | payload.enable_disable = 1; |
| 442 | payload.pid = getpid(); |
| 443 | |
| 444 | VAPI_CALL(req.execute()); |
| 445 | |
| 446 | wait(); |
| 447 | |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 448 | return (rc_t::OK); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | void |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 452 | events_cmd::retire(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 453 | { |
| 454 | /* |
| 455 | * disable interface events. |
| 456 | */ |
| 457 | msg_t req(con.ctx(), std::ref(*(static_cast<rpc_cmd*>(this)))); |
| 458 | |
| 459 | auto& payload = req.get_request().get_payload(); |
| 460 | payload.enable_disable = 0; |
| 461 | payload.pid = getpid(); |
| 462 | |
| 463 | VAPI_CALL(req.execute()); |
| 464 | |
| 465 | wait(); |
| 466 | } |
| 467 | |
| 468 | void |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 469 | events_cmd::notify() |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 470 | { |
| 471 | m_listener.handle_interface_event(this); |
| 472 | } |
| 473 | |
| 474 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 475 | events_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 476 | { |
| 477 | return ("itf-events"); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Interface statistics |
| 482 | */ |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 483 | stats_enable_cmd::stats_enable_cmd(interface::stat_listener& el, |
| 484 | const handle_t& handle) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 485 | : event_cmd(el.status()) |
| 486 | , m_listener(el) |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 487 | , m_swifindex(handle) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 488 | { |
| 489 | } |
| 490 | |
| 491 | bool |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 492 | stats_enable_cmd::operator==(const stats_enable_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 493 | { |
| 494 | return (true); |
| 495 | } |
| 496 | |
| 497 | rc_t |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 498 | stats_enable_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 499 | { |
| 500 | /* |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 501 | * First set the call back to handle the interface stats |
| 502 | */ |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 503 | m_reg.reset(new reg_t(con.ctx(), std::ref(*(static_cast<event_cmd*>(this))))); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 504 | |
| 505 | /* |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 506 | * then send the request to enable them |
| 507 | */ |
| 508 | msg_t req(con.ctx(), 1, std::ref(*(static_cast<rpc_cmd*>(this)))); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 509 | |
| 510 | auto& payload = req.get_request().get_payload(); |
| 511 | payload.enable_disable = 1; |
| 512 | payload.pid = getpid(); |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 513 | payload.num = 1; |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 514 | |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 515 | payload.sw_ifs[0] = m_swifindex.value(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 516 | |
| 517 | VAPI_CALL(req.execute()); |
| 518 | |
| 519 | wait(); |
| 520 | |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 521 | return (rc_t::OK); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | void |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 525 | stats_enable_cmd::retire(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 526 | { |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 527 | /* |
| 528 | * disable interface stats. |
| 529 | */ |
| 530 | msg_t req(con.ctx(), 1, std::ref(*(static_cast<rpc_cmd*>(this)))); |
| 531 | |
| 532 | auto& payload = req.get_request().get_payload(); |
| 533 | payload.enable_disable = 0; |
| 534 | payload.pid = getpid(); |
| 535 | payload.num = 1; |
| 536 | payload.sw_ifs[0] = m_swifindex.value(); |
| 537 | |
| 538 | VAPI_CALL(req.execute()); |
| 539 | |
| 540 | wait(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | void |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 544 | stats_enable_cmd::notify() |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 545 | { |
| 546 | m_listener.handle_interface_stat(this); |
| 547 | } |
| 548 | |
| 549 | std::string |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 550 | stats_enable_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 551 | { |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 552 | std::ostringstream s; |
| 553 | s << "itf-stats-enable itf:" << m_swifindex.to_string(); |
| 554 | return (s.str()); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 557 | stats_disable_cmd::stats_disable_cmd(const handle_t& handle) |
| 558 | : rpc_cmd(m_res) |
| 559 | , m_swifindex(handle) |
| 560 | { |
| 561 | } |
| 562 | |
| 563 | bool |
| 564 | stats_disable_cmd::operator==(const stats_disable_cmd& other) const |
| 565 | { |
| 566 | return (true); |
| 567 | } |
| 568 | |
| 569 | rc_t |
| 570 | stats_disable_cmd::issue(connection& con) |
| 571 | { |
| 572 | /* |
| 573 | * then send the request to enable them |
| 574 | */ |
| 575 | msg_t req(con.ctx(), 1, std::ref(*this)); |
| 576 | |
| 577 | auto& payload = req.get_request().get_payload(); |
| 578 | payload.enable_disable = 0; |
| 579 | payload.pid = getpid(); |
| 580 | payload.num = 1; |
| 581 | |
| 582 | payload.sw_ifs[0] = m_swifindex.value(); |
| 583 | |
| 584 | VAPI_CALL(req.execute()); |
| 585 | |
| 586 | wait(); |
| 587 | |
| 588 | return (rc_t::OK); |
| 589 | } |
| 590 | |
| 591 | std::string |
| 592 | stats_disable_cmd::to_string() const |
| 593 | { |
| 594 | std::ostringstream s; |
| 595 | s << "itf-stats-disable itf:" << m_swifindex.to_string(); |
| 596 | return (s.str()); |
| 597 | } |
| 598 | |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 599 | dump_cmd::dump_cmd() |
| 600 | { |
| 601 | } |
| 602 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 603 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 604 | dump_cmd::operator==(const dump_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 605 | { |
| 606 | return (true); |
| 607 | } |
| 608 | |
| 609 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 610 | dump_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 611 | { |
| 612 | m_dump.reset(new msg_t(con.ctx(), std::ref(*this))); |
| 613 | |
| 614 | auto& payload = m_dump->get_request().get_payload(); |
| 615 | payload.name_filter_valid = 0; |
| 616 | |
| 617 | VAPI_CALL(m_dump->execute()); |
| 618 | |
| 619 | wait(); |
| 620 | |
| 621 | return rc_t::OK; |
| 622 | } |
| 623 | |
| 624 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 625 | dump_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 626 | { |
| 627 | return ("itf-dump"); |
| 628 | } |
| 629 | |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 630 | vhost_dump_cmd::vhost_dump_cmd() |
| 631 | { |
| 632 | } |
| 633 | |
| 634 | bool |
| 635 | vhost_dump_cmd::operator==(const vhost_dump_cmd& other) const |
| 636 | { |
| 637 | return (true); |
| 638 | } |
| 639 | |
| 640 | rc_t |
| 641 | vhost_dump_cmd::issue(connection& con) |
| 642 | { |
| 643 | m_dump.reset(new msg_t(con.ctx(), std::ref(*this))); |
| 644 | |
| 645 | VAPI_CALL(m_dump->execute()); |
| 646 | |
| 647 | wait(); |
| 648 | |
| 649 | return rc_t::OK; |
| 650 | } |
| 651 | |
| 652 | std::string |
| 653 | vhost_dump_cmd::to_string() const |
| 654 | { |
| 655 | return ("vhost-itf-dump"); |
| 656 | } |
| 657 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 658 | set_tag::set_tag(HW::item<handle_t>& item, const std::string& name) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 659 | : rpc_cmd(item) |
| 660 | , m_name(name) |
| 661 | { |
| 662 | } |
| 663 | |
| 664 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 665 | set_tag::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 666 | { |
| 667 | msg_t req(con.ctx(), std::ref(*this)); |
| 668 | |
| 669 | auto& payload = req.get_request().get_payload(); |
| 670 | payload.is_add = 1; |
| 671 | payload.sw_if_index = m_hw_item.data().value(); |
| 672 | memcpy(payload.tag, m_name.c_str(), m_name.length()); |
| 673 | |
| 674 | VAPI_CALL(req.execute()); |
| 675 | |
| 676 | wait(); |
| 677 | |
| 678 | return rc_t::OK; |
| 679 | } |
| 680 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 681 | set_tag::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 682 | { |
| 683 | std::ostringstream s; |
| 684 | s << "itf-set-tag: " << m_hw_item.to_string() << " name:" << m_name; |
| 685 | |
| 686 | return (s.str()); |
| 687 | } |
| 688 | |
| 689 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 690 | set_tag::operator==(const set_tag& o) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 691 | { |
| 692 | return ((m_name == o.m_name) && (m_hw_item.data() == o.m_hw_item.data())); |
| 693 | } |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 694 | }; // namespace interface_cmds |
| 695 | }; // namespace VOM |
| 696 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 697 | /* |
| 698 | * fd.io coding-style-patch-verification: ON |
| 699 | * |
| 700 | * Local Variables: |
| 701 | * eval: (c-set-style "mozilla") |
| 702 | * End: |
| 703 | */ |