author | Tommaso Pecorella <tommaso.pecorella@unifi.it> |
Sat, 13 Jul 2013 12:35:55 +0200 | |
changeset 9946 | df4a7e93c13d |
parent 9144 | 6a15c50388bc |
child 10968 | 2d29fee2b7b8 |
permissions | -rw-r--r-- |
7385
10beb0e53130
standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents:
7256
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
242 | 2 |
/* |
3 |
* Copyright (c) 2006 INRIA |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License version 2 as |
|
7 |
* published by the Free Software Foundation; |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 |
* |
|
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
19 |
*/ |
|
976
e82bac1816ce
ethernet Header and Trailer classes
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
524
diff
changeset
|
20 |
#include "address-utils.h" |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
21 |
#include "inet-socket-address.h" |
9144
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
22 |
#include "ns3/log.h" |
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
23 |
|
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
24 |
NS_LOG_COMPONENT_DEFINE ("AddressUtils"); |
242 | 25 |
|
26 |
namespace ns3 { |
|
27 |
||
28 |
void WriteTo (Buffer::Iterator &i, Ipv4Address ad) |
|
29 |
{ |
|
9144
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
30 |
NS_LOG_FUNCTION (&i << &ad); |
3179
1763f7ac8e80
bug 146: s/HostOrder//
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
31 |
i.WriteHtonU32 (ad.Get ()); |
242 | 32 |
} |
3852 | 33 |
void WriteTo (Buffer::Iterator &i, Ipv6Address ad) |
34 |
{ |
|
9144
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
35 |
NS_LOG_FUNCTION (&i << &ad); |
3852 | 36 |
uint8_t buf[16]; |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
6823
diff
changeset
|
37 |
ad.GetBytes (buf); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
6823
diff
changeset
|
38 |
i.Write (buf, 16); |
3852 | 39 |
} |
1167 | 40 |
void WriteTo (Buffer::Iterator &i, const Address &ad) |
242 | 41 |
{ |
9144
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
42 |
NS_LOG_FUNCTION (&i << &ad); |
1167 | 43 |
uint8_t mac[Address::MAX_SIZE]; |
44 |
ad.CopyTo (mac); |
|
247
fb7375bb43d7
make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
242
diff
changeset
|
45 |
i.Write (mac, ad.GetLength ()); |
242 | 46 |
} |
9946
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
47 |
void WriteTo (Buffer::Iterator &i, Mac64Address ad) |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
48 |
{ |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
49 |
NS_LOG_FUNCTION (&i << &ad); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
50 |
uint8_t mac[8]; |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
51 |
ad.CopyTo (mac); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
52 |
i.Write (mac, 8); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
53 |
} |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
54 |
void WriteTo (Buffer::Iterator &i, Mac48Address ad) |
1167 | 55 |
{ |
9144
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
56 |
NS_LOG_FUNCTION (&i << &ad); |
1167 | 57 |
uint8_t mac[6]; |
58 |
ad.CopyTo (mac); |
|
59 |
i.Write (mac, 6); |
|
60 |
} |
|
9946
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
61 |
void WriteTo (Buffer::Iterator &i, Mac16Address ad) |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
62 |
{ |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
63 |
NS_LOG_FUNCTION (&i << &ad); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
64 |
uint8_t mac[2]; |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
65 |
ad.CopyTo (mac); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
66 |
i.Write (mac+1, 1); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
67 |
i.Write (mac, 1); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
68 |
} |
242 | 69 |
|
70 |
void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad) |
|
71 |
{ |
|
9144
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
72 |
NS_LOG_FUNCTION (&i << &ad); |
3179
1763f7ac8e80
bug 146: s/HostOrder//
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
73 |
ad.Set (i.ReadNtohU32 ()); |
242 | 74 |
} |
3852 | 75 |
void ReadFrom (Buffer::Iterator &i, Ipv6Address &ad) |
76 |
{ |
|
9144
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
77 |
NS_LOG_FUNCTION (&i << &ad); |
3852 | 78 |
uint8_t ipv6[16]; |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
6823
diff
changeset
|
79 |
i.Read (ipv6, 16); |
3852 | 80 |
ad.Set (ipv6); |
81 |
} |
|
1167 | 82 |
void ReadFrom (Buffer::Iterator &i, Address &ad, uint32_t len) |
242 | 83 |
{ |
9144
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
84 |
NS_LOG_FUNCTION (&i << &ad << len); |
1167 | 85 |
uint8_t mac[Address::MAX_SIZE]; |
242 | 86 |
i.Read (mac, len); |
1167 | 87 |
ad.CopyFrom (mac, len); |
88 |
} |
|
9946
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
89 |
void ReadFrom (Buffer::Iterator &i, Mac64Address &ad) |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
90 |
{ |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
91 |
NS_LOG_FUNCTION (&i << &ad); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
92 |
uint8_t mac[8]; |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
93 |
i.Read (mac, 8); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
94 |
ad.CopyFrom (mac); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
95 |
} |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
96 |
void ReadFrom (Buffer::Iterator &i, Mac48Address &ad) |
1167 | 97 |
{ |
9144
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
98 |
NS_LOG_FUNCTION (&i << &ad); |
1167 | 99 |
uint8_t mac[6]; |
100 |
i.Read (mac, 6); |
|
101 |
ad.CopyFrom (mac); |
|
242 | 102 |
} |
9946
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
103 |
void ReadFrom (Buffer::Iterator &i, Mac16Address &ad) |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
104 |
{ |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
105 |
NS_LOG_FUNCTION (&i << &ad); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
106 |
uint8_t mac[2]; |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
107 |
i.Read (mac+1, 1); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
108 |
i.Read (mac, 1); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
109 |
ad.CopyFrom (mac); |
df4a7e93c13d
Mac16Address added, Mac64Address refactored, and Mac[16,64]Address can be used in IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
9144
diff
changeset
|
110 |
} |
242 | 111 |
|
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
112 |
namespace addressUtils { |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
113 |
|
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
114 |
bool IsMulticast (const Address &ad) |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
115 |
{ |
9144
6a15c50388bc
Clean up function logging of network module.
Maja Grubišić <maja.grubisic@live.com>
parents:
7385
diff
changeset
|
116 |
NS_LOG_FUNCTION (&ad); |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
117 |
if (InetSocketAddress::IsMatchingType (ad)) |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
118 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
119 |
InetSocketAddress inetAddr = InetSocketAddress::ConvertFrom (ad); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
120 |
Ipv4Address ipv4 = inetAddr.GetIpv4 (); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
121 |
return ipv4.IsMulticast (); |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
122 |
} |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
123 |
// IPv6 case can go here, in future |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
124 |
return false; |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
125 |
} |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
126 |
|
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
127 |
} // namespace addressUtils |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3852
diff
changeset
|
128 |
|
1167 | 129 |
} // namespace ns3 |