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"
21 singular_db<gbp_contract::key_t, gbp_contract> gbp_contract::m_db;
23 gbp_contract::event_handler gbp_contract::m_evh;
25 gbp_contract::gbp_contract(epg_id_t src_epg_id,
27 const ACL::l3_list& acl)
29 , m_src_epg_id(src_epg_id)
30 , m_dst_epg_id(dst_epg_id)
31 , m_acl(acl.singular())
35 gbp_contract::gbp_contract(const gbp_contract& gbpc)
37 , m_src_epg_id(gbpc.m_src_epg_id)
38 , m_dst_epg_id(gbpc.m_dst_epg_id)
43 gbp_contract::~gbp_contract()
47 // not in the DB anymore.
48 m_db.release(key(), this);
51 const gbp_contract::key_t
52 gbp_contract::key() const
54 return (std::make_pair(m_src_epg_id, m_dst_epg_id));
58 gbp_contract::operator==(const gbp_contract& gbpc) const
60 return ((key() == gbpc.key()) && (m_acl->handle() == gbpc.m_acl->handle()));
68 new gbp_contract_cmds::delete_cmd(m_hw, m_src_epg_id, m_dst_epg_id));
74 gbp_contract::replay()
77 HW::enqueue(new gbp_contract_cmds::create_cmd(
78 m_hw, m_src_epg_id, m_dst_epg_id, m_acl->handle()));
83 gbp_contract::to_string() const
86 s << "gbp-contract:[{" << m_src_epg_id << ", " << m_dst_epg_id << "}, "
87 << m_acl->to_string() << "]";
93 gbp_contract::update(const gbp_contract& r)
96 * create the table if it is not yet created
98 if (rc_t::OK != m_hw.rc()) {
99 HW::enqueue(new gbp_contract_cmds::create_cmd(
100 m_hw, m_src_epg_id, m_dst_epg_id, m_acl->handle()));
104 std::shared_ptr<gbp_contract>
105 gbp_contract::find_or_add(const gbp_contract& temp)
107 return (m_db.find_or_add(temp.key(), temp));
110 std::shared_ptr<gbp_contract>
111 gbp_contract::find(const key_t& k)
113 return (m_db.find(k));
116 std::shared_ptr<gbp_contract>
117 gbp_contract::singular() const
119 return find_or_add(*this);
123 gbp_contract::dump(std::ostream& os)
128 gbp_contract::event_handler::event_handler()
130 OM::register_listener(this);
131 inspect::register_handler({ "gbp-contract" }, "GBP Contract", this);
135 gbp_contract::event_handler::handle_replay()
141 gbp_contract::event_handler::handle_populate(const client_db::key_t& key)
143 std::shared_ptr<gbp_contract_cmds::dump_cmd> cmd =
144 std::make_shared<gbp_contract_cmds::dump_cmd>();
149 for (auto& record : *cmd) {
150 auto& payload = record.get_payload();
152 std::shared_ptr<ACL::l3_list> acl =
153 ACL::l3_list::find(payload.contract.acl_index);
156 gbp_contract gbpc(payload.contract.src_epg, payload.contract.dst_epg,
158 OM::commit(key, gbpc);
160 VOM_LOG(log_level_t::DEBUG) << "read: " << gbpc.to_string();
166 gbp_contract::event_handler::order() const
168 return (dependency_t::ENTRY);
172 gbp_contract::event_handler::show(std::ostream& os)
178 operator<<(std::ostream& os, const gbp_contract::key_t& key)
180 os << "{ " << key.first << "," << key.second << "}";
188 * fd.io coding-style-patch-verification: ON
191 * eval: (c-set-style "mozilla")