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 | #ifndef __VOM_L2_BINDING_H__ |
| 17 | #define __VOM_L2_BINDING_H__ |
| 18 | |
| 19 | #include "vom/bridge_domain.hpp" |
| 20 | #include "vom/hw.hpp" |
| 21 | #include "vom/inspect.hpp" |
| 22 | #include "vom/interface.hpp" |
| 23 | #include "vom/object_base.hpp" |
| 24 | #include "vom/om.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 25 | #include "vom/singular_db.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 26 | |
| 27 | namespace VOM { |
| 28 | /** |
| 29 | * A Clas representing the binding of an L2 interface to a bridge-domain |
| 30 | * and the properties of that binding. |
| 31 | */ |
| 32 | class l2_binding : public object_base |
| 33 | { |
| 34 | public: |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 35 | /** |
| 36 | * Key type for an L2 binding in the singular DB |
| 37 | */ |
| 38 | typedef interface::key_t key_t; |
| 39 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 40 | struct l2_vtr_op_t : public enum_base<l2_vtr_op_t> |
| 41 | { |
| 42 | l2_vtr_op_t(const l2_vtr_op_t& l) = default; |
| 43 | ~l2_vtr_op_t() = default; |
| 44 | |
| 45 | const static l2_vtr_op_t L2_VTR_DISABLED; |
| 46 | const static l2_vtr_op_t L2_VTR_PUSH_1; |
| 47 | const static l2_vtr_op_t L2_VTR_PUSH_2; |
| 48 | const static l2_vtr_op_t L2_VTR_POP_1; |
| 49 | const static l2_vtr_op_t L2_VTR_POP_2; |
| 50 | const static l2_vtr_op_t L2_VTR_TRANSLATE_1_1; |
| 51 | const static l2_vtr_op_t L2_VTR_TRANSLATE_1_2; |
| 52 | const static l2_vtr_op_t L2_VTR_TRANSLATE_2_1; |
| 53 | const static l2_vtr_op_t L2_VTR_TRANSLATE_2_2; |
| 54 | |
| 55 | private: |
| 56 | l2_vtr_op_t(int v, const std::string s); |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * Construct a new object matching the desried state |
| 61 | */ |
| 62 | l2_binding(const interface& itf, const bridge_domain& bd); |
| 63 | |
| 64 | /** |
| 65 | * Copy Constructor |
| 66 | */ |
| 67 | l2_binding(const l2_binding& o); |
| 68 | |
| 69 | /** |
| 70 | * Destructor |
| 71 | */ |
| 72 | ~l2_binding(); |
| 73 | |
| 74 | /** |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 75 | * Return the binding's key |
| 76 | */ |
| 77 | const key_t& key() const; |
| 78 | |
| 79 | /** |
| 80 | * Comparison operator - for UT |
| 81 | */ |
| 82 | bool operator==(const l2_binding& l) const; |
| 83 | |
| 84 | /** |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 85 | * Return the 'singular instance' of the L2 config that matches this |
| 86 | * object |
| 87 | */ |
| 88 | std::shared_ptr<l2_binding> singular() const; |
| 89 | |
| 90 | /** |
| 91 | * convert to string format for debug purposes |
| 92 | */ |
| 93 | std::string to_string() const; |
| 94 | |
| 95 | /** |
| 96 | * Dump all l2_bindings into the stream provided |
| 97 | */ |
| 98 | static void dump(std::ostream& os); |
| 99 | |
| 100 | /** |
| 101 | * Set the VTR operation on the binding/interface |
| 102 | */ |
| 103 | void set(const l2_vtr_op_t& op, uint16_t tag); |
| 104 | |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 105 | /** |
| 106 | * Static function to find the bridge_domain in the model |
| 107 | */ |
| 108 | static std::shared_ptr<l2_binding> find(const key_t& key); |
| 109 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 110 | private: |
| 111 | /** |
| 112 | * Class definition for listeners to OM events |
| 113 | */ |
| 114 | class event_handler : public OM::listener, public inspect::command_handler |
| 115 | { |
| 116 | public: |
| 117 | event_handler(); |
| 118 | virtual ~event_handler() = default; |
| 119 | |
| 120 | /** |
| 121 | * Handle a populate event |
| 122 | */ |
| 123 | void handle_populate(const client_db::key_t& key); |
| 124 | |
| 125 | /** |
| 126 | * Handle a replay event |
| 127 | */ |
| 128 | void handle_replay(); |
| 129 | |
| 130 | /** |
| 131 | * Show the object in the Singular DB |
| 132 | */ |
| 133 | void show(std::ostream& os); |
| 134 | |
| 135 | /** |
| 136 | * Get the sortable Id of the listener |
| 137 | */ |
| 138 | dependency_t order() const; |
| 139 | }; |
| 140 | |
| 141 | /** |
| 142 | * event_handler to register with OM |
| 143 | */ |
| 144 | static event_handler m_evh; |
| 145 | |
| 146 | /** |
| 147 | * Enquue commonds to the VPP command Q for the update |
| 148 | */ |
| 149 | void update(const l2_binding& obj); |
| 150 | |
| 151 | /** |
| 152 | * Find or Add the singular instance in the DB |
| 153 | */ |
| 154 | static std::shared_ptr<l2_binding> find_or_add(const l2_binding& temp); |
| 155 | |
| 156 | /* |
| 157 | * It's the OM class that calls singular() |
| 158 | */ |
| 159 | friend class OM; |
| 160 | |
| 161 | /** |
| 162 | * It's the singular_db class that calls replay() |
| 163 | */ |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 164 | friend class singular_db<key_t, l2_binding>; |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * Sweep/reap the object if still stale |
| 168 | */ |
| 169 | void sweep(void); |
| 170 | |
| 171 | /** |
| 172 | * replay the object to create it in hardware |
| 173 | */ |
| 174 | void replay(void); |
| 175 | |
| 176 | /** |
| 177 | * A reference counting pointer the interface that this L2 layer |
| 178 | * represents. By holding the reference here, we can guarantee that |
| 179 | * this object will outlive the interface |
| 180 | */ |
| 181 | const std::shared_ptr<interface> m_itf; |
| 182 | |
| 183 | /** |
| 184 | * A reference counting pointer the Bridge-Domain that this L2 |
| 185 | * interface is bound to. By holding the reference here, we can |
| 186 | * guarantee that this object will outlive the BD. |
| 187 | */ |
Neale Ranns | 088f0e2 | 2017-12-01 00:19:43 -0800 | [diff] [blame] | 188 | std::shared_ptr<bridge_domain> m_bd; |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * HW configuration for the binding. The bool representing the |
| 192 | * do/don't bind. |
Neale Ranns | 088f0e2 | 2017-12-01 00:19:43 -0800 | [diff] [blame] | 193 | */ |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 194 | HW::item<bool> m_binding; |
| 195 | |
| 196 | /** |
| 197 | * HW configuration for the VTR option |
| 198 | */ |
| 199 | HW::item<l2_vtr_op_t> m_vtr_op; |
| 200 | |
| 201 | /** |
| 202 | * The Dot1q tag for the VTR operation |
| 203 | */ |
| 204 | uint16_t m_vtr_op_tag; |
| 205 | |
| 206 | /** |
| 207 | * A map of all L2 interfaces key against the interface's handle_t |
| 208 | */ |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 209 | static singular_db<key_t, l2_binding> m_db; |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 210 | }; |
| 211 | }; |
| 212 | |
| 213 | /* |
| 214 | * fd.io coding-style-patch-verification: ON |
| 215 | * |
| 216 | * Local Variables: |
| 217 | * eval: (c-set-style "mozilla") |
| 218 | * End: |
| 219 | */ |
| 220 | |
| 221 | #endif |