/
arp_proto.h
336 lines (294 loc) · 12 KB
/
arp_proto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef vnsw_agent_arp_proto_hpp
#define vnsw_agent_arp_proto_hpp
#include "pkt/proto.h"
#include "services/arp_handler.h"
#include "services/arp_entry.h"
#define ARP_TRACE(obj, ...) \
do { \
Arp##obj::TraceMsg(ArpTraceBuf, __FILE__, __LINE__, ##__VA_ARGS__); \
} while (false) \
struct ArpVrfState;
class ArpProto : public Proto {
public:
static const uint16_t kGratRetries = 2;
static const uint32_t kGratRetryTimeout = 2000; // milli seconds
static const uint16_t kMaxRetries = 8;
static const uint32_t kRetryTimeout = 2000; // milli seconds
static const uint32_t kAgingTimeout = (5 * 60 * 1000); // milli seconds
typedef std::map<ArpKey, ArpEntry *> ArpCache;
typedef std::pair<ArpKey, ArpEntry *> ArpCachePair;
typedef std::map<ArpKey, ArpEntry *>::iterator ArpIterator;
typedef std::set<ArpKey> ArpKeySet;
enum ArpMsgType {
ARP_RESOLVE,
ARP_DELETE,
ARP_SEND_GRATUITOUS,
RETRY_TIMER_EXPIRED,
AGING_TIMER_EXPIRED,
GRATUITOUS_TIMER_EXPIRED,
};
struct ArpIpc : InterTaskMsg {
ArpIpc(ArpProto::ArpMsgType msg, ArpKey &akey, const Interface* itf)
: InterTaskMsg(msg), key(akey), interface(itf) {}
ArpIpc(ArpProto::ArpMsgType msg, in_addr_t ip, const VrfEntry *vrf,
const Interface* itf) :
InterTaskMsg(msg), key(ip, vrf), interface(itf) {}
ArpKey key;
const Interface *interface;
};
struct ArpStats {
ArpStats() { Reset(); }
void Reset() {
arp_req = arp_replies = arp_gratuitous =
resolved = max_retries_exceeded = errors = 0;
arp_invalid_packets = arp_invalid_interface = arp_invalid_vrf =
arp_invalid_address = vm_arp_req = 0;
}
uint32_t arp_req;
uint32_t arp_replies;
uint32_t arp_gratuitous;
uint32_t resolved;
uint32_t max_retries_exceeded;
uint32_t errors;
uint32_t arp_invalid_packets;
uint32_t arp_invalid_interface;
uint32_t arp_invalid_vrf;
uint32_t arp_invalid_address;
uint32_t vm_arp_req;
};
struct InterfaceArpInfo {
InterfaceArpInfo() : arp_key_list(), stats() {}
ArpKeySet arp_key_list;
ArpStats stats;
};
typedef std::map<uint32_t, InterfaceArpInfo> InterfaceArpMap;
typedef std::pair<uint32_t, InterfaceArpInfo> InterfaceArpPair;
void Shutdown();
ArpProto(Agent *agent, boost::asio::io_service &io, bool run_with_vrouter);
virtual ~ArpProto();
ProtoHandler *AllocProtoHandler(boost::shared_ptr<PktInfo> info,
boost::asio::io_service &io);
bool TimerExpiry(ArpKey &key, uint32_t timer_type, const Interface *itf);
bool AddArpEntry(ArpEntry *entry);
bool DeleteArpEntry(ArpEntry *entry);
ArpEntry *FindArpEntry(const ArpKey &key);
std::size_t GetArpCacheSize() { return arp_cache_.size(); }
const ArpCache& arp_cache() { return arp_cache_; }
const InterfaceArpMap& interface_arp_map() { return interface_arp_map_; }
Interface *ip_fabric_interface() const { return ip_fabric_interface_; }
uint32_t ip_fabric_interface_index() const {
return ip_fabric_interface_index_;
}
const MacAddress &ip_fabric_interface_mac() const {
return ip_fabric_interface_mac_;
}
void set_ip_fabric_interface(Interface *itf) { ip_fabric_interface_ = itf; }
void set_ip_fabric_interface_index(uint32_t ind) {
ip_fabric_interface_index_ = ind;
}
void set_ip_fabric_interface_mac(const MacAddress &mac) {
ip_fabric_interface_mac_ = mac;
}
void AddGratuitousArpEntry(ArpKey &key);
void DeleteGratuitousArpEntry(ArpEntry *entry);
ArpEntry* GratiousArpEntry (const ArpKey &key);
ArpProto::ArpIterator GratiousArpEntryIterator(const ArpKey & key,
bool *key_valid);
void IncrementStatsArpReq() { arp_stats_.arp_req++; }
void IncrementStatsArpReplies() { arp_stats_.arp_replies++; }
void IncrementStatsGratuitous() { arp_stats_.arp_gratuitous++; }
void IncrementStatsResolved() { arp_stats_.resolved++; }
void IncrementStatsMaxRetries() { arp_stats_.max_retries_exceeded++; }
void IncrementStatsErrors() { arp_stats_.errors++; }
void IncrementStatsVmArpReq() { arp_stats_.vm_arp_req++; }
void IncrementStatsInvalidPackets() {
IncrementStatsErrors();
arp_stats_.arp_invalid_packets++;
}
void IncrementStatsInvalidInterface() {
IncrementStatsErrors();
arp_stats_.arp_invalid_interface++;
}
void IncrementStatsInvalidVrf() {
IncrementStatsErrors();
arp_stats_.arp_invalid_vrf++;
}
void IncrementStatsInvalidAddress() {
IncrementStatsErrors();
arp_stats_.arp_invalid_address++;
}
const ArpStats &GetStats() const { return arp_stats_; }
void ClearStats() { arp_stats_.Reset(); }
void IncrementStatsArpRequest(uint32_t idx);
void IncrementStatsArpReply(uint32_t idx);
void IncrementStatsResolved(uint32_t idx);
InterfaceArpInfo& ArpMapIndexToEntry(uint32_t idx);
uint32_t ArpRequestStatsCounter(uint32_t idx);
uint32_t ArpReplyStatsCounter(uint32_t idx);
uint32_t ArpResolvedStatsCounter(uint32_t idx);
void ClearInterfaceArpStats(uint32_t idx);
uint16_t max_retries() const { return max_retries_; }
uint32_t retry_timeout() const { return retry_timeout_; }
uint32_t aging_timeout() const { return aging_timeout_; }
void set_max_retries(uint16_t retries) { max_retries_ = retries; }
void set_retry_timeout(uint32_t timeout) { retry_timeout_ = timeout; }
void set_aging_timeout(uint32_t timeout) { aging_timeout_ = timeout; }
void SendArpIpc(ArpProto::ArpMsgType type, in_addr_t ip,
const VrfEntry *vrf, const Interface* itf);
bool ValidateAndClearVrfState(VrfEntry *vrf, const ArpVrfState *vrf_state);
ArpIterator FindUpperBoundArpEntry(const ArpKey &key);
ArpIterator FindLowerBoundArpEntry(const ArpKey &key);
DBTableBase::ListenerId vrf_table_listener_id() const {
return vrf_table_listener_id_;
}
private:
void VrfNotify(DBTablePartBase *part, DBEntryBase *entry);
void NextHopNotify(DBEntryBase *entry);
void InterfaceNotify(DBEntryBase *entry);
void SendArpIpc(ArpProto::ArpMsgType type, ArpKey &key,
const Interface* itf);
ArpProto::ArpIterator DeleteArpEntry(ArpProto::ArpIterator iter);
ArpCache arp_cache_;
ArpStats arp_stats_;
ArpCache gratuitous_arp_cache_;
bool run_with_vrouter_;
uint32_t ip_fabric_interface_index_;
MacAddress ip_fabric_interface_mac_;
Interface *ip_fabric_interface_;
DBTableBase::ListenerId vrf_table_listener_id_;
DBTableBase::ListenerId interface_table_listener_id_;
DBTableBase::ListenerId nexthop_table_listener_id_;
InterfaceArpMap interface_arp_map_;
uint16_t max_retries_;
uint32_t retry_timeout_; // milli seconds
uint32_t aging_timeout_; // milli seconds
DISALLOW_COPY_AND_ASSIGN(ArpProto);
};
//Stucture used to retry ARP queries when a particular route is in
//backup state.
class ArpPathPreferenceState {
public:
static const uint32_t kMaxRetry = 30 * 5; //retries upto 5 minutes,
//30 tries/per minutes
static const uint32_t kTimeout = 2000;
typedef std::map<uint32_t, uint32_t> WaitForTrafficIntfMap;
typedef std::set<uint32_t> ArpTransmittedIntfMap;
ArpPathPreferenceState(ArpVrfState *state, uint32_t vrf_id,
const IpAddress &vm_ip, uint8_t plen);
~ArpPathPreferenceState();
bool SendArpRequest();
bool SendArpRequest(WaitForTrafficIntfMap &wait_for_traffic_map,
ArpTransmittedIntfMap &arp_transmitted_intf_map);
void SendArpRequestForAllIntf(const AgentRoute *route);
void StartTimer();
ArpVrfState* vrf_state() {
return vrf_state_;
}
const IpAddress& ip() const {
return vm_ip_;
}
bool IntfPresentInIpMap(uint32_t id) {
if (l3_wait_for_traffic_map_.find(id) ==
l3_wait_for_traffic_map_.end()) {
return false;
}
return true;
}
bool IntfPresentInEvpnMap(uint32_t id) {
if (evpn_wait_for_traffic_map_.find(id) ==
evpn_wait_for_traffic_map_.end()) {
return false;
}
return true;
}
uint32_t IntfRetryCountInIpMap(uint32_t id) {
return l3_wait_for_traffic_map_[id];
}
uint32_t IntfRetryCountInEvpnMap(uint32_t id) {
return evpn_wait_for_traffic_map_[id];
}
private:
friend void intrusive_ptr_add_ref(ArpPathPreferenceState *aps);
friend void intrusive_ptr_release(ArpPathPreferenceState *aps);
ArpVrfState *vrf_state_;
Timer *arp_req_timer_;
uint32_t vrf_id_;
IpAddress vm_ip_;
uint8_t plen_;
IpAddress gw_ip_;
WaitForTrafficIntfMap l3_wait_for_traffic_map_;
WaitForTrafficIntfMap evpn_wait_for_traffic_map_;
tbb::atomic<int> refcount_;
};
typedef boost::intrusive_ptr<ArpPathPreferenceState> ArpPathPreferenceStatePtr;
void intrusive_ptr_add_ref(ArpPathPreferenceState *aps);
void intrusive_ptr_release(ArpPathPreferenceState *aps);
struct ArpVrfState : public DBState {
public:
typedef std::map<const IpAddress,
ArpPathPreferenceState*> ArpPathPreferenceStateMap;
typedef std::pair<const IpAddress,
ArpPathPreferenceState*> ArpPathPreferenceStatePair;
ArpVrfState(Agent *agent, ArpProto *proto, VrfEntry *vrf,
AgentRouteTable *table, AgentRouteTable *evpn_table);
~ArpVrfState();
void RouteUpdate(DBTablePartBase *part, DBEntryBase *entry);
void EvpnRouteUpdate(DBTablePartBase *part, DBEntryBase *entry);
void ManagedDelete() { deleted = true;}
void Delete();
bool DeleteRouteState(DBTablePartBase *part, DBEntryBase *entry);
bool DeleteEvpnRouteState(DBTablePartBase *part, DBEntryBase *entry);
bool PreWalkDone(DBTableBase *partition);
static void WalkDone(DBTableBase *partition, ArpVrfState *state);
ArpPathPreferenceState* Locate(const IpAddress &ip);
void Erase(const IpAddress &ip);
ArpPathPreferenceState* Get(const IpAddress ip) {
return arp_path_preference_map_[ip];
}
bool l3_walk_completed() const {
return l3_walk_completed_;
}
bool evpn_walk_completed() const {
return evpn_walk_completed_;
}
Agent *agent;
ArpProto *arp_proto;
VrfEntry *vrf;
AgentRouteTable *rt_table;
AgentRouteTable *evpn_rt_table;
DBTableBase::ListenerId route_table_listener_id;
DBTableBase::ListenerId evpn_route_table_listener_id;
LifetimeRef<ArpVrfState> table_delete_ref;
LifetimeRef<ArpVrfState> evpn_table_delete_ref;
bool deleted;
DBTableWalker::WalkId walk_id_;
DBTableWalker::WalkId evpn_walk_id_;
ArpPathPreferenceStateMap arp_path_preference_map_;
bool l3_walk_completed_;
bool evpn_walk_completed_;
friend class ArpProto;
};
class ArpDBState : public DBState {
public:
static const uint32_t kMaxRetry = 30 * 5; //retries upto 5 minutes,
//30 tries/per minutes
static const uint32_t kTimeout = 2000;
typedef std::map<uint32_t, uint32_t> WaitForTrafficIntfMap;
ArpDBState(ArpVrfState *vrf_state, uint32_t vrf_id,
IpAddress vm_ip_addr, uint8_t plen);
~ArpDBState();
void Update(const AgentRoute *route);
void UpdateArpRoutes(const InetUnicastRouteEntry *route);
void Delete(const InetUnicastRouteEntry *rt);
private:
ArpVrfState *vrf_state_;
SecurityGroupList sg_list_;
bool policy_;
bool resolve_route_;
VnListType vn_list_;
ArpPathPreferenceStatePtr arp_path_preference_state_;
};
#endif // vnsw_agent_arp_proto_hpp