author | Kirill Andreev <andreev@iitp.ru> |
Wed, 17 Jun 2009 20:37:32 +0400 | |
changeset 5082 | 528da3d1e5a4 |
parent 5080 | f97dc799fea0 |
child 5083 | 5b154b30a8a1 |
permissions | -rw-r--r-- |
5079
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
2 |
/* |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
3 |
* Copyright (c) 2009 IITP RAS |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
4 |
* |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
8 |
* |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
13 |
* |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
17 |
* |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
18 |
* Author: Kirill Andreev <andreev@iitp.ru> |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
19 |
*/ |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
20 |
|
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
21 |
#include "flame-protocol.h" |
5082 | 22 |
#include "flame-rtable.h" |
23 |
#include "flame-header.h" |
|
24 |
#include "ns3/log.h" |
|
25 |
#include "ns3/simulator.h" |
|
26 |
#include "ns3/packet.h" |
|
27 |
#include "ns3/mesh-point-device.h" |
|
28 |
#include "ns3/wifi-net-device.h" |
|
29 |
#include "ns3/mesh-point-device.h" |
|
30 |
#include "ns3/mesh-wifi-interface-mac.h" |
|
31 |
#include "ns3/random-variable.h" |
|
32 |
||
5079
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
33 |
namespace ns3 { |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
34 |
namespace flame { |
5080 | 35 |
//----------------------------------------------------------------------------- |
36 |
// FlameTag |
|
37 |
//----------------------------------------------------------------------------- |
|
38 |
NS_OBJECT_ENSURE_REGISTERED (FlameTag); |
|
39 |
||
40 |
TypeId |
|
41 |
FlameTag::GetTypeId () |
|
42 |
{ |
|
43 |
static TypeId tid = TypeId ("ns3::flame::FlameTag") |
|
44 |
.SetParent<Tag> () |
|
45 |
.AddConstructor<FlameTag> (); |
|
46 |
return tid; |
|
47 |
} |
|
48 |
||
49 |
TypeId |
|
50 |
FlameTag::GetInstanceTypeId () const |
|
51 |
{ |
|
52 |
return GetTypeId (); |
|
53 |
} |
|
54 |
||
55 |
uint32_t |
|
56 |
FlameTag::GetSerializedSize () const |
|
57 |
{ |
|
5082 | 58 |
return 6; |
5080 | 59 |
} |
60 |
||
61 |
void |
|
62 |
FlameTag::Serialize (TagBuffer i) const |
|
63 |
{ |
|
64 |
uint8_t buf[6]; |
|
65 |
address.CopyTo (buf); |
|
66 |
for (int j = 0; j < 6; j ++) |
|
67 |
i.WriteU8 (buf[j]); |
|
68 |
} |
|
69 |
||
70 |
void |
|
71 |
FlameTag::Deserialize (TagBuffer i) |
|
72 |
{ |
|
73 |
uint8_t buf[6]; |
|
74 |
for (int j = 0; j < 6; j ++) |
|
75 |
buf[j] = i.ReadU8 (); |
|
76 |
address.CopyFrom (buf); |
|
77 |
} |
|
78 |
||
79 |
void |
|
80 |
FlameTag::Print (std::ostream &os) const |
|
81 |
{ |
|
5082 | 82 |
os << "address = " << address; |
5080 | 83 |
} |
84 |
||
5082 | 85 |
//----------------------------------------------------------------------------- |
86 |
// FlameTag |
|
87 |
//----------------------------------------------------------------------------- |
|
88 |
TypeId |
|
89 |
FlameProtocol::GetTypeId () |
|
90 |
{ |
|
91 |
static TypeId tid = TypeId ("ns3::flame::FlameProtocol") |
|
92 |
.SetParent<MeshL2RoutingProtocol> () |
|
93 |
.AddConstructor<FlameProtocol> () |
|
94 |
.AddAttribute ("BroadcastInterval", "How often we must send broadcast packets", |
|
95 |
TimeValue (Seconds (5)), |
|
96 |
MakeTimeAccessor (&FlameProtocol::m_broadcastInterval), |
|
97 |
MakeTimeChecker () |
|
98 |
); |
|
99 |
return tid; |
|
100 |
} |
|
101 |
FlameProtocol::FlameProtocol () : |
|
102 |
m_broadcastInterval (Seconds (5)), |
|
103 |
m_lastBroadcast (Simulator::Now ()), |
|
104 |
m_myLastSeqno (0) |
|
105 |
{ |
|
106 |
} |
|
107 |
FlameProtocol::~FlameProtocol () |
|
108 |
{ |
|
109 |
} |
|
110 |
void |
|
111 |
FlameProtocol::DoDispose () |
|
112 |
{ |
|
113 |
} |
|
114 |
bool |
|
115 |
FlameProtocol::RequestRoute (uint32_t sourceIface, const Mac48Address source, const Mac48Address destination, |
|
116 |
Ptr<const Packet> const_packet, uint16_t protocolType, RouteReplyCallback routeReply) |
|
117 |
{ |
|
118 |
Ptr<Packet> packet = const_packet->Copy (); |
|
119 |
NS_LOG_UNCOND("Forwarding packet from "<<source <<", to "<<destination<<"protocol = "<<protocolType); |
|
120 |
if (source == m_address) |
|
121 |
{ |
|
122 |
//Packet from upper layer! |
|
123 |
if(destination == Mac48Address::GetBroadcast ()) |
|
124 |
{ |
|
125 |
//Broadcast always is forwarded as broadcast! |
|
126 |
FlameHeader flameHdr; |
|
127 |
FlameTag tag (Mac48Address::GetBroadcast ()); |
|
128 |
flameHdr.AddCost (0); |
|
129 |
flameHdr.SetSeqno (m_myLastSeqno ++); |
|
130 |
flameHdr.SetProtocol (protocolType); |
|
131 |
flameHdr.SetOrigDst (destination); |
|
132 |
flameHdr.SetOrigSrc (source); |
|
133 |
packet->AddHeader (flameHdr); |
|
134 |
packet->AddPacketTag (tag); |
|
135 |
routeReply (true, packet, source, destination, FLAME_PORT, FlameRtable::INTERFACE_ANY); |
|
136 |
} |
|
137 |
else |
|
138 |
NS_FATAL_ERROR ("not done yet!"); |
|
139 |
} |
|
140 |
else |
|
141 |
{ |
|
142 |
NS_FATAL_ERROR ("not done yet!"); |
|
143 |
} |
|
144 |
return true; |
|
145 |
} |
|
146 |
bool |
|
147 |
FlameProtocol::Install (Ptr<MeshPointDevice> mp) |
|
148 |
{ |
|
149 |
m_mp = mp; |
|
150 |
std::vector<Ptr<NetDevice> > interfaces = mp->GetInterfaces (); |
|
151 |
for (std::vector<Ptr<NetDevice> >::const_iterator i = interfaces.begin (); i != interfaces.end(); i++) |
|
152 |
{ |
|
153 |
// Checking for compatible net device |
|
154 |
Ptr<WifiNetDevice> wifiNetDev = (*i)->GetObject<WifiNetDevice> (); |
|
155 |
if (wifiNetDev == 0) |
|
156 |
return false; |
|
157 |
Ptr<MeshWifiInterfaceMac> mac = wifiNetDev->GetMac ()->GetObject<MeshWifiInterfaceMac> (); |
|
158 |
if (mac == 0) |
|
159 |
return false; |
|
160 |
// Installing plugins: |
|
161 |
Ptr<FlameMacPlugin> flameMac = Create<FlameMacPlugin> (wifiNetDev->GetIfIndex (), this); |
|
162 |
m_interfaces[wifiNetDev->GetIfIndex ()] = flameMac; |
|
163 |
mac->InstallPlugin (flameMac); |
|
164 |
} |
|
165 |
mp->SetRoutingProtocol (this); |
|
166 |
// Mesh point aggregates all installed protocols |
|
167 |
mp->AggregateObject (this); |
|
168 |
m_address = Mac48Address::ConvertFrom (mp->GetAddress ());//* address; |
|
169 |
return true; |
|
170 |
} |
|
171 |
Mac48Address |
|
172 |
FlameProtocol::GetAddress () |
|
173 |
{ |
|
174 |
return m_address; |
|
175 |
} |
|
5079
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
176 |
} //namespace flame |
245215e5e6ed
Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
177 |
} //namespace ns3 |