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
flame-protocol-mac.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 IITP RAS
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: Kirill Andreev <andreev@iitp.ru>
19
*/
20
21
#include "
flame-protocol-mac.h
"
22
#include "
flame-protocol.h
"
23
#include "
flame-header.h
"
24
#include "ns3/log.h"
25
namespace
ns3 {
26
namespace
flame {
27
NS_LOG_COMPONENT_DEFINE
(
"FlameProtocolMac"
);
28
FlameProtocolMac::FlameProtocolMac
(uint32_t ifIndex,
Ptr<FlameProtocol>
protocol) :
29
m_protocol (protocol), m_ifIndex (ifIndex)
30
{
31
}
32
FlameProtocolMac::~FlameProtocolMac
()
33
{
34
m_protocol
= 0;
35
m_parent
= 0;
36
}
37
void
38
FlameProtocolMac::SetParent
(
Ptr<MeshWifiInterfaceMac>
parent)
39
{
40
m_parent
= parent;
41
}
42
43
bool
44
FlameProtocolMac::Receive
(
Ptr<Packet>
packet,
const
WifiMacHeader
& header)
45
{
46
if
(!header.
IsData
())
47
{
48
return
true
;
49
}
50
FlameTag
tag;
51
if
(packet->
PeekPacketTag
(tag))
52
{
53
NS_FATAL_ERROR
(
"FLAME tag is not supposed to be received by network"
);
54
}
55
tag.
receiver
= header.
GetAddr1
();
56
tag.
transmitter
= header.
GetAddr2
();
57
if
(tag.
receiver
==
Mac48Address::GetBroadcast
())
58
{
59
m_stats
.
rxBroadcast
++;
60
}
61
else
62
{
63
m_stats
.
rxUnicast
++;
64
}
65
m_stats
.
rxBytes
+= packet->
GetSize
();
66
packet->
AddPacketTag
(tag);
67
return
true
;
68
}
69
bool
70
FlameProtocolMac::UpdateOutcomingFrame
(
Ptr<Packet>
packet,
WifiMacHeader
& header,
Mac48Address
from,
71
Mac48Address
to)
72
{
73
if
(!header.
IsData
())
74
{
75
return
true
;
76
}
77
FlameTag
tag;
78
if
(!packet->
RemovePacketTag
(tag))
79
{
80
NS_FATAL_ERROR
(
"FLAME tag must exist here"
);
81
}
82
header.
SetAddr1
(tag.
receiver
);
83
if
(tag.
receiver
==
Mac48Address::GetBroadcast
())
84
{
85
m_stats
.
txBroadcast
++;
86
}
87
else
88
{
89
m_stats
.
txUnicast
++;
90
}
91
m_stats
.
txBytes
+= packet->
GetSize
();
92
return
true
;
93
}
94
uint16_t
95
FlameProtocolMac::GetChannelId
()
const
96
{
97
return
m_parent
->
GetFrequencyChannel
();
98
}
99
FlameProtocolMac::Statistics::Statistics
() :
100
txUnicast (0), txBroadcast (0), txBytes (0), rxUnicast (0), rxBroadcast (0), rxBytes (0)
101
{
102
}
103
void
104
FlameProtocolMac::Statistics::Print
(std::ostream &os)
const
105
{
106
os <<
"<Statistics "
107
"txUnicast=\""
<< txUnicast <<
"\" "
108
"txBroadcast=\""
<< txBroadcast <<
"\" "
109
"txBytes=\""
<< txBytes <<
"\" "
110
"rxUnicast=\""
<< rxUnicast <<
"\" "
111
"rxBroadcast=\""
<< rxBroadcast <<
"\" "
112
"rxBytes=\""
<< rxBytes <<
"\"/>"
<< std::endl;
113
}
114
void
115
FlameProtocolMac::Report
(std::ostream & os)
const
116
{
117
os <<
"<FlameProtocolMac"
<< std::endl <<
118
"address =\""
<<
m_parent
->
GetAddress
() <<
"\">"
<< std::endl;
119
m_stats
.
Print
(os);
120
os <<
"</FlameProtocolMac>"
<< std::endl;
121
122
}
123
void
124
FlameProtocolMac::ResetStats
()
125
{
126
m_stats
=
Statistics
();
127
}
128
129
}
// namespace flame
130
}
// namespace ns3
src
mesh
model
flame
flame-protocol-mac.cc
Generated on Fri Dec 21 2012 19:00:42 for ns-3 by
1.8.1.2