Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [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_GBP_ENDPOINT_H__ |
| 17 | #define __VOM_GBP_ENDPOINT_H__ |
| 18 | |
| 19 | #include "vom/interface.hpp" |
| 20 | #include "vom/singular_db.hpp" |
| 21 | #include "vom/types.hpp" |
| 22 | |
| 23 | namespace VOM { |
| 24 | |
| 25 | /** |
| 26 | * EPG IDs are 32 bit integers |
| 27 | */ |
| 28 | typedef uint32_t epg_id_t; |
| 29 | |
| 30 | /** |
| 31 | * A entry in the ARP termination table of a Bridge Domain |
| 32 | */ |
| 33 | class gbp_endpoint : public object_base |
| 34 | { |
| 35 | public: |
| 36 | /** |
| 37 | * The key for a GBP endpoint; interface and IP |
| 38 | */ |
| 39 | typedef std::pair<interface::key_t, boost::asio::ip::address> key_t; |
| 40 | |
| 41 | /** |
| 42 | * Construct a GBP endpoint |
| 43 | */ |
| 44 | gbp_endpoint(const interface& itf, |
| 45 | const boost::asio::ip::address& ip_addr, |
| 46 | epg_id_t epg_id); |
| 47 | |
| 48 | /** |
| 49 | * Copy Construct |
| 50 | */ |
| 51 | gbp_endpoint(const gbp_endpoint& r); |
| 52 | |
| 53 | /** |
| 54 | * Destructor |
| 55 | */ |
| 56 | ~gbp_endpoint(); |
| 57 | |
| 58 | /** |
| 59 | * Return the object's key |
| 60 | */ |
| 61 | const key_t key() const; |
| 62 | |
| 63 | /** |
| 64 | * comparison operator |
| 65 | */ |
| 66 | bool operator==(const gbp_endpoint& bdae) const; |
| 67 | |
| 68 | /** |
| 69 | * Return the matching 'singular instance' |
| 70 | */ |
| 71 | std::shared_ptr<gbp_endpoint> singular() const; |
| 72 | |
| 73 | /** |
| 74 | * Find the instnace of the bridge_domain domain in the OM |
| 75 | */ |
| 76 | static std::shared_ptr<gbp_endpoint> find(const key_t& k); |
| 77 | |
| 78 | /** |
| 79 | * Dump all bridge_domain-doamin into the stream provided |
| 80 | */ |
| 81 | static void dump(std::ostream& os); |
| 82 | |
| 83 | /** |
| 84 | * replay the object to create it in hardware |
| 85 | */ |
| 86 | void replay(void); |
| 87 | |
| 88 | /** |
| 89 | * Convert to string for debugging |
| 90 | */ |
| 91 | std::string to_string() const; |
| 92 | |
| 93 | private: |
| 94 | /** |
| 95 | * Class definition for listeners to OM events |
| 96 | */ |
| 97 | class event_handler : public OM::listener, public inspect::command_handler |
| 98 | { |
| 99 | public: |
| 100 | event_handler(); |
| 101 | virtual ~event_handler() = default; |
| 102 | |
| 103 | /** |
| 104 | * Handle a populate event |
| 105 | */ |
| 106 | void handle_populate(const client_db::key_t& key); |
| 107 | |
| 108 | /** |
| 109 | * Handle a replay event |
| 110 | */ |
| 111 | void handle_replay(); |
| 112 | |
| 113 | /** |
| 114 | * Show the object in the Singular DB |
| 115 | */ |
| 116 | void show(std::ostream& os); |
| 117 | |
| 118 | /** |
| 119 | * Get the sortable Id of the listener |
| 120 | */ |
| 121 | dependency_t order() const; |
| 122 | }; |
| 123 | |
| 124 | /** |
| 125 | * event_handler to register with OM |
| 126 | */ |
| 127 | static event_handler m_evh; |
| 128 | |
| 129 | /** |
| 130 | * Commit the acculmulated changes into VPP. i.e. to a 'HW" write. |
| 131 | */ |
| 132 | void update(const gbp_endpoint& obj); |
| 133 | |
| 134 | /** |
| 135 | * Find or add the instnace of the bridge_domain domain in the OM |
| 136 | */ |
| 137 | static std::shared_ptr<gbp_endpoint> find_or_add(const gbp_endpoint& temp); |
| 138 | |
| 139 | /* |
| 140 | * It's the VPPHW class that updates the objects in HW |
| 141 | */ |
| 142 | friend class OM; |
| 143 | |
| 144 | /** |
| 145 | * It's the singular_db class that calls replay() |
| 146 | */ |
| 147 | friend class singular_db<key_t, gbp_endpoint>; |
| 148 | |
| 149 | /** |
| 150 | * Sweep/reap the object if still stale |
| 151 | */ |
| 152 | void sweep(void); |
| 153 | |
| 154 | /** |
| 155 | * HW configuration for the result of creating the endpoint |
| 156 | */ |
| 157 | HW::item<bool> m_hw; |
| 158 | |
| 159 | /** |
| 160 | * The interface the endpoint is attached to. |
| 161 | */ |
| 162 | std::shared_ptr<interface> m_itf; |
| 163 | |
| 164 | /** |
| 165 | * The IP address of the endpoint |
| 166 | */ |
| 167 | boost::asio::ip::address m_ip_addr; |
| 168 | |
| 169 | /** |
| 170 | * The EPG ID |
| 171 | */ |
| 172 | epg_id_t m_epg_id; |
| 173 | |
| 174 | /** |
| 175 | * A map of all bridge_domains |
| 176 | */ |
| 177 | static singular_db<key_t, gbp_endpoint> m_db; |
| 178 | }; |
| 179 | |
| 180 | std::ostream& operator<<(std::ostream& os, const gbp_endpoint::key_t& key); |
| 181 | }; // namespace |
| 182 | |
| 183 | /* |
| 184 | * fd.io coding-style-patch-verification: ON |
| 185 | * |
| 186 | * Local Variables: |
| 187 | * eval: (c-set-style "mozilla") |
| 188 | * End: |
| 189 | */ |
| 190 | |
| 191 | #endif |