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"
18 #include "vom/nat_binding_cmds.hpp"
21 singular_db<const nat_binding::key_t, nat_binding> nat_binding::m_db;
23 nat_binding::event_handler nat_binding::m_evh;
25 const nat_binding::zone_t nat_binding::zone_t::INSIDE(0, "inside");
26 const nat_binding::zone_t nat_binding::zone_t::OUTSIDE(0, "outside");
28 nat_binding::zone_t::zone_t(int v, const std::string s)
34 * Construct a new object matching the desried state
36 nat_binding::nat_binding(const interface& itf,
37 const direction_t& dir,
38 const l3_proto_t& proto,
41 , m_itf(itf.singular())
48 nat_binding::nat_binding(const nat_binding& o)
49 : m_binding(o.m_binding)
57 nat_binding::~nat_binding()
60 m_db.release(make_tuple(m_itf->key(), m_dir, m_proto), this);
67 if (direction_t::INPUT == m_dir) {
68 HW::enqueue(new nat_binding_cmds::unbind_44_input_cmd(
69 m_binding, m_itf->handle(), m_zone));
71 assert(!"Unimplemented");
81 if (direction_t::INPUT == m_dir) {
82 HW::enqueue(new nat_binding_cmds::bind_44_input_cmd(
83 m_binding, m_itf->handle(), m_zone));
85 assert(!"Unimplemented");
91 nat_binding::update(const nat_binding& desired)
94 * the desired state is always that the interface should be created
97 if (direction_t::INPUT == m_dir) {
98 HW::enqueue(new nat_binding_cmds::bind_44_input_cmd(
99 m_binding, m_itf->handle(), m_zone));
101 assert(!"Unimplemented");
107 nat_binding::to_string() const
109 std::ostringstream s;
110 s << "nat-binding:[" << m_itf->to_string() << " " << m_dir.to_string() << " "
111 << m_proto.to_string() << " " << m_zone.to_string() << "]";
116 std::shared_ptr<nat_binding>
117 nat_binding::find_or_add(const nat_binding& temp)
119 return (m_db.find_or_add(
120 make_tuple(temp.m_itf->key(), temp.m_dir, temp.m_proto), temp));
123 std::shared_ptr<nat_binding>
124 nat_binding::singular() const
126 return find_or_add(*this);
130 nat_binding::dump(std::ostream& os)
136 operator<<(std::ostream& os, const nat_binding::key_t& key)
138 os << "[" << std::get<0>(key) << ", " << std::get<1>(key) << ", "
139 << std::get<2>(key) << "]";
144 nat_binding::event_handler::event_handler()
146 OM::register_listener(this);
147 inspect::register_handler({ "nat-binding" }, "NAT bindings", this);
151 nat_binding::event_handler::handle_replay()
157 nat_binding::event_handler::handle_populate(const client_db::key_t& key)
160 * This is done while populating the interfaces
165 nat_binding::event_handler::order() const
167 return (dependency_t::BINDING);
171 nat_binding::event_handler::show(std::ostream& os)
178 * fd.io coding-style-patch-verification: ON
181 * eval: (c-set-style "mozilla")