FD.io VPP  v18.01.1-37-g7ea3975
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  /**
31  * The key for a neighbour entry;
32  * the interface and IP address
33  */
34  typedef std::pair<interface::key_t, boost::asio::ip::address> key_t;
35 
36  /**
37  * Construct an ARP entry
38  */
39  neighbour(const interface& itf,
40  const boost::asio::ip::address& ip_addr,
41  const mac_address_t& mac);
42 
43  /**
44  * Copy Construct
45  */
46  neighbour(const neighbour& r);
47 
48  /**
49  * Destructor
50  */
51  ~neighbour();
52 
53  /**
54  * Return the object's key
55  */
56  const key_t key() const;
57 
58  /**
59  * Comparison operator
60  */
61  bool operator==(const neighbour& n) const;
62 
63  /**
64  * Return the matching 'singular instance'
65  */
66  std::shared_ptr<neighbour> singular() const;
67 
68  /**
69  * Find the neighbour fromits key
70  */
71  static std::shared_ptr<neighbour> find(const key_t& k);
72 
73  /**
74  * Dump all neighbours into the stream provided
75  */
76  static void dump(std::ostream& os);
77 
78  /**
79  * replay the object to create it in hardware
80  */
81  void replay(void);
82 
83  /**
84  * Convert to string for debugging
85  */
86  std::string to_string() const;
87 
88 private:
89  /**
90  * Class definition for listeners to OM events
91  */
92  class event_handler : public OM::listener, public inspect::command_handler
93  {
94  public:
95  event_handler();
96  virtual ~event_handler() = default;
97 
98  /**
99  * Handle a populate event
100  */
101  void handle_populate(const client_db::key_t& key);
102 
103  /**
104  * Handle a replay event
105  */
106  void handle_replay();
107 
108  /**
109  * Show the object in the Singular DB
110  */
111  void show(std::ostream& os);
112 
113  /**
114  * Get the sortable Id of the listener
115  */
116  dependency_t order() const;
117  };
118 
119  /**
120  * event_handler to register with OM
121  */
122  static event_handler m_evh;
123 
124  /**
125  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
126  */
127  void update(const neighbour& obj);
128 
129  /**
130  * Do the populate work
131  */
132  static void populate_i(const client_db::key_t& key,
133  std::shared_ptr<interface> itf,
134  const l3_proto_t& proto);
135 
136  /**
137  * Find or add the instnace of the neighbour in the OM
138  */
139  static std::shared_ptr<neighbour> find_or_add(const neighbour& temp);
140 
141  /*
142  * It's the VPPHW class that updates the objects in HW
143  */
144  friend class OM;
145 
146  /**
147  * It's the singular_db class that calls replay()
148  */
149  friend class singular_db<key_t, neighbour>;
150 
151  /**
152  * Sweep/reap the object if still stale
153  */
154  void sweep(void);
155 
156  /**
157  * HW configuration for the result of creating the bridge_domain
158  */
159  HW::item<bool> m_hw;
160 
161  /**
162  * The bridge_domain domain the bridge_domain is in.
163  */
164  std::shared_ptr<interface> m_itf;
165 
166  /**
167  * The IP address
168  */
169  boost::asio::ip::address m_ip_addr;
170 
171  /**
172  * The mac to match
173  */
174  mac_address_t m_mac;
175 
176  /**
177  * A map of all bridge_domains
178  */
179  static singular_db<key_t, neighbour> m_db;
180 };
181 
182 std::ostream& operator<<(std::ostream& os, const neighbour::key_t& key);
183 };
184 
185 /*
186  * fd.io coding-style-patch-verification: ON
187  *
188  * Local Variables:
189  * eval: (c-set-style "mozilla")
190  * End:
191  */
192 
193 #endif
const key_t key() const
Return the object&#39;s key.
Definition: neighbour.cpp:56
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::shared_ptr< neighbour > singular() const
Return the matching &#39;singular instance&#39;.
Definition: neighbour.cpp:115
Types belonging to Routing.
Definition: prefix.hpp:32
std::string to_string() const
Convert to string for debugging.
Definition: neighbour.cpp:81
bool operator==(const neighbour &n) const
Comparison operator.
Definition: neighbour.cpp:50
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:32
A entry in the neighbour entry (ARP or IPv6 ND)
Definition: neighbour.hpp:27
A representation of an interface in VPP.
Definition: interface.hpp:41
Class definition for listeners to OM events.
Definition: om.hpp:284
inspect command handler Handler
Definition: inspect.hpp:54
void replay(void)
replay the object to create it in hardware
Definition: neighbour.cpp:72
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
static void dump(std::ostream &os)
Dump all neighbours into the stream provided.
Definition: neighbour.cpp:121
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
static std::shared_ptr< neighbour > find(const key_t &k)
Find the neighbour fromits key.
Definition: neighbour.cpp:109
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
~neighbour()
Destructor.
Definition: neighbour.cpp:41
neighbour(const interface &itf, const boost::asio::ip::address &ip_addr, const mac_address_t &mac)
Construct an ARP entry.
Definition: neighbour.cpp:23
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:34
Type def of a Ethernet address.
Definition: types.hpp:221