Mohsin Kazmi | ed76ee2 | 2018-03-02 12:31:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 | #ifndef __VOM_BOND_INTERFACE_H__ |
| 17 | #define __VOM_BOND_INTERFACE_H__ |
| 18 | |
| 19 | #include "vom/interface.hpp" |
| 20 | |
| 21 | namespace VOM { |
| 22 | /** |
| 23 | * A bond-interface. e.g. a bond interface |
| 24 | */ |
| 25 | class bond_interface : public interface |
| 26 | { |
| 27 | public: |
| 28 | /** |
| 29 | * A bond interface mode |
| 30 | */ |
| 31 | struct mode_t : enum_base<mode_t> |
| 32 | { |
| 33 | /** |
| 34 | * Round-Robin bond interface mode |
| 35 | */ |
| 36 | const static mode_t ROUND_ROBIN; |
| 37 | /** |
| 38 | * Active-backup bond interface mode |
| 39 | */ |
| 40 | const static mode_t ACTIVE_BACKUP; |
| 41 | /** |
| 42 | * XOR bond interface mode |
| 43 | */ |
| 44 | const static mode_t XOR; |
| 45 | /** |
| 46 | * Broadcast bond interface mode |
| 47 | */ |
| 48 | const static mode_t BROADCAST; |
| 49 | /** |
| 50 | * LACP bond interface mode |
| 51 | */ |
| 52 | const static mode_t LACP; |
| 53 | /** |
| 54 | * Unspecificed bond interface mode |
| 55 | */ |
| 56 | const static mode_t UNSPECIFIED; |
| 57 | |
| 58 | /** |
| 59 | * Convert VPP's value of the bond to a mode |
| 60 | */ |
| 61 | static const mode_t from_numeric_val(uint8_t v); |
| 62 | |
| 63 | private: |
| 64 | /** |
| 65 | * Private constructor taking the value and the string name |
| 66 | */ |
| 67 | mode_t(int v, const std::string& s); |
| 68 | }; |
| 69 | |
| 70 | /** |
| 71 | * A bond interface load balance |
| 72 | */ |
| 73 | struct lb_t : enum_base<lb_t> |
| 74 | { |
| 75 | /** |
| 76 | * L2 bond interface lb |
| 77 | */ |
| 78 | const static lb_t L2; |
| 79 | /** |
| 80 | * L34 bond interface lb |
| 81 | */ |
| 82 | const static lb_t L34; |
| 83 | /** |
| 84 | * L23 bond interface lb |
| 85 | */ |
| 86 | const static lb_t L23; |
| 87 | /** |
| 88 | * Unspecificed bond interface lb |
| 89 | */ |
| 90 | const static lb_t UNSPECIFIED; |
| 91 | |
| 92 | /** |
| 93 | * Convert VPP's value of the bond to a lb |
| 94 | */ |
| 95 | static const lb_t from_numeric_val(uint8_t v); |
| 96 | |
| 97 | private: |
| 98 | /** |
| 99 | * Private constructor taking the value and the string name |
| 100 | */ |
| 101 | lb_t(int v, const std::string& s); |
| 102 | }; |
| 103 | |
| 104 | bond_interface(const std::string& name, |
| 105 | admin_state_t state, |
| 106 | mode_t mode, |
| 107 | lb_t lb = lb_t::UNSPECIFIED); |
| 108 | |
| 109 | bond_interface(const std::string& name, |
| 110 | admin_state_t state, |
| 111 | const l2_address_t& l2_address, |
| 112 | mode_t mode, |
| 113 | lb_t lb = lb_t::UNSPECIFIED); |
| 114 | |
| 115 | ~bond_interface(); |
| 116 | bond_interface(const bond_interface& o); |
| 117 | |
| 118 | /** |
| 119 | * The the singular instance of the bond interface in the DB by handle |
| 120 | */ |
| 121 | static std::shared_ptr<bond_interface> find(const handle_t& hdl); |
| 122 | |
| 123 | /** |
| 124 | * Return the matching 'singular instance' of the BOND interface |
| 125 | */ |
| 126 | std::shared_ptr<bond_interface> singular() const; |
| 127 | |
| 128 | /** |
| 129 | * set the mode |
| 130 | */ |
| 131 | void set(mode_t mode); |
| 132 | |
| 133 | /** |
| 134 | * set the lb |
| 135 | */ |
| 136 | void set(lb_t lb); |
| 137 | |
| 138 | /** |
| 139 | * convert to string |
| 140 | */ |
| 141 | virtual std::string to_string() const; |
| 142 | |
| 143 | protected: |
| 144 | /** |
| 145 | * set the handle |
| 146 | */ |
| 147 | void set(handle_t& handle); |
| 148 | friend class interface_factory; |
| 149 | |
| 150 | private: |
| 151 | /** |
| 152 | * l2 address on bond interface |
| 153 | */ |
| 154 | l2_address_t m_l2_address; |
| 155 | |
| 156 | /** |
| 157 | * mode on bond interface |
| 158 | */ |
| 159 | mode_t m_mode; |
| 160 | |
| 161 | /** |
| 162 | * lb mode on bond interface |
| 163 | */ |
| 164 | lb_t m_lb; |
| 165 | |
| 166 | /** |
| 167 | * Return the matching 'instance' of the sub-interface |
| 168 | * over-ride from the base class |
| 169 | */ |
| 170 | std::shared_ptr<interface> singular_i() const; |
| 171 | |
| 172 | /** |
| 173 | * Virtual functions to construct an interface create commands. |
| 174 | */ |
| 175 | virtual std::queue<cmd*>& mk_create_cmd(std::queue<cmd*>& cmds); |
| 176 | |
| 177 | /** |
| 178 | * Virtual functions to construct an interface delete commands. |
| 179 | */ |
| 180 | virtual std::queue<cmd*>& mk_delete_cmd(std::queue<cmd*>& cmds); |
| 181 | |
| 182 | /* |
| 183 | * It's the OM class that call singular() |
| 184 | */ |
| 185 | friend class OM; |
| 186 | }; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * fd.io coding-style-patch-verification: ON |
| 191 | * |
| 192 | * Local Variables: |
| 193 | * eval: (c-set-style "mozilla") |
| 194 | * End: |
| 195 | */ |
| 196 | |
| 197 | #endif |