From c4c4537faa354412e32fbd9b07da15649efc8e62 Mon Sep 17 00:00:00 2001 From: John Abraham Date: Sun, 12 Mar 2017 15:26:01 -0700 Subject: [PATCH] NetAnim: Wave support --- src/netanim/model/animation-interface.cc | 71 ++++++++++++++++++++++-- src/netanim/model/animation-interface.h | 9 ++- src/netanim/wscript | 2 +- 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/src/netanim/model/animation-interface.cc b/src/netanim/model/animation-interface.cc index c18993134..63cce487c 100644 --- a/src/netanim/model/animation-interface.cc +++ b/src/netanim/model/animation-interface.cc @@ -458,6 +458,7 @@ AnimationInterface::MobilityAutoCheck () PurgePendingPackets (AnimationInterface::LTE); PurgePendingPackets (AnimationInterface::CSMA); PurgePendingPackets (AnimationInterface::LRWPAN); + PurgePendingPackets (AnimationInterface::WAVE); Simulator::Schedule (m_mobilityPollInterval, &AnimationInterface::MobilityAutoCheck, this); } } @@ -990,6 +991,52 @@ AnimationInterface::LrWpanPhyRxBeginTrace (std::string context, OutputWirelessPacketRxInfo (p, m_pendingLrWpanPackets[animUid], animUid); } +void +AnimationInterface::WavePhyTxBeginTrace (std::string context, Ptr p) +{ + NS_LOG_FUNCTION (this); + return GenericWirelessTxTrace (context, p, AnimationInterface::WAVE); +} + +void +AnimationInterface::WavePhyRxBeginTrace (std::string context, Ptr p) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + UpdatePosition (ndev); + uint64_t animUid = GetAnimUidFromPacket (p); + NS_LOG_INFO ("Wave RxBeginTrace for packet:" << animUid); + if (!IsPacketPending (animUid, AnimationInterface::WAVE)) + { + NS_ASSERT (0); + NS_LOG_WARN ("WavePhyRxBeginTrace: unknown Uid"); + std::ostringstream oss; + WifiMacHeader hdr; + if (!p->PeekHeader (hdr)) + { + NS_LOG_WARN ("WaveMacHeader not present"); + return; + } + oss << hdr.GetAddr2 (); + if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ()) + { + NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping"); + return; + } + Ptr txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]); + UpdatePosition (txNode); + AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]); + AddPendingPacket (AnimationInterface::WAVE, animUid, pktInfo); + NS_LOG_WARN ("WavePhyRxBegin: unknown Uid, but we are adding a wave packet"); + } + /// \todo NS_ASSERT (WavePacketIsPending (animUid) == true); + m_pendingWavePackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); + OutputWirelessPacketRxInfo (p, m_pendingWavePackets[animUid], animUid); +} + + void AnimationInterface::WimaxTxTrace (std::string context, Ptr p, const Mac48Address & m) { @@ -1290,6 +1337,11 @@ AnimationInterface::ProtocolTypeToPendingPackets (AnimationInterface::ProtocolTy pendingPackets = &m_pendingLrWpanPackets; break; } + case AnimationInterface::WAVE: + { + pendingPackets = &m_pendingWavePackets; + break; + } } return pendingPackets; @@ -1331,6 +1383,11 @@ AnimationInterface::ProtocolTypeToString (AnimationInterface::ProtocolType proto result = "LRWPAN"; break; } + case AnimationInterface::WAVE: + { + result = "WAVE"; + break; + } } return result; } @@ -1631,6 +1688,12 @@ AnimationInterface::ConnectCallbacks () MakeCallback (&AnimationInterface::LrWpanMacRxTrace, this)); Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRxDrop", MakeCallback (&AnimationInterface::LrWpanMacRxDropTrace, this)); + + // Wave + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyTxBegin", + MakeCallback (&AnimationInterface::WavePhyTxBeginTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyRxBegin", + MakeCallback (&AnimationInterface::WavePhyRxBeginTrace, this)); } Vector @@ -1878,13 +1941,13 @@ AnimationInterface::WriteLinkProperties () AddToIpv6AddressNodeIdTable(ipv6Addresses, n->GetId ()); if (!ipv4Addresses.empty ()) { - if (ipv4Addresses.size () > 1) - WriteNonP2pLinkProperties(n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType); + NS_LOG_INFO ("Writing Ipv4 link"); + WriteNonP2pLinkProperties(n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType); } else if (!ipv6Addresses.empty ()) { - if (ipv6Addresses.size () > 1) - WriteNonP2pLinkProperties(n->GetId (), GetIpv6Address (dev) + "~" + GetMacAddress (dev), channelType); + NS_LOG_INFO ("Writing Ipv6 link"); + WriteNonP2pLinkProperties(n->GetId (), GetIpv6Address (dev) + "~" + GetMacAddress (dev), channelType); } continue; } diff --git a/src/netanim/model/animation-interface.h b/src/netanim/model/animation-interface.h index f609d1e47..387a62da4 100644 --- a/src/netanim/model/animation-interface.h +++ b/src/netanim/model/animation-interface.h @@ -498,7 +498,8 @@ private: WIFI, WIMAX, CSMA, - LRWPAN + LRWPAN, + WAVE } ProtocolType; typedef struct @@ -595,6 +596,8 @@ private: AnimUidPacketInfoMap m_pendingLtePackets; AnimUidPacketInfoMap m_pendingCsmaPackets; AnimUidPacketInfoMap m_pendingUanPackets; + AnimUidPacketInfoMap m_pendingWavePackets; + std::map m_nodeLocation; std::map m_macToNodeIdMap; std::map m_ipv4ToNodeIdMap; @@ -725,6 +728,10 @@ private: Ptr p); void WifiPhyRxBeginTrace (std::string context, Ptr p); + void WavePhyTxBeginTrace (std::string context, + Ptr p); + void WavePhyRxBeginTrace (std::string context, + Ptr p); void LrWpanPhyTxBeginTrace (std::string context, Ptr p); void LrWpanPhyRxBeginTrace (std::string context, diff --git a/src/netanim/wscript b/src/netanim/wscript index 834d2aae5..7be7b6ae1 100644 --- a/src/netanim/wscript +++ b/src/netanim/wscript @@ -6,7 +6,7 @@ import wutils NETANIM_RELEASE_NAME = "netanim-3.108" def build (bld) : - module = bld.create_ns3_module ('netanim', ['internet', 'mobility', 'wimax', 'wifi', 'csma', 'lte', 'uan', 'lr-wpan', 'energy']) + module = bld.create_ns3_module ('netanim', ['internet', 'mobility', 'wimax', 'wifi', 'csma', 'lte', 'uan', 'lr-wpan', 'energy', 'wave']) module.includes = '.' module.source = [ 'model/animation-interface.cc', ] netanim_test = bld.create_ns3_module_test_library('netanim')