A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
animation-interface.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Author: George F. Riley<riley@ece.gatech.edu>
17  * Modified by: John Abraham <john.abraham@gatech.edu>
18  * Contributions: Eugene Kalishenko <ydginster@gmail.com> (Open Source and Linux Laboratory http://dev.osll.ru/)
19  */
20 
21 // Interface between ns3 and the network animator
22 
23 
24 // ns3 includes
25 #include "ns3/animation-interface.h"
26 #include "ns3/channel.h"
27 #include "ns3/config.h"
28 #include "ns3/node.h"
29 #include "ns3/mobility-model.h"
30 #include "ns3/packet.h"
31 #include "ns3/simulator.h"
32 #include "ns3/animation-interface-helper.h"
33 #include "ns3/wifi-mac-header.h"
34 #include "ns3/wimax-mac-header.h"
35 #include "ns3/wifi-net-device.h"
36 #include "ns3/wifi-mac.h"
37 #include "ns3/constant-position-mobility-model.h"
38 #include "ns3/lte-ue-phy.h"
39 #include "ns3/lte-enb-phy.h"
40 #include "ns3/uan-net-device.h"
41 #include "ns3/uan-mac.h"
42 #include "ns3/ipv4.h"
43 #include "ns3/ipv4-routing-protocol.h"
44 #include "ns3/energy-source-container.h"
45 
46 #include <cstdio>
47 #include <unistd.h>
48 #include <sstream>
49 #include <fstream>
50 #include <string>
51 #include <iomanip>
52 #include <map>
53 
54 NS_LOG_COMPONENT_DEFINE ("AnimationInterface");
55 
56 namespace ns3 {
57 
58 #define PURGE_INTERVAL 5
59 
60 static bool initialized = false;
61 std::map <uint32_t, std::string> AnimationInterface::nodeDescriptions;
62 std::map <uint32_t, Rgb> AnimationInterface::nodeColors;
63 std::map <P2pLinkNodeIdPair, LinkProperties, LinkPairCompare> AnimationInterface::linkProperties;
65 
66 
67 AnimationInterface::AnimationInterface (const std::string fn, uint64_t maxPktsPerFile, bool usingXML)
68  : m_routingF (0), m_xml (usingXML), m_mobilityPollInterval (Seconds (0.25)),
69  m_outputFileName (fn),
70  m_outputFileSet (false), gAnimUid (0), m_randomPosition (true),
71  m_writeCallback (0), m_started (false),
72  m_enablePacketMetadata (false), m_startTime (Seconds (0)), m_stopTime (Seconds (3600 * 1000)),
73  m_maxPktsPerFile (maxPktsPerFile), m_originalFileName (fn),
74  m_routingStopTime (Seconds (0)), m_routingFileName (""),
75  m_routingPollInterval (Seconds (5))
76 {
77  m_uniformRandomVariable = CreateObject<UniformRandomVariable> ();
78  initialized = true;
79  StartAnimation ();
80 }
81 
83 {
84  if (userBoundary)
85  {
86  delete userBoundary;
87  }
88  StopAnimation ();
89 }
90 
92 {
93  m_routingFileName = fileName;
96  m_routingPollInterval = pollInterval;
99  return *this;
100 }
101 
103 {
104  m_routingNc = nc;
105  return EnableIpv4RouteTracking (fileName, startTime, stopTime, pollInterval);
106 }
107 
109 {
110 
111  NS_ASSERT (n);
112  Ptr <ns3::Ipv4> ipv4 = n->GetObject <ns3::Ipv4> ();
113  if (!ipv4)
114  {
115  NS_LOG_WARN ("Node " << n->GetId () << " Does not have an Ipv4 object");
116  return "";
117  }
118  std::stringstream stream;
119  Ptr<OutputStreamWrapper> routingstream = Create<OutputStreamWrapper> (&stream);
120  ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingstream);
121  return stream.str ();
122 
123 }
124 
125 void AnimationInterface::RecursiveIpv4RoutePathSearch (std::string from, std::string to, Ipv4RoutePathElements & rpElements)
126 {
127  NS_LOG_INFO ("RecursiveIpv4RoutePathSearch from:" << from.c_str () << " to:" << to.c_str ());
128  if ((from == "0.0.0.0") || (from == "127.0.0.1"))
129  {
130  NS_LOG_INFO ("Got " << from.c_str () << " End recursion");
131  return;
132  }
135  if (fromNode->GetId () == toNode->GetId ())
136  {
137  Ipv4RoutePathElement elem = { fromNode->GetId (), "L" };
138  rpElements.push_back (elem);
139  return;
140  }
141  if (!fromNode)
142  {
143  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[from] << " Not found");
144  return;
145  }
146  if (!toNode)
147  {
148  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[to] << " Not found");
149  return;
150  }
151  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
152  if (!ipv4)
153  {
154  NS_LOG_WARN ("ipv4 object not found");
155  return;
156  }
158  if (!rp)
159  {
160  NS_LOG_WARN ("Routing protocol object not found");
161  return;
162  }
163  Ptr<Packet> pkt = Create<Packet> ();
164  Ipv4Header header;
165  header.SetDestination (Ipv4Address (to.c_str ()));
166  Socket::SocketErrno sockerr;
167  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
168  if (!rt)
169  {
170  return;
171  }
172  NS_LOG_DEBUG ("Node: " << fromNode->GetId () << " G:" << rt->GetGateway ());
173  std::ostringstream oss;
174  oss << rt->GetGateway ();
175  if (oss.str () == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
176  {
177  NS_LOG_INFO ("Null gw");
178  Ipv4RoutePathElement elem = { fromNode->GetId (), "C" };
179  rpElements.push_back (elem);
180  if ( m_ipv4ToNodeIdMap.find (to) != m_ipv4ToNodeIdMap.end ())
181  {
182  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[to], "L" };
183  rpElements.push_back (elem2);
184  }
185  return;
186  }
187  NS_LOG_INFO ("Node:" << fromNode->GetId () << "-->" << rt->GetGateway ());
188  Ipv4RoutePathElement elem = { fromNode->GetId (), oss.str () };
189  rpElements.push_back (elem);
190  RecursiveIpv4RoutePathSearch (oss.str (), to, rpElements);
191 
192 }
193 
195 {
196  if (m_ipv4RouteTrackElements.empty ())
197  {
198  return;
199  }
200  for (std::vector <Ipv4RouteTrackElement>::const_iterator i = m_ipv4RouteTrackElements.begin ();
201  i != m_ipv4RouteTrackElements.end ();
202  ++i)
203  {
204  Ipv4RouteTrackElement trackElement = *i;
205  Ptr <Node> fromNode = NodeList::GetNode (trackElement.fromNodeId);
206  if (!fromNode)
207  {
208  NS_FATAL_ERROR ("Node: " << trackElement.fromNodeId << " Not found");
209  continue;
210  }
211  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
212  if (!ipv4)
213  {
214  NS_LOG_WARN ("ipv4 object not found");
215  continue;
216  }
218  if (!rp)
219  {
220  NS_LOG_WARN ("Routing protocol object not found");
221  continue;
222  }
223  NS_LOG_INFO ("Begin Track Route for: " << trackElement.destination.c_str () << " From:" << trackElement.fromNodeId);
224  Ptr<Packet> pkt = Create<Packet> ();
225  Ipv4Header header;
226  header.SetDestination (Ipv4Address (trackElement.destination.c_str ()));
227  Socket::SocketErrno sockerr;
228  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
229  Ipv4RoutePathElements rpElements;
230  if (!rt)
231  {
232  NS_LOG_INFO ("No route to :" << trackElement.destination.c_str ());
233  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
234  rpElements.push_back (elem);
235  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
236  continue;
237  }
238  std::ostringstream oss;
239  oss << rt->GetGateway ();
240  NS_LOG_INFO ("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway ());
241  if (rt->GetGateway () == "0.0.0.0")
242  {
243  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "C" };
244  rpElements.push_back (elem);
245  if ( m_ipv4ToNodeIdMap.find (trackElement.destination) != m_ipv4ToNodeIdMap.end ())
246  {
247  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[trackElement.destination], "L" };
248  rpElements.push_back (elem2);
249  }
250  }
251  else if (rt->GetGateway () == "127.0.0.1")
252  {
253  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
254  rpElements.push_back (elem);
255  }
256  else
257  {
258  Ipv4RoutePathElement elem = { trackElement.fromNodeId, oss.str () };
259  rpElements.push_back (elem);
260  }
261  RecursiveIpv4RoutePathSearch (oss.str (), trackElement.destination, rpElements);
262  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
263  }
264 
265 }
266 
268 {
270  {
271  NS_LOG_INFO ("TrackIpv4Route completed");
272  return;
273  }
274  if (m_routingNc.GetN ())
275  {
276  for (NodeContainer::Iterator i = m_routingNc.Begin (); i != m_routingNc.End (); ++i)
277  {
278  Ptr <Node> n = *i;
280  }
281  }
282  else
283  {
284  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
285  {
286  Ptr <Node> n = *i;
288  }
289  }
292 }
293 
295 {
296  NS_LOG_INFO ("XML output set");
297  m_xml = true;
298 }
299 
300 
302 {
303  static int i = 0;
304  std::ostringstream oss;
305  oss << i;
308  {
309  return;
310  }
311  StopAnimation (true);
312  m_outputFileName = m_originalFileName + "-" + oss.str ();
313  StartAnimation (true);
314  ++i;
315 
316 }
317 
319 {
320  return "netanim-3.104";
321 }
322 
324 {
325  m_startTime = t;
326 }
327 
329 {
330  m_stopTime = t;
331 }
332 
333 bool AnimationInterface::SetOutputFile (const std::string& fn)
334 {
335  if (m_outputFileSet)
336  {
337  return true;
338  }
339  NS_LOG_INFO ("Creating new trace file:" << fn.c_str ());
340  m_f = std::fopen (fn.c_str (), "w");
341  if (!m_f)
342  {
343  NS_FATAL_ERROR ("Unable to open Animation output file");
344  return false; // Can't open
345  }
346  m_outputFileName = fn;
347  m_outputFileSet = true;
348  return true;
349 }
350 
351 bool AnimationInterface::SetRoutingOutputFile (const std::string& fn)
352 {
353  if (m_routingF)
354  {
355  NS_FATAL_ERROR ("SetRoutingOutputFile already used once");
356  return false;
357  }
358  m_routingF = std::fopen (fn.c_str (), "w");
359  if (!m_routingF)
360  {
361  NS_FATAL_ERROR ("Unable to open Animation Routing output file");
362  return false;
363  }
364  return true;
365 }
366 
368 {
369  m_enablePacketMetadata = enable;
370  if (enable)
372 }
373 
375 {
376  return initialized;
377 }
378 
380 {
381  return m_started;
382 
383 }
384 
385 void AnimationInterface::SetAnimWriteCallback (AnimWriteCallback cb)
386 {
387  m_writeCallback = cb;
388 }
389 
391 {
392  m_writeCallback = 0;
393 }
394 
396 {
397  if ((Simulator::Now () >= m_startTime) &&
398  (Simulator::Now () <= m_stopTime))
399  return true;
400  else
401  return false;
402 }
403 
405 {
406  return (m_pendingUanPackets.find (AnimUid) != m_pendingUanPackets.end ());
407 }
408 
410 {
411  return (m_pendingWifiPackets.find (AnimUid) != m_pendingWifiPackets.end ());
412 }
413 
415 {
416  return (m_pendingCsmaPackets.find (AnimUid) != m_pendingCsmaPackets.end ());
417 }
418 
419 
421 {
422  return (m_pendingWimaxPackets.find (AnimUid) != m_pendingWimaxPackets.end ());
423 }
424 
426 {
427  return (m_pendingLtePackets.find (AnimUid) != m_pendingLtePackets.end ());
428 }
429 
431 {
433 }
434 
436 {
437  m_randomPosition = setRandPos;
438 }
439 
441 {
443  if (loc)
444  {
445  m_nodeLocation[n->GetId ()] = loc->GetPosition ();
446  }
447  else
448  {
449  NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary");
450  Vector deterministicVector (100,100,0);
452  if (m_randomPosition)
453  {
454  m_nodeLocation[n->GetId ()] = randomVector;
455  }
456  else
457  {
458  m_nodeLocation[n->GetId ()] = deterministicVector;
459  }
460  }
461  return m_nodeLocation[n->GetId ()];
462 }
463 
465 {
466  m_nodeLocation[n->GetId ()] = v;
467  return v;
468 }
469 
471 {
472  #ifdef NS_LOG
473  if (m_nodeLocation.find (n->GetId ()) == m_nodeLocation.end ())
474  {
475  NS_FATAL_ERROR ("Node:" <<n->GetId () << " not found in Location table");
476  }
477  #endif
478  return m_nodeLocation[n->GetId ()];
479 }
480 
482 {
483  if (m_pendingWifiPackets.empty ())
484  return;
485  std::vector <uint64_t> purgeList;
486  for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingWifiPackets.begin ();
487  i != m_pendingWifiPackets.end ();
488  ++i)
489  {
490 
491  AnimPacketInfo pktInfo = i->second;
492  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
493  if (delta > PURGE_INTERVAL)
494  {
495  purgeList.push_back (i->first);
496  }
497  }
498 
499  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
500  i != purgeList.end ();
501  ++i)
502  {
503  m_pendingWifiPackets.erase (*i);
504  }
505 
506 }
507 
509 {
510  if (m_pendingWimaxPackets.empty ())
511  return;
512  std::vector <uint64_t> purgeList;
513  for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingWimaxPackets.begin ();
514  i != m_pendingWimaxPackets.end ();
515  ++i)
516  {
517 
518  AnimPacketInfo pktInfo = i->second;
519  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
520  if (delta > PURGE_INTERVAL)
521  {
522  purgeList.push_back (i->first);
523  }
524  }
525 
526  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
527  i != purgeList.end ();
528  ++i)
529  {
530  m_pendingWimaxPackets.erase (*i);
531  }
532 
533 }
534 
535 
537 {
538  if (m_pendingLtePackets.empty ())
539  return;
540  std::vector <uint64_t> purgeList;
541  for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingLtePackets.begin ();
542  i != m_pendingLtePackets.end ();
543  ++i)
544  {
545 
546  AnimPacketInfo pktInfo = i->second;
547  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
548  if (delta > PURGE_INTERVAL)
549  {
550  purgeList.push_back (i->first);
551  }
552  }
553 
554  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
555  i != purgeList.end ();
556  ++i)
557  {
558  m_pendingLtePackets.erase (*i);
559  }
560 }
561 
563 {
564  if (m_pendingCsmaPackets.empty ())
565  return;
566  std::vector <uint64_t> purgeList;
567  for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingCsmaPackets.begin ();
568  i != m_pendingCsmaPackets.end ();
569  ++i)
570  {
571 
572  AnimPacketInfo pktInfo = i->second;
573  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
574  if (delta > PURGE_INTERVAL)
575  {
576  purgeList.push_back (i->first);
577  }
578  }
579 
580  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
581  i != purgeList.end ();
582  ++i)
583  {
584  m_pendingCsmaPackets.erase (*i);
585  }
586 
587 }
588 
590 {
591  Address nodeAddr = nd->GetAddress ();
592  std::ostringstream oss;
593  oss << nodeAddr;
594  return oss.str ().substr (6); // Skip the first 6 chars to get the Mac
595 }
596 
598 {
599  Ptr<Ipv4> ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
600  if (!ipv4)
601  {
602  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found");
603  return "0.0.0.0";
604  }
605  int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
606  if (ifIndex == -1)
607  {
608  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
609  return "0.0.0.0";
610  }
611  Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, 0);
612  std::ostringstream oss;
613  oss << addr.GetLocal ();
614  return oss.str ();
615 }
616 
618 {
619  m_currentPktCount = 0;
620  m_started = true;
622 
623  // Find the min/max x/y for the xml topology element
624  m_topoMinX = -2;
625  m_topoMinY = -2;
626  m_topoMaxX = 2;
627  m_topoMaxY = 2;
628  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
629  {
630  Ptr<Node> n = *i;
631  NS_LOG_INFO ("Update Position for Node: " << n->GetId ());
632  Vector v = UpdatePosition (n);
633  m_topoMinX = std::min (m_topoMinX, v.x);
634  m_topoMinY = std::min (m_topoMinY, v.y);
635  m_topoMaxX = std::max (m_topoMaxX, v.x);
636  m_topoMaxY = std::max (m_topoMaxY, v.y);
637  struct Rgb rgb = {255, 0, 0};
638  if (nodeColors.find (n->GetId ()) == nodeColors.end ())
639  {
640  nodeColors[n->GetId ()] = rgb;
641  }
642  }
643 
644 
645  std::ostringstream oss;
646  oss << GetXMLOpen_anim (0);
647  oss << GetPreamble ();
649  WriteN (oss.str (), m_f);
650  NS_LOG_INFO ("Setting topology for "<<NodeList::GetNNodes ()<<" Nodes");
651  // Dump the topology
652  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
653  {
654  Ptr<Node> n = *i;
655  std::ostringstream oss;
656  Vector v = GetPosition (n);
657  struct Rgb rgb = nodeColors[n->GetId ()];
658  oss << GetXMLOpenClose_node (0, n->GetId (), v.x, v.y, rgb);
659  WriteN (oss.str (), m_f);
660  }
661  NS_LOG_INFO ("Setting p2p links");
662  // Now dump the p2p links
663  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
664  {
665  Ptr<Node> n = *i;
666  uint32_t n1Id = n->GetId ();
667  uint32_t nDev = n->GetNDevices (); // Number of devices
668  for (uint32_t i = 0; i < nDev; ++i)
669  {
670  Ptr<NetDevice> dev = n->GetDevice (i);
671  NS_ASSERT (dev);
672  Ptr<Channel> ch = dev->GetChannel ();
673  if (!ch)
674  {
675  NS_LOG_DEBUG ("No channel can't be a p2p device");
676  // Try to see if it is an LTE NetDevice, which does not return a channel
677  if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") ||
678  (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")||
679  (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice"))
680  {
681  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), dev->GetInstanceTypeId ().GetName ());
683  }
684  continue;
685  }
686  std::string channelType = ch->GetInstanceTypeId ().GetName ();
687  NS_LOG_DEBUG ("Got ChannelType" << channelType);
688  if (channelType == std::string ("ns3::PointToPointChannel"))
689  { // Since these are duplex links, we only need to dump
690  // if srcid < dstid
691  uint32_t nChDev = ch->GetNDevices ();
692  for (uint32_t j = 0; j < nChDev; ++j)
693  {
694  Ptr<NetDevice> chDev = ch->GetDevice (j);
695  uint32_t n2Id = chDev->GetNode ()->GetId ();
696  if (n1Id < n2Id)
697  {
698  // ouptut the p2p link
699  NS_LOG_INFO ("Link:" << GetIpv4Address (dev) << ":" << GetMacAddress (dev) << "----" << GetIpv4Address (chDev) << ":" << GetMacAddress (chDev) );
700  SetLinkDescription (n1Id, n2Id, "", GetIpv4Address (dev) + "~" + GetMacAddress (dev), GetIpv4Address (chDev) + "~" + GetMacAddress (chDev));
703  std::ostringstream oss;
704  if (m_xml)
705  {
706  oss << GetXMLOpenClose_link (0, n1Id, 0, n2Id);
707  }
708  else
709  {
710  oss << "0.0 L " << n1Id << " " << n2Id << std::endl;
711  }
712  WriteN (oss.str (), m_f);
713  }
714  }
715  }
716  else
717  {
718  NS_LOG_INFO ("Link:" << GetIpv4Address (dev) << " Channel Type:" << channelType << " Mac: " << GetMacAddress (dev));
719  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType);
721  }
722  }
723  }
724  linkProperties.clear ();
725  if (m_xml && !restart)
726  {
727  WriteN (GetXMLClose ("topology"), m_f);
729  }
730  if (!restart)
731  ConnectCallbacks ();
732 }
733 
734 void AnimationInterface::AddToIpv4AddressNodeIdTable (std::string ipv4Address, uint32_t nodeId)
735 {
736  m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
737 }
738 
739 AnimationInterface & AnimationInterface::AddSourceDestination (uint32_t fromNodeId, std::string ipv4Address)
740 {
741  Ipv4RouteTrackElement element = { ipv4Address, fromNodeId };
742  m_ipv4RouteTrackElements.push_back (element);
743  return *this;
744 }
745 
746 
748 {
749 
750  Ptr<LteEnbPhy> lteEnbPhy = nd->GetPhy ();
751  Ptr<LteSpectrumPhy> dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy ();
752  Ptr<LteSpectrumPhy> ulPhy = lteEnbPhy->GetUplinkSpectrumPhy ();
753  std::ostringstream oss;
754  //NodeList/*/DeviceList/*/
755  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
756  if (dlPhy)
757  {
758  dlPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
759  dlPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
760  }
761  if (ulPhy)
762  {
763  ulPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
764  ulPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
765  }
766 }
767 
768 
769 
771 {
772 
773  Ptr<LteUePhy> lteUePhy = nd->GetPhy ();
774  Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy ();
775  Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy ();
776  std::ostringstream oss;
777  //NodeList/*/DeviceList/*/
778  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
779  if (dlPhy)
780  {
781  dlPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
782  dlPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
783  }
784  if (ulPhy)
785  {
786  ulPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
787  ulPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
788  }
789 }
790 
792 {
793 
794  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
795  {
796  Ptr<Node> n = *i;
797  NS_ASSERT (n);
798  uint32_t nDevices = n->GetNDevices ();
799  for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
800  {
801  Ptr <NetDevice> nd = n->GetDevice (devIndex);
802  if (!nd)
803  continue;
804  Ptr<LteUeNetDevice> lteUeNetDevice = DynamicCast<LteUeNetDevice> (nd);
805  if (lteUeNetDevice)
806  {
807  ConnectLteUe (n, lteUeNetDevice, devIndex);
808  continue;
809  }
810  Ptr<LteEnbNetDevice> lteEnbNetDevice = DynamicCast<LteEnbNetDevice> (nd);
811  if (lteEnbNetDevice)
812  ConnectLteEnb (n, lteEnbNetDevice, devIndex);
813  }
814 
815  }
816 }
817 
819 {
820  // Connect the callbacks
821  Config::Connect ("/ChannelList/*/TxRxPointToPoint",
823  Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
825  Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
827  Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange",
829  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
831  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx",
833  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
835  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
837  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
839  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
841  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
843  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
845  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
847  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
849  Config::Connect ("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy",
851 
852  ConnectLte ();
853 
854 }
855 
856 
857 void AnimationInterface::StopAnimation (bool onlyAnimation)
858 {
859  m_started = false;
860  NS_LOG_INFO ("Stopping Animation");
862  if (m_f)
863  {
864  if (m_xml)
865  { // Terminate the anim element
866  WriteN (GetXMLClose ("anim"), m_f);
867  }
868  std::fclose (m_f);
869  }
870  m_outputFileSet = false;
871  if (onlyAnimation)
872  {
873  return;
874  }
875  if (m_routingF)
876  {
877  WriteN (GetXMLClose ("anim"), m_routingF);
878  std::fclose (m_routingF);
879  }
880 }
881 
882 int AnimationInterface::WriteN (const std::string& st, FILE * f)
883 {
884  if (m_writeCallback)
885  {
886  m_writeCallback (st.c_str ());
887  }
888  return WriteN (st.c_str (), st.length (), f);
889 }
890 
891 std::vector <Ptr <Node> > AnimationInterface::RecalcTopoBounds ()
892 {
893  std::vector < Ptr <Node> > MovedNodes;
894  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
895  {
896  Ptr<Node> n = *i;
897  NS_ASSERT (n);
898  Ptr <MobilityModel> mobility = n->GetObject <MobilityModel> ();
899  Vector newLocation;
900  if (!mobility)
901  {
902  newLocation = GetPosition (n);
903  }
904  else
905  {
906  newLocation = mobility->GetPosition ();
907  }
908  if (!NodeHasMoved (n, newLocation))
909  {
910  continue; //Location has not changed
911  }
912  else
913  {
914  UpdatePosition (n, newLocation);
915  RecalcTopoBounds (newLocation);
916  MovedNodes.push_back (n);
917  }
918  }
919  return MovedNodes;
920 }
921 
923 {
924  m_topoMinX = std::min (m_topoMinX, v.x);
925  m_topoMinY = std::min (m_topoMinY, v.y);
926  m_topoMaxX = std::max (m_topoMaxX, v.x);
927  m_topoMaxY = std::max (m_topoMaxY, v.y);
928 
929 }
930 
931 int AnimationInterface::WriteN (const char* data, uint32_t count, FILE * f)
932 {
933  // Write count bytes to h from data
934  uint32_t nLeft = count;
935  const char* p = data;
936  uint32_t written = 0;
937  while (nLeft)
938  {
939  int n = std::fwrite (p, 1, nLeft, f);
940  if (n <= 0)
941  {
942  return written;
943  }
944  written += n;
945  nLeft -= n;
946  p += n;
947  }
948  return written;
949 }
950 
952 {
953  Time now = Simulator::Now ();
954  std::ostringstream oss;
955  double fbTx = now.GetSeconds ();
956  double lbTx = now.GetSeconds ();
957  double fbRx = now.GetSeconds ();
958  double lbRx = now.GetSeconds ();
959  oss << GetXMLOpenClose_p ("p", 0, fbTx, lbTx, 0, fbRx, lbRx, "", "DummyPktIgnoreThis");
960  WriteN (oss.str (), m_f);
961 
962 
963 }
964 
965 void AnimationInterface::WriteRoutePath (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
966 {
967  NS_LOG_INFO ("Writing Route Path From :" << nodeId << " To: " << destination.c_str ());
968  WriteN (GetXMLOpenClose_rp (nodeId, destination, rpElements), m_routingF);
969  /*for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
970  i != rpElements.end ();
971  ++i)
972  {
973  Ipv4RoutePathElement rpElement = *i;
974  NS_LOG_INFO ("Node:" << rpElement.nodeId << "-->" << rpElement.nextHop.c_str ());
975  WriteN (GetXMLOpenClose_rp (rpElement.node, GetIpv4RoutingTable (n)), m_routingF);
976 
977  }
978  */
979 }
980 
981 void AnimationInterface::WriteNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
982 {
983  std::ostringstream oss;
984  oss << GetXMLOpenClose_NonP2pLinkProperties (id, ipv4Address, channelType);
985  WriteN (oss.str (), m_f);
986 }
987 
990  Time txTime, Time rxTime)
991 {
992  if (!m_started || !IsInTimeWindow ())
993  return;
994  NS_ASSERT (tx);
995  NS_ASSERT (rx);
996  Time now = Simulator::Now ();
997  std::ostringstream oss;
998  double fbTx = now.GetSeconds ();
999  double lbTx = (now + txTime).GetSeconds ();
1000  double fbRx = (now + rxTime - txTime).GetSeconds ();
1001  double lbRx = (now + rxTime).GetSeconds ();
1002  if (m_xml)
1003  {
1004  oss << GetXMLOpenClose_p ("p", tx->GetNode ()->GetId (), fbTx, lbTx, rx->GetNode ()->GetId (),
1005  fbRx, lbRx, m_enablePacketMetadata? GetPacketMetadata (p):"");
1006  StartNewTraceFile ();
1008  }
1009  else
1010  {
1011  oss << std::setprecision (10);
1012  oss << now.GetSeconds () << " P "
1013  << tx->GetNode ()->GetId () << " "
1014  << rx->GetNode ()->GetId () << " "
1015  << (now + txTime).GetSeconds () << " " // last bit tx time
1016  << (now + rxTime - txTime).GetSeconds () << " " // first bit rx time
1017  << (now + rxTime).GetSeconds () << std::endl; // last bit rx time
1018  }
1019  WriteN (oss.str (), m_f);
1020 }
1021 
1022 
1023 Ptr <Node>
1024 AnimationInterface::GetNodeFromContext (const std::string& context) const
1025 {
1026  // Use "NodeList/*/ as reference
1027  // where element [1] is the Node Id
1028 
1029  std::vector <std::string> elements = GetElementsFromContext (context);
1030  Ptr <Node> n = NodeList::GetNode (atoi (elements.at (1).c_str ()));
1031  NS_ASSERT (n);
1032 
1033  return n;
1034 }
1035 
1038 {
1039  // Use "NodeList/*/DeviceList/*/ as reference
1040  // where element [1] is the Node Id
1041  // element [2] is the NetDevice Id
1042 
1043  std::vector <std::string> elements = GetElementsFromContext (context);
1044  Ptr <Node> n = GetNodeFromContext (context);
1045 
1046  return n->GetDevice (atoi (elements.at (3).c_str ()));
1047 }
1048 
1050 {
1051  m_pendingUanPackets[AnimUid] = pktinfo;
1052 }
1053 
1054 
1056 {
1057  m_pendingWifiPackets[AnimUid] = pktinfo;
1058 }
1059 
1061 {
1062  NS_ASSERT (pktinfo.m_txnd);
1063  m_pendingWimaxPackets[AnimUid] = pktinfo;
1064 }
1065 
1067 {
1068  NS_ASSERT (pktinfo.m_txnd);
1069  m_pendingLtePackets[AnimUid] = pktinfo;
1070 }
1071 
1073 {
1074  NS_ASSERT (pktinfo.m_txnd);
1075  m_pendingCsmaPackets[AnimUid] = pktinfo;
1076 }
1077 
1079 {
1080  AnimByteTag tag;
1081  TypeId tid = tag.GetInstanceTypeId ();
1083  bool found = false;
1084  while (i.HasNext ())
1085  {
1086  ByteTagIterator::Item item = i.Next ();
1087  if (tid == item.GetTypeId ())
1088  {
1089  item.GetTag (tag);
1090  found = true;
1091  }
1092  }
1093  if (found)
1094  {
1095  return tag.Get ();
1096  }
1097  else
1098  {
1099  return 0;
1100  }
1101 }
1102 
1104 {
1105  if (!m_started || !IsInTimeWindow ())
1106  return;
1107  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1108  NS_ASSERT (ndev);
1109  Ptr <Node> n = ndev->GetNode ();
1110  NS_ASSERT (n);
1111  gAnimUid++;
1112  NS_LOG_INFO ("Uan TxBeginTrace for packet:" << gAnimUid);
1113  AnimByteTag tag;
1114  tag.Set (gAnimUid);
1115  p->AddByteTag (tag);
1116  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1117  AddPendingUanPacket (gAnimUid, pktinfo);
1118 
1119 
1120 }
1121 
1123 {
1124  if (!m_started || !IsInTimeWindow ())
1125  return;
1126  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1127  NS_ASSERT (ndev);
1128  Ptr <Node> n = ndev->GetNode ();
1129  NS_ASSERT (n);
1130  uint64_t AnimUid = GetAnimUidFromPacket (p);
1131  NS_LOG_INFO ("UanPhyGenRxTrace for packet:" << AnimUid);
1132  if (!UanPacketIsPending (AnimUid))
1133  {
1134  NS_LOG_WARN ("UanPhyGenRxBeginTrace: unknown Uid");
1135  return;
1136  }
1137  m_pendingUanPackets[AnimUid].ProcessRxBegin (ndev, Simulator::Now ());
1138  m_pendingUanPackets[AnimUid].ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
1139  OutputWirelessPacket (p, m_pendingUanPackets[AnimUid], m_pendingUanPackets[AnimUid].GetRxInfo (ndev));
1140 
1141 }
1142 
1143 void AnimationInterface::RemainingEnergyTrace (std::string context, double previousEnergy, double currentEnergy)
1144 {
1145  if (!m_started || !IsInTimeWindow ())
1146  return;
1147 
1148  const Ptr <const Node> node = GetNodeFromContext (context);
1149  const uint32_t nodeId = node->GetId ();
1150 
1151  NS_LOG_INFO ("Remaining energy on one of sources on node " << nodeId << ": " << currentEnergy);
1152 
1153  const Ptr<EnergySource> energySource = node->GetObject<EnergySource> ();
1154 
1155  NS_ASSERT (energySource);
1156  // Don't call GetEnergyFraction () because of recursion
1157  const double energyFraction = currentEnergy / energySource->GetInitialEnergy ();
1158 
1159  NS_LOG_INFO ("Total energy fraction on node " << nodeId << ": " << energyFraction);
1160 
1161  m_nodeEnergyFraction[nodeId] = energyFraction;
1162  WriteNodeUpdate (nodeId);
1163 }
1164 
1167 {
1168  if (!m_started || !IsInTimeWindow ())
1169  return;
1170  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1171  NS_ASSERT (ndev);
1172  Ptr <Node> n = ndev->GetNode ();
1173  NS_ASSERT (n);
1174  // Add a new pending wireless
1175  gAnimUid++;
1176  NS_LOG_INFO ("Wifi TxBeginTrace for packet:" << gAnimUid);
1177  AnimByteTag tag;
1178  tag.Set (gAnimUid);
1179  p->AddByteTag (tag);
1180  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1181  AddPendingWifiPacket (gAnimUid, pktinfo);
1182  Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (ndev);
1183  Mac48Address nodeAddr = netDevice->GetMac ()->GetAddress ();
1184  std::ostringstream oss;
1185  oss << nodeAddr;
1186  m_macToNodeIdMap[oss.str ()] = n->GetId ();
1187  NS_LOG_INFO ("Added Mac" << oss.str () << " node:" <<m_macToNodeIdMap[oss.str ()]);
1188 }
1189 
1190 void AnimationInterface::WifiPhyTxEndTrace (std::string context,
1192 {
1193 }
1194 
1195 void AnimationInterface::WifiPhyTxDropTrace (std::string context,
1197 {
1198  if (!m_started || !IsInTimeWindow ())
1199  return;
1200  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1201  NS_ASSERT (ndev);
1202  // Erase pending wifi
1203  uint64_t AnimUid = GetAnimUidFromPacket (p);
1204  NS_LOG_INFO ("TxDropTrace for packet:" << AnimUid);
1205  NS_ASSERT (WifiPacketIsPending (AnimUid) == true);
1206  m_pendingWifiPackets.erase (m_pendingWifiPackets.find (AnimUid));
1207 }
1208 
1209 
1212 {
1213  if (!m_started || !IsInTimeWindow ())
1214  return;
1215  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1216  NS_ASSERT (ndev);
1217  Ptr <Node> n = ndev->GetNode ();
1218  NS_ASSERT (n);
1219  uint64_t AnimUid = GetAnimUidFromPacket (p);
1220  NS_LOG_INFO ("Wifi RxBeginTrace for packet:" << AnimUid);
1221  if (!WifiPacketIsPending (AnimUid))
1222  {
1223  NS_LOG_WARN ("WifiPhyRxBeginTrace: unknown Uid");
1224  std::ostringstream oss;
1225  WifiMacHeader hdr;
1226  if (!p->PeekHeader (hdr))
1227  {
1228  NS_LOG_WARN ("WifiMacHeader not present");
1229  return;
1230  }
1231  oss << hdr.GetAddr2 ();
1232  if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
1233  {
1234  //NS_LOG_UNCOND (oss.str ());
1235  return;
1236  }
1237  Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
1238  AnimPacketInfo pktinfo (0, Simulator::Now (), Simulator::Now (), UpdatePosition (txNode), m_macToNodeIdMap[oss.str ()]);
1239  AddPendingWifiPacket (AnimUid, pktinfo);
1240  NS_LOG_WARN ("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
1241  }
1243  m_pendingWifiPackets[AnimUid].ProcessRxBegin (ndev, Simulator::Now ());
1244  m_pendingWifiPackets[AnimUid].ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
1245  OutputWirelessPacket (p, m_pendingWifiPackets[AnimUid], m_pendingWifiPackets[AnimUid].GetRxInfo (ndev));
1246 }
1247 
1248 
1249 void AnimationInterface::WifiPhyRxEndTrace (std::string context,
1251 {
1252  if (!m_started || !IsInTimeWindow ())
1253  return;
1254  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1255  NS_ASSERT (ndev);
1256  Ptr <Node> n = ndev->GetNode ();
1257  NS_ASSERT (n);
1258  uint64_t AnimUid = GetAnimUidFromPacket (p);
1259  if (!WifiPacketIsPending (AnimUid))
1260  {
1261  NS_LOG_WARN ("WifiPhyRxEndTrace: unknown Uid");
1262  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1263  AddPendingWifiPacket (AnimUid, pktinfo);
1264  }
1266  AnimPacketInfo& pktInfo = m_pendingWifiPackets[AnimUid];
1267  pktInfo.ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
1268  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1269  if (pktrxInfo.IsPhyRxComplete ())
1270  {
1271  NS_LOG_INFO ("MacRxTrace for packet:" << AnimUid << " complete");
1272  OutputWirelessPacket (p, pktInfo, pktrxInfo);
1273  }
1274 }
1275 
1276 void AnimationInterface::WifiMacRxTrace (std::string context,
1278 {
1279  if (!m_started || !IsInTimeWindow ())
1280  return;
1281  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1282  NS_ASSERT (ndev);
1283  Ptr <Node> n = ndev->GetNode ();
1284  NS_ASSERT (n);
1285  uint64_t AnimUid = GetAnimUidFromPacket (p);
1286  if (!WifiPacketIsPending (AnimUid))
1287  {
1288  NS_LOG_WARN ("WifiMacRxTrace: unknown Uid");
1289  return;
1290  }
1292  AnimPacketInfo& pktInfo = m_pendingWifiPackets[AnimUid];
1293  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1294  if (pktrxInfo.IsPhyRxComplete ())
1295  {
1296  NS_LOG_INFO ("MacRxTrace for packet:" << AnimUid << " complete");
1297  OutputWirelessPacket (p, pktInfo, pktrxInfo);
1298  }
1299 
1300 }
1301 void AnimationInterface::WifiPhyRxDropTrace (std::string context,
1303 {
1304 }
1305 
1306 void AnimationInterface::WimaxTxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
1307 {
1308  if (!m_started || !IsInTimeWindow ())
1309  return;
1310  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1311  NS_ASSERT (ndev);
1312  Ptr <Node> n = ndev->GetNode ();
1313  NS_ASSERT (n);
1314  gAnimUid++;
1315  NS_LOG_INFO ("WimaxTxTrace for packet:" << gAnimUid);
1316  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1318  AnimByteTag tag;
1319  tag.Set (gAnimUid);
1320  p->AddByteTag (tag);
1321  AddPendingWimaxPacket (gAnimUid, pktinfo);
1322 }
1323 
1324 
1325 void AnimationInterface::WimaxRxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
1326 {
1327  if (!m_started || !IsInTimeWindow ())
1328  return;
1329  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1330  NS_ASSERT (ndev);
1331  Ptr <Node> n = ndev->GetNode ();
1332  NS_ASSERT (n);
1333  uint64_t AnimUid = GetAnimUidFromPacket (p);
1334  NS_LOG_INFO ("WimaxRxTrace for packet:" << AnimUid);
1335  NS_ASSERT (WimaxPacketIsPending (AnimUid) == true);
1336  AnimPacketInfo& pktInfo = m_pendingWimaxPackets[AnimUid];
1337  pktInfo.ProcessRxBegin (ndev, Simulator::Now ());
1338  pktInfo.ProcessRxEnd (ndev, Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1340  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1341  OutputWirelessPacket (p, pktInfo, pktrxInfo);
1342 }
1343 
1344 void AnimationInterface::LteTxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
1345 {
1346  if (!m_started || !IsInTimeWindow ())
1347  return;
1348  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1349  NS_ASSERT (ndev);
1350  Ptr <Node> n = ndev->GetNode ();
1351  NS_ASSERT (n);
1352  gAnimUid++;
1353  NS_LOG_INFO ("LteTxTrace for packet:" << gAnimUid);
1354  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1356  AnimByteTag tag;
1357  tag.Set (gAnimUid);
1358  p->AddByteTag (tag);
1359  AddPendingLtePacket (gAnimUid, pktinfo);
1360 }
1361 
1362 
1363 void AnimationInterface::LteRxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
1364 {
1365  if (!m_started || !IsInTimeWindow ())
1366  return;
1367  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1368  NS_ASSERT (ndev);
1369  Ptr <Node> n = ndev->GetNode ();
1370  NS_ASSERT (n);
1371  uint64_t AnimUid = GetAnimUidFromPacket (p);
1372  NS_LOG_INFO ("LteRxTrace for packet:" << gAnimUid);
1373  if (!LtePacketIsPending (AnimUid))
1374  {
1375  NS_LOG_WARN ("LteRxTrace: unknown Uid");
1376  return;
1377  }
1378  AnimPacketInfo& pktInfo = m_pendingLtePackets[AnimUid];
1379  pktInfo.ProcessRxBegin (ndev, Simulator::Now ());
1380  pktInfo.ProcessRxEnd (ndev, Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1382  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1383  OutputWirelessPacket (p, pktInfo, pktrxInfo);
1384 }
1385 
1387 {
1388  if (!m_started || !IsInTimeWindow ())
1389  return;
1390  if (!pb)
1391  {
1392  NS_LOG_WARN ("pb == 0. Not yet supported");
1393  return;
1394  }
1395  context = "/" + context;
1396  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1397  NS_ASSERT (ndev);
1398  Ptr <Node> n = ndev->GetNode ();
1399  NS_ASSERT (n);
1400 
1401  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1402  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1403  i != pbList.end ();
1404  ++i)
1405  {
1406  Ptr <Packet> p = *i;
1407  gAnimUid++;
1408  NS_LOG_INFO ("LteSpectrumPhyTxTrace for packet:" << gAnimUid);
1409  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1411  AnimByteTag tag;
1412  tag.Set (gAnimUid);
1413  p->AddByteTag (tag);
1414  AddPendingLtePacket (gAnimUid, pktinfo);
1415  }
1416 }
1417 
1419 {
1420  if (!m_started || !IsInTimeWindow ())
1421  return;
1422  if (!pb)
1423  {
1424  NS_LOG_WARN ("pb == 0. Not yet supported");
1425  return;
1426  }
1427  context = "/" + context;
1428  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1429  NS_ASSERT (ndev);
1430  Ptr <Node> n = ndev->GetNode ();
1431  NS_ASSERT (n);
1432 
1433  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1434  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1435  i != pbList.end ();
1436  ++i)
1437  {
1438  Ptr <Packet> p = *i;
1439  uint64_t AnimUid = GetAnimUidFromPacket (p);
1440  NS_LOG_INFO ("LteSpectrumPhyRxTrace for packet:" << gAnimUid);
1441  if (!LtePacketIsPending (AnimUid))
1442  {
1443  NS_LOG_WARN ("LteSpectrumPhyRxTrace: unknown Uid");
1444  return;
1445  }
1446  AnimPacketInfo& pktInfo = m_pendingLtePackets[AnimUid];
1447  pktInfo.ProcessRxBegin (ndev, Simulator::Now ());
1448  pktInfo.ProcessRxEnd (ndev, Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1450  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1451  OutputWirelessPacket (p, pktInfo, pktrxInfo);
1452  }
1453 }
1454 
1456 {
1457  if (!m_started || !IsInTimeWindow ())
1458  return;
1459  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1460  NS_ASSERT (ndev);
1461  Ptr <Node> n = ndev->GetNode ();
1462  NS_ASSERT (n);
1463  gAnimUid++;
1464  NS_LOG_INFO ("CsmaPhyTxBeginTrace for packet:" << gAnimUid);
1465  AnimByteTag tag;
1466  tag.Set (gAnimUid);
1467  p->AddByteTag (tag);
1468  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1469  AddPendingCsmaPacket (gAnimUid, pktinfo);
1470 
1471 }
1472 
1474 {
1475  if (!m_started || !IsInTimeWindow ())
1476  return;
1477  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1478  NS_ASSERT (ndev);
1479  Ptr <Node> n = ndev->GetNode ();
1480  NS_ASSERT (n);
1481  uint64_t AnimUid = GetAnimUidFromPacket (p);
1482  NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << AnimUid);
1483  if (!CsmaPacketIsPending (AnimUid))
1484  {
1485  NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid");
1486  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1487  AddPendingCsmaPacket (AnimUid, pktinfo);
1488  NS_LOG_WARN ("Unknown Uid, but adding Csma Packet anyway");
1489  }
1491  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[AnimUid];
1492  pktInfo.m_lbTx = Simulator::Now ().GetSeconds ();
1493 }
1494 
1496 {
1497  if (!m_started || !IsInTimeWindow ())
1498  return;
1499  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1500  NS_ASSERT (ndev);
1501  Ptr <Node> n = ndev->GetNode ();
1502  NS_ASSERT (n);
1503  uint64_t AnimUid = GetAnimUidFromPacket (p);
1504  if (!CsmaPacketIsPending (AnimUid))
1505  {
1506  NS_LOG_WARN ("CsmaPhyRxEndTrace: unknown Uid");
1507  return;
1508  }
1510  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[AnimUid];
1511  m_pendingCsmaPackets[AnimUid].ProcessRxBegin (ndev, Simulator::Now ());
1512  pktInfo.ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
1513  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << AnimUid);
1514  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1515  if (pktrxInfo.IsPhyRxComplete ())
1516  {
1517  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << AnimUid << " complete");
1518  OutputCsmaPacket (p, pktInfo, pktrxInfo);
1519  }
1520 }
1521 
1522 
1523 void AnimationInterface::CsmaMacRxTrace (std::string context,
1525 {
1526  if (!m_started || !IsInTimeWindow ())
1527  return;
1528  NS_LOG_FUNCTION (this);
1529  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1530  NS_ASSERT (ndev);
1531  Ptr <Node> n = ndev->GetNode ();
1532  NS_ASSERT (n);
1533  uint64_t AnimUid = GetAnimUidFromPacket (p);
1534  if (!CsmaPacketIsPending (AnimUid))
1535  {
1536  NS_LOG_WARN ("CsmaMacRxTrace: unknown Uid");
1537  return;
1538  }
1540  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[AnimUid];
1541  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1542  if (pktrxInfo.IsPhyRxComplete ())
1543  {
1544  NS_LOG_INFO ("MacRxTrace for packet:" << AnimUid << " complete");
1545  OutputCsmaPacket (p, pktInfo, pktrxInfo);
1546  }
1547 }
1548 
1549 
1551 
1552 {
1553  if (!m_started || !IsInTimeWindow ())
1554  return;
1555  Ptr <Node> n = mobility->GetObject <Node> ();
1556  NS_ASSERT (n);
1557  Vector v ;
1558  if (!mobility)
1559  {
1560  v = GetPosition (n);
1561  }
1562  else
1563  {
1564  v = mobility->GetPosition ();
1565  }
1566  UpdatePosition (n,v);
1567  RecalcTopoBounds (v);
1568  std::ostringstream oss;
1570  oss << GetXMLOpenClose_node (0, n->GetId (), v.x, v.y, nodeColors[n->GetId ()]);
1571  oss << GetXMLClose ("topology");
1572  WriteN (oss.str (), m_f);
1573  WriteDummyPacket ();
1574 }
1575 
1577 {
1578  Vector oldLocation = GetPosition (n);
1579  if ((ceil (oldLocation.x) == ceil (newLocation.x)) &&
1580  (ceil (oldLocation.y) == ceil (newLocation.y)))
1581  {
1582 
1583  return false;
1584  }
1585  else
1586  {
1587  return true;
1588  }
1589 }
1590 
1592 {
1593  if (!m_started || !IsInTimeWindow ())
1594  return;
1595  std::vector <Ptr <Node> > MovedNodes = RecalcTopoBounds ();
1596  std::ostringstream oss;
1598  for (uint32_t i = 0; i < MovedNodes.size (); i++)
1599  {
1600  Ptr <Node> n = MovedNodes [i];
1601  NS_ASSERT (n);
1602  Vector v = GetPosition (n);
1603  oss << GetXMLOpenClose_node (0, n->GetId (), v.x, v.y);
1604  }
1605  oss << GetXMLClose ("topology");
1606  WriteN (oss.str (), m_f);
1607  WriteDummyPacket ();
1608  if (!Simulator::IsFinished ())
1609  {
1610  PurgePendingWifi ();
1611  PurgePendingWimax ();
1612  PurgePendingLte ();
1613  PurgePendingCsma ();
1615  }
1616 }
1617 
1619 {
1620  std::ostringstream oss;
1621  p->Print (oss);
1622  return oss.str ();
1623 }
1624 
1626 {
1627  return m_currentPktCount;
1628 }
1629 
1631 {
1632  const EnergyFractionMap::const_iterator fractionIter = m_nodeEnergyFraction.find (node->GetId ());
1633 
1634  NS_ASSERT (fractionIter != m_nodeEnergyFraction.end ());
1635  return fractionIter->second;
1636 }
1637 
1638 int64_t
1640 {
1641  NS_LOG_FUNCTION (this << stream);
1643  return 1;
1644 }
1645 
1646 // Helper to output a wireless packet.
1647 // For now, only the XML interface is supported
1648 
1649 
1651 {
1652  std::string s =
1653  "<information><!-- \n\
1654  Description of attributes:\n\
1655  =========================\n\
1656  anim\n\
1657  * ver = Current version\n\
1658  topology\n\
1659  * minX = minimum X coordinate of the canvas\n\
1660  * minY = minimum Y coordinate of the canvas\n\
1661  * maxX = maximum X coordinate of the canvas\n\
1662  * maxY = maximum Y coordinate of the canvas\n\
1663  node\n\
1664  * id = Node Id\n\
1665  * locX = X coordinate\n\
1666  * locY = Y coordinate\n\
1667  * r = Red component\n\
1668  * g = Green component\n\
1669  * b = Blue component\n\
1670  link\n\
1671  * fromId = From Node Id\n\
1672  * toId = To Node Id\n\
1673  * fd = From Node description (for IP Address)\n\
1674  * td = To Node description (for IP Address)\n\
1675  * ld = Link description (for Bandwidth, delay etc)\n\
1676  linkupdate\n\
1677  * t = Simulation time\n\
1678  * ld = Link description (for Bandwidth, delay etc)\n\
1679  nodeupdate\n\
1680  * t = Simulation time\n\
1681  * descr = Node description\n\
1682  * r = Red component\n\
1683  * g = Green component\n\
1684  * b = Blue component\n\
1685  * visible = Node visibility\n\
1686  * rc = Residual energy (between 0 and 1)\n\
1687  p\n\
1688  * fId = From Node Id\n\
1689  * fbTx = First bit transmit time\n\
1690  * lbTx = Last bit transmit time\n\
1691  * tId = To Node Id\n\
1692  * fbRx = First bit Rx Time\n\
1693  * lbRx = Last bit Rx\n\
1694  * meta-info = Packet meta data\n\
1695  wp\n\
1696  * fId = From Node Id\n\
1697  * fbTx = First bit transmit time\n\
1698  * lbTx = Last bit transmit time\n\
1699  * range = Reception range\n\
1700  * tId = To Node Id\n\
1701  * fbRx = First bit Rx time\n\
1702  * meta-info = Packet meta data\n\
1703  * lbRx = Last bit Rx time-->\n\
1704  </information>\n";
1705 return s;
1706 }
1707 
1709 {
1710  StartNewTraceFile ();
1711  NS_ASSERT (m_xml);
1712  std::ostringstream oss;
1713  uint32_t nodeId = 0;
1714  if (pktInfo.m_txnd)
1715  nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1716  else
1717  nodeId = pktInfo.m_txNodeId;
1718 
1719  double lbTx = pktInfo.firstlastbitDelta + pktInfo.m_fbTx;
1720  uint32_t rxId = pktrxInfo.m_rxnd->GetNode ()->GetId ();
1721 
1722  oss << GetXMLOpenClose_p ("wp", nodeId, pktInfo.m_fbTx, lbTx, rxId,
1723  pktrxInfo.m_fbRx, pktrxInfo.m_lbRx, m_enablePacketMetadata? GetPacketMetadata (p):"");
1724  WriteN (oss.str (), m_f);
1725 }
1726 
1728 {
1729  StartNewTraceFile ();
1730  NS_ASSERT (m_xml);
1731  std::ostringstream oss;
1732  NS_ASSERT (pktInfo.m_txnd);
1733  uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1734  uint32_t rxId = pktrxInfo.m_rxnd->GetNode ()->GetId ();
1735 
1736  oss << GetXMLOpenClose_p ("p", nodeId, pktInfo.m_fbTx, pktInfo.m_lbTx, rxId,
1737  pktrxInfo.m_fbRx, pktrxInfo.m_lbRx, m_enablePacketMetadata? GetPacketMetadata (p):"");
1738  WriteN (oss.str (), m_f);
1739 }
1740 
1741 void AnimationInterface::SetConstantPosition (Ptr <Node> n, double x, double y, double z)
1742 {
1743  NS_ASSERT (n);
1745  if (hubLoc == 0)
1746  {
1747  hubLoc = CreateObject<ConstantPositionMobilityModel> ();
1748  n->AggregateObject (hubLoc);
1749  }
1750  Vector hubVec (x, y, z);
1751  hubLoc->SetPosition (hubVec);
1752  NS_LOG_INFO ("Node:" << n->GetId () << " Position set to:(" << x << "," << y << "," << z << ")");
1753 
1754 }
1755 
1756 void AnimationInterface::SetBoundary (double minX, double minY, double maxX, double maxY)
1757 {
1758  if (initialized)
1759  NS_FATAL_ERROR ("SetBoundary must be used prior to creating the AnimationInterface object");
1760  NS_ASSERT (minX < maxX);
1761  NS_ASSERT (minY < maxY);
1762  if (!userBoundary)
1763  {
1764  userBoundary = new Rectangle;
1765  }
1766  userBoundary->xMax = maxX;
1767  userBoundary->yMax = maxY;
1768  userBoundary->xMin = minX;
1769  userBoundary->yMin = minY;
1770 }
1771 
1772 void AnimationInterface::SetNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b)
1773 {
1774  if (initialized)
1775  NS_FATAL_ERROR ("SetNodeColor must be used prior to creating the AnimationInterface object");
1776  NS_ASSERT (n);
1777  NS_LOG_INFO ("Setting node color for Node Id:" << n->GetId ());
1778  struct Rgb rgb = {r, g, b};
1779  nodeColors[n->GetId ()] = rgb;
1780 }
1781 
1782 void AnimationInterface::ShowNode (uint32_t nodeId, bool show)
1783 {
1784  NS_ASSERT (NodeList::GetNode (nodeId));
1785  NS_LOG_INFO ("Setting node visibility for Node Id:" << nodeId);
1786  WriteNodeUpdate (nodeId);
1787 }
1788 
1790 {
1791  ShowNode (n, show);
1792 }
1793 
1795 {
1796  std::ostringstream oss;
1797  oss << GetXMLOpenClose_nodeupdate (nodeId);
1798  WriteN (oss.str (), m_f);
1799 }
1800 
1801 void AnimationInterface::UpdateNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b)
1802 {
1803  UpdateNodeColor (n->GetId (), r, g, b);
1804 }
1805 
1806 void AnimationInterface::UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
1807 {
1808  NS_ASSERT (NodeList::GetNode (nodeId));
1809  NS_LOG_INFO ("Setting node color for Node Id:" << nodeId);
1810  struct Rgb rgb = {r, g, b};
1811  nodeColors[nodeId] = rgb;
1812  WriteNodeUpdate (nodeId);
1813 }
1814 
1815 
1816 
1817 void AnimationInterface::SetNodeColor (NodeContainer nc, uint8_t r, uint8_t g, uint8_t b)
1818 {
1819  for (uint32_t i = 0; i < nc.GetN (); ++i)
1820  {
1821  Ptr <Node> n = nc.Get (i);
1822  NS_ASSERT (n);
1823  SetNodeColor (n, r, g, b);
1824  }
1825 }
1826 
1827 
1828 void AnimationInterface::UpdateLinkDescription (uint32_t fromNode, uint32_t toNode,
1829  std::string linkDescription)
1830 {
1831  std::ostringstream oss;
1832  oss << GetXMLOpenClose_linkupdate (fromNode, toNode, linkDescription);
1833  WriteN (oss.str (), m_f);
1834 }
1835 
1837  std::string linkDescription)
1838 {
1839  NS_ASSERT (fromNode);
1840  NS_ASSERT (toNode);
1841  std::ostringstream oss;
1842  oss << GetXMLOpenClose_linkupdate (fromNode->GetId (), toNode->GetId (), linkDescription);
1843  WriteN (oss.str (), m_f);
1844 }
1845 
1846 void AnimationInterface::SetLinkDescription (uint32_t fromNode, uint32_t toNode,
1847  std::string linkDescription,
1848  std::string fromNodeDescription,
1849  std::string toNodeDescription)
1850 {
1851 
1852  P2pLinkNodeIdPair p2pPair;
1853  p2pPair.fromNode = fromNode;
1854  p2pPair.toNode = toNode;
1855  LinkProperties lp = { fromNodeDescription, toNodeDescription, linkDescription };
1856  linkProperties[p2pPair] = lp;
1857  /* DEBUG */
1858  /*
1859  for (std::map <P2pLinkNodeIdPair, LinkProperties>::const_iterator i = linkProperties.begin ();
1860  i != linkProperties.end (); ++i)
1861  {
1862  P2pLinkNodeIdPair ppair = i->first;
1863  LinkProperties l = i->second;
1864  NS_LOG_UNCOND ("A:" << ppair.fromNode << " B:" << ppair.toNode << " ad:" << l.fromNodeDescription << " bd:" << l.toNodeDescription << " ld:" << l.linkDescription);
1865 
1866  }
1867  */
1868 }
1869 
1871  std::string linkDescription,
1872  std::string fromNodeDescription,
1873  std::string toNodeDescription)
1874 {
1875  NS_ASSERT (fromNode);
1876  NS_ASSERT (toNode);
1877  SetLinkDescription (fromNode->GetId (), toNode->GetId (), linkDescription, fromNodeDescription, toNodeDescription);
1878 }
1879 
1880 
1882 {
1883  if (initialized)
1884  NS_FATAL_ERROR ("SetNodeDescription must be used prior to creating the AnimationInterface object");
1885  NS_ASSERT (n);
1886  nodeDescriptions[n->GetId ()] = descr;
1887 }
1888 
1890 {
1891  UpdateNodeDescription (n->GetId (), descr);
1892 }
1893 
1894 void AnimationInterface::UpdateNodeDescription (uint32_t nodeId, std::string descr)
1895 {
1896  NS_ASSERT (NodeList::GetNode (nodeId));
1897  nodeDescriptions[nodeId] = descr;
1898  std::ostringstream oss;
1899  oss << GetXMLOpenClose_nodeupdate (nodeId);
1900  WriteN (oss.str (), m_f);
1901 }
1902 
1903 
1904 
1906 {
1907  if (initialized)
1908  NS_FATAL_ERROR ("SetNodeDescription must be used prior to creating the AnimationInterface object");
1909  for (uint32_t i = 0; i < nc.GetN (); ++i)
1910  {
1911  Ptr <Node> n = nc.Get (i);
1912  NS_ASSERT (n);
1913  nodeDescriptions[n->GetId ()] = descr;
1914  }
1915 }
1916 
1917 
1918 // XML Private Helpers
1919 
1920 std::string AnimationInterface::GetXMLOpen_anim (uint32_t lp)
1921 {
1922  std::ostringstream oss;
1923  oss <<"<anim ver=\"" << GetNetAnimVersion () << "\">\n";
1924  return oss.str ();
1925 }
1926 std::string AnimationInterface::GetXMLOpen_topology (double minX, double minY, double maxX, double maxY)
1927 {
1928  if (userBoundary)
1929  {
1930  minX = userBoundary->xMin;
1931  minY = userBoundary->yMin;
1932  maxX = userBoundary->xMax;
1933  maxY = userBoundary->yMax;
1934  }
1935  std::ostringstream oss;
1936  oss << "<topology minX = \"" << minX << "\" minY = \"" << minY
1937  << "\" maxX = \"" << maxX << "\" maxY = \"" << maxY
1938  << "\">" << std::endl;
1939  return oss.str ();
1940 
1941 }
1942 
1943 std::string AnimationInterface::GetXMLOpenClose_nodeupdate (uint32_t id, bool visible)
1944 {
1945  std::ostringstream oss;
1946  oss << "<nodeupdate id=\"" << id << "\"";
1947  oss << " t=\"" << Simulator::Now ().GetSeconds () << "\"";
1948  if (visible)
1949  oss << " visible=\"" << 1 << "\"";
1950  else
1951  oss << " visible=\"" << 0 << "\"";
1952  AppendXMLNodeDescription (oss, id);
1953  AppendXMLNodeColor (oss, nodeColors[id]);
1954  AppendXMLRemainingEnergy (oss, id);
1955 
1956  oss <<"/>\n";
1957 
1958  return oss.str ();
1959 
1960 }
1961 
1962 std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp, uint32_t id, double locX, double locY)
1963 {
1964  std::ostringstream oss;
1965  oss <<"<node id=\"" << id << "\"";
1966  AppendXMLNodeDescription (oss, id);
1967  oss << " locX = \"" << locX << "\" " << "locY = \"" << locY << "\"";
1968  AppendXMLRemainingEnergy (oss, id);
1969 
1970  oss <<"/>\n";
1971 
1972  return oss.str ();
1973 }
1974 
1975 std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp, uint32_t id, double locX, double locY, struct Rgb rgb)
1976 {
1977  std::ostringstream oss;
1978  oss <<"<node id = \"" << id << "\"";
1979  AppendXMLNodeDescription (oss, id);
1980  oss << " locX=\"" << locX << "\" " << "locY=\"" << locY << "\"";
1981  AppendXMLNodeColor (oss, rgb);
1982  AppendXMLRemainingEnergy (oss, id);
1983 
1984  oss <<"/>\n";
1985 
1986  return oss.str ();
1987 }
1988 
1989 std::string AnimationInterface::GetXMLOpenClose_linkupdate (uint32_t fromId, uint32_t toId, std::string linkDescription)
1990 {
1991  std::ostringstream oss;
1992  oss << "<linkupdate t=\"" << Simulator::Now ().GetSeconds () << "\""
1993  << " fromId=\"" << fromId
1994  << "\" toId=\"" << toId
1995  << "\" ";
1996 
1997  oss << " ld=\"" << linkDescription << "\""
1998  << " />\n";
1999  return oss.str ();
2000 
2001 }
2002 
2003 std::string AnimationInterface::GetXMLOpenClose_link (uint32_t fromLp, uint32_t fromId, uint32_t toLp, uint32_t toId)
2004 {
2005  std::ostringstream oss;
2006  oss << "<link fromId=\"" << fromId
2007  << "\" toId=\"" << toId
2008  << "\" ";
2009 
2010  LinkProperties lprop ;
2011  lprop.fromNodeDescription = "";
2012  lprop.toNodeDescription = "";
2013  lprop.linkDescription = "";
2014 
2015  P2pLinkNodeIdPair p1 = { fromId, toId };
2016  P2pLinkNodeIdPair p2 = { toId, fromId };
2017  if (linkProperties.find (p1) != linkProperties.end ())
2018  {
2019  lprop = linkProperties[p1];
2020  }
2021  else if (linkProperties.find (p2) != linkProperties.end ())
2022  {
2023  lprop = linkProperties[p2];
2024  }
2025 
2026  oss << " fd=\"" << lprop.fromNodeDescription << "\""
2027  << " td=\"" << lprop.toNodeDescription << "\""
2028  << " ld=\"" << lprop.linkDescription << "\""
2029  << " />\n";
2030  return oss.str ();
2031 }
2032 
2033 
2034 std::string AnimationInterface::GetXMLOpen_packet (uint32_t fromLp, uint32_t fromId, double fbTx, double lbTx, std::string auxInfo)
2035 {
2036  std::ostringstream oss;
2037  oss << std::setprecision (10);
2038  oss << "<p fId=\"" << fromId
2039  << "\" fbTx=\"" << fbTx
2040  << "\" lbTx=\"" << lbTx
2041  << (auxInfo.empty ()?"":"\" aux=\"") << auxInfo.c_str () << "\">";
2042  return oss.str ();
2043 }
2044 
2045 std::string AnimationInterface::GetXMLOpenClose_routing (uint32_t nodeId, std::string routingInfo)
2046 {
2047  std::ostringstream oss;
2048  oss << "<" << "rt" << " t=\"" << Simulator::Now ().GetSeconds () << "\""
2049  << " id=\"" << nodeId << "\""
2050  << " info=\"" << routingInfo.c_str () << "\""
2051  << "/>" << std::endl;
2052  return oss.str ();
2053 }
2054 
2055 std::string AnimationInterface::GetXMLOpenClose_rp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
2056 {
2057  std::ostringstream oss;
2058  oss << "<" << "rp" << " t =\"" << Simulator::Now ().GetSeconds () << "\""
2059  << " id=\"" << nodeId << "\"" << " d=\"" << destination.c_str () << "\""
2060  << " c=\"" << rpElements.size () << "\"" << ">" << std::endl;
2061  for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
2062  i != rpElements.end ();
2063  ++i)
2064  {
2065  Ipv4RoutePathElement rpElement = *i;
2066  oss << "<rpe" << " n=\"" << rpElement.nodeId << "\"" << " nH=\"" << rpElement.nextHop.c_str () << "\"" << "/>" << std::endl;
2067  }
2068  oss << "</rp>" << std::endl;
2069  return oss.str ();
2070 }
2071 
2072 
2073 std::string AnimationInterface::GetXMLOpenClose_p (std::string pktType, uint32_t fId, double fbTx, double lbTx,
2074  uint32_t tId, double fbRx, double lbRx, std::string metaInfo,
2075  std::string auxInfo)
2076 {
2077  std::ostringstream oss;
2078  oss << std::setprecision (10);
2079  oss << "<" << pktType << " fId=\"" << fId
2080  << "\" fbTx=\"" << fbTx
2081  << "\" lbTx=\"" << lbTx << "\"";
2082  if (!auxInfo.empty ())
2083  {
2084  oss << " aux=\"" << auxInfo.c_str () << "\"";
2085  }
2086  if (!metaInfo.empty ())
2087  {
2088  oss << " meta-info=\"" << metaInfo.c_str () << "\"";
2089  }
2090  oss << " tId=\"" << tId << "\" fbRx=\"" << fbRx << "\" lbRx=\"" << lbRx << "\">" << std::endl;
2091  return oss.str ();
2092 }
2093 
2094 
2095 
2096 std::string AnimationInterface::GetXMLOpen_wpacket (uint32_t fromLp, uint32_t fromId, double fbTx, double lbTx, double range)
2097 {
2098  std::ostringstream oss;
2099  oss << std::setprecision (10);
2100  oss << "<wpacket fromId=\"" << fromId
2101  << "\" fbTx=\"" << fbTx
2102  << "\" lbTx=\"" << lbTx
2103  << "\" range=\"" << range << "\">" << std::endl;
2104  return oss.str ();
2105 
2106 }
2107 
2108 std::string AnimationInterface::GetXMLOpenClose_rx (uint32_t toLp, uint32_t toId, double fbRx, double lbRx)
2109 {
2110  std::ostringstream oss;
2111  oss << std::setprecision (10);
2112  oss << "<rx toId=\"" << toId
2113  << "\" fbRx=\"" << fbRx
2114  << "\" lbRx=\"" << lbRx
2115  << "\"/>" << std::endl;
2116  return oss.str ();
2117 }
2118 
2119 std::string AnimationInterface::GetXMLOpenClose_meta (std::string metaInfo)
2120 {
2121  std::ostringstream oss;
2122  oss << "<meta info=\""
2123  << metaInfo << "\" />" << std::endl;
2124  return oss.str ();
2125 }
2126 
2127 
2128 std::string AnimationInterface::GetXMLOpenClose_NonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
2129 {
2130  std::ostringstream oss;
2131  oss << "<nonp2plinkproperties id=\""
2132  << id << "\""
2133  << " ipv4Address=\"" << ipv4Address << "\""
2134  << " channelType=\"" << channelType << "\""
2135  << "/>" << std::endl;
2136  return oss.str ();
2137 }
2138 
2139 
2140 const std::vector<std::string> AnimationInterface::GetElementsFromContext (const std::string& context) const
2141 {
2142  std::vector <std::string> elements;
2143  size_t pos1=0, pos2;
2144  while (pos1 != context.npos)
2145  {
2146  pos1 = context.find ("/",pos1);
2147  pos2 = context.find ("/",pos1+1);
2148  elements.push_back (context.substr (pos1+1,pos2-(pos1+1)));
2149  pos1 = pos2;
2150  pos2 = context.npos;
2151  }
2152  return elements;
2153 }
2154 
2155 void AnimationInterface::AppendXMLNodeDescription (std::ostream& ostream, uint32_t id) const
2156 {
2157  if (nodeDescriptions.find (id) != nodeDescriptions.end ())
2158  {
2159  ostream << " descr=\""<< nodeDescriptions[id] << "\"";
2160  }
2161  else
2162  {
2163  ostream << " descr=\"\"";
2164  }
2165 }
2166 
2167 void AnimationInterface::AppendXMLNodeColor (std::ostream& ostream, const Rgb& color) const
2168 {
2169  const uint8_t r = color.r;
2170  const uint8_t g = color.g;
2171  const uint8_t b = color.b;
2172 
2173  ostream << " r=\"" << (uint32_t)r << "\" "
2174  << " g=\"" << (uint32_t)g << "\" "
2175  << " b=\"" << (uint32_t)b <<"\" ";
2176 }
2177 
2178 void AnimationInterface::AppendXMLRemainingEnergy (std::ostream& ostream, uint32_t id) const
2179 {
2180  const EnergyFractionMap::const_iterator fractionIter = m_nodeEnergyFraction.find (id);
2181 
2182  if (fractionIter != m_nodeEnergyFraction.end ())
2183  ostream << "rc = \"" << fractionIter->second <<"\" ";
2184  else if (NodeList::GetNode (id)->GetObject<EnergySource>())
2185  ostream << "rc = \"1\" ";
2186 }
2187 
2188 TypeId
2190 {
2191  static TypeId tid = TypeId ("ns3::AnimByteTag")
2192  .SetParent<Tag> ()
2193  .AddConstructor<AnimByteTag> ()
2194  ;
2195  return tid;
2196 }
2197 TypeId
2199 {
2200  return GetTypeId ();
2201 }
2202 
2203 uint32_t
2205 {
2206  return sizeof (uint64_t);
2207 }
2208 void
2210 {
2211  i.WriteU64 (m_AnimUid);
2212 }
2213 void
2215 {
2216  m_AnimUid = i.ReadU64 ();
2217 }
2218 void
2219 AnimByteTag::Print (std::ostream &os) const
2220 {
2221  os << "AnimUid=" << m_AnimUid;
2222 }
2223 void
2224 AnimByteTag::Set (uint64_t AnimUid)
2225 {
2226  m_AnimUid = AnimUid;
2227 }
2228 
2229 uint64_t
2230 AnimByteTag::Get (void) const
2231 {
2232  return m_AnimUid;
2233 }
2234 
2235 
2236 } // namespace ns3
bool HasNext(void) const
Definition: packet.cc:65
uint64_t GetAnimUidFromPacket(Ptr< const Packet >)
void Set(uint64_t AnimUid)
Set global Uid in tag.
std::string GetXMLOpenClose_nodeupdate(uint32_t id, bool visible=true)
uint64_t GetTracePktCount()
Get trace file packet count (This used only for testing)
void AddToIpv4AddressNodeIdTable(std::string, uint32_t)
bool WifiPacketIsPending(uint64_t AnimUid)
double x
x coordinate of vector
Definition: vector.h:49
void CsmaMacRxTrace(std::string context, Ptr< const Packet > p)
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
std::string GetXMLOpen_anim(uint32_t lp)
bool CsmaPacketIsPending(uint64_t AnimUid)
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:298
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
AnimRxInfo GetRxInfo(Ptr< const NetDevice > nd)
GetRxInfo.
static uint32_t GetNNodes(void)
Definition: node-list.cc:200
std::vector< Ptr< Node > > RecalcTopoBounds()
void AddPendingWifiPacket(uint64_t AnimUid, AnimPacketInfo &)
std::vector< Ptr< Node > >::const_iterator Iterator
bool LtePacketIsPending(uint64_t AnimUid)
Ipv4Address GetLocal(void) const
Get the local address.
std::string GetIpv4Address(Ptr< NetDevice > nd)
void WriteU64(uint64_t v)
Definition: tag-buffer.cc:102
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:194
AnimationInterface & AddSourceDestination(uint32_t fromNodeId, std::string destinationIpv4Address)
Helper function to print the routing path from a source node to destination IP.
AnimRxInfo helper class.
void EnablePacketMetadata(bool enable)
Enable Packet metadata.
static TypeId GetTypeId(void)
Get Type Id.
std::string GetXMLOpenClose_NonP2pLinkProperties(uint32_t id, std::string ipv4Address, std::string channelType)
Energy source base class.
Definition: energy-source.h:71
void CsmaPhyTxBeginTrace(std::string context, Ptr< const Packet > p)
static void SetNodeColor(Ptr< Node > n, uint8_t r, uint8_t g, uint8_t b)
Helper function to set the node color.
Mobility model for which the current position does not change once it has been set and until it is se...
bool ProcessRxEnd(Ptr< const NetDevice > nd, const Time &fbRx, Vector rxLoc)
Process RxEnd notifications.
static bool IsInitialized(void)
Check if AnimationInterface is initialized.
#define NS_ASSERT(condition)
Definition: assert.h:64
std::string GetXMLClose(std::string name)
void WifiMacRxTrace(std::string context, Ptr< const Packet > p)
void OutputCsmaPacket(Ptr< const Packet > p, AnimPacketInfo &pktInfo, AnimRxInfo pktrxInfo)
std::map< std::string, uint32_t > m_macToNodeIdMap
void LteSpectrumPhyRxStart(std::string context, Ptr< const PacketBurst > pb)
Ptr< NetDevice > GetNetDeviceFromContext(std::string context)
Vector GetPosition(void) const
void WifiPhyTxBeginTrace(std::string context, Ptr< const Packet > p)
std::map< uint64_t, AnimPacketInfo > m_pendingWimaxPackets
bool SetRoutingOutputFile(const std::string &fn)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
#define NS_LOG_INFO(msg)
Definition: log.h:298
std::string GetXMLOpenClose_rx(uint32_t toLp, uint32_t toId, double fbRx, double lbRx)
void LteTxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &)
void WimaxRxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &)
double yMax
Definition: rectangle.h:91
std::map< std::string, uint32_t > m_ipv4ToNodeIdMap
void RecursiveIpv4RoutePathSearch(std::string fromIpv4, std::string toIpv4, Ipv4RoutePathElements &)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
virtual void Deserialize(TagBuffer i)
Deserialize function.
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:728
void ConnectLteEnb(Ptr< Node > n, Ptr< LteEnbNetDevice > nd, uint32_t devIndex)
std::string GetIpv4RoutingTable(Ptr< Node > n)
void Print(std::ostream &os) const
Definition: packet.cc:429
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
void SetStartTime(Time t)
Specify the time at which capture should start.
void SetStopTime(Time t)
Specify the time at which capture should stop.
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(void) const =0
Get the routing protocol to be used by this Ipv4 stack.
a 3d vector
Definition: vector.h:31
void WifiPhyRxBeginTrace(std::string context, Ptr< const Packet > p)
void UpdateNodeColor(Ptr< Node > n, uint8_t r, uint8_t g, uint8_t b)
Helper function to update the node color.
double stopTime
double xMin
Definition: rectangle.h:85
void ProcessRxBegin(Ptr< const NetDevice > nd, const Time &fbRx)
Process RxBegin notifications.
void ResetAnimWriteCallback()
Reset the write callback function.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
std::string GetXMLOpenClose_node(uint32_t lp, uint32_t id, double locX, double locY)
AnimWriteCallback m_writeCallback
void WifiPhyRxDropTrace(std::string context, Ptr< const Packet > p)
a polymophic address class
Definition: address.h:86
void UanPhyGenTxTrace(std::string context, Ptr< const Packet >)
static void SetConstantPosition(Ptr< Node > n, double x, double y, double z=0)
Helper function to set Constant Position for a given node.
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
void ConnectLteUe(Ptr< Node > n, Ptr< LteUeNetDevice > nd, uint32_t devIndex)
std::map< uint32_t, Vector > m_nodeLocation
virtual void Print(std::ostream &os) const
Print tag info.
Keep track of the current position and velocity of an object.
static void SetLinkDescription(uint32_t fromNode, uint32_t toNode, std::string linkDescription, std::string fromNodeDescription="", std::string toNodeDescription="")
Helper function to set the description for a link.
Packet header for IPv4.
Definition: ipv4-header.h:31
static void SetBoundary(double minX, double minY, double maxX, double maxY)
Helper function to set the topology boundary rectangle.
void SetXMLOutput()
Specify that animation commands are to be written in XML format.
double GetSeconds(void) const
Definition: nstime.h:274
std::string GetXMLOpen_packet(uint32_t fromLp, uint32_t fromId, double fbTx, double lbTx, std::string auxInfo="")
void CsmaPhyRxEndTrace(std::string context, Ptr< const Packet > p)
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
Definition: packet.h:57
void RemainingEnergyTrace(std::string context, double previousEnergy, double currentEnergy)
std::string GetXMLOpenClose_p(std::string pktType, uint32_t fId, double fbTx, double lbTx, uint32_t tId, double fbRx, double lbRx, std::string metaInfo="", std::string auxInfo="")
static void EnablePrinting(void)
By default, packets do not keep around enough metadata to perform the operations requested by the Pri...
Definition: packet.cc:552
void SetRandomPosition(bool setRandPos)
Set random position if a Mobility Model does not exists for the node.
~AnimationInterface()
Destructor for the animator interface.
EnergyFractionMap m_nodeEnergyFraction
double startTime
static Iterator End(void)
Definition: node-list.cc:188
uint8_t data[writeSize]
Ptr< SampleEmitter > s
Ptr< const NetDevice > m_rxnd
Ptr to receiving NetDevice.
double GetNodeEnergyFraction(Ptr< const Node > node) const
Get node's energy fraction (This used only for testing)
Ptr< Node > GetNodeFromContext(const std::string &context) const
void WriteNodeUpdate(uint32_t nodeId)
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
double m_fbRx
First bit receive time.
double firstlastbitDelta
Time delta between First bit Rx and Last bit Rx.
static void SetNodeDescription(Ptr< Node > n, std::string descr)
Helper function to set a brief description for a given node.
void UanPhyGenRxTrace(std::string context, Ptr< const Packet >)
Ptr< NetDevice > GetDevice(uint32_t index) const
Definition: node.cc:132
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1238
ByteTagIterator GetByteTagIterator(void) const
Definition: packet.cc:818
std::map< uint64_t, AnimPacketInfo > m_pendingLtePackets
Item Next(void)
Definition: packet.cc:70
void StartAnimation(bool restart=false)
Writes the topology information and sets up the appropriate animation packet tx callback.
double xMax
Definition: rectangle.h:87
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
NS_LOG_COMPONENT_DEFINE("AnimationInterface")
std::vector< Ipv4RoutePathElement > Ipv4RoutePathElements
AnimationInterface & EnableIpv4RouteTracking(std::string fileName, Time startTime, Time stopTime, Time pollInterval=Seconds(5))
Enable tracking of the Ipv4 routing table for all Nodes.
void OutputWirelessPacket(Ptr< const Packet > p, AnimPacketInfo &pktInfo, AnimRxInfo pktrxInfo)
#define PURGE_INTERVAL
static std::map< uint32_t, Rgb > nodeColors
double yMin
Definition: rectangle.h:89
void WifiPhyTxDropTrace(std::string context, Ptr< const Packet > p)
void AggregateObject(Ptr< Object > other)
Definition: object.cc:243
Ipv4Address GetGateway(void) const
Definition: ipv4-route.cc:70
#define list
std::map< uint64_t, AnimPacketInfo > m_pendingCsmaPackets
void CsmaPhyTxEndTrace(std::string context, Ptr< const Packet > p)
std::string GetPacketMetadata(Ptr< const Packet > p)
std::string GetXMLOpen_wpacket(uint32_t fromLp, uint32_t fromId, double fbTx, double lbTx, double range)
int WriteN(const char *, uint32_t, FILE *f)
double m_lbTx
Last bit transmission time.
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:75
void DevTxTrace(std::string context, Ptr< const Packet > p, Ptr< NetDevice > tx, Ptr< NetDevice > rx, Time txTime, Time rxTime)
uint32_t GetNDevices(void) const
Definition: node.cc:140
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:277
uint32_t m_txNodeId
Tx Node Id if NetDevice is unknown.
tag a set of bytes in a packet
Definition: tag.h:36
void AddPendingUanPacket(uint64_t AnimUid, AnimPacketInfo &)
keep track of a set of node pointers.
void UpdateLinkDescription(uint32_t fromNode, uint32_t toNode, std::string linkDescription)
Helper function to update the description for a link.
uint64_t ReadU64(void)
Definition: tag-buffer.cc:134
std::vector< Ptr< Node > >::const_iterator Iterator
Definition: node-list.h:43
void AppendXMLRemainingEnergy(std::ostream &ostream, uint32_t id) const
void AddPendingWimaxPacket(uint64_t AnimUid, AnimPacketInfo &)
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
bool NodeHasMoved(Ptr< Node > n, Vector newLocation)
double GetValue(double min, double max)
Returns a random double from the uniform distribution with the specified range.
Iterator over the set of byte tags in a packet.
Definition: packet.h:50
static Rectangle * userBoundary
#define NS_LOG_UNCOND(msg)
Definition: log.h:377
an EUI-48 address
Definition: mac48-address.h:41
double y
y coordinate of vector
Definition: vector.h:53
TypeId GetTypeId(void) const
Definition: packet.cc:34
virtual void Serialize(TagBuffer i) const
Serialize function.
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
bool UanPacketIsPending(uint64_t AnimUid)
const std::vector< std::string > GetElementsFromContext(const std::string &context) const
bool SetOutputFile(const std::string &fn)
Specify that animation commands are to be written to the specified output file.
Byte tag using by Anim to uniquely identify packets.
virtual TypeId GetInstanceTypeId(void) const
Get Instance Type Id.
void StopAnimation(bool onlyAnimation=false)
Closes the interface to the animator.
double m_lbRx
Last bit receive time.
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
Definition: packet.cc:49
Vector UpdatePosition(Ptr< Node > n)
bool IsPhyRxComplete()
Check if Wifi Phy Rx is Complete.
uint64_t Get(void) const
Get Uid in tag.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
std::vector< Ipv4RouteTrackElement > m_ipv4RouteTrackElements
void MobilityCourseChangeTrace(Ptr< const MobilityModel > mob)
read and write tag data
Definition: tag-buffer.h:51
std::map< uint64_t, AnimPacketInfo > m_pendingWifiPackets
uint32_t GetId(void) const
Definition: node.cc:104
a class to store IPv4 address information on an interface
std::map< uint64_t, AnimPacketInfo > m_pendingUanPackets
std::string GetXMLOpenClose_linkupdate(uint32_t fromId, uint32_t toId, std::string)
std::string GetXMLOpenClose_routing(uint32_t id, std::string routingInfo)
static bool initialized
Ptr< const NetDevice > m_txnd
Ptr to NetDevice that is transmitting.
#define NS_LOG_WARN(msg)
Definition: log.h:280
std::string GetMacAddress(Ptr< NetDevice > nd)
static Iterator Begin(void)
Definition: node-list.cc:182
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
A network Node.
Definition: node.h:55
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
AnimationInterface(const std::string filename, uint64_t maxPktsPerFile=MAX_PKTS_PER_TRACE_FILE, bool usingXML=true)
Constructor.
std::string GetXMLOpenClose_rp(uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
void WifiPhyTxEndTrace(std::string context, Ptr< const Packet > p)
virtual uint32_t GetSerializedSize(void) const
Get Serialized Size.
Interface to network animator.
void WriteNonP2pLinkProperties(uint32_t id, std::string ipv4Address, std::string channelType)
void WifiPhyRxEndTrace(std::string context, Ptr< const Packet > p)
static std::map< P2pLinkNodeIdPair, LinkProperties, LinkPairCompare > linkProperties
double m_fbTx
First bit transmission time.
static bool IsFinished(void)
If there are no more events lefts to be scheduled, or if simulation time has already reached the "sto...
Definition: simulator.cc:150
void SetAnimWriteCallback(AnimWriteCallback cb)
Set a callback function to listen to AnimationInterface write events.
void SetMobilityPollInterval(Time t)
Set mobility poll interval:WARNING: setting a low interval can cause slowness.
void AddPendingLtePacket(uint64_t AnimUid, AnimPacketInfo &)
void AddPendingCsmaPacket(uint64_t AnimUid, AnimPacketInfo &)
void AppendXMLNodeDescription(std::ostream &ostream, uint32_t id) const
void AppendXMLNodeColor(std::ostream &ostream, const Rgb &color) const
void WriteRoutePath(uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
A structure to store red, blue and green components for entities such as nodes.
std::string GetXMLOpenClose_meta(std::string metaInfo)
void ShowNode(uint32_t nodeId, bool show=true)
Helper function to show/hide a node.
bool IsStarted(void)
Is AnimationInterface started.
Ptr< T > GetObject(void) const
Definition: object.h:361
bool WimaxPacketIsPending(uint64_t AnimUid)
Vector GetPosition(Ptr< Node > n)
a unique identifier for an interface.
Definition: type-id.h:49
static std::map< uint32_t, std::string > nodeDescriptions
a 2d rectangle
Definition: rectangle.h:33
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
std::string GetXMLOpenClose_link(uint32_t fromLp, uint32_t fromId, uint32_t toLp, uint32_t toId)
std::string GetXMLOpen_topology(double minX, double minY, double maxX, double maxY)
void LteRxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &)
void UpdateNodeDescription(Ptr< Node > n, std::string descr)
Helper function to update the description for a given node.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:717
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
void LteSpectrumPhyTxStart(std::string context, Ptr< const PacketBurst > pb)
void WimaxTxTrace(std::string context, Ptr< const Packet > p, const Mac48Address &)
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:808
AnimPacketInfo helper class.