NetAnim: Handle special case for missing Wifi TxTrace

This commit is contained in:
John Abraham
2012-03-28 11:04:38 -07:00
parent 0e8b2225af
commit 06586a2a1c
5 changed files with 59 additions and 26 deletions

View File

@@ -138,7 +138,7 @@ main (int argc, char *argv[])
// Install applications
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (wifiApNode.Get (0));
ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (15.0));
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (1), 9);

View File

@@ -33,10 +33,12 @@ AnimPacketInfo::AnimPacketInfo()
}
AnimPacketInfo::AnimPacketInfo(Ptr <const NetDevice> txnd, const Time& fbTx,
const Time& lbTx, Vector txLoc)
const Time& lbTx, Vector txLoc, uint32_t txNodeId)
: m_txnd (txnd), m_fbTx (fbTx.GetSeconds ()), m_lbTx (lbTx.GetSeconds ()),
m_txLoc (txLoc)
{
if (!m_txnd)
m_txNodeId = txNodeId;
}
void AnimPacketInfo::ProcessRxBegin (Ptr<const NetDevice> nd, const Time& fbRx)

View File

@@ -144,7 +144,7 @@ public:
* \param txLoc Transmitter Location
*
*/
AnimPacketInfo(Ptr <const NetDevice> tx_nd, const Time& fbTx, const Time& lbTx,Vector txLoc);
AnimPacketInfo(Ptr <const NetDevice> tx_nd, const Time& fbTx, const Time& lbTx,Vector txLoc, uint32_t txNodeId = 0);
/**
* \brief Ptr to NetDevice that is transmitting
@@ -153,6 +153,13 @@ public:
*/
Ptr <const NetDevice> m_txnd;
/**
* \brief Tx Node Id if NetDevice is unknown
* \param m_txNodeId Tx Node Id if NetDevice is unknown
*
*/
uint32_t m_txNodeId;
/**
* \brief First bit transmission time
* \param m_fbTx First bit transmission time

View File

@@ -32,6 +32,8 @@
#include "ns3/animation-interface-helper.h"
#include "ns3/wifi-mac-header.h"
#include "ns3/wimax-mac-header.h"
#include "ns3/wifi-net-device.h"
#include "ns3/wifi-mac.h"
#include "ns3/constant-position-mobility-model.h"
#include <stdio.h>
@@ -61,7 +63,7 @@ AnimationInterface::AnimationInterface ()
: m_fHandle (STDOUT_FILENO), m_xml (false), mobilitypollinterval (Seconds(0.25)),
usingSockets (false), mport (0), outputfilename (""),
OutputFileSet (false), ServerPortSet (false), gAnimUid (0),randomPosition (true),
m_writeCallback (0), m_started (false), m_enforceWifiMacRx (true),
m_writeCallback (0), m_started (false),
m_enablePacketMetadata (false)
{
initialized = true;
@@ -72,7 +74,7 @@ AnimationInterface::AnimationInterface (const std::string fn, bool usingXML)
: m_fHandle (STDOUT_FILENO), m_xml (usingXML), mobilitypollinterval (Seconds(0.25)),
usingSockets (false), mport (0), outputfilename (fn),
OutputFileSet (false), ServerPortSet (false), gAnimUid (0), randomPosition (true),
m_writeCallback (0), m_started (false), m_enforceWifiMacRx (true),
m_writeCallback (0), m_started (false),
m_enablePacketMetadata (false)
{
initialized = true;
@@ -83,7 +85,7 @@ AnimationInterface::AnimationInterface (const uint16_t port, bool usingXML)
: m_fHandle (STDOUT_FILENO), m_xml (usingXML), mobilitypollinterval (Seconds(0.25)),
usingSockets (true), mport (port), outputfilename (""),
OutputFileSet (false), ServerPortSet (false), gAnimUid (0), randomPosition (true),
m_writeCallback (0), m_started (false), m_enforceWifiMacRx (true),
m_writeCallback (0), m_started (false),
m_enablePacketMetadata (false)
{
initialized = true;
@@ -490,10 +492,6 @@ void AnimationInterface::ConnectCallbacks ()
MakeCallback (&AnimationInterface::WifiPhyTxBeginTrace, this));
Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
MakeCallback (&AnimationInterface::WifiPhyRxBeginTrace, this));
Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxEnd",
MakeCallback (&AnimationInterface::WifiPhyRxEndTrace, this));
Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
MakeCallback (&AnimationInterface::WifiMacRxTrace, this));
Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange",
MakeCallback (&AnimationInterface::MobilityCourseChangeTrace, this));
Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
@@ -550,11 +548,6 @@ int AnimationInterface::WriteN (int h, const std::string& st)
return WriteN (h, st.c_str (), st.length ());
}
void AnimationInterface::ShowAll802_11 (bool showAll)
{
m_enforceWifiMacRx = !showAll;
}
// Private methods
void AnimationInterface::AddMargin ()
{
@@ -711,7 +704,6 @@ AnimationInterface::GetNetDeviceFromContext (std::string context)
void AnimationInterface::AddPendingWifiPacket (uint64_t AnimUid, AnimPacketInfo &pktinfo)
{
NS_ASSERT (pktinfo.m_txnd);
pendingWifiPackets[AnimUid] = pktinfo;
}
@@ -763,6 +755,12 @@ void AnimationInterface::WifiPhyTxBeginTrace (std::string context,
p->AddByteTag (tag);
AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
AddPendingWifiPacket (gAnimUid, pktinfo);
Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (ndev);
Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
std::ostringstream oss;
oss << nodeAddr;
m_macToNodeIdMap[oss.str ()] = n->GetId ();
NS_LOG_INFO ("Added Mac" << oss.str () << " node:" <<m_macToNodeIdMap[oss.str ()]);
}
void AnimationInterface::WifiPhyTxEndTrace (std::string context,
@@ -799,12 +797,26 @@ void AnimationInterface::WifiPhyRxBeginTrace (std::string context,
if (!WifiPacketIsPending (AnimUid))
{
NS_LOG_WARN ("WifiPhyRxBeginTrace: unknown Uid");
return;
std::ostringstream oss;
WifiMacHeader hdr;
if(!p->PeekHeader (hdr))
{
NS_LOG_WARN ("WifiMacHeader not present");
return;
}
oss << hdr.GetAddr2 ();
if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
{
NS_LOG_UNCOND (oss.str ());
return;
}
Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
AnimPacketInfo pktinfo (0, Simulator::Now (), Simulator::Now (), UpdatePosition (txNode), m_macToNodeIdMap[oss.str ()]);
AddPendingWifiPacket (AnimUid, pktinfo);
NS_LOG_WARN ("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
}
// TODO: NS_ASSERT (WifiPacketIsPending (AnimUid) == true);
pendingWifiPackets[AnimUid].ProcessRxBegin (ndev, Simulator::Now ());
if (m_enforceWifiMacRx)
return;
pendingWifiPackets[AnimUid].ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
OutputWirelessPacket (p, pendingWifiPackets[AnimUid], pendingWifiPackets[AnimUid].GetRxInfo (ndev));
}
@@ -823,18 +835,23 @@ void AnimationInterface::WifiPhyRxEndTrace (std::string context,
if (!WifiPacketIsPending (AnimUid))
{
NS_LOG_WARN ("WifiPhyRxEndTrace: unknown Uid");
return;
AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
AddPendingWifiPacket (AnimUid, pktinfo);
}
// TODO: NS_ASSERT (WifiPacketIsPending (AnimUid) == true);
AnimPacketInfo& pktInfo = pendingWifiPackets[AnimUid];
pktInfo.ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
if (pktrxInfo.IsPhyRxComplete ())
{
NS_LOG_INFO ("MacRxTrace for packet:" << AnimUid << " complete");
OutputWirelessPacket (p, pktInfo, pktrxInfo);
}
}
void AnimationInterface::WifiMacRxTrace (std::string context,
Ptr<const Packet> p)
{
if (!m_enforceWifiMacRx)
return;
if (!m_started)
return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
@@ -967,12 +984,15 @@ void AnimationInterface::CsmaPhyTxEndTrace (std::string context, Ptr<const Packe
return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
Ptr <Node> n = ndev->GetNode ();
NS_ASSERT (n);
uint64_t AnimUid = GetAnimUidFromPacket (p);
NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << AnimUid);
if (!CsmaPacketIsPending (AnimUid))
{
NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid");
return;
AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
AddPendingCsmaPacket (AnimUid, pktinfo);
}
// TODO: NS_ASSERT (CsmaPacketIsPending (AnimUid) == true);
AnimPacketInfo& pktInfo = pendingCsmaPackets[AnimUid];
@@ -1156,8 +1176,11 @@ void AnimationInterface::OutputWirelessPacket (Ptr<const Packet> p, AnimPacketIn
{
NS_ASSERT (m_xml);
std::ostringstream oss;
NS_ASSERT (pktInfo.m_txnd);
uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
uint32_t nodeId = 0;
if (pktInfo.m_txnd)
nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
else
nodeId = pktInfo.m_txNodeId;
double lbTx = pktInfo.firstlastbitDelta + pktInfo.m_fbTx;
oss << GetXMLOpen_wpacket (0, nodeId, pktInfo.m_fbTx, lbTx, pktrxInfo.rxRange);

View File

@@ -343,8 +343,9 @@ private:
void ConnectCallbacks ();
bool m_started;
bool m_enforceWifiMacRx;
bool m_enablePacketMetadata;
std::map <std::string, uint32_t> m_macToNodeIdMap;
// Path helper
std::vector<std::string> GetElementsFromContext (std::string context);