FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gbp_contract.hpp
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #ifndef __VOM_GBP_CONTRACT_H__
17 #define __VOM_GBP_CONTRACT_H__
18 
19 #include "vom/acl_l3_list.hpp"
20 #include "vom/gbp_rule.hpp"
21 #include "vom/gbp_types.hpp"
22 #include "vom/interface.hpp"
23 #include "vom/singular_db.hpp"
24 #include "vom/types.hpp"
25 
26 namespace VOM {
27 
28 /**
29  * A entry in the ARP termination table of a Bridge Domain
30  */
31 class gbp_contract : public object_base
32 {
33 public:
34  /**
35  * set of gbp rules
36  */
37  typedef std::set<gbp_rule> gbp_rules_t;
38 
39  /**
40  * The key for a contract is the pair of EPG-IDs
41  */
42  typedef std::tuple<scope_t, sclass_t, sclass_t> key_t;
43 
44  /**
45  * A set of allowed ethertypes
46  */
47  typedef std::set<ethertype_t> ethertype_set_t;
48 
49  /**
50  * Construct a GBP contract
51  */
55  const ACL::l3_list& acl,
56  const gbp_rules_t& gpb_rules,
58 
59  /**
60  * Copy Construct
61  */
62  gbp_contract(const gbp_contract& r);
63 
64  /**
65  * Destructor
66  */
67  ~gbp_contract();
68 
69  /**
70  * Return the object's key
71  */
72  const key_t key() const;
73 
74  /**
75  * comparison operator
76  */
77  bool operator==(const gbp_contract& bdae) const;
78 
79  /**
80  * Return the matching 'singular instance'
81  */
82  std::shared_ptr<gbp_contract> singular() const;
83 
84  /**
85  * Find the instnace of the bridge_domain domain in the OM
86  */
87  static std::shared_ptr<gbp_contract> find(const key_t& k);
88 
89  /**
90  * Dump all bridge_domain-doamin into the stream provided
91  */
92  static void dump(std::ostream& os);
93 
94  /**
95  * replay the object to create it in hardware
96  */
97  void replay(void);
98 
99  /**
100  * Convert to string for debugging
101  */
102  std::string to_string() const;
103 
104 private:
105  /**
106  * Class definition for listeners to OM events
107  */
109  {
110  public:
111  event_handler();
112  virtual ~event_handler() = default;
113 
114  /**
115  * Handle a populate event
116  */
117  void handle_populate(const client_db::key_t& key);
118 
119  /**
120  * Handle a replay event
121  */
122  void handle_replay();
123 
124  /**
125  * Show the object in the Singular DB
126  */
127  void show(std::ostream& os);
128 
129  /**
130  * Get the sortable Id of the listener
131  */
132  dependency_t order() const;
133  };
134 
135  /**
136  * event_handler to register with OM
137  */
138  static event_handler m_evh;
139 
140  /**
141  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
142  */
143  void update(const gbp_contract& obj);
144 
145  /**
146  * Find or add the instance of the contract domain in the OM
147  */
148  static std::shared_ptr<gbp_contract> find_or_add(const gbp_contract& temp);
149 
150  /*
151  * It's the VPPHW class that updates the objects in HW
152  */
153  friend class OM;
154 
155  /**
156  * It's the singular_db class that calls replay()
157  */
159 
160  /**
161  * Sweep/reap the object if still stale
162  */
163  void sweep(void);
164 
165  /**
166  * HW configuration for the result of creating the endpoint
167  */
168  HW::item<uint32_t> m_hw;
169 
170  /*
171  * The scope of the contract
172  */
173  scope_t m_scope;
174 
175  /**
176  * The source EPG ID
177  */
178  sclass_t m_sclass;
179 
180  /**
181  * The destination EPG ID
182  */
183  sclass_t m_dclass;
184 
185  /**
186  * The ACL applied to traffic between the gourps
187  */
188  std::shared_ptr<ACL::l3_list> m_acl;
189 
190  /**
191  * The gbp rules applied to traffic between the gourps
192  */
193  gbp_rules_t m_gbp_rules;
194 
195  /**
196  * the set of Ether-types allowed by this contract
197  */
198  ethertype_set_t m_allowed_ethertypes;
199 
200  /**
201  * A map of all bridge_domains
202  */
204 };
205 
206 std::ostream& operator<<(std::ostream& os, const gbp_contract::key_t& key);
207 }; // namespace
208 
209 /*
210  * fd.io coding-style-patch-verification: OFF
211  *
212  * Local Variables:
213  * eval: (c-set-style "mozilla")
214  * End:
215  */
216 
217 #endif
VOM::HW::item< uint32_t >
acl_l3_list.hpp
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::scope_t
uint16_t scope_t
Definition: gbp_types.hpp:28
VOM::dependency_t
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
VOM::gbp_contract::operator==
bool operator==(const gbp_contract &bdae) const
comparison operator
Definition: gbp_contract.cpp:69
VOM::gbp_contract::key
const key_t key() const
Return the object's key.
Definition: gbp_contract.cpp:63
VOM::OM
The interface to writing objects into VPP OM.
Definition: om.hpp:140
types.hpp
VOM::inspect::command_handler
inspect command handler Handler
Definition: inspect.hpp:54
VOM::gbp_contract::dump
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: gbp_contract.cpp:147
VOM::OM::listener
Class definition for listeners to OM events.
Definition: om.hpp:284
VOM::sclass_t
uint16_t sclass_t
Definition: gbp_types.hpp:27
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
allowed_ethertypes
u16 allowed_ethertypes[16]
Definition: gbp.api:336
key
typedef key
Definition: ipsec_types.api:91
VOM::gbp_contract::to_string
std::string to_string() const
Convert to string for debugging.
Definition: gbp_contract.cpp:95
VOM::gbp_contract::ethertype_set_t
std::set< ethertype_t > ethertype_set_t
A set of allowed ethertypes.
Definition: gbp_contract.hpp:47
VOM::gbp_contract::replay
void replay(void)
replay the object to create it in hardware
Definition: gbp_contract.cpp:85
VOM::gbp_contract::key_t
std::tuple< scope_t, sclass_t, sclass_t > key_t
The key for a contract is the pair of EPG-IDs.
Definition: gbp_contract.hpp:42
VOM::client_db::key_t
const typedef std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
scope
vl_api_gbp_scope_t scope
Definition: gbp.api:78
VOM::gbp_contract::~gbp_contract
~gbp_contract()
Destructor.
Definition: gbp_contract.cpp:54
sclass
u16 sclass
Definition: gbp.api:131
gbp_types.hpp
gbp_rule.hpp
VOM::operator<<
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Definition: acl_binding.cpp:201
VOM::ACL::l3_list
An L3 ACL list comprises a set of match actions rules to be applied to packets.
Definition: acl_l3_list.hpp:35
dclass
u16 dclass
Definition: gbp.api:333
singular_db.hpp
VOM::gbp_contract::gbp_rules_t
std::set< gbp_rule > gbp_rules_t
set of gbp rules
Definition: gbp_contract.hpp:37
interface.hpp
VOM::gbp_contract::gbp_contract
gbp_contract(scope_t scope, sclass_t sclass, sclass_t dclass, const ACL::l3_list &acl, const gbp_rules_t &gpb_rules, const ethertype_set_t &allowed_ethertypes)
Construct a GBP contract.
Definition: gbp_contract.cpp:27
VOM::singular_db
A Database to store the unique 'singular' instances of a single object type.
Definition: singular_db.hpp:33
show
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
event_handler
void event_handler(void *tls_async)
Definition: tls_async.c:334
VOM::gbp_contract::singular
std::shared_ptr< gbp_contract > singular() const
Return the matching 'singular instance'.
Definition: gbp_contract.cpp:141
VOM::gbp_contract::find
static std::shared_ptr< gbp_contract > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
Definition: gbp_contract.cpp:135
VOM::object_base
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
VOM::gbp_contract
A entry in the ARP termination table of a Bridge Domain.
Definition: gbp_contract.hpp:31
string
const char *const string
Definition: cJSON.h:172