00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARP_CACHE_H
00021 #define ARP_CACHE_H
00022
00023 #include <stdint.h>
00024 #include <list>
00025 #include "ns3/simulator.h"
00026 #include "ns3/callback.h"
00027 #include "ns3/packet.h"
00028 #include "ns3/nstime.h"
00029 #include "ns3/net-device.h"
00030 #include "ns3/ipv4-address.h"
00031 #include "ns3/address.h"
00032 #include "ns3/ptr.h"
00033 #include "ns3/object.h"
00034 #include "ns3/traced-callback.h"
00035 #include "sgi-hashmap.h"
00036
00037 namespace ns3 {
00038
00039 class NetDevice;
00040 class Ipv4Interface;
00041
00042
00043
00044
00045
00046
00047
00048
00049 class ArpCache : public Object
00050 {
00051 public:
00052 static TypeId GetTypeId (void);
00053 class Entry;
00054 ArpCache ();
00055 ~ArpCache ();
00056
00057
00058
00059
00060
00061 void SetDevice (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface);
00062
00063
00064
00065 Ptr<NetDevice> GetDevice (void) const;
00066
00067
00068
00069 Ptr<Ipv4Interface> GetInterface (void) const;
00070
00071 void SetAliveTimeout (Time aliveTimeout);
00072 void SetDeadTimeout (Time deadTimeout);
00073 void SetWaitReplyTimeout (Time waitReplyTimeout);
00074 Time GetAliveTimeout (void) const;
00075 Time GetDeadTimeout (void) const;
00076 Time GetWaitReplyTimeout (void) const;
00077
00078
00079
00080
00081
00082
00083
00084
00085 void SetArpRequestCallback (Callback<void, Ptr<const ArpCache>,
00086 Ipv4Address> arpRequestCallback);
00087
00088
00089
00090
00091
00092 void StartWaitReplyTimer (void);
00093
00094
00095
00096
00097
00098
00099 ArpCache::Entry *Lookup (Ipv4Address destination);
00100
00101
00102
00103 ArpCache::Entry *Add (Ipv4Address to);
00104
00105
00106
00107 void Flush (void);
00108
00109
00110
00111
00112 class Entry {
00113 public:
00114
00115
00116
00117
00118 Entry (ArpCache *arp);
00119
00120
00121
00122
00123 void MarkDead (void);
00124
00125
00126
00127 void MarkAlive (Address macAddress);
00128
00129
00130
00131 void MarkWaitReply (Ptr<Packet> waiting);
00132
00133
00134
00135
00136 bool UpdateWaitReply (Ptr<Packet> waiting);
00137
00138
00139
00140 bool IsDead (void);
00141
00142
00143
00144 bool IsAlive (void);
00145
00146
00147
00148 bool IsWaitReply (void);
00149
00150
00151
00152
00153 Address GetMacAddress (void) const;
00154
00155
00156
00157 Ipv4Address GetIpv4Address (void) const;
00158
00159
00160
00161 void SetIpv4Address (Ipv4Address destination);
00162
00163
00164
00165 bool IsExpired (void);
00166
00167
00168
00169
00170
00171 Ptr<Packet> DequeuePending (void);
00172
00173
00174
00175
00176 uint32_t GetRetries (void) const;
00177
00178
00179
00180 void IncrementRetries (void);
00181
00182
00183
00184 void ClearRetries (void);
00185
00186 private:
00187 enum ArpCacheEntryState_e {
00188 ALIVE,
00189 WAIT_REPLY,
00190 DEAD
00191 };
00192
00193 void UpdateSeen (void);
00194 ArpCache *m_arp;
00195 ArpCacheEntryState_e m_state;
00196 Time m_lastSeen;
00197 Address m_macAddress;
00198 Ipv4Address m_ipv4Address;
00199 std::list<Ptr<Packet> > m_pending;
00200 uint32_t m_retries;
00201 };
00202
00203 private:
00204 typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash> Cache;
00205 typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI;
00206
00207 virtual void DoDispose (void);
00208
00209 Ptr<NetDevice> m_device;
00210 Ptr<Ipv4Interface> m_interface;
00211 Time m_aliveTimeout;
00212 Time m_deadTimeout;
00213 Time m_waitReplyTimeout;
00214 EventId m_waitReplyTimer;
00215 Callback<void, Ptr<const ArpCache>, Ipv4Address> m_arpRequestCallback;
00216 uint32_t m_maxRetries;
00217
00218
00219
00220
00221
00222 void HandleWaitReplyTimeout (void);
00223 uint32_t m_pendingQueueSize;
00224 Cache m_arpCache;
00225 TracedCallback<Ptr<const Packet> > m_dropTrace;
00226 };
00227
00228
00229 };
00230
00231 #endif