author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 17 Mar 2008 13:12:17 -0700 | |
changeset 2643 | 2a3324f4dabe |
parent 1236 | cfa5e0b39281 |
child 2646 | c1fef7686472 |
permissions | -rw-r--r-- |
242 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2005 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 |
||
286
57e6a2006962
convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
258
diff
changeset
|
22 |
#include "ns3/assert.h" |
976
e82bac1816ce
ethernet Header and Trailer classes
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
902
diff
changeset
|
23 |
#include "ns3/address-utils.h" |
242 | 24 |
#include "arp-header.h" |
25 |
||
1236
cfa5e0b39281
rework the NS_XX_ENSURE_REGISTERED macros and make sure we typecheck the input to TraceContext::Add and TraceContext::Get methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1234
diff
changeset
|
26 |
namespace ns3 { |
1152
1d06449f0a98
macros to ensure proper initialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1151
diff
changeset
|
27 |
|
1236
cfa5e0b39281
rework the NS_XX_ENSURE_REGISTERED macros and make sure we typecheck the input to TraceContext::Add and TraceContext::Get methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1234
diff
changeset
|
28 |
NS_HEADER_ENSURE_REGISTERED (ArpHeader); |
2643
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
29 |
NS_OBJECT_ENSURE_REGISTERED (ArpHeader); |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
30 |
|
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
31 |
TypeId |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
32 |
ArpHeader::GetTypeId (void) |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
33 |
{ |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
34 |
static TypeId tid = TypeId ("ns3::ArpHeader") |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
35 |
.SetParent<Header> () |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
36 |
; |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
37 |
return tid; |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
38 |
} |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
39 |
TypeId |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
40 |
ArpHeader::GetInstanceTypeId (void) const |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
41 |
{ |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
42 |
return GetTypeId (); |
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
43 |
} |
242 | 44 |
|
1151
527d7b7e25af
force users to register their header/trailer uid strings by hand rather than do lazy uid allocation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1133
diff
changeset
|
45 |
uint32_t |
1126
06484dd65e76
add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
976
diff
changeset
|
46 |
ArpHeader::GetUid (void) |
06484dd65e76
add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
976
diff
changeset
|
47 |
{ |
1234
ca195a6a7e1e
Trailer::Register -> Trailer::AllocateUid and Header::Register -> Header::AllocateUid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
48 |
static uint32_t uid = AllocateUid<ArpHeader> ("ArpHeader.ns3"); |
1151
527d7b7e25af
force users to register their header/trailer uid strings by hand rather than do lazy uid allocation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1133
diff
changeset
|
49 |
return uid; |
1126
06484dd65e76
add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
976
diff
changeset
|
50 |
} |
06484dd65e76
add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
976
diff
changeset
|
51 |
|
242 | 52 |
void |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
902
diff
changeset
|
53 |
ArpHeader::SetRequest (Address sourceHardwareAddress, |
242 | 54 |
Ipv4Address sourceProtocolAddress, |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
902
diff
changeset
|
55 |
Address destinationHardwareAddress, |
242 | 56 |
Ipv4Address destinationProtocolAddress) |
57 |
{ |
|
58 |
m_type = ARP_TYPE_REQUEST; |
|
59 |
m_macSource = sourceHardwareAddress; |
|
60 |
m_macDest = destinationHardwareAddress; |
|
61 |
m_ipv4Source = sourceProtocolAddress; |
|
62 |
m_ipv4Dest = destinationProtocolAddress; |
|
63 |
} |
|
64 |
void |
|
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
902
diff
changeset
|
65 |
ArpHeader::SetReply (Address sourceHardwareAddress, |
242 | 66 |
Ipv4Address sourceProtocolAddress, |
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
902
diff
changeset
|
67 |
Address destinationHardwareAddress, |
242 | 68 |
Ipv4Address destinationProtocolAddress) |
69 |
{ |
|
70 |
m_type = ARP_TYPE_REPLY; |
|
71 |
m_macSource = sourceHardwareAddress; |
|
72 |
m_macDest = destinationHardwareAddress; |
|
73 |
m_ipv4Source = sourceProtocolAddress; |
|
74 |
m_ipv4Dest = destinationProtocolAddress; |
|
75 |
} |
|
76 |
bool |
|
77 |
ArpHeader::IsRequest (void) const |
|
78 |
{ |
|
79 |
return (m_type == ARP_TYPE_REQUEST)?true:false; |
|
80 |
} |
|
81 |
bool |
|
82 |
ArpHeader::IsReply (void) const |
|
83 |
{ |
|
84 |
return (m_type == ARP_TYPE_REPLY)?true:false; |
|
85 |
} |
|
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
902
diff
changeset
|
86 |
Address |
242 | 87 |
ArpHeader::GetSourceHardwareAddress (void) |
88 |
{ |
|
89 |
return m_macSource; |
|
90 |
} |
|
1161
bb72baff8b26
replace MacAddress by Address
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
902
diff
changeset
|
91 |
Address |
242 | 92 |
ArpHeader::GetDestinationHardwareAddress (void) |
93 |
{ |
|
94 |
return m_macDest; |
|
95 |
} |
|
96 |
Ipv4Address |
|
97 |
ArpHeader::GetSourceIpv4Address (void) |
|
98 |
{ |
|
99 |
return m_ipv4Source; |
|
100 |
} |
|
101 |
Ipv4Address |
|
102 |
ArpHeader::GetDestinationIpv4Address (void) |
|
103 |
{ |
|
104 |
return m_ipv4Dest; |
|
105 |
} |
|
106 |
||
795
cd108c9817d0
add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
107 |
std::string |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1198
diff
changeset
|
108 |
ArpHeader::GetName (void) const |
795
cd108c9817d0
add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
109 |
{ |
902
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
110 |
return "ARP"; |
795
cd108c9817d0
add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
111 |
} |
242 | 112 |
|
113 |
void |
|
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1198
diff
changeset
|
114 |
ArpHeader::Print (std::ostream &os) const |
242 | 115 |
{ |
116 |
if (IsRequest ()) |
|
117 |
{ |
|
902
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
118 |
os << "(" |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
119 |
<< "request " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
120 |
<< "source mac: " << m_macSource << " " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
121 |
<< "source ipv4: " << m_ipv4Source << " " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
122 |
<< "dest ipv4: " << m_ipv4Dest |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
123 |
<< ")" |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
124 |
; |
242 | 125 |
} |
126 |
else |
|
127 |
{ |
|
286
57e6a2006962
convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
258
diff
changeset
|
128 |
NS_ASSERT (IsReply ()); |
902
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
129 |
os << "(" |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
130 |
<< "reply " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
131 |
<< "source mac: " << m_macSource << " " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
132 |
<< "source ipv4: " << m_ipv4Source << " " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
133 |
<< "dest mac: " << m_macDest << " " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
134 |
<< "dest ipv4: " <<m_ipv4Dest |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
135 |
<< ")" |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
136 |
; |
242 | 137 |
} |
138 |
} |
|
139 |
uint32_t |
|
140 |
ArpHeader::GetSerializedSize (void) const |
|
141 |
{ |
|
142 |
/* this is the size of an ARP payload. */ |
|
143 |
return 28; |
|
144 |
} |
|
145 |
||
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
286
diff
changeset
|
146 |
void |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1198
diff
changeset
|
147 |
ArpHeader::Serialize (Buffer::Iterator start) const |
242 | 148 |
{ |
149 |
Buffer::Iterator i = start; |
|
286
57e6a2006962
convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
258
diff
changeset
|
150 |
NS_ASSERT (m_macSource.GetLength () == m_macDest.GetLength ()); |
242 | 151 |
|
152 |
/* ethernet */ |
|
153 |
i.WriteHtonU16 (0x0001); |
|
154 |
/* ipv4 */ |
|
155 |
i.WriteHtonU16 (0x0800); |
|
258
df3bca25ae37
make sure that mac addr len is correctly written
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
156 |
i.WriteU8 (m_macSource.GetLength ()); |
242 | 157 |
i.WriteU8 (4); |
158 |
i.WriteHtonU16 (m_type); |
|
159 |
WriteTo (i, m_macSource); |
|
160 |
WriteTo (i, m_ipv4Source); |
|
161 |
WriteTo (i, m_macDest); |
|
162 |
WriteTo (i, m_ipv4Dest); |
|
163 |
} |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
286
diff
changeset
|
164 |
uint32_t |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1198
diff
changeset
|
165 |
ArpHeader::Deserialize (Buffer::Iterator start) |
242 | 166 |
{ |
167 |
Buffer::Iterator i = start; |
|
168 |
i.Next (2+2); |
|
169 |
uint32_t hardwareAddressLen = i.ReadU8 (); |
|
170 |
i.Next (1); |
|
171 |
m_type = i.ReadNtohU16 (); |
|
172 |
ReadFrom (i, m_macSource, hardwareAddressLen); |
|
173 |
ReadFrom (i, m_ipv4Source); |
|
174 |
ReadFrom (i, m_macDest, hardwareAddressLen); |
|
175 |
ReadFrom (i, m_ipv4Dest); |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
286
diff
changeset
|
176 |
return GetSerializedSize (); |
242 | 177 |
} |
178 |
||
179 |
}; // namespace ns3 |