21 #include "flame-protocol.h"
22 #include "flame-protocol-mac.h"
23 #include "flame-header.h"
24 #include "flame-rtable.h"
25 #include "ns3/llc-snap-header.h"
27 #include "ns3/simulator.h"
28 #include "ns3/packet.h"
29 #include "ns3/mesh-point-device.h"
30 #include "ns3/wifi-net-device.h"
31 #include "ns3/mesh-point-device.h"
32 #include "ns3/mesh-wifi-interface-mac.h"
41 NS_OBJECT_ENSURE_REGISTERED (FlameTag);
42 NS_OBJECT_ENSURE_REGISTERED (FlameProtocol);
45 FlameTag::GetTypeId ()
47 static TypeId tid = TypeId (
"ns3::flame::FlameTag").SetParent<Tag> ().AddConstructor<FlameTag> ();
68 for (
int j = 0; j < 6; j++)
73 for (
int j = 0; j < 6; j++)
84 for (
int j = 0; j < 6; j++)
89 for (
int j = 0; j < 6; j++)
107 FlameProtocol::GetTypeId ()
109 static TypeId tid =
TypeId (
"ns3::flame::FlameProtocol")
111 .AddConstructor<FlameProtocol> ()
112 .AddAttribute (
"BroadcastInterval",
113 "How often we must send broadcast packets",
116 &FlameProtocol::m_broadcastInterval),
119 .AddAttribute (
"MaxCost",
120 "Cost threshold after which packet will be dropped",
122 MakeUintegerAccessor (
124 MakeUintegerChecker<uint8_t> (3)
129 FlameProtocol::FlameProtocol () :
131 m_maxCost (32), m_myLastSeqno (1), m_rtable (CreateObject<
FlameRtable> ())
134 FlameProtocol::~FlameProtocol ()
140 m_interfaces.clear ();
149 if (sourceIface ==
m_mp->GetIfIndex ())
155 NS_FATAL_ERROR (
"FLAME tag is not supposed to be received from upper layers");
169 flameHdr.AddCost (0);
171 flameHdr.SetProtocol (protocolType);
172 flameHdr.SetOrigDst (destination);
173 flameHdr.SetOrigSrc (source);
174 m_stats.txBytes += packet->
GetSize ();
176 tag.
receiver = result.retransmitter;
179 m_stats.txBroadcast++;
187 routeReply (
true, packet, source, destination,
FLAME_PROTOCOL, result.ifIndex);
204 flameHdr.AddCost (1);
205 m_stats.txBytes += packet->
GetSize ();
209 m_stats.txBroadcast++;
225 NS_LOG_DEBUG (
"unicast packet dropped, because no route! I am " << GetAddress ()
227 m_stats.totalDropped++;
230 tag.
receiver = result.retransmitter;
238 m_stats.txBroadcast++;
244 m_stats.txBytes += packet->
GetSize ();
245 flameHdr.AddCost (1);
248 routeReply (
true, packet, source, destination,
FLAME_PROTOCOL, result.ifIndex);
260 if (source == GetAddress ())
268 NS_FATAL_ERROR (
"FLAME tag must exist when packet is coming to protocol");
278 if ((destination == GetAddress ()) && ((m_lastBroadcast + m_broadcastInterval <
Simulator::Now ())
279 || (m_lastBroadcast ==
Seconds (0))))
286 protocolType = flameHdr.GetProtocol ();
293 std::vector<Ptr<NetDevice> > interfaces = mp->GetInterfaces ();
294 for (std::vector<
Ptr<NetDevice> >::const_iterator i = interfaces.begin (); i != interfaces.end (); i++)
309 m_interfaces[wifiNetDev->GetIfIndex ()] = flameMac;
310 mac->SetBeaconGeneration (
false);
311 mac->InstallPlugin (flameMac);
313 mp->SetRoutingProtocol (
this);
315 mp->AggregateObject (
this);
320 FlameProtocol::GetAddress ()
328 if (source == GetAddress ())
330 m_stats.totalDropped++;
340 m_stats.droppedTtl++;
343 m_rtable->AddPath (source, receiver, fromInterface, flameHdr.GetCost (), flameHdr.GetSeqno ());
347 FlameProtocol::Statistics::Statistics () :
348 txUnicast (0), txBroadcast (0), txBytes (0), droppedTtl (0), totalDropped (0)
352 FlameProtocol::Statistics::Print (std::ostream & os)
const
355 "txUnicast=\"" << txUnicast <<
"\" "
356 "txBroadcast=\"" << txBroadcast <<
"\" "
357 "txBytes=\"" << txBytes <<
"\" "
358 "droppedTtl=\"" << droppedTtl <<
"\" "
359 "totalDropped=\"" << totalDropped <<
"\"/>" << std::endl;
365 "address=\"" << m_address <<
"\"" << std::endl <<
366 "broadcastInterval=\"" << m_broadcastInterval.
GetSeconds () <<
"\"" << std::endl <<
367 "maxCost=\"" << (uint16_t)
m_maxCost <<
"\">" << std::endl;
369 for (FlamePluginMap::const_iterator plugin = m_interfaces.begin (); plugin != m_interfaces.end (); plugin++)
371 plugin->second->Report (os);
373 os <<
"</Flame>" << std::endl;
376 FlameProtocol::ResetStats ()
378 m_stats = Statistics ();
379 for (FlamePluginMap::const_iterator plugin = m_interfaces.begin (); plugin != m_interfaces.end (); plugin++)
381 plugin->second->ResetStats ();
uint32_t RemoveHeader(Header &header)
uint32_t GetSerializedSize() const
bool RemoveRoutingStuff(uint32_t fromIface, const Mac48Address source, const Mac48Address destination, Ptr< Packet > packet, uint16_t &protocolType)
Cleanup flame headers!
void Print(std::ostream &os) const
void AddPacketTag(const Tag &tag) const
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
uint32_t GetSize(void) const
TAG_BUFFER_INLINE uint8_t ReadU8(void)
#define NS_FATAL_ERROR(msg)
fatal error handling
uint8_t m_maxCost
Max Cost value (or TTL, because cost is actually hopcount)
bool HandleDataFrame(uint16_t seqno, Mac48Address source, const FlameHeader flameHdr, Mac48Address receiver, uint32_t fromIface)
Handles a packet: adds a routing information and drops packets by TTL or Seqno.
double GetSeconds(void) const
void CopyTo(uint8_t buffer[6]) const
bool PeekPacketTag(Tag &tag) const
Ptr< FlameRtable > m_rtable
Routing table:
Ptr< MeshPointDevice > m_mp
Host mesh point.
void Serialize(TagBuffer i) const
hold objects of type ns3::Time
Hold an unsigned integer type.
Hold together all Wifi-related objects.This class holds together ns3::WifiChannel, ns3::WifiPhy, ns3::WifiMac, and, ns3::WifiRemoteStationManager.
static Mac48Address GetBroadcast(void)
static Mac48Address ConvertFrom(const Address &address)
Ptr< Packet > Copy(void) const
Route lookup result, return type of LookupXXX methods.
bool Install(Ptr< MeshPointDevice >)
Install FLAME on given mesh point.
bool RequestRoute(uint32_t sourceIface, const Mac48Address source, const Mac48Address destination, Ptr< const Packet > packet, uint16_t protocolType, RouteReplyCallback routeReply)
Route request, inherited from MeshL2RoutingProtocol.
void Deserialize(TagBuffer i)
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
void CopyFrom(const uint8_t buffer[6])
Interface for L2 mesh routing protocol and mesh point communication.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
static const uint32_t INTERFACE_ANY
Means all interfaces.
bool RemovePacketTag(Tag &tag)
#define NS_LOG_DEBUG(msg)
void Report(std::ostream &) const
Statistics.
TypeId GetInstanceTypeId() const
Mac48Address receiver
Receiver of the packet:
uint16_t m_myLastSeqno
Sequence number:
static const uint16_t FLAME_PROTOCOL
LLC protocol number reserved by flame.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Basic MAC of mesh point Wi-Fi interface. Its function is extendable through plugins mechanism...
void AddHeader(const Header &header)
Transmitter and receiver addresses.
Mac48Address transmitter
transmitter for incoming: