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/tap_interface_cmds.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 17 | |
| 18 | #include <vapi/tap.api.vapi.hpp> |
| 19 | |
| 20 | namespace VOM { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 21 | namespace tap_interface_cmds { |
| 22 | create_cmd::create_cmd(HW::item<handle_t>& item, |
| 23 | const std::string& name, |
| 24 | route::prefix_t& prefix, |
| 25 | const l2_address_t& l2_address) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 26 | : interface::create_cmd<vapi::Tap_connect>(item, name) |
| 27 | , m_prefix(prefix) |
| 28 | , m_l2_address(l2_address) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 33 | create_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 34 | { |
| 35 | msg_t req(con.ctx(), std::ref(*this)); |
| 36 | |
| 37 | auto& payload = req.get_request().get_payload(); |
| 38 | memset(payload.tap_name, 0, sizeof(payload.tap_name)); |
| 39 | memcpy(payload.tap_name, m_name.c_str(), |
| 40 | std::min(m_name.length(), sizeof(payload.tap_name))); |
| 41 | if (m_prefix != route::prefix_t::ZERO) { |
| 42 | if (m_prefix.address().is_v6()) { |
| 43 | m_prefix.to_vpp(&payload.ip6_address_set, payload.ip6_address, |
| 44 | &payload.ip6_mask_width); |
| 45 | } else { |
| 46 | m_prefix.to_vpp(&payload.ip4_address_set, payload.ip4_address, |
| 47 | &payload.ip4_mask_width); |
| 48 | payload.ip4_address_set = 1; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | if (m_l2_address != l2_address_t::ZERO) { |
| 53 | m_l2_address.to_bytes(payload.mac_address, 6); |
| 54 | } else { |
| 55 | payload.use_random_mac = 1; |
| 56 | } |
| 57 | |
| 58 | VAPI_CALL(req.execute()); |
| 59 | |
| 60 | m_hw_item = wait(); |
| 61 | |
| 62 | return rc_t::OK; |
| 63 | } |
| 64 | |
| 65 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 66 | create_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 67 | { |
| 68 | std::ostringstream s; |
| 69 | s << "tap-intf-create: " << m_hw_item.to_string() |
| 70 | << " ip-prefix:" << m_prefix.to_string(); |
| 71 | |
| 72 | return (s.str()); |
| 73 | } |
| 74 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 75 | delete_cmd::delete_cmd(HW::item<handle_t>& item) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 76 | : interface::delete_cmd<vapi::Tap_delete>(item) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 81 | delete_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 82 | { |
| 83 | // finally... call VPP |
| 84 | |
| 85 | return rc_t::OK; |
| 86 | } |
| 87 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 88 | delete_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 89 | { |
| 90 | std::ostringstream s; |
| 91 | s << "tap-itf-delete: " << m_hw_item.to_string(); |
| 92 | |
| 93 | return (s.str()); |
| 94 | } |
| 95 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 96 | dump_cmd::dump_cmd() |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 97 | { |
| 98 | } |
| 99 | |
| 100 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 101 | dump_cmd::operator==(const dump_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 102 | { |
| 103 | return (true); |
| 104 | } |
| 105 | |
| 106 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 107 | dump_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 108 | { |
| 109 | m_dump.reset(new msg_t(con.ctx(), std::ref(*this))); |
| 110 | |
| 111 | VAPI_CALL(m_dump->execute()); |
| 112 | |
| 113 | wait(); |
| 114 | |
| 115 | return rc_t::INPROGRESS; |
| 116 | } |
| 117 | |
| 118 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 119 | dump_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 120 | { |
| 121 | return ("tap-itf-dump"); |
| 122 | } |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 123 | } // namespace tap_interface_cmds |
| 124 | } // namespace VOM |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 125 | |
| 126 | /* |
| 127 | * fd.io coding-style-patch-verification: ON |
| 128 | * |
| 129 | * Local Variables: |
| 130 | * eval: (c-set-style "mozilla") |
| 131 | * End: |
| 132 | */ |