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_LLDP_BINDING_H__ |
| 17 | #define __VOM_LLDP_BINDING_H__ |
| 18 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 19 | #include "vom/hw.hpp" |
| 20 | #include "vom/inspect.hpp" |
| 21 | #include "vom/interface.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" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 25 | |
| 26 | namespace VOM { |
| 27 | /** |
| 28 | * A representation of LLDP client configuration on an interface |
| 29 | */ |
| 30 | class lldp_binding : public object_base |
| 31 | { |
| 32 | public: |
| 33 | /** |
| 34 | * Construct a new object matching the desried state |
| 35 | */ |
| 36 | lldp_binding(const interface& itf, const std::string& hostname); |
| 37 | |
| 38 | /** |
| 39 | * Copy Constructor |
| 40 | */ |
| 41 | lldp_binding(const lldp_binding& o); |
| 42 | /** |
| 43 | * Destructor |
| 44 | */ |
| 45 | ~lldp_binding(); |
| 46 | |
| 47 | /** |
| 48 | * Return the 'singular' of the LLDP binding that matches this object |
| 49 | */ |
| 50 | std::shared_ptr<lldp_binding> singular() const; |
| 51 | |
| 52 | /** |
| 53 | * convert to string format for debug purposes |
| 54 | */ |
| 55 | std::string to_string() const; |
| 56 | |
| 57 | /** |
| 58 | * Dump all LLDP bindings into the stream provided |
| 59 | */ |
| 60 | static void dump(std::ostream& os); |
| 61 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 62 | private: |
| 63 | /** |
| 64 | * Class definition for listeners to OM events |
| 65 | */ |
| 66 | class event_handler : public OM::listener, public inspect::command_handler |
| 67 | { |
| 68 | public: |
| 69 | event_handler(); |
| 70 | virtual ~event_handler() = default; |
| 71 | |
| 72 | /** |
| 73 | * Handle a populate event |
| 74 | */ |
| 75 | void handle_populate(const client_db::key_t& key); |
| 76 | |
| 77 | /** |
| 78 | * Handle a replay event |
| 79 | */ |
| 80 | void handle_replay(); |
| 81 | |
| 82 | /** |
| 83 | * Show the object in the Singular DB |
| 84 | */ |
| 85 | void show(std::ostream& os); |
| 86 | |
| 87 | /** |
| 88 | * Get the sortable Id of the listener |
| 89 | */ |
| 90 | dependency_t order() const; |
| 91 | }; |
| 92 | |
| 93 | /** |
| 94 | * event_handler to register with OM |
| 95 | */ |
| 96 | static event_handler m_evh; |
| 97 | |
| 98 | /** |
| 99 | * Enquue commonds to the VPP command Q for the update |
| 100 | */ |
| 101 | void update(const lldp_binding& obj); |
| 102 | |
| 103 | /** |
| 104 | * Find or add LLDP binding to the OM |
| 105 | */ |
| 106 | static std::shared_ptr<lldp_binding> find_or_add(const lldp_binding& temp); |
| 107 | |
| 108 | /* |
| 109 | * It's the OM class that calls singular() |
| 110 | */ |
| 111 | friend class OM; |
| 112 | |
| 113 | /** |
| 114 | * It's the singular_db class that calls replay() |
| 115 | */ |
| 116 | friend class singular_db<interface::key_type, lldp_binding>; |
| 117 | |
| 118 | /** |
| 119 | * Sweep/reap the object if still stale |
| 120 | */ |
| 121 | void sweep(void); |
| 122 | |
| 123 | /** |
| 124 | * replay the object to create it in hardware |
| 125 | */ |
| 126 | void replay(void); |
| 127 | |
| 128 | /** |
| 129 | * A reference counting pointer to the interface on which LLDP config |
| 130 | * resides. By holding the reference here, we can guarantee that |
| 131 | * this object will outlive the interface |
| 132 | */ |
| 133 | const std::shared_ptr<interface> m_itf; |
| 134 | |
| 135 | /** |
| 136 | * The port-description in the LLDP configuration |
| 137 | */ |
| 138 | const std::string m_port_desc; |
| 139 | |
| 140 | /** |
| 141 | * HW configuration for the binding. The bool representing the |
| 142 | * do/don't bind. |
| 143 | */ |
| 144 | HW::item<bool> m_binding; |
| 145 | |
| 146 | /** |
| 147 | * A map of all Lldp bindings keyed against the interface. |
| 148 | */ |
| 149 | static singular_db<interface::key_type, lldp_binding> m_db; |
| 150 | }; |
| 151 | }; |
| 152 | |
| 153 | /* |
| 154 | * fd.io coding-style-patch-verification: ON |
| 155 | * |
| 156 | * Local Variables: |
| 157 | * eval: (c-set-style "mozilla") |
| 158 | * End: |
| 159 | */ |
| 160 | |
| 161 | #endif |