FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
gbp_endpoint.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_ENDPOINT_H__
17 #define __VOM_GBP_ENDPOINT_H__
18 
19 #include <ostream>
20 #include <vector>
21 
23 #include "vom/interface.hpp"
24 #include "vom/singular_db.hpp"
25 
26 namespace VOM {
27 /**
28  * A GBP Enpoint (i.e. a VM)
29  */
30 class gbp_endpoint : public object_base
31 {
32 public:
33  /**
34  * Endpoint flags
35  */
36  struct flags_t : enum_base<flags_t>
37  {
38  const static flags_t NONE;
39  const static flags_t BOUNCE;
40  const static flags_t REMOTE;
41  const static flags_t LEARNT;
42  const static flags_t EXTERNAL;
43 
44  private:
45  /**
46  * Private constructor taking the value and the string name
47  */
48  flags_t(int v, const std::string& s);
49  };
50 
51  /**
52  * The key for a GBP endpoint; interface and IP
53  */
54  typedef std::pair<interface::key_t, mac_address_t> key_t;
55 
56  /**
57  * Construct a GBP endpoint
58  */
59  gbp_endpoint(const interface& itf,
60  const std::vector<boost::asio::ip::address>& ip_addr,
61  const mac_address_t& mac,
62  const gbp_endpoint_group& epg,
63  const flags_t& flags = flags_t::NONE);
64 
65  /**
66  * Copy Construct
67  */
68  gbp_endpoint(const gbp_endpoint& r);
69 
70  /**
71  * Destructor
72  */
73  ~gbp_endpoint();
74 
75  /**
76  * Return the object's key
77  */
78  const key_t key() const;
79 
80  /**
81  * comparison operator
82  */
83  bool operator==(const gbp_endpoint& bdae) const;
84 
85  /**
86  * Return the matching 'singular instance'
87  */
88  std::shared_ptr<gbp_endpoint> singular() const;
89 
90  /**
91  * Find the instnace of the bridge_domain domain in the OM
92  */
93  static std::shared_ptr<gbp_endpoint> find(const key_t& k);
94 
95  /**
96  * Dump all bridge_domain-doamin into the stream provided
97  */
98  static void dump(std::ostream& os);
99 
100  /**
101  * replay the object to create it in hardware
102  */
103  void replay(void);
104 
105  /**
106  * Convert to string for debugging
107  */
108  std::string to_string() const;
109 
110 private:
111  /**
112  * Class definition for listeners to OM events
113  */
115  {
116  public:
117  event_handler();
118  virtual ~event_handler() = default;
119 
120  /**
121  * Handle a populate event
122  */
123  void handle_populate(const client_db::key_t& key);
124 
125  /**
126  * Handle a replay event
127  */
128  void handle_replay();
129 
130  /**
131  * Show the object in the Singular DB
132  */
133  void show(std::ostream& os);
134 
135  /**
136  * Get the sortable Id of the listener
137  */
138  dependency_t order() const;
139  };
140 
141  /**
142  * event_handler to register with OM
143  */
144  static event_handler m_evh;
145 
146  /**
147  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
148  */
149  void update(const gbp_endpoint& obj);
150 
151  /**
152  * Find or add the instnace of the bridge_domain domain in the OM
153  */
154  static std::shared_ptr<gbp_endpoint> find_or_add(const gbp_endpoint& temp);
155 
156  /*
157  * It's the VPPHW class that updates the objects in HW
158  */
159  friend class OM;
160 
161  /**
162  * It's the singular_db class that calls replay()
163  */
164  friend class singular_db<key_t, gbp_endpoint>;
165 
166  /**
167  * Sweep/reap the object if still stale
168  */
169  void sweep(void);
170 
171  /**
172  * HW configuration for the result of creating the endpoint
173  */
174  HW::item<handle_t> m_hdl;
175 
176  /**
177  * The interface the endpoint is attached to.
178  */
179  std::shared_ptr<interface> m_itf;
180 
181  /**
182  * The IP address of the endpoint
183  */
184  std::vector<boost::asio::ip::address> m_ips;
185 
186  /**
187  * The MAC address of the endpoint
188  */
189  mac_address_t m_mac;
190 
191  /**
192  * The EPG the endpoint is in
193  */
194  std::shared_ptr<gbp_endpoint_group> m_epg;
195 
196  /**
197  * Endpoint flags
198  */
199  flags_t m_flags;
200 
201  /**
202  * A map of all bridge_domains
203  */
205 };
206 
207 std::ostream& operator<<(std::ostream& os, const gbp_endpoint::key_t& key);
208 }; // namespace
209 
210 /*
211  * fd.io coding-style-patch-verification: ON
212  *
213  * Local Variables:
214  * eval: (c-set-style "mozilla")
215  * End:
216  */
217 
218 #endif
static const flags_t LEARNT
static const flags_t BOUNCE
u32 flags
Definition: vhost_user.h:141
std::shared_ptr< gbp_endpoint > singular() const
Return the matching &#39;singular instance&#39;.
static const flags_t NONE
vl_api_mac_address_t mac
Definition: l2.api:490
A template base class for all enum types.
Definition: enum_base.hpp:30
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
std::pair< interface::key_t, mac_address_t > key_t
The key for a GBP endpoint; interface and IP.
~gbp_endpoint()
Destructor.
bool operator==(const enum_base &e) const
Comparison operator.
Definition: enum_base.hpp:41
gbp_endpoint(const interface &itf, const std::vector< boost::asio::ip::address > &ip_addr, const mac_address_t &mac, const gbp_endpoint_group &epg, const flags_t &flags=flags_t::NONE)
Construct a GBP endpoint.
const key_t key() const
Return the object&#39;s key.
A GBP Enpoint (i.e.
static const flags_t REMOTE
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
static const flags_t EXTERNAL
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
A representation of an interface in VPP.
Definition: interface.hpp:41
A entry in the ARP termination table of a Bridge Domain.
Class definition for listeners to OM events.
Definition: om.hpp:284
inspect command handler Handler
Definition: inspect.hpp:54
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
void event_handler(void *tls_async)
Definition: tls_async.c:338
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
void replay(void)
replay the object to create it in hardware
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
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
static std::shared_ptr< gbp_endpoint > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
Type def of a Ethernet address.
Definition: types.hpp:295