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/gbp_contract.hpp"
17 #include "vom/gbp_contract_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
22 singular_db<gbp_contract::key_t, gbp_contract> gbp_contract::m_db;
24 gbp_contract::event_handler gbp_contract::m_evh;
26 gbp_contract::gbp_contract(epg_id_t src_epg_id,
28 const ACL::l3_list& acl)
30 , m_src_epg_id(src_epg_id)
31 , m_dst_epg_id(dst_epg_id)
32 , m_acl(acl.singular())
36 gbp_contract::gbp_contract(const gbp_contract& gbpc)
38 , m_src_epg_id(gbpc.m_src_epg_id)
39 , m_dst_epg_id(gbpc.m_dst_epg_id)
44 gbp_contract::~gbp_contract()
48 // not in the DB anymore.
49 m_db.release(key(), this);
52 const gbp_contract::key_t
53 gbp_contract::key() const
55 return (std::make_pair(m_src_epg_id, m_dst_epg_id));
59 gbp_contract::operator==(const gbp_contract& gbpc) const
61 return ((key() == gbpc.key()) && (m_acl->handle() == gbpc.m_acl->handle()));
69 new gbp_contract_cmds::delete_cmd(m_hw, m_src_epg_id, m_dst_epg_id));
75 gbp_contract::replay()
78 HW::enqueue(new gbp_contract_cmds::create_cmd(
79 m_hw, m_src_epg_id, m_dst_epg_id, m_acl->handle()));
84 gbp_contract::to_string() const
87 s << "gbp-contract:[{" << m_src_epg_id << ", " << m_dst_epg_id << "}, "
88 << m_acl->to_string() << "]";
94 gbp_contract::update(const gbp_contract& r)
97 * create the table if it is not yet created
99 if (rc_t::OK != m_hw.rc()) {
100 HW::enqueue(new gbp_contract_cmds::create_cmd(
101 m_hw, m_src_epg_id, m_dst_epg_id, m_acl->handle()));
105 std::shared_ptr<gbp_contract>
106 gbp_contract::find_or_add(const gbp_contract& temp)
108 return (m_db.find_or_add(temp.key(), temp));
111 std::shared_ptr<gbp_contract>
112 gbp_contract::find(const key_t& k)
114 return (m_db.find(k));
117 std::shared_ptr<gbp_contract>
118 gbp_contract::singular() const
120 return find_or_add(*this);
124 gbp_contract::dump(std::ostream& os)
129 gbp_contract::event_handler::event_handler()
131 OM::register_listener(this);
132 inspect::register_handler({ "gbp-contract" }, "GBP Contract", this);
136 gbp_contract::event_handler::handle_replay()
142 gbp_contract::event_handler::handle_populate(const client_db::key_t& key)
144 std::shared_ptr<gbp_contract_cmds::dump_cmd> cmd =
145 std::make_shared<gbp_contract_cmds::dump_cmd>();
150 for (auto& record : *cmd) {
151 auto& payload = record.get_payload();
153 std::shared_ptr<ACL::l3_list> acl =
154 ACL::l3_list::find(payload.contract.acl_index);
157 gbp_contract gbpc(payload.contract.src_epg, payload.contract.dst_epg,
159 OM::commit(key, gbpc);
161 VOM_LOG(log_level_t::DEBUG) << "read: " << gbpc.to_string();
167 gbp_contract::event_handler::order() const
169 return (dependency_t::ENTRY);
173 gbp_contract::event_handler::show(std::ostream& os)
179 operator<<(std::ostream& os, const gbp_contract::key_t& key)
181 os << "{ " << key.first << "," << key.second << "}";
189 * fd.io coding-style-patch-verification: ON
192 * eval: (c-set-style "mozilla")