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 | |
| 16 | #include "vom/l3_binding.hpp" |
| 17 | |
| 18 | DEFINE_VAPI_MSG_IDS_IP_API_JSON; |
| 19 | |
| 20 | namespace VOM { |
| 21 | l3_binding::bind_cmd::bind_cmd(HW::item<bool>& item, |
| 22 | const handle_t& itf, |
| 23 | const route::prefix_t& pfx) |
| 24 | : rpc_cmd(item) |
| 25 | , m_itf(itf) |
| 26 | , m_pfx(pfx) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | bool |
| 31 | l3_binding::bind_cmd::operator==(const bind_cmd& other) const |
| 32 | { |
| 33 | return ((m_itf == other.m_itf) && (m_pfx == other.m_pfx)); |
| 34 | } |
| 35 | |
| 36 | rc_t |
| 37 | l3_binding::bind_cmd::issue(connection& con) |
| 38 | { |
| 39 | msg_t req(con.ctx(), std::ref(*this)); |
| 40 | |
| 41 | auto& payload = req.get_request().get_payload(); |
| 42 | payload.sw_if_index = m_itf.value(); |
| 43 | payload.is_add = 1; |
| 44 | payload.del_all = 0; |
| 45 | |
| 46 | m_pfx.to_vpp(&payload.is_ipv6, payload.address, &payload.address_length); |
| 47 | |
| 48 | VAPI_CALL(req.execute()); |
| 49 | |
| 50 | m_hw_item.set(wait()); |
| 51 | |
| 52 | return rc_t::OK; |
| 53 | } |
| 54 | |
| 55 | std::string |
| 56 | l3_binding::bind_cmd::to_string() const |
| 57 | { |
| 58 | std::ostringstream s; |
| 59 | s << "L3-bind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string() |
| 60 | << " pfx:" << m_pfx.to_string(); |
| 61 | |
| 62 | return (s.str()); |
| 63 | } |
| 64 | |
| 65 | l3_binding::unbind_cmd::unbind_cmd(HW::item<bool>& item, |
| 66 | const handle_t& itf, |
| 67 | const route::prefix_t& pfx) |
| 68 | : rpc_cmd(item) |
| 69 | , m_itf(itf) |
| 70 | , m_pfx(pfx) |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | bool |
| 75 | l3_binding::unbind_cmd::operator==(const unbind_cmd& other) const |
| 76 | { |
| 77 | return ((m_itf == other.m_itf) && (m_pfx == other.m_pfx)); |
| 78 | } |
| 79 | |
| 80 | rc_t |
| 81 | l3_binding::unbind_cmd::issue(connection& con) |
| 82 | { |
| 83 | msg_t req(con.ctx(), std::ref(*this)); |
| 84 | |
| 85 | auto& payload = req.get_request().get_payload(); |
| 86 | payload.sw_if_index = m_itf.value(); |
| 87 | payload.is_add = 0; |
| 88 | payload.del_all = 0; |
| 89 | |
| 90 | m_pfx.to_vpp(&payload.is_ipv6, payload.address, &payload.address_length); |
| 91 | |
| 92 | VAPI_CALL(req.execute()); |
| 93 | |
| 94 | wait(); |
| 95 | m_hw_item.set(rc_t::NOOP); |
| 96 | |
| 97 | return rc_t::OK; |
| 98 | } |
| 99 | |
| 100 | std::string |
| 101 | l3_binding::unbind_cmd::to_string() const |
| 102 | { |
| 103 | std::ostringstream s; |
| 104 | s << "L3-unbind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string() |
| 105 | << " pfx:" << m_pfx.to_string(); |
| 106 | |
| 107 | return (s.str()); |
| 108 | } |
| 109 | |
| 110 | l3_binding::dump_v4_cmd::dump_v4_cmd(const handle_t& hdl) |
| 111 | : m_itf(hdl) |
| 112 | { |
| 113 | } |
| 114 | |
| 115 | l3_binding::dump_v4_cmd::dump_v4_cmd(const dump_v4_cmd& d) |
| 116 | : m_itf(d.m_itf) |
| 117 | { |
| 118 | } |
| 119 | |
| 120 | bool |
| 121 | l3_binding::dump_v4_cmd::operator==(const dump_v4_cmd& other) const |
| 122 | { |
| 123 | return (true); |
| 124 | } |
| 125 | |
| 126 | rc_t |
| 127 | l3_binding::dump_v4_cmd::issue(connection& con) |
| 128 | { |
| 129 | m_dump.reset(new msg_t(con.ctx(), std::ref(*this))); |
| 130 | |
| 131 | auto& payload = m_dump->get_request().get_payload(); |
| 132 | payload.sw_if_index = m_itf.value(); |
| 133 | payload.is_ipv6 = 0; |
| 134 | |
| 135 | VAPI_CALL(m_dump->execute()); |
| 136 | |
| 137 | wait(); |
| 138 | |
| 139 | return rc_t::OK; |
| 140 | } |
| 141 | |
| 142 | std::string |
| 143 | l3_binding::dump_v4_cmd::to_string() const |
| 144 | { |
| 145 | return ("L3-binding-dump"); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * fd.io coding-style-patch-verification: ON |
| 151 | * |
| 152 | * Local Variables: |
| 153 | * eval: (c-set-style "mozilla") |
| 154 | * End: |
| 155 | */ |