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/vxlan_tunnel_cmds.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 17 | |
| 18 | DEFINE_VAPI_MSG_IDS_VXLAN_API_JSON; |
| 19 | |
| 20 | namespace VOM { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 21 | namespace vxlan_tunnel_cmds { |
| 22 | |
| 23 | create_cmd::create_cmd(HW::item<handle_t>& item, |
| 24 | const std::string& name, |
| 25 | const vxlan_tunnel::endpoint_t& ep) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 26 | : interface::create_cmd<vapi::Vxlan_add_del_tunnel>(item, name) |
| 27 | , m_ep(ep) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 32 | create_cmd::operator==(const create_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 33 | { |
| 34 | return (m_ep == other.m_ep); |
| 35 | } |
| 36 | |
| 37 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 38 | create_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 39 | { |
| 40 | msg_t req(con.ctx(), std::ref(*this)); |
| 41 | |
| 42 | auto& payload = req.get_request().get_payload(); |
| 43 | payload.is_add = 1; |
| 44 | payload.is_ipv6 = 0; |
| 45 | to_bytes(m_ep.src, &payload.is_ipv6, payload.src_address); |
| 46 | to_bytes(m_ep.dst, &payload.is_ipv6, payload.dst_address); |
| 47 | payload.mcast_sw_if_index = ~0; |
| 48 | payload.encap_vrf_id = 0; |
| 49 | payload.decap_next_index = ~0; |
| 50 | payload.vni = m_ep.vni; |
| 51 | |
| 52 | VAPI_CALL(req.execute()); |
| 53 | |
| 54 | m_hw_item = wait(); |
| 55 | |
| 56 | if (m_hw_item) { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 57 | insert_interface(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | return rc_t::OK; |
| 61 | } |
| 62 | |
| 63 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 64 | create_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 65 | { |
| 66 | std::ostringstream s; |
| 67 | s << "vxlan-tunnel-create: " << m_hw_item.to_string() << m_ep.to_string(); |
| 68 | |
| 69 | return (s.str()); |
| 70 | } |
| 71 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 72 | delete_cmd::delete_cmd(HW::item<handle_t>& item, |
| 73 | const vxlan_tunnel::endpoint_t& ep) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 74 | : interface::delete_cmd<vapi::Vxlan_add_del_tunnel>(item) |
| 75 | , m_ep(ep) |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 80 | delete_cmd::operator==(const delete_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 81 | { |
| 82 | return (m_ep == other.m_ep); |
| 83 | } |
| 84 | |
| 85 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 86 | delete_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 87 | { |
| 88 | msg_t req(con.ctx(), std::ref(*this)); |
| 89 | |
| 90 | auto payload = req.get_request().get_payload(); |
| 91 | payload.is_add = 0; |
| 92 | payload.is_ipv6 = 0; |
| 93 | to_bytes(m_ep.src, &payload.is_ipv6, payload.src_address); |
| 94 | to_bytes(m_ep.dst, &payload.is_ipv6, payload.dst_address); |
| 95 | payload.mcast_sw_if_index = ~0; |
| 96 | payload.encap_vrf_id = 0; |
| 97 | payload.decap_next_index = ~0; |
| 98 | payload.vni = m_ep.vni; |
| 99 | |
| 100 | VAPI_CALL(req.execute()); |
| 101 | |
| 102 | wait(); |
| 103 | m_hw_item.set(rc_t::NOOP); |
| 104 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 105 | remove_interface(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 106 | return (rc_t::OK); |
| 107 | } |
| 108 | |
| 109 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 110 | delete_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 111 | { |
| 112 | std::ostringstream s; |
| 113 | s << "vxlan-tunnel-delete: " << m_hw_item.to_string() << m_ep.to_string(); |
| 114 | |
| 115 | return (s.str()); |
| 116 | } |
| 117 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 118 | dump_cmd::dump_cmd() |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 119 | { |
| 120 | } |
| 121 | |
| 122 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 123 | dump_cmd::operator==(const dump_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 124 | { |
| 125 | return (true); |
| 126 | } |
| 127 | |
| 128 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 129 | dump_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 130 | { |
| 131 | m_dump.reset(new msg_t(con.ctx(), std::ref(*this))); |
| 132 | |
| 133 | auto& payload = m_dump->get_request().get_payload(); |
| 134 | payload.sw_if_index = ~0; |
| 135 | |
| 136 | VAPI_CALL(m_dump->execute()); |
| 137 | |
| 138 | wait(); |
| 139 | |
| 140 | return rc_t::OK; |
| 141 | } |
| 142 | |
| 143 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 144 | dump_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 145 | { |
| 146 | return ("Vpp-vxlan_tunnels-Dump"); |
| 147 | } |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 148 | } // namespace vxlan_tunnel_cmds |
| 149 | } // namespace VOM |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 150 | |
| 151 | /* |
| 152 | * fd.io coding-style-patch-verification: ON |
| 153 | * |
| 154 | * Local Variables: |
| 155 | * eval: (c-set-style "mozilla") |
| 156 | * End: |
| 157 | */ |