blob: caad96b88db263eef272699dffbac7c7b99e62fc [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
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_BRIDGE_DOMAIN_ARP_ENTRY_H__
17#define __VOM_BRIDGE_DOMAIN_ARP_ENTRY_H__
18
19#include "vom/bridge_domain.hpp"
20#include "vom/interface.hpp"
21#include "vom/singular_db.hpp"
22#include "vom/types.hpp"
23
Neale Ranns812ed392017-10-16 04:20:13 -070024namespace VOM {
25/**
26 * A entry in the ARP termination table of a Bridge Domain
27 */
28class bridge_domain_arp_entry : public object_base
29{
30public:
31 /**
32 * The key for a bridge_domain ARP entry;
33 * the BD, IP address and MAC address
34 */
35 typedef std::tuple<uint32_t, mac_address_t, boost::asio::ip::address> key_t;
36
37 /**
38 * Construct a bridge_domain in the given bridge domain
39 */
40 bridge_domain_arp_entry(const bridge_domain& bd,
41 const mac_address_t& mac,
42 const boost::asio::ip::address& ip_addr);
43
44 /**
45 * Construct a bridge_domain in the default table
46 */
47 bridge_domain_arp_entry(const mac_address_t& mac,
48 const boost::asio::ip::address& ip_addr);
49
50 /**
51 * Copy Construct
52 */
53 bridge_domain_arp_entry(const bridge_domain_arp_entry& r);
54
55 /**
56 * Destructor
57 */
58 ~bridge_domain_arp_entry();
59
60 /**
61 * Return the matching 'singular instance'
62 */
63 std::shared_ptr<bridge_domain_arp_entry> singular() const;
64
65 /**
66 * Find the instnace of the bridge_domain domain in the OM
67 */
68 static std::shared_ptr<bridge_domain_arp_entry> find(
69 const bridge_domain_arp_entry& temp);
70
71 /**
72 * Dump all bridge_domain-doamin into the stream provided
73 */
74 static void dump(std::ostream& os);
75
76 /**
77 * replay the object to create it in hardware
78 */
79 void replay(void);
80
81 /**
82 * Convert to string for debugging
83 */
84 std::string to_string() const;
85
Neale Ranns812ed392017-10-16 04:20:13 -070086private:
87 /**
88 * Class definition for listeners to OM events
89 */
90 class event_handler : public OM::listener, public inspect::command_handler
91 {
92 public:
93 event_handler();
94 virtual ~event_handler() = default;
95
96 /**
97 * Handle a populate event
98 */
99 void handle_populate(const client_db::key_t& key);
100
101 /**
102 * Handle a replay event
103 */
104 void handle_replay();
105
106 /**
107 * Show the object in the Singular DB
108 */
109 void show(std::ostream& os);
110
111 /**
112 * Get the sortable Id of the listener
113 */
114 dependency_t order() const;
115 };
116
117 /**
118 * event_handler to register with OM
119 */
120 static event_handler m_evh;
121
122 /**
123 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
124 */
125 void update(const bridge_domain_arp_entry& obj);
126
127 /**
128 * Find or add the instnace of the bridge_domain domain in the OM
129 */
130 static std::shared_ptr<bridge_domain_arp_entry> find_or_add(
131 const bridge_domain_arp_entry& temp);
132
133 /*
134 * It's the VPPHW class that updates the objects in HW
135 */
136 friend class OM;
137
138 /**
139 * It's the singular_db class that calls replay()
140 */
141 friend class singular_db<key_t, bridge_domain_arp_entry>;
142
143 /**
144 * Sweep/reap the object if still stale
145 */
146 void sweep(void);
147
148 /**
149 * HW configuration for the result of creating the bridge_domain
150 */
151 HW::item<bool> m_hw;
152
153 /**
154 * The bridge_domain domain the bridge_domain is in.
155 */
156 std::shared_ptr<bridge_domain> m_bd;
157
158 /**
159 * The mac to match
160 */
161 mac_address_t m_mac;
162
163 /**
164 * The IP address
165 */
166 boost::asio::ip::address m_ip_addr;
167
168 /**
169 * A map of all bridge_domains
170 */
171 static singular_db<key_t, bridge_domain_arp_entry> m_db;
172};
173
174std::ostream& operator<<(std::ostream& os,
175 const bridge_domain_arp_entry::key_t& key);
176};
177
178/*
179 * fd.io coding-style-patch-verification: ON
180 *
181 * Local Variables:
182 * eval: (c-set-style "mozilla")
183 * End:
184 */
185
186#endif