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
uan-mac-aloha.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 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
* Author: Leonard Tracy <lentracy@gmail.com>
19
*/
20
21
#include "
uan-mac-aloha.h
"
22
#include "
uan-tx-mode.h
"
23
#include "
uan-address.h
"
24
#include "ns3/log.h"
25
#include "
uan-phy.h
"
26
#include "
uan-header-common.h
"
27
28
#include <iostream>
29
NS_LOG_COMPONENT_DEFINE
(
"UanMacAloha"
);
30
31
32
namespace
ns3
33
{
34
35
NS_OBJECT_ENSURE_REGISTERED
(UanMacAloha);
36
37
UanMacAloha::UanMacAloha
()
38
:
UanMac
(),
39
m_cleared (false)
40
{
41
}
42
43
UanMacAloha::~UanMacAloha
()
44
{
45
}
46
47
void
48
UanMacAloha::Clear
()
49
{
50
if
(
m_cleared
)
51
{
52
return
;
53
}
54
m_cleared
=
true
;
55
if
(
m_phy
)
56
{
57
m_phy
->Clear ();
58
m_phy
= 0;
59
}
60
}
61
62
void
63
UanMacAloha::DoDispose
()
64
{
65
Clear
();
66
UanMac::DoDispose
();
67
}
68
69
TypeId
70
UanMacAloha::GetTypeId
(
void
)
71
{
72
static
TypeId
tid =
TypeId
(
"ns3::UanMacAloha"
)
73
.
SetParent
<
Object
> ()
74
.AddConstructor<UanMacAloha> ()
75
;
76
return
tid;
77
}
78
79
Address
80
UanMacAloha::GetAddress
(
void
)
81
{
82
return
m_address
;
83
}
84
85
void
86
UanMacAloha::SetAddress
(
UanAddress
addr)
87
{
88
m_address
=addr;
89
}
90
bool
91
UanMacAloha::Enqueue
(
Ptr<Packet>
packet,
const
Address
&dest, uint16_t protocolNumber)
92
{
93
NS_LOG_DEBUG
(
""
<<
Simulator::Now
().GetSeconds () <<
" MAC "
<<
UanAddress::ConvertFrom
(
GetAddress
()) <<
" Queueing packet for "
<<
UanAddress::ConvertFrom
(dest));
94
95
if
(!
m_phy
->IsStateTx ())
96
{
97
UanAddress
src =
UanAddress::ConvertFrom
(
GetAddress
());
98
UanAddress
udest =
UanAddress::ConvertFrom
(dest);
99
100
UanHeaderCommon
header;
101
header.
SetSrc
(src);
102
header.
SetDest
(udest);
103
header.
SetType
(0);
104
105
packet->
AddHeader
(header);
106
m_phy
->SendPacket (packet, protocolNumber);
107
return
true
;
108
}
109
else
110
return
false
;
111
}
112
113
void
114
UanMacAloha::SetForwardUpCb
(
Callback
<
void
,
Ptr<Packet>
,
const
UanAddress
& > cb)
115
{
116
m_forUpCb
= cb;
117
}
118
void
119
UanMacAloha::AttachPhy
(
Ptr<UanPhy>
phy)
120
{
121
m_phy
= phy;
122
m_phy
->SetReceiveOkCallback (
MakeCallback
(&
UanMacAloha::RxPacketGood
,
this
));
123
m_phy
->SetReceiveErrorCallback (
MakeCallback
(&
UanMacAloha::RxPacketError
,
this
));
124
125
}
126
void
127
UanMacAloha::RxPacketGood
(
Ptr<Packet>
pkt,
double
sinr,
UanTxMode
txMode)
128
{
129
UanHeaderCommon
header;
130
pkt->
RemoveHeader
(header);
131
NS_LOG_DEBUG
(
"Receiving packet from "
<< header.
GetSrc
() <<
" For "
<< header.
GetDest
());
132
133
if
(header.
GetDest
() ==
GetAddress
() || header.
GetDest
() ==
UanAddress::GetBroadcast
())
134
{
135
m_forUpCb
(pkt, header.
GetSrc
());
136
}
137
138
}
139
140
void
141
UanMacAloha::RxPacketError
(
Ptr<Packet>
pkt,
double
sinr)
142
{
143
NS_LOG_DEBUG
(
""
<<
Simulator::Now
() <<
" MAC "
<<
UanAddress::ConvertFrom
(
GetAddress
()) <<
" Received packet in error with sinr "
<< sinr);
144
}
145
146
Address
147
UanMacAloha::GetBroadcast
(
void
)
const
148
{
149
UanAddress
broadcast (255);
150
return
broadcast;
151
}
152
153
int64_t
154
UanMacAloha::AssignStreams
(int64_t stream)
155
{
156
NS_LOG_FUNCTION
(
this
<< stream);
157
return
0;
158
}
159
160
}
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Definition:
packet.cc:268
ns3::UanMacAloha::m_phy
Ptr< UanPhy > m_phy
Definition:
uan-mac-aloha.h:71
ns3::Ptr< Packet >
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:311
ns3::Callback
Callback template class.
Definition:
callback.h:920
ns3::UanMacAloha::SetAddress
virtual void SetAddress(UanAddress addr)
Definition:
uan-mac-aloha.cc:86
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Definition:
log.h:122
ns3::UanMacAloha::m_forUpCb
Callback< void, Ptr< Packet >, const UanAddress & > m_forUpCb
Definition:
uan-mac-aloha.h:72
ns3::Object::DoDispose
virtual void DoDispose(void)
Definition:
object.cc:335
ns3::UanMacAloha::GetAddress
Address GetAddress(void)
Definition:
uan-mac-aloha.cc:80
ns3::UanMacAloha::GetBroadcast
virtual Address GetBroadcast(void) const
Definition:
uan-mac-aloha.cc:147
ns3::Address
a polymophic address class
Definition:
address.h:86
ns3::UanMac
Virtual base class for all UAN MAC protocols.
Definition:
uan-mac.h:47
uan-address.h
ns3::UanAddress
Definition:
uan-address.h:37
ns3::UanAddress::ConvertFrom
static UanAddress ConvertFrom(const Address &address)
Definition:
uan-address.cc:54
ns3::UanHeaderCommon::SetSrc
void SetSrc(UanAddress src)
Definition:
uan-header-common.cc:67
ns3::UanMacAloha::RxPacketGood
void RxPacketGood(Ptr< Packet > pkt, double sinr, UanTxMode txMode)
Receive packet from lower layer (passed to PHY as callback)
Definition:
uan-mac-aloha.cc:127
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
ns3::UanMacAloha::SetForwardUpCb
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)
Definition:
uan-mac-aloha.cc:114
ns3::UanTxMode
Abstraction of packet modulation information.
Definition:
uan-tx-mode.h:36
ns3::UanMacAloha::GetTypeId
static TypeId GetTypeId(void)
Definition:
uan-mac-aloha.cc:70
ns3::MakeCallback
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition:
callback.h:1238
ns3::UanHeaderCommon::SetDest
void SetDest(UanAddress dest)
Definition:
uan-header-common.cc:62
ns3::UanMacAloha::RxPacketError
void RxPacketError(Ptr< Packet > pkt, double sinr)
Packet received at lower layer in error.
Definition:
uan-mac-aloha.cc:141
ns3::UanMacAloha::~UanMacAloha
virtual ~UanMacAloha()
Definition:
uan-mac-aloha.cc:43
ns3::UanAddress::GetBroadcast
static UanAddress GetBroadcast(void)
Definition:
uan-address.cc:92
ns3::UanHeaderCommon
Definition:
uan-header-common.h:37
ns3::UanHeaderCommon::GetDest
UanAddress GetDest(void) const
Definition:
uan-header-common.cc:79
uan-tx-mode.h
ns3::UanMacAloha::Clear
virtual void Clear(void)
Definition:
uan-mac-aloha.cc:48
ns3::UanMacAloha::Enqueue
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
Definition:
uan-mac-aloha.cc:91
ns3::Simulator::Now
static Time Now(void)
Definition:
simulator.cc:180
uan-mac-aloha.h
ns3::UanMacAloha::m_cleared
bool m_cleared
Definition:
uan-mac-aloha.h:73
ns3::UanMacAloha::AttachPhy
virtual void AttachPhy(Ptr< UanPhy > phy)
Definition:
uan-mac-aloha.cc:119
ns3::UanMacAloha::UanMacAloha
UanMacAloha()
Definition:
uan-mac-aloha.cc:37
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Definition:
log.h:255
uan-header-common.h
ns3::UanHeaderCommon::SetType
void SetType(uint8_t type)
Definition:
uan-header-common.cc:73
ns3::UanHeaderCommon::GetSrc
UanAddress GetSrc(void) const
Definition:
uan-header-common.cc:84
ns3::UanMacAloha::DoDispose
virtual void DoDispose()
Definition:
uan-mac-aloha.cc:63
ns3::Object
a base class which provides memory management and object aggregation
Definition:
object.h:63
ns3::UanMacAloha::AssignStreams
int64_t AssignStreams(int64_t stream)
Definition:
uan-mac-aloha.cc:154
uan-phy.h
ns3::UanMacAloha::m_address
UanAddress m_address
Definition:
uan-mac-aloha.h:70
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:610
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Definition:
packet.cc:253
src
uan
model
uan-mac-aloha.cc
Generated on Sat Nov 16 2013 12:55:39 for ns-3 by
1.8.5