FD.io VPP  v19.01.3-6-g70449b9b9
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_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"
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 pari of EPG-IDs
41  */
42  typedef std::pair<epg_id_t, epg_id_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  */
52  gbp_contract(epg_id_t src_epg_id,
53  epg_id_t dst_epg_id,
54  const ACL::l3_list& acl,
55  const gbp_rules_t& gpb_rules,
56  const ethertype_set_t& allowed_ethertypes);
57 
58  /**
59  * Copy Construct
60  */
61  gbp_contract(const gbp_contract& r);
62 
63  /**
64  * Destructor
65  */
66  ~gbp_contract();
67 
68  /**
69  * Return the object's key
70  */
71  const key_t key() const;
72 
73  /**
74  * comparison operator
75  */
76  bool operator==(const gbp_contract& bdae) const;
77 
78  /**
79  * Return the matching 'singular instance'
80  */
81  std::shared_ptr<gbp_contract> singular() const;
82 
83  /**
84  * Find the instnace of the bridge_domain domain in the OM
85  */
86  static std::shared_ptr<gbp_contract> find(const key_t& k);
87 
88  /**
89  * Dump all bridge_domain-doamin into the stream provided
90  */
91  static void dump(std::ostream& os);
92 
93  /**
94  * replay the object to create it in hardware
95  */
96  void replay(void);
97 
98  /**
99  * Convert to string for debugging
100  */
101  std::string to_string() const;
102 
103 private:
104  /**
105  * Class definition for listeners to OM events
106  */
108  {
109  public:
110  event_handler();
111  virtual ~event_handler() = default;
112 
113  /**
114  * Handle a populate event
115  */
116  void handle_populate(const client_db::key_t& key);
117 
118  /**
119  * Handle a replay event
120  */
121  void handle_replay();
122 
123  /**
124  * Show the object in the Singular DB
125  */
126  void show(std::ostream& os);
127 
128  /**
129  * Get the sortable Id of the listener
130  */
131  dependency_t order() const;
132  };
133 
134  /**
135  * event_handler to register with OM
136  */
137  static event_handler m_evh;
138 
139  /**
140  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
141  */
142  void update(const gbp_contract& obj);
143 
144  /**
145  * Find or add the instance of the contract domain in the OM
146  */
147  static std::shared_ptr<gbp_contract> find_or_add(const gbp_contract& temp);
148 
149  /*
150  * It's the VPPHW class that updates the objects in HW
151  */
152  friend class OM;
153 
154  /**
155  * It's the singular_db class that calls replay()
156  */
157  friend class singular_db<key_t, gbp_contract>;
158 
159  /**
160  * Sweep/reap the object if still stale
161  */
162  void sweep(void);
163 
164  /**
165  * HW configuration for the result of creating the endpoint
166  */
167  HW::item<bool> m_hw;
168 
169  /**
170  * The source EPG ID
171  */
172  epg_id_t m_src_epg_id;
173 
174  /**
175  * The destination EPG ID
176  */
177  epg_id_t m_dst_epg_id;
178 
179  /**
180  * The ACL applied to traffic between the gourps
181  */
182  std::shared_ptr<ACL::l3_list> m_acl;
183 
184  /**
185  * The gbp rules applied to traffic between the gourps
186  */
187  gbp_rules_t m_gbp_rules;
188 
189  /**
190  * the set of Ether-types allowed by this contract
191  */
192  ethertype_set_t m_allowed_ethertypes;
193 
194  /**
195  * A map of all bridge_domains
196  */
198 };
199 
200 std::ostream& operator<<(std::ostream& os, const gbp_contract::key_t& key);
201 }; // namespace
202 
203 /*
204  * fd.io coding-style-patch-verification: ON
205  *
206  * Local Variables:
207  * eval: (c-set-style "mozilla")
208  * End:
209  */
210 
211 #endif
bool operator==(const gbp_contract &bdae) const
comparison operator
const 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
An ACL list comprises a set of match actions rules to be applied to packets.
Definition: acl_list.hpp:37
uint32_t epg_id_t
EPG IDs are 32 bit integers.
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
const key_t key() const
Return the object&#39;s key.
std::string to_string() const
Convert to string for debugging.
std::set< ethertype_t > ethertype_set_t
A set of allowed ethertypes.
u16 allowed_ethertypes[n_ether_types]
Definition: gbp.api:299
void replay(void)
replay the object to create it in hardware
gbp_contract(epg_id_t src_epg_id, epg_id_t dst_epg_id, const ACL::l3_list &acl, const gbp_rules_t &gpb_rules, const ethertype_set_t &allowed_ethertypes)
Construct a GBP contract.
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
A entry in the ARP termination table of a Bridge Domain.
~gbp_contract()
Destructor.
std::pair< epg_id_t, epg_id_t > key_t
The key for a contract is the pari of EPG-IDs.
Class definition for listeners to OM events.
Definition: om.hpp:284
inspect command handler Handler
Definition: inspect.hpp:54
void event_handler(void *tls_async)
Definition: tls_async.c:340
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
The interface to writing objects into VPP OM.
Definition: om.hpp:140
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
std::set< gbp_rule > gbp_rules_t
set of gbp rules
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
static std::shared_ptr< gbp_contract > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
std::shared_ptr< gbp_contract > singular() const
Return the matching &#39;singular instance&#39;.