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
#include "ns3/log.h"
23
24
NS_LOG_COMPONENT_DEFINE
(
"PacketSocketAddress"
);
25
26
namespace
ns3 {
27
28
PacketSocketAddress::PacketSocketAddress
()
29
{
30
NS_LOG_FUNCTION
(
this
);
31
}
32
void
33
PacketSocketAddress::SetProtocol
(uint16_t protocol)
34
{
35
NS_LOG_FUNCTION
(
this
<< protocol);
36
m_protocol
= protocol;
37
}
38
void
39
PacketSocketAddress::SetAllDevices
(
void
)
40
{
41
NS_LOG_FUNCTION
(
this
);
42
m_isSingleDevice
=
false
;
43
m_device
= 0;
44
}
45
void
46
PacketSocketAddress::SetSingleDevice
(uint32_t index)
47
{
48
NS_LOG_FUNCTION
(
this
<< index);
49
m_isSingleDevice
=
true
;
50
m_device
= index;
51
}
52
void
53
PacketSocketAddress::SetPhysicalAddress
(
const
Address
address
)
54
{
55
NS_LOG_FUNCTION
(
this
<< address);
56
m_address
=
address
;
57
}
58
59
uint16_t
60
PacketSocketAddress::GetProtocol
(
void
)
const
61
{
62
NS_LOG_FUNCTION
(
this
);
63
return
m_protocol
;
64
}
65
bool
66
PacketSocketAddress::IsSingleDevice
(
void
)
const
67
{
68
NS_LOG_FUNCTION
(
this
);
69
return
m_isSingleDevice
;
70
}
71
uint32_t
72
PacketSocketAddress::GetSingleDevice
(
void
)
const
73
{
74
NS_LOG_FUNCTION
(
this
);
75
return
m_device
;
76
}
77
Address
78
PacketSocketAddress::GetPhysicalAddress
(
void
)
const
79
{
80
NS_LOG_FUNCTION
(
this
);
81
return
m_address
;
82
}
83
84
PacketSocketAddress::operator
Address
()
const
85
{
86
return
ConvertTo ();
87
}
88
89
Address
90
PacketSocketAddress::ConvertTo
(
void
)
const
91
{
92
NS_LOG_FUNCTION
(
this
);
93
Address
address
;
94
uint8_t buffer[
Address::MAX_SIZE
];
95
buffer[0] =
m_protocol
& 0xff;
96
buffer[1] = (
m_protocol
>> 8) & 0xff;
97
buffer[2] = (
m_device
>> 24) & 0xff;
98
buffer[3] = (
m_device
>> 16) & 0xff;
99
buffer[4] = (
m_device
>> 8) & 0xff;
100
buffer[5] = (
m_device
>> 0) & 0xff;
101
buffer[6] =
m_isSingleDevice
? 1 : 0;
102
uint32_t copied =
m_address
.
CopyAllTo
(buffer + 7,
Address::MAX_SIZE
- 7);
103
return
Address
(
GetType
(), buffer, 7 + copied);
104
}
105
PacketSocketAddress
106
PacketSocketAddress::ConvertFrom
(
const
Address
&
address
)
107
{
108
NS_LOG_FUNCTION
(address);
109
NS_ASSERT
(
IsMatchingType
(address));
110
uint8_t buffer[
Address::MAX_SIZE
];
111
address.
CopyTo
(buffer);
112
uint16_t protocol = buffer[0] | (buffer[1] << 8);
113
uint32_t device = 0;
114
device |= buffer[2];
115
device <<= 8;
116
device |= buffer[3];
117
device <<= 8;
118
device |= buffer[4];
119
device <<= 8;
120
device |= buffer[5];
121
bool
isSingleDevice = (buffer[6] == 1) ?
true
:
false
;
122
Address
physical;
123
physical.
CopyAllFrom
(buffer + 7,
Address::MAX_SIZE
- 7);
124
PacketSocketAddress
ad;
125
ad.
SetProtocol
(protocol);
126
if
(isSingleDevice)
127
{
128
ad.
SetSingleDevice
(device);
129
}
130
else
131
{
132
ad.
SetAllDevices
();
133
}
134
ad.
SetPhysicalAddress
(physical);
135
return
ad;
136
}
137
bool
138
PacketSocketAddress::IsMatchingType
(
const
Address
&
address
)
139
{
140
NS_LOG_FUNCTION
(address);
141
return
address.
IsMatchingType
(
GetType
());
142
}
143
uint8_t
144
PacketSocketAddress::GetType
(
void
)
145
{
146
NS_LOG_FUNCTION_NOARGS
();
147
static
uint8_t type =
Address::Register
();
148
return
type;
149
}
150
151
}
// namespace ns3
ns3::PacketSocketAddress::GetProtocol
uint16_t GetProtocol(void) const
Definition:
packet-socket-address.cc:60
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
ns3::Address::MAX_SIZE
Definition:
address.h:94
ns3::Address::IsMatchingType
bool IsMatchingType(uint8_t type) const
Definition:
address.cc:131
ns3::PacketSocketAddress
an address for a packet socket
Definition:
packet-socket-address.h:38
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::PacketSocketAddress::IsMatchingType
static bool IsMatchingType(const Address &address)
Definition:
packet-socket-address.cc:138
ns3::PacketSocketAddress::SetAllDevices
void SetAllDevices(void)
Definition:
packet-socket-address.cc:39
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition:
log.h:309
ns3::PacketSocketAddress::GetSingleDevice
uint32_t GetSingleDevice(void) const
Definition:
packet-socket-address.cc:72
ns3::PacketSocketAddress::SetSingleDevice
void SetSingleDevice(uint32_t device)
Definition:
packet-socket-address.cc:46
ns3::Address
a polymophic address class
Definition:
address.h:86
ns3::PacketSocketAddress::PacketSocketAddress
PacketSocketAddress()
Definition:
packet-socket-address.cc:28
ns3::Address::CopyAllTo
uint32_t CopyAllTo(uint8_t *buffer, uint8_t len) const
Definition:
address.cc:90
packet-socket-address.h
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("PacketSocketAddress")
ns3::PacketSocketAddress::m_device
uint32_t m_device
Definition:
packet-socket-address.h:76
ns3::Address::CopyAllFrom
uint32_t CopyAllFrom(const uint8_t *buffer, uint8_t len)
Definition:
address.cc:110
ns3::PacketSocketAddress::GetType
static uint8_t GetType(void)
Definition:
packet-socket-address.cc:144
ns3::PacketSocketAddress::SetPhysicalAddress
void SetPhysicalAddress(const Address address)
Definition:
packet-socket-address.cc:53
ns3::PacketSocketAddress::GetPhysicalAddress
Address GetPhysicalAddress(void) const
Definition:
packet-socket-address.cc:78
ns3::PacketSocketAddress::m_protocol
uint16_t m_protocol
Definition:
packet-socket-address.h:74
ns3::PacketSocketAddress::m_address
Address m_address
Definition:
packet-socket-address.h:77
ns3::Address::CopyTo
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Definition:
address.cc:82
ns3::PacketSocketAddress::IsSingleDevice
bool IsSingleDevice(void) const
Definition:
packet-socket-address.cc:66
ns3::PacketSocketAddress::SetProtocol
void SetProtocol(uint16_t protocol)
Definition:
packet-socket-address.cc:33
ns3::PacketSocketAddress::ConvertFrom
static PacketSocketAddress ConvertFrom(const Address &address)
Definition:
packet-socket-address.cc:106
ns3::PacketSocketAddress::ConvertTo
Address ConvertTo(void) const
Definition:
packet-socket-address.cc:90
first.address
tuple address
Definition:
first.py:37
ns3::PacketSocketAddress::m_isSingleDevice
bool m_isSingleDevice
Definition:
packet-socket-address.h:75
ns3::Address::Register
static uint8_t Register(void)
Allocate a new type id for a new type of address.
Definition:
address.cc:138
src
network
utils
packet-socket-address.cc
Generated on Sat Apr 19 2014 14:07:06 for ns-3 by
1.8.6