author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Fri, 03 Aug 2007 17:26:10 +0200 | |
changeset 1133 | 2878564d62ff |
parent 1126 | 06484dd65e76 |
child 1151 | 527d7b7e25af |
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 |
||
26 |
namespace ns3 { |
|
27 |
||
1133
2878564d62ff
fix valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1126
diff
changeset
|
28 |
std::string |
1126
06484dd65e76
add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
976
diff
changeset
|
29 |
ArpHeader::GetUid (void) |
06484dd65e76
add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
976
diff
changeset
|
30 |
{ |
06484dd65e76
add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
976
diff
changeset
|
31 |
return "ArpHeader.ns3"; |
06484dd65e76
add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
976
diff
changeset
|
32 |
} |
06484dd65e76
add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
976
diff
changeset
|
33 |
|
242 | 34 |
ArpHeader::~ArpHeader () |
35 |
{} |
|
36 |
||
37 |
void |
|
38 |
ArpHeader::SetRequest (MacAddress sourceHardwareAddress, |
|
39 |
Ipv4Address sourceProtocolAddress, |
|
40 |
MacAddress destinationHardwareAddress, |
|
41 |
Ipv4Address destinationProtocolAddress) |
|
42 |
{ |
|
43 |
m_type = ARP_TYPE_REQUEST; |
|
44 |
m_macSource = sourceHardwareAddress; |
|
45 |
m_macDest = destinationHardwareAddress; |
|
46 |
m_ipv4Source = sourceProtocolAddress; |
|
47 |
m_ipv4Dest = destinationProtocolAddress; |
|
48 |
} |
|
49 |
void |
|
50 |
ArpHeader::SetReply (MacAddress sourceHardwareAddress, |
|
51 |
Ipv4Address sourceProtocolAddress, |
|
52 |
MacAddress destinationHardwareAddress, |
|
53 |
Ipv4Address destinationProtocolAddress) |
|
54 |
{ |
|
55 |
m_type = ARP_TYPE_REPLY; |
|
56 |
m_macSource = sourceHardwareAddress; |
|
57 |
m_macDest = destinationHardwareAddress; |
|
58 |
m_ipv4Source = sourceProtocolAddress; |
|
59 |
m_ipv4Dest = destinationProtocolAddress; |
|
60 |
} |
|
61 |
bool |
|
62 |
ArpHeader::IsRequest (void) const |
|
63 |
{ |
|
64 |
return (m_type == ARP_TYPE_REQUEST)?true:false; |
|
65 |
} |
|
66 |
bool |
|
67 |
ArpHeader::IsReply (void) const |
|
68 |
{ |
|
69 |
return (m_type == ARP_TYPE_REPLY)?true:false; |
|
70 |
} |
|
71 |
MacAddress |
|
72 |
ArpHeader::GetSourceHardwareAddress (void) |
|
73 |
{ |
|
74 |
return m_macSource; |
|
75 |
} |
|
76 |
MacAddress |
|
77 |
ArpHeader::GetDestinationHardwareAddress (void) |
|
78 |
{ |
|
79 |
return m_macDest; |
|
80 |
} |
|
81 |
Ipv4Address |
|
82 |
ArpHeader::GetSourceIpv4Address (void) |
|
83 |
{ |
|
84 |
return m_ipv4Source; |
|
85 |
} |
|
86 |
Ipv4Address |
|
87 |
ArpHeader::GetDestinationIpv4Address (void) |
|
88 |
{ |
|
89 |
return m_ipv4Dest; |
|
90 |
} |
|
91 |
||
795
cd108c9817d0
add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
92 |
std::string |
cd108c9817d0
add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
93 |
ArpHeader::DoGetName (void) const |
cd108c9817d0
add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
94 |
{ |
902
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
95 |
return "ARP"; |
795
cd108c9817d0
add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
96 |
} |
242 | 97 |
|
98 |
void |
|
99 |
ArpHeader::PrintTo (std::ostream &os) const |
|
100 |
{ |
|
101 |
if (IsRequest ()) |
|
102 |
{ |
|
902
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
103 |
os << "(" |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
104 |
<< "request " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
105 |
<< "source mac: " << m_macSource << " " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
106 |
<< "source ipv4: " << m_ipv4Source << " " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
107 |
<< "dest ipv4: " << m_ipv4Dest |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
108 |
<< ")" |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
109 |
; |
242 | 110 |
} |
111 |
else |
|
112 |
{ |
|
286
57e6a2006962
convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
258
diff
changeset
|
113 |
NS_ASSERT (IsReply ()); |
902
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
114 |
os << "(" |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
115 |
<< "reply " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
116 |
<< "source mac: " << m_macSource << " " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
117 |
<< "source ipv4: " << m_ipv4Source << " " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
118 |
<< "dest mac: " << m_macDest << " " |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
119 |
<< "dest ipv4: " <<m_ipv4Dest |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
120 |
<< ")" |
b85919168708
change arp pretty printing to new format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
121 |
; |
242 | 122 |
} |
123 |
} |
|
124 |
uint32_t |
|
125 |
ArpHeader::GetSerializedSize (void) const |
|
126 |
{ |
|
127 |
/* this is the size of an ARP payload. */ |
|
128 |
return 28; |
|
129 |
} |
|
130 |
||
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
286
diff
changeset
|
131 |
void |
242 | 132 |
ArpHeader::SerializeTo (Buffer::Iterator start) const |
133 |
{ |
|
134 |
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
|
135 |
NS_ASSERT (m_macSource.GetLength () == m_macDest.GetLength ()); |
242 | 136 |
|
137 |
/* ethernet */ |
|
138 |
i.WriteHtonU16 (0x0001); |
|
139 |
/* ipv4 */ |
|
140 |
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
|
141 |
i.WriteU8 (m_macSource.GetLength ()); |
242 | 142 |
i.WriteU8 (4); |
143 |
i.WriteHtonU16 (m_type); |
|
144 |
WriteTo (i, m_macSource); |
|
145 |
WriteTo (i, m_ipv4Source); |
|
146 |
WriteTo (i, m_macDest); |
|
147 |
WriteTo (i, m_ipv4Dest); |
|
148 |
} |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
286
diff
changeset
|
149 |
uint32_t |
242 | 150 |
ArpHeader::DeserializeFrom (Buffer::Iterator start) |
151 |
{ |
|
152 |
Buffer::Iterator i = start; |
|
153 |
i.Next (2+2); |
|
154 |
uint32_t hardwareAddressLen = i.ReadU8 (); |
|
155 |
i.Next (1); |
|
156 |
m_type = i.ReadNtohU16 (); |
|
157 |
ReadFrom (i, m_macSource, hardwareAddressLen); |
|
158 |
ReadFrom (i, m_ipv4Source); |
|
159 |
ReadFrom (i, m_macDest, hardwareAddressLen); |
|
160 |
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
|
161 |
return GetSerializedSize (); |
242 | 162 |
} |
163 |
||
164 |
}; // namespace ns3 |