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/nat_binding_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 nat_binding_cmds { |
| 20 | bind_44_input_cmd::bind_44_input_cmd(HW::item<bool>& item, |
| 21 | const handle_t& itf, |
| 22 | const nat_binding::zone_t& zone) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 23 | : rpc_cmd(item) |
| 24 | , m_itf(itf) |
| 25 | , m_zone(zone) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 30 | bind_44_input_cmd::operator==(const bind_44_input_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 31 | { |
| 32 | return ((m_itf == other.m_itf) && (m_zone == other.m_zone)); |
| 33 | } |
| 34 | |
| 35 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 36 | bind_44_input_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 37 | { |
| 38 | msg_t req(con.ctx(), std::ref(*this)); |
| 39 | |
| 40 | auto& payload = req.get_request().get_payload(); |
| 41 | payload.is_add = 1; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 42 | payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 43 | payload.sw_if_index = m_itf.value(); |
| 44 | |
| 45 | VAPI_CALL(req.execute()); |
| 46 | |
| 47 | m_hw_item.set(wait()); |
| 48 | |
| 49 | return rc_t::OK; |
| 50 | } |
| 51 | |
| 52 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 53 | bind_44_input_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 54 | { |
| 55 | std::ostringstream s; |
| 56 | s << "nat-44-input-binding-create: " << m_hw_item.to_string() |
| 57 | << " itf:" << m_itf << " " << m_zone.to_string(); |
| 58 | |
| 59 | return (s.str()); |
| 60 | } |
| 61 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 62 | unbind_44_input_cmd::unbind_44_input_cmd(HW::item<bool>& item, |
| 63 | const handle_t& itf, |
| 64 | const nat_binding::zone_t& zone) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 65 | : rpc_cmd(item) |
| 66 | , m_itf(itf) |
| 67 | , m_zone(zone) |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 72 | unbind_44_input_cmd::operator==(const unbind_44_input_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 73 | { |
| 74 | return ((m_itf == other.m_itf) && (m_zone == other.m_zone)); |
| 75 | } |
| 76 | |
| 77 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 78 | unbind_44_input_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 79 | { |
| 80 | msg_t req(con.ctx(), std::ref(*this)); |
| 81 | |
| 82 | auto& payload = req.get_request().get_payload(); |
| 83 | payload.is_add = 0; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 84 | payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 85 | payload.sw_if_index = m_itf.value(); |
| 86 | |
| 87 | VAPI_CALL(req.execute()); |
| 88 | |
| 89 | m_hw_item.set(wait()); |
| 90 | |
| 91 | return rc_t::OK; |
| 92 | } |
| 93 | |
| 94 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 95 | unbind_44_input_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 96 | { |
| 97 | std::ostringstream s; |
| 98 | s << "nat-44-input-binding-create: " << m_hw_item.to_string() |
| 99 | << " itf:" << m_itf << " " << m_zone.to_string(); |
| 100 | |
| 101 | return (s.str()); |
| 102 | } |
| 103 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 104 | dump_44_cmd::dump_44_cmd() |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 105 | { |
| 106 | } |
| 107 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 108 | dump_44_cmd::dump_44_cmd(const dump_44_cmd& d) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 109 | { |
| 110 | } |
| 111 | |
| 112 | bool |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 113 | dump_44_cmd::operator==(const dump_44_cmd& other) const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 114 | { |
| 115 | return (true); |
| 116 | } |
| 117 | |
| 118 | rc_t |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 119 | dump_44_cmd::issue(connection& con) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 120 | { |
| 121 | m_dump.reset(new msg_t(con.ctx(), std::ref(*this))); |
| 122 | |
| 123 | VAPI_CALL(m_dump->execute()); |
| 124 | |
| 125 | wait(); |
| 126 | |
| 127 | return rc_t::OK; |
| 128 | } |
| 129 | |
| 130 | std::string |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 131 | dump_44_cmd::to_string() const |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 132 | { |
| 133 | return ("nat-binding-dump"); |
| 134 | } |
| 135 | } |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 136 | } |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 137 | |
| 138 | /* |
| 139 | * fd.io coding-style-patch-verification: ON |
| 140 | * |
| 141 | * Local Variables: |
| 142 | * eval: (c-set-style "mozilla") |
| 143 | * End: |
| 144 | */ |