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_binding.hpp"
17 #include "vom/cmd.hpp"
20 singular_db<const nat_binding::key_t, nat_binding> nat_binding::m_db;
22 nat_binding::event_handler nat_binding::m_evh;
24 const nat_binding::zone_t nat_binding::zone_t::INSIDE(0, "inside");
25 const nat_binding::zone_t nat_binding::zone_t::OUTSIDE(0, "outside");
27 nat_binding::zone_t::zone_t(int v, const std::string s)
33 * Construct a new object matching the desried state
35 nat_binding::nat_binding(const interface& itf,
36 const direction_t& dir,
37 const l3_proto_t& proto,
40 , m_itf(itf.singular())
47 nat_binding::nat_binding(const nat_binding& o)
48 : m_binding(o.m_binding)
56 nat_binding::~nat_binding()
59 m_db.release(make_tuple(m_itf->key(), m_dir, m_proto), this);
66 if (direction_t::INPUT == m_dir) {
67 HW::enqueue(new unbind_44_input_cmd(m_binding, m_itf->handle(), m_zone));
69 assert(!"Unimplemented");
79 if (direction_t::INPUT == m_dir) {
80 HW::enqueue(new bind_44_input_cmd(m_binding, m_itf->handle(), m_zone));
82 assert(!"Unimplemented");
88 nat_binding::update(const nat_binding& desired)
91 * the desired state is always that the interface should be created
94 if (direction_t::INPUT == m_dir) {
95 HW::enqueue(new bind_44_input_cmd(m_binding, m_itf->handle(), m_zone));
97 assert(!"Unimplemented");
103 nat_binding::to_string() const
105 std::ostringstream s;
106 s << "nat-binding:[" << m_itf->to_string() << " " << m_dir.to_string() << " "
107 << m_proto.to_string() << " " << m_zone.to_string() << "]";
112 std::shared_ptr<nat_binding>
113 nat_binding::find_or_add(const nat_binding& temp)
115 return (m_db.find_or_add(
116 make_tuple(temp.m_itf->key(), temp.m_dir, temp.m_proto), temp));
119 std::shared_ptr<nat_binding>
120 nat_binding::singular() const
122 return find_or_add(*this);
126 nat_binding::dump(std::ostream& os)
132 operator<<(std::ostream& os, const nat_binding::key_t& key)
134 os << "[" << std::get<0>(key) << ", " << std::get<1>(key) << ", "
135 << std::get<2>(key) << "]";
140 nat_binding::event_handler::event_handler()
142 OM::register_listener(this);
143 inspect::register_handler({ "nat-binding" }, "NAT bindings", this);
147 nat_binding::event_handler::handle_replay()
153 nat_binding::event_handler::handle_populate(const client_db::key_t& key)
156 * This is done while populating the interfaces
161 nat_binding::event_handler::order() const
163 return (dependency_t::BINDING);
167 nat_binding::event_handler::show(std::ostream& os)
174 * fd.io coding-style-patch-verification: ON
177 * eval: (c-set-style "mozilla")