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
point-to-point-channel.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007, 2008 University of Washington
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
19
#include "
point-to-point-channel.h
"
20
#include "
point-to-point-net-device.h
"
21
#include "ns3/trace-source-accessor.h"
22
#include "ns3/packet.h"
23
#include "ns3/simulator.h"
24
#include "ns3/log.h"
25
26
NS_LOG_COMPONENT_DEFINE
(
"PointToPointChannel"
);
27
28
namespace
ns3 {
29
30
NS_OBJECT_ENSURE_REGISTERED
(PointToPointChannel);
31
32
TypeId
33
PointToPointChannel::GetTypeId
(
void
)
34
{
35
static
TypeId
tid =
TypeId
(
"ns3::PointToPointChannel"
)
36
.
SetParent
<
Channel
> ()
37
.AddConstructor<PointToPointChannel> ()
38
.AddAttribute (
"Delay"
,
"Transmission delay through the channel"
,
39
TimeValue
(
Seconds
(0)),
40
MakeTimeAccessor (&
PointToPointChannel::m_delay
),
41
MakeTimeChecker ())
42
.AddTraceSource (
"TxRxPointToPoint"
,
43
"Trace source indicating transmission of packet from the PointToPointChannel, used by the Animation interface."
,
44
MakeTraceSourceAccessor
(&
PointToPointChannel::m_txrxPointToPoint
))
45
;
46
return
tid;
47
}
48
49
//
50
// By default, you get a channel that
51
// has an "infitely" fast transmission speed and zero delay.
52
PointToPointChannel::PointToPointChannel
()
53
:
54
Channel
(),
55
m_delay (
Seconds
(0.)),
56
m_nDevices (0)
57
{
58
NS_LOG_FUNCTION_NOARGS
();
59
}
60
61
void
62
PointToPointChannel::Attach
(
Ptr<PointToPointNetDevice>
device)
63
{
64
NS_LOG_FUNCTION
(
this
<< device);
65
NS_ASSERT_MSG
(
m_nDevices
<
N_DEVICES
,
"Only two devices permitted"
);
66
NS_ASSERT
(device != 0);
67
68
m_link
[
m_nDevices
++].
m_src
= device;
69
//
70
// If we have both devices connected to the channel, then finish introducing
71
// the two halves and set the links to IDLE.
72
//
73
if
(
m_nDevices
==
N_DEVICES
)
74
{
75
m_link
[0].
m_dst
=
m_link
[1].
m_src
;
76
m_link
[1].
m_dst
=
m_link
[0].
m_src
;
77
m_link
[0].
m_state
=
IDLE
;
78
m_link
[1].
m_state
=
IDLE
;
79
}
80
}
81
82
bool
83
PointToPointChannel::TransmitStart
(
84
Ptr<Packet>
p,
85
Ptr<PointToPointNetDevice>
src,
86
Time
txTime)
87
{
88
NS_LOG_FUNCTION
(
this
<< p << src);
89
NS_LOG_LOGIC
(
"UID is "
<< p->
GetUid
() <<
")"
);
90
91
NS_ASSERT
(
m_link
[0].m_state !=
INITIALIZING
);
92
NS_ASSERT
(
m_link
[1].m_state !=
INITIALIZING
);
93
94
uint32_t wire = src ==
m_link
[0].
m_src
? 0 : 1;
95
96
Simulator::ScheduleWithContext
(
m_link
[wire].m_dst->GetNode ()->GetId (),
97
txTime +
m_delay
, &
PointToPointNetDevice::Receive
,
98
m_link
[wire].
m_dst
, p);
99
100
// Call the tx anim callback on the net device
101
m_txrxPointToPoint
(p, src,
m_link
[wire].m_dst, txTime, txTime + m_delay);
102
return
true
;
103
}
104
105
uint32_t
106
PointToPointChannel::GetNDevices
(
void
)
const
107
{
108
NS_LOG_FUNCTION_NOARGS
();
109
return
m_nDevices
;
110
}
111
112
Ptr<PointToPointNetDevice>
113
PointToPointChannel::GetPointToPointDevice
(uint32_t i)
const
114
{
115
NS_LOG_FUNCTION_NOARGS
();
116
NS_ASSERT
(i < 2);
117
return
m_link
[i].
m_src
;
118
}
119
120
Ptr<NetDevice>
121
PointToPointChannel::GetDevice
(uint32_t i)
const
122
{
123
NS_LOG_FUNCTION_NOARGS
();
124
return
GetPointToPointDevice
(i);
125
}
126
127
Time
128
PointToPointChannel::GetDelay
(
void
)
const
129
{
130
return
m_delay
;
131
}
132
133
Ptr<PointToPointNetDevice>
134
PointToPointChannel::GetSource
(uint32_t i)
const
135
{
136
return
m_link
[i].
m_src
;
137
}
138
139
Ptr<PointToPointNetDevice>
140
PointToPointChannel::GetDestination
(uint32_t i)
const
141
{
142
return
m_link
[i].
m_dst
;
143
}
144
145
bool
146
PointToPointChannel::IsInitialized
(
void
)
const
147
{
148
NS_ASSERT
(
m_link
[0].m_state !=
INITIALIZING
);
149
NS_ASSERT
(
m_link
[1].m_state !=
INITIALIZING
);
150
return
true
;
151
}
152
153
}
// namespace ns3
src
point-to-point
model
point-to-point-channel.cc
Generated on Tue Nov 13 2012 10:32:21 for ns-3 by
1.8.1.2