A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
packet-socket-address.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 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
*/
20
#include "
packet-socket-address.h
"
21
#include "ns3/net-device.h"
22
23
namespace
ns3 {
24
25
PacketSocketAddress::PacketSocketAddress
()
26
{
27
}
28
void
29
PacketSocketAddress::SetProtocol
(uint16_t protocol)
30
{
31
m_protocol
= protocol;
32
}
33
void
34
PacketSocketAddress::SetAllDevices
(
void
)
35
{
36
m_isSingleDevice
=
false
;
37
m_device
= 0;
38
}
39
void
40
PacketSocketAddress::SetSingleDevice
(uint32_t index)
41
{
42
m_isSingleDevice
=
true
;
43
m_device
= index;
44
}
45
void
46
PacketSocketAddress::SetPhysicalAddress
(
const
Address
address)
47
{
48
m_address
= address;
49
}
50
51
uint16_t
52
PacketSocketAddress::GetProtocol
(
void
)
const
53
{
54
return
m_protocol
;
55
}
56
bool
57
PacketSocketAddress::IsSingleDevice
(
void
)
const
58
{
59
return
m_isSingleDevice
;
60
}
61
uint32_t
62
PacketSocketAddress::GetSingleDevice
(
void
)
const
63
{
64
return
m_device
;
65
}
66
Address
67
PacketSocketAddress::GetPhysicalAddress
(
void
)
const
68
{
69
return
m_address
;
70
}
71
72
PacketSocketAddress::operator
Address
()
const
73
{
74
return
ConvertTo ();
75
}
76
77
Address
78
PacketSocketAddress::ConvertTo
(
void
)
const
79
{
80
Address
address;
81
uint8_t buffer[
Address::MAX_SIZE
];
82
buffer[0] =
m_protocol
& 0xff;
83
buffer[1] = (
m_protocol
>> 8) & 0xff;
84
buffer[2] = (
m_device
>> 24) & 0xff;
85
buffer[3] = (
m_device
>> 16) & 0xff;
86
buffer[4] = (
m_device
>> 8) & 0xff;
87
buffer[5] = (
m_device
>> 0) & 0xff;
88
buffer[6] =
m_isSingleDevice
? 1 : 0;
89
uint32_t copied =
m_address
.
CopyAllTo
(buffer + 7,
Address::MAX_SIZE
- 7);
90
return
Address
(
GetType
(), buffer, 7 + copied);
91
}
92
PacketSocketAddress
93
PacketSocketAddress::ConvertFrom
(
const
Address
&address)
94
{
95
NS_ASSERT
(
IsMatchingType
(address));
96
uint8_t buffer[
Address::MAX_SIZE
];
97
address.
CopyTo
(buffer);
98
uint16_t protocol = buffer[0] | (buffer[1] << 8);
99
uint32_t device = 0;
100
device |= buffer[2];
101
device <<= 8;
102
device |= buffer[3];
103
device <<= 8;
104
device |= buffer[4];
105
device <<= 8;
106
device |= buffer[5];
107
bool
isSingleDevice = (buffer[6] == 1) ?
true
:
false
;
108
Address
physical;
109
physical.
CopyAllFrom
(buffer + 7,
Address::MAX_SIZE
- 7);
110
PacketSocketAddress
ad;
111
ad.
SetProtocol
(protocol);
112
if
(isSingleDevice)
113
{
114
ad.
SetSingleDevice
(device);
115
}
116
else
117
{
118
ad.
SetAllDevices
();
119
}
120
ad.
SetPhysicalAddress
(physical);
121
return
ad;
122
}
123
bool
124
PacketSocketAddress::IsMatchingType
(
const
Address
&address)
125
{
126
return
address.
IsMatchingType
(
GetType
());
127
}
128
uint8_t
129
PacketSocketAddress::GetType
(
void
)
130
{
131
static
uint8_t type =
Address::Register
();
132
return
type;
133
}
134
135
}
// namespace ns3
src
network
utils
packet-socket-address.cc
Generated on Tue Oct 9 2012 16:45:44 for ns-3 by
1.8.1.2