author | Craig Dowell <craigdo@ee.washington.edu> |
Fri, 24 Aug 2007 16:57:54 -0700 | |
changeset 1440 | c77745b2731c |
parent 1161 | bb72baff8b26 |
child 1341 | f685d4bf320f |
permissions | -rw-r--r-- |
242 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2006 INRIA |
|
4 |
* All rights reserved. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License version 2 as |
|
8 |
* published by the Free Software Foundation; |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 |
* |
|
19 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
20 |
*/ |
|
21 |
#ifndef ARP_CACHE_H |
|
22 |
#define ARP_CACHE_H |
|
23 |
||
24 |
#include <stdint.h> |
|
25 |
#include "ns3/packet.h" |
|
26 |
#include "ns3/nstime.h" |
|
524
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
474
diff
changeset
|
27 |
#include "ns3/net-device.h" |
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
474
diff
changeset
|
28 |
#include "ns3/ipv4-address.h" |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
632
diff
changeset
|
29 |
#include "ns3/address.h" |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
551
diff
changeset
|
30 |
#include "ns3/ptr.h" |
242 | 31 |
#include "sgi-hashmap.h" |
32 |
||
33 |
namespace ns3 { |
|
34 |
||
35 |
class NetDevice; |
|
551
12ed30c77cab
revert Ipv4Interface * -> Ptr<Ipv4Interface>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
548
diff
changeset
|
36 |
class Ipv4Interface; |
242 | 37 |
|
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
38 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
39 |
* \brief An ARP cache |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
40 |
* |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
41 |
* A cached lookup table for translating layer 3 addresses to layer 2. |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
42 |
* This implementation does lookups from IPv4 to a MAC address |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
43 |
*/ |
242 | 44 |
class ArpCache { |
45 |
public: |
|
46 |
class Entry; |
|
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
47 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
48 |
* \param device The hardware NetDevice associated with this ARP chache |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
49 |
* \param interface the Ipv4Interface associated with this ARP chache |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
50 |
*/ |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
551
diff
changeset
|
51 |
ArpCache (Ptr<NetDevice> device, Ipv4Interface *interface); |
242 | 52 |
~ArpCache (); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
53 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
54 |
* \return The NetDevice that this ARP cache is associated with |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
55 |
*/ |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
551
diff
changeset
|
56 |
Ptr<NetDevice> GetDevice (void) const; |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
57 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
58 |
* \return the Ipv4Interface that this ARP cache is associated with |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
59 |
*/ |
551
12ed30c77cab
revert Ipv4Interface * -> Ptr<Ipv4Interface>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
548
diff
changeset
|
60 |
Ipv4Interface *GetInterface (void) const; |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
61 |
|
242 | 62 |
void SetAliveTimeout (Time aliveTimeout); |
63 |
void SetDeadTimeout (Time deadTimeout); |
|
64 |
void SetWaitReplyTimeout (Time waitReplyTimeout); |
|
65 |
Time GetAliveTimeout (void) const; |
|
66 |
Time GetDeadTimeout (void) const; |
|
67 |
Time GetWaitReplyTimeout (void) const; |
|
68 |
||
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
69 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
70 |
* \brief Do lookup in the ARP chache against an IP address |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
71 |
* \param destination The destination IPv4 address to lookup the MAC address |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
72 |
* of |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
73 |
* \return An ArpCache::Entry with info about layer 2 |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
74 |
*/ |
242 | 75 |
ArpCache::Entry *Lookup (Ipv4Address destination); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
76 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
77 |
* \brief Add an Ipv4Address to this ARP cache |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
78 |
*/ |
242 | 79 |
ArpCache::Entry *Add (Ipv4Address to); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
80 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
81 |
* \brief Clear the ArpCache of all entries |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
82 |
*/ |
242 | 83 |
void Flush (void); |
84 |
||
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
85 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
86 |
* \brief A record that that holds information about an ArpCache entry |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
87 |
*/ |
242 | 88 |
class Entry { |
89 |
public: |
|
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
90 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
91 |
* \brief Constructor |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
92 |
* \param arp The ArpCache this entry belongs to |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
93 |
*/ |
242 | 94 |
Entry (ArpCache *arp); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
95 |
|
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
96 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
97 |
* \brief Changes the state of this entry to dead |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
98 |
*/ |
242 | 99 |
void MarkDead (void); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
100 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
101 |
* \param macAddress |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
102 |
* \return |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
103 |
*/ |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
632
diff
changeset
|
104 |
Packet MarkAlive (Address macAddress); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
105 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
106 |
* \param waiting |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
107 |
*/ |
242 | 108 |
void MarkWaitReply (Packet waiting); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
109 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
110 |
* \param waiting |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
111 |
* \return |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
112 |
*/ |
242 | 113 |
Packet UpdateWaitReply (Packet waiting); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
114 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
115 |
* \return True if the state of this entry is dead; false otherwise. |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
116 |
*/ |
242 | 117 |
bool IsDead (void); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
118 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
119 |
* \return True if the state of this entry is alive; false otherwise. |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
120 |
*/ |
242 | 121 |
bool IsAlive (void); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
122 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
123 |
* \return True if the state of this entry is wait_reply; false otherwise. |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
124 |
*/ |
242 | 125 |
bool IsWaitReply (void); |
126 |
||
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
127 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
128 |
* \return The MacAddress of this entry |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
129 |
*/ |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
632
diff
changeset
|
130 |
Address GetMacAddress (void); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
131 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
132 |
* \return True if this entry has timedout; false otherwise. |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
568
diff
changeset
|
133 |
*/ |
242 | 134 |
bool IsExpired (void); |
135 |
private: |
|
136 |
enum ArpCacheEntryState_e { |
|
137 |
ALIVE, |
|
138 |
WAIT_REPLY, |
|
139 |
DEAD |
|
140 |
}; |
|
141 |
||
142 |
void UpdateSeen (void); |
|
143 |
ArpCache *m_arp; |
|
144 |
ArpCacheEntryState_e m_state; |
|
145 |
Time m_lastSeen; |
|
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
632
diff
changeset
|
146 |
Address m_macAddress; |
242 | 147 |
Packet m_waiting; |
148 |
}; |
|
149 |
||
150 |
private: |
|
151 |
typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash> Cache; |
|
152 |
typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI; |
|
153 |
||
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
551
diff
changeset
|
154 |
Ptr<NetDevice> m_device; |
551
12ed30c77cab
revert Ipv4Interface * -> Ptr<Ipv4Interface>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
548
diff
changeset
|
155 |
Ipv4Interface *m_interface; |
242 | 156 |
Time m_aliveTimeout; |
157 |
Time m_deadTimeout; |
|
158 |
Time m_waitReplyTimeout; |
|
159 |
Cache m_arpCache; |
|
160 |
}; |
|
161 |
||
162 |
||
163 |
}; // namespace ns3 |
|
164 |
||
165 |
#endif /* ARP_CACHE_H */ |