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