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/neighbour_cmds.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 17 | |
| 18 | namespace VOM { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 19 | namespace neighbour_cmds { |
| 20 | create_cmd::create_cmd(HW::item<bool>& item, |
| 21 | handle_t itf, |
| 22 | const mac_address_t& mac, |
| 23 | const boost::asio::ip::address& ip_addr) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 24 | : rpc_cmd(item) |
| 25 | , m_itf(itf) |
| 26 | , m_mac(mac) |
| 27 | , m_ip_addr(ip_addr) |
| 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_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) && |
| 35 | (m_itf == other.m_itf)); |
| 36 | } |
| 37 | |
| 38 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 39 | create_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 40 | { |
| 41 | msg_t req(con.ctx(), std::ref(*this)); |
| 42 | |
| 43 | auto& payload = req.get_request().get_payload(); |
| 44 | payload.sw_if_index = m_itf.value(); |
| 45 | payload.is_add = 1; |
| 46 | payload.is_static = 1; |
| 47 | m_mac.to_bytes(payload.mac_address, 6); |
| 48 | to_bytes(m_ip_addr, &payload.is_ipv6, payload.dst_address); |
| 49 | |
| 50 | VAPI_CALL(req.execute()); |
| 51 | |
| 52 | m_hw_item.set(wait()); |
| 53 | |
| 54 | return rc_t::OK; |
| 55 | } |
| 56 | |
| 57 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 58 | create_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 59 | { |
| 60 | std::ostringstream s; |
| 61 | s << "nieghbour-create: " << m_hw_item.to_string() |
| 62 | << " itf:" << m_itf.to_string() << " mac:" << m_mac.to_string() |
| 63 | << " ip:" << m_ip_addr.to_string(); |
| 64 | |
| 65 | return (s.str()); |
| 66 | } |
| 67 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 68 | delete_cmd::delete_cmd(HW::item<bool>& item, |
| 69 | handle_t itf, |
| 70 | const mac_address_t& mac, |
| 71 | const boost::asio::ip::address& ip_addr) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 72 | : rpc_cmd(item) |
| 73 | , m_itf(itf) |
| 74 | , m_mac(mac) |
| 75 | , m_ip_addr(ip_addr) |
| 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_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) && |
| 83 | (m_itf == other.m_itf)); |
| 84 | } |
| 85 | |
| 86 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 87 | delete_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 88 | { |
| 89 | msg_t req(con.ctx(), std::ref(*this)); |
| 90 | |
| 91 | auto& payload = req.get_request().get_payload(); |
| 92 | payload.sw_if_index = m_itf.value(); |
| 93 | payload.is_add = 0; |
| 94 | payload.is_static = 1; |
| 95 | m_mac.to_bytes(payload.mac_address, 6); |
| 96 | to_bytes(m_ip_addr, &payload.is_ipv6, payload.dst_address); |
| 97 | |
| 98 | VAPI_CALL(req.execute()); |
| 99 | |
| 100 | wait(); |
| 101 | m_hw_item.set(rc_t::NOOP); |
| 102 | |
| 103 | return rc_t::OK; |
| 104 | } |
| 105 | |
| 106 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 107 | delete_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 108 | { |
| 109 | std::ostringstream s; |
| 110 | s << "neighbour-delete: " << m_hw_item.to_string() |
| 111 | << " itf:" << m_itf.to_string() << " mac:" << m_mac.to_string() |
| 112 | << " ip:" << m_ip_addr.to_string(); |
| 113 | |
| 114 | return (s.str()); |
| 115 | } |
| 116 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 117 | dump_cmd::dump_cmd(const handle_t& hdl, const l3_proto_t& proto) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 118 | : m_itf(hdl) |
| 119 | , m_proto(proto) |
| 120 | { |
| 121 | } |
| 122 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 123 | dump_cmd::dump_cmd(const dump_cmd& d) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 124 | : m_itf(d.m_itf) |
| 125 | , m_proto(d.m_proto) |
| 126 | { |
| 127 | } |
| 128 | |
| 129 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 130 | dump_cmd::operator==(const dump_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 131 | { |
| 132 | return (true); |
| 133 | } |
| 134 | |
| 135 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 136 | dump_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 137 | { |
| 138 | m_dump.reset(new msg_t(con.ctx(), std::ref(*this))); |
| 139 | |
| 140 | auto& payload = m_dump->get_request().get_payload(); |
| 141 | payload.sw_if_index = m_itf.value(); |
| 142 | payload.is_ipv6 = m_proto.is_ipv6(); |
| 143 | |
| 144 | VAPI_CALL(m_dump->execute()); |
| 145 | |
| 146 | wait(); |
| 147 | |
| 148 | return rc_t::OK; |
| 149 | } |
| 150 | |
| 151 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 152 | dump_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 153 | { |
| 154 | return ("neighbour-dump"); |
| 155 | } |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 156 | } // namespace neighbour_cmds |
| 157 | } // namespace vom |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | * fd.io coding-style-patch-verification: ON |
| 161 | * |
| 162 | * Local Variables: |
| 163 | * eval: (c-set-style "mozilla") |
| 164 | * End: |
| 165 | */ |