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/l2_binding.hpp" |
| 17 | |
| 18 | namespace VOM { |
| 19 | l2_binding::bind_cmd::bind_cmd(HW::item<bool>& item, |
| 20 | const handle_t& itf, |
| 21 | uint32_t bd, |
| 22 | bool is_bvi) |
| 23 | : rpc_cmd(item) |
| 24 | , m_itf(itf) |
| 25 | , m_bd(bd) |
| 26 | , m_is_bvi(is_bvi) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | bool |
| 31 | l2_binding::bind_cmd::operator==(const bind_cmd& other) const |
| 32 | { |
| 33 | return ((m_itf == other.m_itf) && (m_bd == other.m_bd) && |
| 34 | (m_is_bvi == other.m_is_bvi)); |
| 35 | } |
| 36 | |
| 37 | rc_t |
| 38 | l2_binding::bind_cmd::issue(connection& con) |
| 39 | { |
| 40 | msg_t req(con.ctx(), std::ref(*this)); |
| 41 | |
| 42 | auto& payload = req.get_request().get_payload(); |
| 43 | payload.rx_sw_if_index = m_itf.value(); |
| 44 | payload.bd_id = m_bd; |
| 45 | payload.shg = 0; |
| 46 | payload.bvi = m_is_bvi; |
| 47 | payload.enable = 1; |
| 48 | |
| 49 | VAPI_CALL(req.execute()); |
| 50 | |
| 51 | m_hw_item.set(wait()); |
| 52 | |
| 53 | return (rc_t::OK); |
| 54 | } |
| 55 | |
| 56 | std::string |
| 57 | l2_binding::bind_cmd::to_string() const |
| 58 | { |
| 59 | std::ostringstream s; |
| 60 | s << "L2-bind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string() |
| 61 | << " bd:" << m_bd; |
| 62 | |
| 63 | return (s.str()); |
| 64 | } |
| 65 | |
| 66 | l2_binding::unbind_cmd::unbind_cmd(HW::item<bool>& item, |
| 67 | const handle_t& itf, |
| 68 | uint32_t bd, |
| 69 | bool is_bvi) |
| 70 | : rpc_cmd(item) |
| 71 | , m_itf(itf) |
| 72 | , m_bd(bd) |
| 73 | , m_is_bvi(is_bvi) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | bool |
| 78 | l2_binding::unbind_cmd::operator==(const unbind_cmd& other) const |
| 79 | { |
| 80 | return ((m_itf == other.m_itf) && (m_bd == other.m_bd) && |
| 81 | (m_is_bvi == other.m_is_bvi)); |
| 82 | } |
| 83 | |
| 84 | rc_t |
| 85 | l2_binding::unbind_cmd::issue(connection& con) |
| 86 | { |
| 87 | msg_t req(con.ctx(), std::ref(*this)); |
| 88 | |
| 89 | auto& payload = req.get_request().get_payload(); |
| 90 | payload.rx_sw_if_index = m_itf.value(); |
| 91 | payload.bd_id = m_bd; |
| 92 | payload.shg = 0; |
| 93 | payload.bvi = m_is_bvi; |
| 94 | payload.enable = 0; |
| 95 | |
| 96 | VAPI_CALL(req.execute()); |
| 97 | |
| 98 | wait(); |
| 99 | m_hw_item.set(rc_t::NOOP); |
| 100 | |
| 101 | return (rc_t::OK); |
| 102 | } |
| 103 | |
| 104 | std::string |
| 105 | l2_binding::unbind_cmd::to_string() const |
| 106 | { |
| 107 | std::ostringstream s; |
| 108 | s << "L2-unbind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string() |
| 109 | << " bd:" << m_bd; |
| 110 | |
| 111 | return (s.str()); |
| 112 | } |
| 113 | |
| 114 | l2_binding::set_vtr_op_cmd::set_vtr_op_cmd(HW::item<l2_vtr_op_t>& item, |
| 115 | const handle_t& itf, |
| 116 | uint16_t tag) |
| 117 | : rpc_cmd(item) |
| 118 | , m_itf(itf) |
| 119 | , m_tag(tag) |
| 120 | { |
| 121 | } |
| 122 | |
| 123 | bool |
| 124 | l2_binding::set_vtr_op_cmd::operator==(const set_vtr_op_cmd& other) const |
| 125 | { |
| 126 | return ( |
| 127 | (m_hw_item.data() == other.m_hw_item.data() && m_itf == other.m_itf) && |
| 128 | (m_tag == other.m_tag)); |
| 129 | } |
| 130 | |
| 131 | rc_t |
| 132 | l2_binding::set_vtr_op_cmd::issue(connection& con) |
| 133 | { |
| 134 | msg_t req(con.ctx(), std::ref(*this)); |
| 135 | |
| 136 | auto& payload = req.get_request().get_payload(); |
| 137 | payload.sw_if_index = m_itf.value(); |
| 138 | payload.vtr_op = m_hw_item.data().value(); |
| 139 | payload.push_dot1q = 1; |
| 140 | payload.tag1 = m_tag; |
| 141 | |
| 142 | VAPI_CALL(req.execute()); |
| 143 | |
| 144 | wait(); |
| 145 | m_hw_item.set(rc_t::NOOP); |
| 146 | |
| 147 | return (rc_t::OK); |
| 148 | } |
| 149 | |
| 150 | std::string |
| 151 | l2_binding::set_vtr_op_cmd::to_string() const |
| 152 | { |
| 153 | std::ostringstream s; |
| 154 | s << "L2-set-vtr-op: " << m_hw_item.to_string() |
| 155 | << " itf:" << m_itf.to_string() << " tag:" << m_tag; |
| 156 | |
| 157 | return (s.str()); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * fd.io coding-style-patch-verification: ON |
| 163 | * |
| 164 | * Local Variables: |
| 165 | * eval: (c-set-style "mozilla") |
| 166 | * End: |
| 167 | */ |