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_l3_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 pair of EPG-IDs
42 typedef std::pair<sclass_t, sclass_t> key_t;
45 * A set of allowed ethertypes
47 typedef std::set<ethertype_t> ethertype_set_t;
50 * Construct a GBP contract
52 gbp_contract(sclass_t sclass,
54 const ACL::l3_list& acl,
55 const gbp_rules_t& gpb_rules,
56 const ethertype_set_t& allowed_ethertypes);
61 gbp_contract(const gbp_contract& r);
69 * Return the object's key
71 const key_t key() const;
76 bool operator==(const gbp_contract& bdae) const;
79 * Return the matching 'singular instance'
81 std::shared_ptr<gbp_contract> singular() const;
84 * Find the instnace of the bridge_domain domain in the OM
86 static std::shared_ptr<gbp_contract> find(const key_t& k);
89 * Dump all bridge_domain-doamin into the stream provided
91 static void dump(std::ostream& os);
94 * replay the object to create it in hardware
99 * Convert to string for debugging
101 std::string to_string() const;
105 * Class definition for listeners to OM events
107 class event_handler : public OM::listener, public inspect::command_handler
111 virtual ~event_handler() = default;
114 * Handle a populate event
116 void handle_populate(const client_db::key_t& key);
119 * Handle a replay event
121 void handle_replay();
124 * Show the object in the Singular DB
126 void show(std::ostream& os);
129 * Get the sortable Id of the listener
131 dependency_t order() const;
135 * event_handler to register with OM
137 static event_handler m_evh;
140 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
142 void update(const gbp_contract& obj);
145 * Find or add the instance of the contract domain in the OM
147 static std::shared_ptr<gbp_contract> find_or_add(const gbp_contract& temp);
150 * It's the VPPHW class that updates the objects in HW
155 * It's the singular_db class that calls replay()
157 friend class singular_db<key_t, gbp_contract>;
160 * Sweep/reap the object if still stale
165 * HW configuration for the result of creating the endpoint
175 * The destination EPG ID
180 * The ACL applied to traffic between the gourps
182 std::shared_ptr<ACL::l3_list> m_acl;
185 * The gbp rules applied to traffic between the gourps
187 gbp_rules_t m_gbp_rules;
190 * the set of Ether-types allowed by this contract
192 ethertype_set_t m_allowed_ethertypes;
195 * A map of all bridge_domains
197 static singular_db<key_t, gbp_contract> m_db;
200 std::ostream& operator<<(std::ostream& os, const gbp_contract::key_t& key);
204 * fd.io coding-style-patch-verification: ON
207 * eval: (c-set-style "mozilla")