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