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_BRIDGE_DOMAIN_H__ |
| 17 | #define __VOM_BRIDGE_DOMAIN_H__ |
| 18 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 19 | #include "vom/enum_base.hpp" |
| 20 | #include "vom/hw.hpp" |
| 21 | #include "vom/inspect.hpp" |
| 22 | #include "vom/object_base.hpp" |
| 23 | #include "vom/om.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 24 | #include "vom/singular_db.hpp" |
| 25 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 26 | namespace VOM { |
| 27 | /** |
| 28 | * A base class for all object_base in the VPP object_base-Model. |
| 29 | * provides the abstract interface. |
| 30 | */ |
| 31 | class bridge_domain : public object_base |
| 32 | { |
| 33 | public: |
| 34 | /** |
| 35 | * The value of the defaultbridge domain |
| 36 | */ |
| 37 | const static uint32_t DEFAULT_TABLE = 0; |
| 38 | |
| 39 | /** |
| 40 | * Construct a new object matching the desried state |
| 41 | */ |
| 42 | bridge_domain(uint32_t id); |
| 43 | /** |
| 44 | * Copy Constructor |
| 45 | */ |
| 46 | bridge_domain(const bridge_domain& o); |
| 47 | /** |
| 48 | * Destructor |
| 49 | */ |
| 50 | ~bridge_domain(); |
| 51 | |
| 52 | /** |
| 53 | * Return the matchin 'singular' instance of the bridge-domain |
| 54 | */ |
| 55 | std::shared_ptr<bridge_domain> singular() const; |
| 56 | |
| 57 | /** |
| 58 | * convert to string format for debug purposes |
| 59 | */ |
| 60 | std::string to_string(void) const; |
| 61 | |
| 62 | /** |
| 63 | * Return VPP's handle for this obejct |
| 64 | */ |
| 65 | uint32_t id() const; |
| 66 | |
| 67 | /** |
| 68 | * Static function to find the bridge_domain in the model |
| 69 | */ |
| 70 | static std::shared_ptr<bridge_domain> find(uint32_t id); |
| 71 | |
| 72 | /** |
| 73 | * Dump all bridge-doamin into the stream provided |
| 74 | */ |
| 75 | static void dump(std::ostream& os); |
| 76 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 77 | private: |
| 78 | /** |
| 79 | * Class definition for listeners to OM events |
| 80 | */ |
| 81 | class event_handler : public OM::listener, public inspect::command_handler |
| 82 | { |
| 83 | public: |
| 84 | event_handler(); |
| 85 | virtual ~event_handler() = default; |
| 86 | |
| 87 | /** |
| 88 | * Handle a populate event |
| 89 | */ |
| 90 | void handle_populate(const client_db::key_t& key); |
| 91 | |
| 92 | /** |
| 93 | * Handle a replay event |
| 94 | */ |
| 95 | void handle_replay(); |
| 96 | |
| 97 | /** |
| 98 | * Show the object in the Singular DB |
| 99 | */ |
| 100 | void show(std::ostream& os); |
| 101 | |
| 102 | /** |
| 103 | * Get the sortable Id of the listener |
| 104 | */ |
| 105 | dependency_t order() const; |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | * Instance of the event handler to register with OM |
| 110 | */ |
| 111 | static event_handler m_evh; |
| 112 | |
| 113 | /** |
| 114 | * Commit the acculmulated changes into VPP. i.e. to a 'HW" write. |
| 115 | */ |
| 116 | void update(const bridge_domain& obj); |
| 117 | |
| 118 | /** |
| 119 | * Find or add an singular of a Bridge-Domain in the object_base Model |
| 120 | */ |
| 121 | static std::shared_ptr<bridge_domain> find_or_add(const bridge_domain& temp); |
| 122 | |
| 123 | /* |
| 124 | * It's the OM class that calls singular() |
| 125 | */ |
| 126 | friend class OM; |
| 127 | |
| 128 | /** |
| 129 | * It's the singular_db class that calls replay() |
| 130 | */ |
| 131 | friend class singular_db<uint32_t, bridge_domain>; |
| 132 | |
| 133 | /** |
| 134 | * Sweep/reap the object if still stale |
| 135 | */ |
| 136 | void sweep(void); |
| 137 | |
| 138 | /** |
| 139 | * replay the object to create it in hardware |
| 140 | */ |
| 141 | void replay(void); |
| 142 | |
| 143 | /** |
| 144 | * The ID we assign to this BD and the HW result in VPP |
| 145 | */ |
| 146 | HW::item<uint32_t> m_id; |
| 147 | |
| 148 | /** |
| 149 | * A map of all interfaces key against the interface's name |
| 150 | */ |
| 151 | static singular_db<uint32_t, bridge_domain> m_db; |
| 152 | }; |
| 153 | }; |
| 154 | |
| 155 | /* |
| 156 | * fd.io coding-style-patch-verification: ON |
| 157 | * |
| 158 | * Local Variables: |
| 159 | * eval: (c-set-style "mozilla") |
| 160 | * End: |
| 161 | */ |
| 162 | |
| 163 | #endif |