FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
neighbour.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_NEIGHBOUR_H__
17 #define __VOM_NEIGHBOUR_H__
18 
19 #include "vom/interface.hpp"
20 #include "vom/singular_db.hpp"
21 #include "vom/types.hpp"
22 
23 namespace VOM {
24 /**
25  * A entry in the neighbour entry (ARP or IPv6 ND)
26  */
27 class neighbour : public object_base
28 {
29 public:
30  struct flags_t : public enum_base<flags_t>
31  {
32  /**
33  * Constructor
34  */
35  flags_t(int v, const std::string s);
36 
37  /**
38  * Destructor
39  */
40  ~flags_t() = default;
41 
42  flags_t operator|(const flags_t& e1) const
43  {
44  flags_t e = *this;
45  e |= e1;
46  return e;
47  }
48 
49  const static flags_t NONE;
50  const static flags_t STATIC;
51  const static flags_t NO_FIB_ENTRY;
52  };
53 
54  /**
55  * The key for a neighbour entry;
56  * the interface and IP address
57  */
58  typedef std::pair<interface::key_t, boost::asio::ip::address> key_t;
59 
60  /**
61  * Construct an ARP entry
62  */
63  neighbour(const interface& itf,
64  const boost::asio::ip::address& ip_addr,
65  const mac_address_t& mac,
66  const flags_t flags = flags_t::STATIC);
67 
68  /**
69  * Copy Construct
70  */
71  neighbour(const neighbour& r);
72 
73  /**
74  * Destructor
75  */
76  ~neighbour();
77 
78  /**
79  * Return the object's key
80  */
81  const key_t key() const;
82 
83  /**
84  * Comparison operator
85  */
86  bool operator==(const neighbour& n) const;
87 
88  /**
89  * Return the matching 'singular instance'
90  */
91  std::shared_ptr<neighbour> singular() const;
92 
93  /**
94  * Find the neighbour fromits key
95  */
96  static std::shared_ptr<neighbour> find(const key_t& k);
97 
98  /**
99  * Dump all neighbours into the stream provided
100  */
101  static void dump(std::ostream& os);
102 
103  /**
104  * replay the object to create it in hardware
105  */
106  void replay(void);
107 
108  /**
109  * Convert to string for debugging
110  */
111  std::string to_string() const;
112 
113 private:
114  /**
115  * Class definition for listeners to OM events
116  */
118  {
119  public:
120  event_handler();
121  virtual ~event_handler() = default;
122 
123  /**
124  * Handle a populate event
125  */
126  void handle_populate(const client_db::key_t& key);
127 
128  /**
129  * Handle a replay event
130  */
131  void handle_replay();
132 
133  /**
134  * Show the object in the Singular DB
135  */
136  void show(std::ostream& os);
137 
138  /**
139  * Get the sortable Id of the listener
140  */
141  dependency_t order() const;
142  };
143 
144  /**
145  * event_handler to register with OM
146  */
147  static event_handler m_evh;
148 
149  /**
150  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
151  */
152  void update(const neighbour& obj);
153 
154  /**
155  * Do the populate work
156  */
157  static void populate_i(const client_db::key_t& key,
158  std::shared_ptr<interface> itf,
159  const l3_proto_t& proto);
160 
161  /**
162  * Find or add the instnace of the neighbour in the OM
163  */
164  static std::shared_ptr<neighbour> find_or_add(const neighbour& temp);
165 
166  /*
167  * It's the VPPHW class that updates the objects in HW
168  */
169  friend class OM;
170 
171  /**
172  * It's the singular_db class that calls replay()
173  */
174  friend class singular_db<key_t, neighbour>;
175 
176  /**
177  * Sweep/reap the object if still stale
178  */
179  void sweep(void);
180 
181  /**
182  * HW configuration for the result of creating the bridge_domain
183  */
184  HW::item<handle_t> m_hw;
185 
186  /**
187  * The bridge_domain domain the bridge_domain is in.
188  */
189  std::shared_ptr<interface> m_itf;
190 
191  /**
192  * The IP address
193  */
194  boost::asio::ip::address m_ip_addr;
195 
196  /**
197  * The mac to match
198  */
199  mac_address_t m_mac;
200 
201  /**
202  * flags on the entry
203  */
204  flags_t m_flags;
205 
206  /**
207  * A map of all bridge_domains
208  */
209  static singular_db<key_t, neighbour> m_db;
210 };
211 
212 std::ostream& operator<<(std::ostream& os, const neighbour::key_t& key);
213 };
214 
215 /*
216  * fd.io coding-style-patch-verification: OFF
217  *
218  * Local Variables:
219  * eval: (c-set-style "mozilla")
220  * End:
221  */
222 
223 #endif
VOM::neighbour::neighbour
neighbour(const interface &itf, const boost::asio::ip::address &ip_addr, const mac_address_t &mac, const flags_t flags=flags_t::STATIC)
Construct an ARP entry.
Definition: neighbour.cpp:34
VOM::HW::item< handle_t >
mac
vl_api_mac_address_t mac
Definition: l2.api:559
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
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::OM
The interface to writing objects into VPP OM.
Definition: om.hpp:140
VOM::neighbour::~neighbour
~neighbour()
Destructor.
Definition: neighbour.cpp:55
types.hpp
VOM::inspect::command_handler
inspect command handler Handler
Definition: inspect.hpp:54
VOM::neighbour::key
const key_t key() const
Return the object's key.
Definition: neighbour.cpp:70
VOM::neighbour::dump
static void dump(std::ostream &os)
Dump all neighbours into the stream provided.
Definition: neighbour.cpp:135
VOM::neighbour::key_t
std::pair< interface::key_t, boost::asio::ip::address > key_t
The key for a neighbour entry; the interface and IP address.
Definition: neighbour.hpp:58
VOM::neighbour
A entry in the neighbour entry (ARP or IPv6 ND)
Definition: neighbour.hpp:27
VOM::OM::listener
Class definition for listeners to OM events.
Definition: om.hpp:284
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
VOM::neighbour::flags_t::STATIC
const static flags_t STATIC
Definition: neighbour.hpp:50
key
typedef key
Definition: ipsec_types.api:91
VOM::neighbour::operator==
bool operator==(const neighbour &n) const
Comparison operator.
Definition: neighbour.cpp:64
VOM::neighbour::singular
std::shared_ptr< neighbour > singular() const
Return the matching 'singular instance'.
Definition: neighbour.cpp:129
VOM::enum_base
A template base class for all enum types.
Definition: enum_base.hpp:30
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
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
VOM::neighbour::to_string
std::string to_string() const
Convert to string for debugging.
Definition: neighbour.cpp:95
address
manual_print typedef address
Definition: ip_types.api:96
VOM::neighbour::replay
void replay(void)
replay the object to create it in hardware
Definition: neighbour.cpp:86
VOM::operator<<
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Definition: acl_binding.cpp:201
VOM::l3_proto_t
An L3 protocol can be used to construct a prefix that is used to match packets are part of a route.
Definition: prefix.hpp:52
singular_db.hpp
VOM::mac_address_t
Type def of a Ethernet address.
Definition: types.hpp:295
interface.hpp
VOM::neighbour::flags_t::~flags_t
~flags_t()=default
Destructor.
VOM::neighbour::find
static std::shared_ptr< neighbour > find(const key_t &k)
Find the neighbour fromits key.
Definition: neighbour.cpp:123
VOM::singular_db
A Database to store the unique 'singular' instances of a single object type.
Definition: singular_db.hpp:33
VOM::neighbour::flags_t::operator|
flags_t operator|(const flags_t &e1) const
Definition: neighbour.hpp:42
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
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
VOM::neighbour::flags_t::NO_FIB_ENTRY
const static flags_t NO_FIB_ENTRY
Definition: neighbour.hpp:51
VOM::neighbour::flags_t
Definition: neighbour.hpp:30
VOM::object_base
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
VOM::neighbour::flags_t::flags_t
flags_t(int v, const std::string s)
Constructor.
Definition: neighbour.cpp:29
VOM::neighbour::flags_t::NONE
const static flags_t NONE
Definition: neighbour.hpp:49
string
const char *const string
Definition: cJSON.h:172
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105