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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "vom/nat_static.hpp"
19 singular_db<nat_static::key_t, nat_static> nat_static::m_db;
20 nat_static::event_handler nat_static::m_evh;
22 nat_static::nat_static(const boost::asio::ip::address& inside,
23 const boost::asio::ip::address_v4& outside)
25 , m_rd(route_domain::get_default())
31 nat_static::nat_static(const route_domain& rd,
32 const boost::asio::ip::address& inside,
33 const boost::asio::ip::address_v4& outside)
41 nat_static::nat_static(const nat_static& ns)
44 , m_inside(ns.m_inside)
45 , m_outside(ns.m_outside)
49 nat_static::~nat_static()
53 // not in the DB anymore.
54 m_db.release(std::make_pair(m_rd->key(), m_outside), this);
61 if (m_inside.is_v4()) {
63 new delete_44_cmd(m_hw, m_rd->table_id(), m_inside.to_v4(), m_outside));
73 if (m_inside.is_v4()) {
75 new create_44_cmd(m_hw, m_rd->table_id(), m_inside.to_v4(), m_outside));
81 nat_static::update(const nat_static& r)
84 * create the table if it is not yet created
86 if (rc_t::OK != m_hw.rc()) {
87 if (m_inside.is_v4()) {
89 new create_44_cmd(m_hw, m_rd->table_id(), m_inside.to_v4(), m_outside));
95 nat_static::to_string() const
99 << "table:" << m_rd->to_string() << " inside: " << m_inside.to_string()
100 << " outside " << m_outside.to_string() << "]";
105 std::shared_ptr<nat_static>
106 nat_static::find_or_add(const nat_static& temp)
109 m_db.find_or_add(std::make_pair(temp.m_rd->key(), temp.m_outside), temp));
112 std::shared_ptr<nat_static>
113 nat_static::singular() const
115 return find_or_add(*this);
119 nat_static::dump(std::ostream& os)
125 operator<<(std::ostream& os, const nat_static::key_t& key)
127 os << "[" << key.first << ", " << key.second << "]";
132 nat_static::event_handler::event_handler()
134 OM::register_listener(this);
135 inspect::register_handler({ "nat-static" }, "NAT Statics", this);
139 nat_static::event_handler::handle_replay()
144 /* void nat_static::populate_i(const client_db::key_t &key, */
145 /* std::shared_ptr<interface> itf, */
146 /* const l3_proto_t &proto) */
149 /* * dump VPP current states */
151 /* std::shared_ptr<nat_static::dump_cmd> cmd = */
152 /* std::make_shared<nat_static::dump_cmd>(nat_static::dump_cmd(itf->handle(),
155 /* HW::enqueue(cmd); */
158 /* for (auto & record : *cmd) */
161 /* * construct a nat_static from each recieved record. */
163 /* auto &payload = record.get_payload(); */
165 /* mac_address_t mac(payload.mac_address); */
166 /* boost::asio::ip::address ip_addr = from_bytes(payload.is_ipv6, */
167 /* payload.ip_address);
169 /* nat_static n(*itf, mac, ip_addr); */
171 /* VOM_LOG(log_level_t::DEBUG) << "nat_static-dump: " */
172 /* << itf->to_string() */
173 /* << mac.to_string() */
174 /* << ip_addr.to_string(); */
177 /* * Write each of the discovered interfaces into the OM, */
178 /* * but disable the HW Command q whilst we do, so that no */
179 /* * commands are sent to VPP */
181 /* OM::commit(key, n); */
186 nat_static::event_handler::handle_populate(const client_db::key_t& key)
188 /* auto it = interface::cbegin(); */
190 /* while (it != interface::cend()) */
192 /* nat_static::populate_i(key, it->second.lock(), l3_proto_t::IPV4);
194 /* nat_static::populate_i(key, it->second.lock(), l3_proto_t::IPV6);
202 nat_static::event_handler::order() const
204 return (dependency_t::ENTRY);
208 nat_static::event_handler::show(std::ostream& os)
215 * fd.io coding-style-patch-verification: ON
218 * eval: (c-set-style "mozilla")