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 #ifndef __VOM_GBP_CONTRACT_H__
17 #define __VOM_GBP_CONTRACT_H__
19 #include "vom/acl_list.hpp"
20 #include "vom/gbp_endpoint.hpp"
21 #include "vom/gbp_rule.hpp"
22 #include "vom/interface.hpp"
23 #include "vom/singular_db.hpp"
24 #include "vom/types.hpp"
29 * A entry in the ARP termination table of a Bridge Domain
31 class gbp_contract : public object_base
37 typedef std::set<gbp_rule> gbp_rules_t;
40 * The key for a contract is the pari of EPG-IDs
42 typedef std::pair<epg_id_t, epg_id_t> key_t;
45 * Construct a GBP contract
47 gbp_contract(epg_id_t src_epg_id,
49 const ACL::l3_list& acl);
54 gbp_contract(const gbp_contract& r);
62 * Return the object's key
64 const key_t key() const;
69 bool operator==(const gbp_contract& bdae) const;
72 * Return the matching 'singular instance'
74 std::shared_ptr<gbp_contract> singular() const;
77 * Find the instnace of the bridge_domain domain in the OM
79 static std::shared_ptr<gbp_contract> find(const key_t& k);
82 * Dump all bridge_domain-doamin into the stream provided
84 static void dump(std::ostream& os);
87 * replay the object to create it in hardware
92 * Convert to string for debugging
94 std::string to_string() const;
97 * Set gbp_rules in case of Redirect Contract
99 void set_gbp_rules(const gbp_rules_t& gbp_rules);
103 * Class definition for listeners to OM events
105 class event_handler : public OM::listener, public inspect::command_handler
109 virtual ~event_handler() = default;
112 * Handle a populate event
114 void handle_populate(const client_db::key_t& key);
117 * Handle a replay event
119 void handle_replay();
122 * Show the object in the Singular DB
124 void show(std::ostream& os);
127 * Get the sortable Id of the listener
129 dependency_t order() const;
133 * event_handler to register with OM
135 static event_handler m_evh;
138 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
140 void update(const gbp_contract& obj);
143 * Find or add the instance of the contract domain in the OM
145 static std::shared_ptr<gbp_contract> find_or_add(const gbp_contract& temp);
148 * It's the VPPHW class that updates the objects in HW
153 * It's the singular_db class that calls replay()
155 friend class singular_db<key_t, gbp_contract>;
158 * Sweep/reap the object if still stale
163 * HW configuration for the result of creating the endpoint
170 epg_id_t m_src_epg_id;
173 * The destination EPG ID
175 epg_id_t m_dst_epg_id;
178 * The ACL applied to traffic between the gourps
180 std::shared_ptr<ACL::l3_list> m_acl;
183 * The gbp rules applied to traffic between the gourps
185 gbp_rules_t m_gbp_rules;
188 * A map of all bridge_domains
190 static singular_db<key_t, gbp_contract> m_db;
193 std::ostream& operator<<(std::ostream& os, const gbp_contract::key_t& key);
197 * fd.io coding-style-patch-verification: ON
200 * eval: (c-set-style "mozilla")