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 | #include "vom/ip_unnumbered.hpp" |
| 17 | #include "vom/cmd.hpp" |
| 18 | |
| 19 | namespace VOM { |
| 20 | /** |
| 21 | * A DB of all LLDP configs |
| 22 | */ |
| 23 | singular_db<ip_unnumbered::key_t, ip_unnumbered> ip_unnumbered::m_db; |
| 24 | |
| 25 | ip_unnumbered::event_handler ip_unnumbered::m_evh; |
| 26 | |
| 27 | ip_unnumbered::ip_unnumbered(const interface& itf, const interface& l3_itf) |
| 28 | : m_itf(itf.singular()) |
| 29 | , m_l3_itf(l3_itf.singular()) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | ip_unnumbered::ip_unnumbered(const ip_unnumbered& o) |
| 34 | : m_itf(o.m_itf) |
| 35 | , m_l3_itf(o.m_l3_itf) |
| 36 | , m_config(o.m_config) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | ip_unnumbered::~ip_unnumbered() |
| 41 | { |
| 42 | sweep(); |
| 43 | |
| 44 | // not in the DB anymore. |
| 45 | m_db.release(m_itf->key(), this); |
| 46 | } |
| 47 | |
| 48 | void |
| 49 | ip_unnumbered::sweep() |
| 50 | { |
| 51 | if (m_config) { |
| 52 | HW::enqueue( |
| 53 | new unconfig_cmd(m_config, m_itf->handle(), m_l3_itf->handle())); |
| 54 | } |
| 55 | HW::write(); |
| 56 | } |
| 57 | |
| 58 | void |
| 59 | ip_unnumbered::dump(std::ostream& os) |
| 60 | { |
| 61 | m_db.dump(os); |
| 62 | } |
| 63 | |
| 64 | void |
| 65 | ip_unnumbered::replay() |
| 66 | { |
| 67 | if (m_config) { |
| 68 | HW::enqueue(new config_cmd(m_config, m_itf->handle(), m_l3_itf->handle())); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | std::string |
| 73 | ip_unnumbered::to_string() const |
| 74 | { |
| 75 | std::ostringstream s; |
| 76 | s << "IP Unnumbered-config:" |
| 77 | << " itf:" << m_itf->to_string() << " l3-itf:" << m_l3_itf->to_string(); |
| 78 | |
| 79 | return (s.str()); |
| 80 | } |
| 81 | |
| 82 | void |
| 83 | ip_unnumbered::update(const ip_unnumbered& desired) |
| 84 | { |
| 85 | if (!m_config) { |
| 86 | HW::enqueue(new config_cmd(m_config, m_itf->handle(), m_l3_itf->handle())); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | std::shared_ptr<ip_unnumbered> |
| 91 | ip_unnumbered::find_or_add(const ip_unnumbered& temp) |
| 92 | { |
| 93 | return (m_db.find_or_add(temp.m_itf->key(), temp)); |
| 94 | } |
| 95 | |
| 96 | std::shared_ptr<ip_unnumbered> |
| 97 | ip_unnumbered::singular() const |
| 98 | { |
| 99 | return find_or_add(*this); |
| 100 | } |
| 101 | |
| 102 | ip_unnumbered::event_handler::event_handler() |
| 103 | { |
| 104 | OM::register_listener(this); |
| 105 | inspect::register_handler({ "ip-un" }, "IP unnumbered configurations", this); |
| 106 | } |
| 107 | |
| 108 | void |
| 109 | ip_unnumbered::event_handler::handle_replay() |
| 110 | { |
| 111 | m_db.replay(); |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | ip_unnumbered::event_handler::handle_populate(const client_db::key_t& key) |
| 116 | { |
| 117 | // VPP provides no dump for IP unnumbered |
| 118 | } |
| 119 | |
| 120 | dependency_t |
| 121 | ip_unnumbered::event_handler::order() const |
| 122 | { |
| 123 | return (dependency_t::BINDING); |
| 124 | } |
| 125 | |
| 126 | void |
| 127 | ip_unnumbered::event_handler::show(std::ostream& os) |
| 128 | { |
| 129 | m_db.dump(os); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | * fd.io coding-style-patch-verification: ON |
| 135 | * |
| 136 | * Local Variables: |
| 137 | * eval: (c-set-style "mozilla") |
| 138 | * End: |
| 139 | */ |