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/arp_proxy_config.hpp" |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 17 | #include "vom/arp_proxy_config_cmds.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 18 | |
| 19 | namespace VOM { |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 20 | singular_db<arp_proxy_config::key_t, arp_proxy_config> arp_proxy_config::m_db; |
| 21 | |
| 22 | arp_proxy_config::event_handler arp_proxy_config::m_evh; |
| 23 | |
| 24 | arp_proxy_config::arp_proxy_config(const boost::asio::ip::address_v4& low, |
| 25 | const boost::asio::ip::address_v4& high) |
| 26 | : m_low(low) |
| 27 | , m_high(high) |
| 28 | , m_config(true) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | arp_proxy_config::arp_proxy_config(const arp_proxy_config& o) |
| 33 | : m_low(o.m_low) |
| 34 | , m_high(o.m_high) |
| 35 | , m_config(o.m_config) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | arp_proxy_config::~arp_proxy_config() |
| 40 | { |
| 41 | sweep(); |
| 42 | |
| 43 | // not in the DB anymore. |
| 44 | m_db.release(std::make_pair(m_low, m_high), this); |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | arp_proxy_config::sweep() |
| 49 | { |
| 50 | if (m_config) { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 51 | HW::enqueue( |
| 52 | new arp_proxy_config_cmds::unconfig_cmd(m_config, m_low, m_high)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 53 | } |
| 54 | HW::write(); |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | arp_proxy_config::dump(std::ostream& os) |
| 59 | { |
| 60 | m_db.dump(os); |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | arp_proxy_config::replay() |
| 65 | { |
| 66 | if (m_config) { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 67 | HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | std::string |
| 72 | arp_proxy_config::to_string() const |
| 73 | { |
| 74 | std::ostringstream s; |
| 75 | s << "ARP-proxy:" |
| 76 | << " low:" << m_low.to_string() << " high:" << m_high.to_string(); |
| 77 | |
| 78 | return (s.str()); |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | arp_proxy_config::update(const arp_proxy_config& desired) |
| 83 | { |
| 84 | if (!m_config) { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 85 | HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | std::shared_ptr<arp_proxy_config> |
| 90 | arp_proxy_config::find_or_add(const arp_proxy_config& temp) |
| 91 | { |
| 92 | return (m_db.find_or_add(std::make_pair(temp.m_low, temp.m_high), temp)); |
| 93 | } |
| 94 | |
| 95 | std::shared_ptr<arp_proxy_config> |
| 96 | arp_proxy_config::singular() const |
| 97 | { |
| 98 | return find_or_add(*this); |
| 99 | } |
| 100 | |
| 101 | arp_proxy_config::event_handler::event_handler() |
| 102 | { |
| 103 | OM::register_listener(this); |
| 104 | inspect::register_handler({ "arp-proxy" }, "ARP Proxy configurations", this); |
| 105 | } |
| 106 | |
| 107 | void |
| 108 | arp_proxy_config::event_handler::handle_replay() |
| 109 | { |
| 110 | m_db.replay(); |
| 111 | } |
| 112 | |
| 113 | void |
| 114 | arp_proxy_config::event_handler::handle_populate(const client_db::key_t& key) |
| 115 | { |
| 116 | // VPP provides no dump for ARP proxy. |
| 117 | } |
| 118 | |
| 119 | dependency_t |
| 120 | arp_proxy_config::event_handler::order() const |
| 121 | { |
| 122 | return (dependency_t::GLOBAL); |
| 123 | } |
| 124 | |
| 125 | void |
| 126 | arp_proxy_config::event_handler::show(std::ostream& os) |
| 127 | { |
| 128 | m_db.dump(os); |
| 129 | } |
| 130 | |
| 131 | std::ostream& |
| 132 | operator<<(std::ostream& os, const arp_proxy_config::key_t& key) |
| 133 | { |
| 134 | os << "[" << key.first << ", " << key.second << "]"; |
| 135 | |
| 136 | return (os); |
| 137 | } |
| 138 | } |
| 139 | /* |
| 140 | * fd.io coding-style-patch-verification: ON |
| 141 | * |
| 142 | * Local Variables: |
| 143 | * eval: (c-set-style "mozilla") |
| 144 | * End: |
| 145 | */ |