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;
64 
65 
66 AnimationInterface::AnimationInterface (const std::string fn, bool enable3105, uint64_t maxPktsPerFile)
67  : m_routingF (0), m_mobilityPollInterval (Seconds (0.25)),
68  m_outputFileName (fn),
69  m_outputFileSet (false), gAnimUid (0), m_randomPosition (true),
70  m_writeCallback (0), m_started (false),
71  m_enablePacketMetadata (false), m_startTime (Seconds (0)), m_stopTime (Seconds (3600 * 1000)),
72  m_maxPktsPerFile (maxPktsPerFile), m_originalFileName (fn),
73  m_routingStopTime (Seconds (0)), m_routingFileName (""),
74  m_routingPollInterval (Seconds (5)), m_enable3105 (enable3105),
75  m_trackPackets (true)
76 {
77  m_uniformRandomVariable = CreateObject<UniformRandomVariable> ();
78  initialized = true;
79  StartAnimation ();
80 }
81 
83 {
84  StopAnimation ();
85 }
86 
88 {
89  m_trackPackets = false;
90 }
91 
93 {
94  m_routingFileName = fileName;
97  m_routingPollInterval = pollInterval;
100  return *this;
101 }
102 
104 {
105  m_routingNc = nc;
106  return EnableIpv4RouteTracking (fileName, startTime, stopTime, pollInterval);
107 }
108 
110 {
111 
112  NS_ASSERT (n);
113  Ptr <ns3::Ipv4> ipv4 = n->GetObject <ns3::Ipv4> ();
114  if (!ipv4)
115  {
116  NS_LOG_WARN ("Node " << n->GetId () << " Does not have an Ipv4 object");
117  return "";
118  }
119  std::stringstream stream;
120  Ptr<OutputStreamWrapper> routingstream = Create<OutputStreamWrapper> (&stream);
121  ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingstream);
122  return stream.str ();
123 
124 }
125 
126 void AnimationInterface::RecursiveIpv4RoutePathSearch (std::string from, std::string to, Ipv4RoutePathElements & rpElements)
127 {
128  NS_LOG_INFO ("RecursiveIpv4RoutePathSearch from:" << from.c_str () << " to:" << to.c_str ());
129  if ((from == "0.0.0.0") || (from == "127.0.0.1"))
130  {
131  NS_LOG_INFO ("Got " << from.c_str () << " End recursion");
132  return;
133  }
136  if (fromNode->GetId () == toNode->GetId ())
137  {
138  Ipv4RoutePathElement elem = { fromNode->GetId (), "L" };
139  rpElements.push_back (elem);
140  return;
141  }
142  if (!fromNode)
143  {
144  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[from] << " Not found");
145  return;
146  }
147  if (!toNode)
148  {
149  NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[to] << " Not found");
150  return;
151  }
152  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
153  if (!ipv4)
154  {
155  NS_LOG_WARN ("ipv4 object not found");
156  return;
157  }
159  if (!rp)
160  {
161  NS_LOG_WARN ("Routing protocol object not found");
162  return;
163  }
164  Ptr<Packet> pkt = Create<Packet> ();
165  Ipv4Header header;
166  header.SetDestination (Ipv4Address (to.c_str ()));
167  Socket::SocketErrno sockerr;
168  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
169  if (!rt)
170  {
171  return;
172  }
173  NS_LOG_DEBUG ("Node: " << fromNode->GetId () << " G:" << rt->GetGateway ());
174  std::ostringstream oss;
175  oss << rt->GetGateway ();
176  if (oss.str () == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST))
177  {
178  NS_LOG_INFO ("Null gw");
179  Ipv4RoutePathElement elem = { fromNode->GetId (), "C" };
180  rpElements.push_back (elem);
181  if ( m_ipv4ToNodeIdMap.find (to) != m_ipv4ToNodeIdMap.end ())
182  {
183  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[to], "L" };
184  rpElements.push_back (elem2);
185  }
186  return;
187  }
188  NS_LOG_INFO ("Node:" << fromNode->GetId () << "-->" << rt->GetGateway ());
189  Ipv4RoutePathElement elem = { fromNode->GetId (), oss.str () };
190  rpElements.push_back (elem);
191  RecursiveIpv4RoutePathSearch (oss.str (), to, rpElements);
192 
193 }
194 
196 {
197  if (m_ipv4RouteTrackElements.empty ())
198  {
199  return;
200  }
201  for (std::vector <Ipv4RouteTrackElement>::const_iterator i = m_ipv4RouteTrackElements.begin ();
202  i != m_ipv4RouteTrackElements.end ();
203  ++i)
204  {
205  Ipv4RouteTrackElement trackElement = *i;
206  Ptr <Node> fromNode = NodeList::GetNode (trackElement.fromNodeId);
207  if (!fromNode)
208  {
209  NS_FATAL_ERROR ("Node: " << trackElement.fromNodeId << " Not found");
210  continue;
211  }
212  Ptr <ns3::Ipv4> ipv4 = fromNode->GetObject <ns3::Ipv4> ();
213  if (!ipv4)
214  {
215  NS_LOG_WARN ("ipv4 object not found");
216  continue;
217  }
219  if (!rp)
220  {
221  NS_LOG_WARN ("Routing protocol object not found");
222  continue;
223  }
224  NS_LOG_INFO ("Begin Track Route for: " << trackElement.destination.c_str () << " From:" << trackElement.fromNodeId);
225  Ptr<Packet> pkt = Create<Packet> ();
226  Ipv4Header header;
227  header.SetDestination (Ipv4Address (trackElement.destination.c_str ()));
228  Socket::SocketErrno sockerr;
229  Ptr <Ipv4Route> rt = rp->RouteOutput (pkt, header, 0, sockerr);
230  Ipv4RoutePathElements rpElements;
231  if (!rt)
232  {
233  NS_LOG_INFO ("No route to :" << trackElement.destination.c_str ());
234  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
235  rpElements.push_back (elem);
236  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
237  continue;
238  }
239  std::ostringstream oss;
240  oss << rt->GetGateway ();
241  NS_LOG_INFO ("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway ());
242  if (rt->GetGateway () == "0.0.0.0")
243  {
244  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "C" };
245  rpElements.push_back (elem);
246  if ( m_ipv4ToNodeIdMap.find (trackElement.destination) != m_ipv4ToNodeIdMap.end ())
247  {
248  Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[trackElement.destination], "L" };
249  rpElements.push_back (elem2);
250  }
251  }
252  else if (rt->GetGateway () == "127.0.0.1")
253  {
254  Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" };
255  rpElements.push_back (elem);
256  }
257  else
258  {
259  Ipv4RoutePathElement elem = { trackElement.fromNodeId, oss.str () };
260  rpElements.push_back (elem);
261  }
262  RecursiveIpv4RoutePathSearch (oss.str (), trackElement.destination, rpElements);
263  WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements);
264  }
265 
266 }
267 
269 {
271  {
272  NS_LOG_INFO ("TrackIpv4Route completed");
273  return;
274  }
275  if (m_routingNc.GetN ())
276  {
277  for (NodeContainer::Iterator i = m_routingNc.Begin (); i != m_routingNc.End (); ++i)
278  {
279  Ptr <Node> n = *i;
281  }
282  }
283  else
284  {
285  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
286  {
287  Ptr <Node> n = *i;
289  }
290  }
293 }
294 
295 
297 {
298  static int i = 0;
299  std::ostringstream oss;
300  oss << i;
303  {
304  return;
305  }
306  StopAnimation (true);
307  m_outputFileName = m_originalFileName + "-" + oss.str ();
308  StartAnimation (true);
309  ++i;
310 
311 }
312 
314 {
315  return "netanim-3.105";
316 }
317 
319 {
320  m_startTime = t;
321 }
322 
324 {
325  m_stopTime = t;
326 }
327 
328 uint32_t AnimationInterface::AddNodeCounter (std::string counterName, CounterType counterType)
329 {
330  m_nodeCounters.push_back (counterName);
331  uint32_t counterId = m_nodeCounters.size () -1;
332  std::ostringstream oss;
333  oss << GetXMLOpenCloseAddNodeCounter (counterId, counterName, counterType);
334  WriteN (oss.str (), m_f);
335  return counterId;
336 }
337 
338 uint32_t AnimationInterface::AddResource (std::string resourcePath)
339 {
340  m_resources.push_back (resourcePath);
341  uint32_t resourceId = m_resources.size () -1;
342  std::ostringstream oss;
343  oss << GetXMLOpenCloseAddResource (resourceId, resourcePath);
344  WriteN (oss.str (), m_f);
345  return resourceId;
346 }
347 
348 bool AnimationInterface::SetOutputFile (const std::string& fn)
349 {
350  if (m_outputFileSet)
351  {
352  return true;
353  }
354  NS_LOG_INFO ("Creating new trace file:" << fn.c_str ());
355  m_f = std::fopen (fn.c_str (), "w");
356  if (!m_f)
357  {
358  NS_FATAL_ERROR ("Unable to open Animation output file");
359  return false; // Can't open
360  }
361  m_outputFileName = fn;
362  m_outputFileSet = true;
363  return true;
364 }
365 
366 bool AnimationInterface::SetRoutingOutputFile (const std::string& fn)
367 {
368  if (m_routingF)
369  {
370  NS_FATAL_ERROR ("SetRoutingOutputFile already used once");
371  return false;
372  }
373  m_routingF = std::fopen (fn.c_str (), "w");
374  if (!m_routingF)
375  {
376  NS_FATAL_ERROR ("Unable to open Animation Routing output file");
377  return false;
378  }
379  return true;
380 }
381 
383 {
384  m_enablePacketMetadata = enable;
385  if (enable)
387 }
388 
390 {
391  return initialized;
392 }
393 
395 {
396  return m_started;
397 
398 }
399 
400 void AnimationInterface::SetAnimWriteCallback (AnimWriteCallback cb)
401 {
402  m_writeCallback = cb;
403 }
404 
406 {
407  m_writeCallback = 0;
408 }
409 
411 {
412  if ((Simulator::Now () >= m_startTime) &&
413  (Simulator::Now () <= m_stopTime))
414  return true;
415  else
416  return false;
417 }
418 
420 {
421  return (m_pendingUanPackets.find (AnimUid) != m_pendingUanPackets.end ());
422 }
423 
425 {
426  return (m_pendingWifiPackets.find (AnimUid) != m_pendingWifiPackets.end ());
427 }
428 
430 {
431  return (m_pendingCsmaPackets.find (AnimUid) != m_pendingCsmaPackets.end ());
432 }
433 
434 
436 {
437  return (m_pendingWimaxPackets.find (AnimUid) != m_pendingWimaxPackets.end ());
438 }
439 
441 {
442  return (m_pendingLtePackets.find (AnimUid) != m_pendingLtePackets.end ());
443 }
444 
446 {
448 }
449 
451 {
452  m_randomPosition = setRandPos;
453 }
454 
456 {
458  if (loc)
459  {
460  m_nodeLocation[n->GetId ()] = loc->GetPosition ();
461  }
462  else
463  {
464  NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary");
465  Vector deterministicVector (100,100,0);
467  if (m_randomPosition)
468  {
469  m_nodeLocation[n->GetId ()] = randomVector;
470  }
471  else
472  {
473  m_nodeLocation[n->GetId ()] = deterministicVector;
474  }
475  }
476  return m_nodeLocation[n->GetId ()];
477 }
478 
480 {
481  m_nodeLocation[n->GetId ()] = v;
482  return v;
483 }
484 
486 {
487  #ifdef NS_LOG
488  if (m_nodeLocation.find (n->GetId ()) == m_nodeLocation.end ())
489  {
490  NS_FATAL_ERROR ("Node:" <<n->GetId () << " not found in Location table");
491  }
492  #endif
493  return m_nodeLocation[n->GetId ()];
494 }
495 
497 {
498  if (m_pendingWifiPackets.empty ())
499  return;
500  std::vector <uint64_t> purgeList;
501  for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingWifiPackets.begin ();
502  i != m_pendingWifiPackets.end ();
503  ++i)
504  {
505 
506  AnimPacketInfo pktInfo = i->second;
507  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
508  if (delta > PURGE_INTERVAL)
509  {
510  purgeList.push_back (i->first);
511  }
512  }
513 
514  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
515  i != purgeList.end ();
516  ++i)
517  {
518  m_pendingWifiPackets.erase (*i);
519  }
520 
521 }
522 
524 {
525  if (m_pendingWimaxPackets.empty ())
526  return;
527  std::vector <uint64_t> purgeList;
528  for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingWimaxPackets.begin ();
529  i != m_pendingWimaxPackets.end ();
530  ++i)
531  {
532 
533  AnimPacketInfo pktInfo = i->second;
534  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
535  if (delta > PURGE_INTERVAL)
536  {
537  purgeList.push_back (i->first);
538  }
539  }
540 
541  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
542  i != purgeList.end ();
543  ++i)
544  {
545  m_pendingWimaxPackets.erase (*i);
546  }
547 
548 }
549 
550 
552 {
553  if (m_pendingLtePackets.empty ())
554  return;
555  std::vector <uint64_t> purgeList;
556  for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingLtePackets.begin ();
557  i != m_pendingLtePackets.end ();
558  ++i)
559  {
560 
561  AnimPacketInfo pktInfo = i->second;
562  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
563  if (delta > PURGE_INTERVAL)
564  {
565  purgeList.push_back (i->first);
566  }
567  }
568 
569  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
570  i != purgeList.end ();
571  ++i)
572  {
573  m_pendingLtePackets.erase (*i);
574  }
575 }
576 
578 {
579  if (m_pendingCsmaPackets.empty ())
580  return;
581  std::vector <uint64_t> purgeList;
582  for (std::map<uint64_t, AnimPacketInfo>::iterator i = m_pendingCsmaPackets.begin ();
583  i != m_pendingCsmaPackets.end ();
584  ++i)
585  {
586 
587  AnimPacketInfo pktInfo = i->second;
588  double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
589  if (delta > PURGE_INTERVAL)
590  {
591  purgeList.push_back (i->first);
592  }
593  }
594 
595  for (std::vector <uint64_t>::iterator i = purgeList.begin ();
596  i != purgeList.end ();
597  ++i)
598  {
599  m_pendingCsmaPackets.erase (*i);
600  }
601 
602 }
603 
605 {
606  Address nodeAddr = nd->GetAddress ();
607  std::ostringstream oss;
608  oss << nodeAddr;
609  return oss.str ().substr (6); // Skip the first 6 chars to get the Mac
610 }
611 
613 {
614  Ptr<Ipv4> ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject <Ipv4> ();
615  if (!ipv4)
616  {
617  NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found");
618  return "0.0.0.0";
619  }
620  int32_t ifIndex = ipv4->GetInterfaceForDevice (nd);
621  if (ifIndex == -1)
622  {
623  NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice");
624  return "0.0.0.0";
625  }
626  Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, 0);
627  std::ostringstream oss;
628  oss << addr.GetLocal ();
629  return oss.str ();
630 }
631 
633 {
634  m_currentPktCount = 0;
635  m_started = true;
637 
638  // Find the min/max x/y for the xml topology element
639  m_topoMinX = -2;
640  m_topoMinY = -2;
641  m_topoMaxX = 2;
642  m_topoMaxY = 2;
643  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
644  {
645  Ptr<Node> n = *i;
646  NS_LOG_INFO ("Update Position for Node: " << n->GetId ());
647  Vector v = UpdatePosition (n);
648  m_topoMinX = std::min (m_topoMinX, v.x);
649  m_topoMinY = std::min (m_topoMinY, v.y);
650  m_topoMaxX = std::max (m_topoMaxX, v.x);
651  m_topoMaxY = std::max (m_topoMaxY, v.y);
652  struct Rgb rgb = {255, 0, 0};
653  if (nodeColors.find (n->GetId ()) == nodeColors.end ())
654  {
655  nodeColors[n->GetId ()] = rgb;
656  }
657  }
658 
659 
660  std::ostringstream oss;
661  oss << GetXMLOpen_anim (0);
662  WriteN (oss.str (), m_f);
663  NS_LOG_INFO ("Setting topology for "<<NodeList::GetNNodes ()<<" Nodes");
664  // Dump the topology
665  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
666  {
667  Ptr<Node> n = *i;
668  std::ostringstream oss;
669  Vector v = GetPosition (n);
670  struct Rgb rgb = nodeColors[n->GetId ()];
671  oss << GetXMLOpenClose_node (0, n->GetId (), v.x, v.y, rgb);
672  WriteN (oss.str (), m_f);
673  }
674  NS_LOG_INFO ("Setting p2p links");
675  // Now dump the p2p links
676  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
677  {
678  Ptr<Node> n = *i;
679  uint32_t n1Id = n->GetId ();
680  uint32_t nDev = n->GetNDevices (); // Number of devices
681  for (uint32_t i = 0; i < nDev; ++i)
682  {
683  Ptr<NetDevice> dev = n->GetDevice (i);
684  NS_ASSERT (dev);
685  Ptr<Channel> ch = dev->GetChannel ();
686  if (!ch)
687  {
688  NS_LOG_DEBUG ("No channel can't be a p2p device");
689  // Try to see if it is an LTE NetDevice, which does not return a channel
690  if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") ||
691  (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")||
692  (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice"))
693  {
694  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), dev->GetInstanceTypeId ().GetName ());
696  }
697  continue;
698  }
699  std::string channelType = ch->GetInstanceTypeId ().GetName ();
700  NS_LOG_DEBUG ("Got ChannelType" << channelType);
701  if (channelType == std::string ("ns3::PointToPointChannel"))
702  { // Since these are duplex links, we only need to dump
703  // if srcid < dstid
704  uint32_t nChDev = ch->GetNDevices ();
705  for (uint32_t j = 0; j < nChDev; ++j)
706  {
707  Ptr<NetDevice> chDev = ch->GetDevice (j);
708  uint32_t n2Id = chDev->GetNode ()->GetId ();
709  if (n1Id < n2Id)
710  {
711  // ouptut the p2p link
712  NS_LOG_INFO ("Link:" << GetIpv4Address (dev) << ":" << GetMacAddress (dev) << "----" << GetIpv4Address (chDev) << ":" << GetMacAddress (chDev) );
713  SetLinkDescription (n1Id, n2Id, "", GetIpv4Address (dev) + "~" + GetMacAddress (dev), GetIpv4Address (chDev) + "~" + GetMacAddress (chDev));
716  std::ostringstream oss;
717  oss << GetXMLOpenClose_link (0, n1Id, 0, n2Id);
718  WriteN (oss.str (), m_f);
719  }
720  }
721  }
722  else
723  {
724  NS_LOG_INFO ("Link:" << GetIpv4Address (dev) << " Channel Type:" << channelType << " Mac: " << GetMacAddress (dev));
725  WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType);
727  }
728  }
729  }
730  linkProperties.clear ();
731  if (m_enable3105)
732  {
733  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
734  {
735  Ptr<Node> n = *i;
736  NS_LOG_INFO ("Update Size for Node: " << n->GetId ());
737  struct NodeSize s = { 1, 1 };
738  m_nodeSizes[n->GetId ()] = s;
739  UpdateNodeSize (n->GetId (), s.width, s.height);
740  }
741  }
742  if (!restart)
743  {
745  }
746  if (!restart)
747  ConnectCallbacks ();
748  if (m_enable3105)
749  {
751  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
752  {
753  Ptr<Node> n = *i;
754  if (NodeList::GetNode (n->GetId ())->GetObject<EnergySource> ())
755  {
757  }
758  }
759  }
760 }
761 
762 void AnimationInterface::AddToIpv4AddressNodeIdTable (std::string ipv4Address, uint32_t nodeId)
763 {
764  m_ipv4ToNodeIdMap[ipv4Address] = nodeId;
765 }
766 
767 AnimationInterface & AnimationInterface::AddSourceDestination (uint32_t fromNodeId, std::string ipv4Address)
768 {
769  Ipv4RouteTrackElement element = { ipv4Address, fromNodeId };
770  m_ipv4RouteTrackElements.push_back (element);
771  return *this;
772 }
773 
774 
776 {
777 
778  Ptr<LteEnbPhy> lteEnbPhy = nd->GetPhy ();
779  Ptr<LteSpectrumPhy> dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy ();
780  Ptr<LteSpectrumPhy> ulPhy = lteEnbPhy->GetUplinkSpectrumPhy ();
781  std::ostringstream oss;
782  //NodeList/*/DeviceList/*/
783  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
784  if (dlPhy)
785  {
786  dlPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
787  dlPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
788  }
789  if (ulPhy)
790  {
791  ulPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
792  ulPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
793  }
794 }
795 
796 
797 
799 {
800 
801  Ptr<LteUePhy> lteUePhy = nd->GetPhy ();
802  Ptr<LteSpectrumPhy> dlPhy = lteUePhy->GetDownlinkSpectrumPhy ();
803  Ptr<LteSpectrumPhy> ulPhy = lteUePhy->GetUplinkSpectrumPhy ();
804  std::ostringstream oss;
805  //NodeList/*/DeviceList/*/
806  oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/";
807  if (dlPhy)
808  {
809  dlPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
810  dlPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
811  }
812  if (ulPhy)
813  {
814  ulPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this));
815  ulPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this));
816  }
817 }
818 
820 {
821 
822  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
823  {
824  Ptr<Node> n = *i;
825  NS_ASSERT (n);
826  uint32_t nDevices = n->GetNDevices ();
827  for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex)
828  {
829  Ptr <NetDevice> nd = n->GetDevice (devIndex);
830  if (!nd)
831  continue;
832  Ptr<LteUeNetDevice> lteUeNetDevice = DynamicCast<LteUeNetDevice> (nd);
833  if (lteUeNetDevice)
834  {
835  ConnectLteUe (n, lteUeNetDevice, devIndex);
836  continue;
837  }
838  Ptr<LteEnbNetDevice> lteEnbNetDevice = DynamicCast<LteEnbNetDevice> (nd);
839  if (lteEnbNetDevice)
840  ConnectLteEnb (n, lteEnbNetDevice, devIndex);
841  }
842 
843  }
844 }
845 
847 {
848  // Connect the callbacks
849  Config::Connect ("/ChannelList/*/TxRxPointToPoint",
851  Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
853  Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin",
855  Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange",
857  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx",
859  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx",
861  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx",
863  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx",
865  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin",
867  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd",
869  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd",
871  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx",
873  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin",
875  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin",
877  Config::Connect ("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy",
879 
880  ConnectLte ();
881 
882 }
883 
884 
885 void AnimationInterface::StopAnimation (bool onlyAnimation)
886 {
887  m_started = false;
888  NS_LOG_INFO ("Stopping Animation");
890  if (m_f)
891  {
892  // Terminate the anim element
893  WriteN (GetXMLClose ("anim"), m_f);
894  std::fclose (m_f);
895  }
896  m_outputFileSet = false;
897  if (onlyAnimation)
898  {
899  return;
900  }
901  if (m_routingF)
902  {
903  WriteN (GetXMLClose ("anim"), m_routingF);
904  std::fclose (m_routingF);
905  }
906 }
907 
908 int AnimationInterface::WriteN (const std::string& st, FILE * f)
909 {
910  if (m_writeCallback)
911  {
912  m_writeCallback (st.c_str ());
913  }
914  return WriteN (st.c_str (), st.length (), f);
915 }
916 
917 std::vector <Ptr <Node> > AnimationInterface::RecalcTopoBounds ()
918 {
919  std::vector < Ptr <Node> > MovedNodes;
920  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
921  {
922  Ptr<Node> n = *i;
923  NS_ASSERT (n);
924  Ptr <MobilityModel> mobility = n->GetObject <MobilityModel> ();
925  Vector newLocation;
926  if (!mobility)
927  {
928  newLocation = GetPosition (n);
929  }
930  else
931  {
932  newLocation = mobility->GetPosition ();
933  }
934  if (!NodeHasMoved (n, newLocation))
935  {
936  continue; //Location has not changed
937  }
938  else
939  {
940  UpdatePosition (n, newLocation);
941  RecalcTopoBounds (newLocation);
942  MovedNodes.push_back (n);
943  }
944  }
945  return MovedNodes;
946 }
947 
949 {
950  m_topoMinX = std::min (m_topoMinX, v.x);
951  m_topoMinY = std::min (m_topoMinY, v.y);
952  m_topoMaxX = std::max (m_topoMaxX, v.x);
953  m_topoMaxY = std::max (m_topoMaxY, v.y);
954 
955 }
956 
957 int AnimationInterface::WriteN (const char* data, uint32_t count, FILE * f)
958 {
959  // Write count bytes to h from data
960  uint32_t nLeft = count;
961  const char* p = data;
962  uint32_t written = 0;
963  while (nLeft)
964  {
965  int n = std::fwrite (p, 1, nLeft, f);
966  if (n <= 0)
967  {
968  return written;
969  }
970  written += n;
971  nLeft -= n;
972  p += n;
973  }
974  return written;
975 }
976 
978 {
979  Time now = Simulator::Now ();
980  std::ostringstream oss;
981  double fbTx = now.GetSeconds ();
982  double lbTx = now.GetSeconds ();
983  double fbRx = now.GetSeconds ();
984  double lbRx = now.GetSeconds ();
985  oss << GetXMLOpenClose_p ("p", 0, fbTx, lbTx, 0, fbRx, lbRx, "", "DummyPktIgnoreThis");
986  WriteN (oss.str (), m_f);
987 
988 
989 }
990 
991 void AnimationInterface::WriteRoutePath (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
992 {
993  NS_LOG_INFO ("Writing Route Path From :" << nodeId << " To: " << destination.c_str ());
994  WriteN (GetXMLOpenClose_rp (nodeId, destination, rpElements), m_routingF);
995  /*for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
996  i != rpElements.end ();
997  ++i)
998  {
999  Ipv4RoutePathElement rpElement = *i;
1000  NS_LOG_INFO ("Node:" << rpElement.nodeId << "-->" << rpElement.nextHop.c_str ());
1001  WriteN (GetXMLOpenClose_rp (rpElement.node, GetIpv4RoutingTable (n)), m_routingF);
1002 
1003  }
1004  */
1005 }
1006 
1007 void AnimationInterface::WriteNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
1008 {
1009  std::ostringstream oss;
1010  oss << GetXMLOpenClose_NonP2pLinkProperties (id, ipv4Address, channelType);
1011  WriteN (oss.str (), m_f);
1012 }
1013 
1016  Time txTime, Time rxTime)
1017 {
1018  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1019  return;
1020  NS_ASSERT (tx);
1021  NS_ASSERT (rx);
1022  Time now = Simulator::Now ();
1023  std::ostringstream oss;
1024  double fbTx = now.GetSeconds ();
1025  double lbTx = (now + txTime).GetSeconds ();
1026  double fbRx = (now + rxTime - txTime).GetSeconds ();
1027  double lbRx = (now + rxTime).GetSeconds ();
1028  oss << GetXMLOpenClose_p ("p", tx->GetNode ()->GetId (), fbTx, lbTx, rx->GetNode ()->GetId (),
1029  fbRx, lbRx, m_enablePacketMetadata? GetPacketMetadata (p):"");
1030  StartNewTraceFile ();
1032  WriteN (oss.str (), m_f);
1033 }
1034 
1035 
1036 Ptr <Node>
1037 AnimationInterface::GetNodeFromContext (const std::string& context) const
1038 {
1039  // Use "NodeList/*/ as reference
1040  // where element [1] is the Node Id
1041 
1042  std::vector <std::string> elements = GetElementsFromContext (context);
1043  Ptr <Node> n = NodeList::GetNode (atoi (elements.at (1).c_str ()));
1044  NS_ASSERT (n);
1045 
1046  return n;
1047 }
1048 
1051 {
1052  // Use "NodeList/*/DeviceList/*/ as reference
1053  // where element [1] is the Node Id
1054  // element [2] is the NetDevice Id
1055 
1056  std::vector <std::string> elements = GetElementsFromContext (context);
1057  Ptr <Node> n = GetNodeFromContext (context);
1058 
1059  return n->GetDevice (atoi (elements.at (3).c_str ()));
1060 }
1061 
1063 {
1064  m_pendingUanPackets[AnimUid] = pktinfo;
1065 }
1066 
1067 
1069 {
1070  m_pendingWifiPackets[AnimUid] = pktinfo;
1071 }
1072 
1074 {
1075  NS_ASSERT (pktinfo.m_txnd);
1076  m_pendingWimaxPackets[AnimUid] = pktinfo;
1077 }
1078 
1080 {
1081  NS_ASSERT (pktinfo.m_txnd);
1082  m_pendingLtePackets[AnimUid] = pktinfo;
1083 }
1084 
1086 {
1087  NS_ASSERT (pktinfo.m_txnd);
1088  m_pendingCsmaPackets[AnimUid] = pktinfo;
1089 }
1090 
1092 {
1093  AnimByteTag tag;
1094  TypeId tid = tag.GetInstanceTypeId ();
1096  bool found = false;
1097  while (i.HasNext ())
1098  {
1099  ByteTagIterator::Item item = i.Next ();
1100  if (tid == item.GetTypeId ())
1101  {
1102  item.GetTag (tag);
1103  found = true;
1104  }
1105  }
1106  if (found)
1107  {
1108  return tag.Get ();
1109  }
1110  else
1111  {
1112  return 0;
1113  }
1114 }
1115 
1117 {
1118  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1119  return;
1120  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1121  NS_ASSERT (ndev);
1122  Ptr <Node> n = ndev->GetNode ();
1123  NS_ASSERT (n);
1124  gAnimUid++;
1125  NS_LOG_INFO ("Uan TxBeginTrace for packet:" << gAnimUid);
1126  AnimByteTag tag;
1127  tag.Set (gAnimUid);
1128  p->AddByteTag (tag);
1129  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1130  AddPendingUanPacket (gAnimUid, pktinfo);
1131 
1132 
1133 }
1134 
1136 {
1137  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1138  return;
1139  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1140  NS_ASSERT (ndev);
1141  Ptr <Node> n = ndev->GetNode ();
1142  NS_ASSERT (n);
1143  uint64_t AnimUid = GetAnimUidFromPacket (p);
1144  NS_LOG_INFO ("UanPhyGenRxTrace for packet:" << AnimUid);
1145  if (!UanPacketIsPending (AnimUid))
1146  {
1147  NS_LOG_WARN ("UanPhyGenRxBeginTrace: unknown Uid");
1148  return;
1149  }
1150  m_pendingUanPackets[AnimUid].ProcessRxBegin (ndev, Simulator::Now ());
1151  m_pendingUanPackets[AnimUid].ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
1152  OutputWirelessPacket (p, m_pendingUanPackets[AnimUid], m_pendingUanPackets[AnimUid].GetRxInfo (ndev));
1153 
1154 }
1155 
1156 void AnimationInterface::RemainingEnergyTrace (std::string context, double previousEnergy, double currentEnergy)
1157 {
1158  if (!m_started || !IsInTimeWindow ())
1159  return;
1160 
1161  const Ptr <const Node> node = GetNodeFromContext (context);
1162  const uint32_t nodeId = node->GetId ();
1163 
1164  NS_LOG_INFO ("Remaining energy on one of sources on node " << nodeId << ": " << currentEnergy);
1165 
1166  const Ptr<EnergySource> energySource = node->GetObject<EnergySource> ();
1167 
1168  NS_ASSERT (energySource);
1169  // Don't call GetEnergyFraction () because of recursion
1170  const double energyFraction = currentEnergy / energySource->GetInitialEnergy ();
1171 
1172  NS_LOG_INFO ("Total energy fraction on node " << nodeId << ": " << energyFraction);
1173 
1174  m_nodeEnergyFraction[nodeId] = energyFraction;
1175  if (!m_enable3105)
1176  {
1177  WriteNodeUpdate (nodeId);
1178  }
1179  else
1180  {
1181  UpdateNodeCounter (m_remainingEnergyCounterId, nodeId, energyFraction);
1182  }
1183 }
1184 
1187 {
1188  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1189  return;
1190  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1191  NS_ASSERT (ndev);
1192  Ptr <Node> n = ndev->GetNode ();
1193  NS_ASSERT (n);
1194  // Add a new pending wireless
1195  gAnimUid++;
1196  NS_LOG_INFO ("Wifi TxBeginTrace for packet:" << gAnimUid);
1197  AnimByteTag tag;
1198  tag.Set (gAnimUid);
1199  p->AddByteTag (tag);
1200  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1201  AddPendingWifiPacket (gAnimUid, pktinfo);
1202  Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (ndev);
1203  Mac48Address nodeAddr = netDevice->GetMac ()->GetAddress ();
1204  std::ostringstream oss;
1205  oss << nodeAddr;
1206  m_macToNodeIdMap[oss.str ()] = n->GetId ();
1207  NS_LOG_INFO ("Added Mac" << oss.str () << " node:" <<m_macToNodeIdMap[oss.str ()]);
1208 }
1209 
1210 void AnimationInterface::WifiPhyTxEndTrace (std::string context,
1212 {
1213 }
1214 
1215 void AnimationInterface::WifiPhyTxDropTrace (std::string context,
1217 {
1218  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1219  return;
1220  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1221  NS_ASSERT (ndev);
1222  // Erase pending wifi
1223  uint64_t AnimUid = GetAnimUidFromPacket (p);
1224  NS_LOG_INFO ("TxDropTrace for packet:" << AnimUid);
1225  NS_ASSERT (WifiPacketIsPending (AnimUid) == true);
1226  m_pendingWifiPackets.erase (m_pendingWifiPackets.find (AnimUid));
1227 }
1228 
1229 
1232 {
1233  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1234  return;
1235  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1236  NS_ASSERT (ndev);
1237  Ptr <Node> n = ndev->GetNode ();
1238  NS_ASSERT (n);
1239  uint64_t AnimUid = GetAnimUidFromPacket (p);
1240  NS_LOG_INFO ("Wifi RxBeginTrace for packet:" << AnimUid);
1241  if (!WifiPacketIsPending (AnimUid))
1242  {
1243  NS_LOG_WARN ("WifiPhyRxBeginTrace: unknown Uid");
1244  std::ostringstream oss;
1245  WifiMacHeader hdr;
1246  if (!p->PeekHeader (hdr))
1247  {
1248  NS_LOG_WARN ("WifiMacHeader not present");
1249  return;
1250  }
1251  oss << hdr.GetAddr2 ();
1252  if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ())
1253  {
1254  //NS_LOG_UNCOND (oss.str ());
1255  return;
1256  }
1257  Ptr <Node> txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]);
1258  AnimPacketInfo pktinfo (0, Simulator::Now (), Simulator::Now (), UpdatePosition (txNode), m_macToNodeIdMap[oss.str ()]);
1259  AddPendingWifiPacket (AnimUid, pktinfo);
1260  NS_LOG_WARN ("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet");
1261  }
1263  m_pendingWifiPackets[AnimUid].ProcessRxBegin (ndev, Simulator::Now ());
1264  m_pendingWifiPackets[AnimUid].ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
1265  OutputWirelessPacket (p, m_pendingWifiPackets[AnimUid], m_pendingWifiPackets[AnimUid].GetRxInfo (ndev));
1266 }
1267 
1268 
1269 void AnimationInterface::WifiPhyRxEndTrace (std::string context,
1271 {
1272  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1273  return;
1274  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1275  NS_ASSERT (ndev);
1276  Ptr <Node> n = ndev->GetNode ();
1277  NS_ASSERT (n);
1278  uint64_t AnimUid = GetAnimUidFromPacket (p);
1279  if (!WifiPacketIsPending (AnimUid))
1280  {
1281  NS_LOG_WARN ("WifiPhyRxEndTrace: unknown Uid");
1282  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1283  AddPendingWifiPacket (AnimUid, pktinfo);
1284  }
1286  AnimPacketInfo& pktInfo = m_pendingWifiPackets[AnimUid];
1287  pktInfo.ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
1288  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1289  if (pktrxInfo.IsPhyRxComplete ())
1290  {
1291  NS_LOG_INFO ("MacRxTrace for packet:" << AnimUid << " complete");
1292  OutputWirelessPacket (p, pktInfo, pktrxInfo);
1293  }
1294 }
1295 
1296 void AnimationInterface::WifiMacRxTrace (std::string context,
1298 {
1299  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1300  return;
1301  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1302  NS_ASSERT (ndev);
1303  Ptr <Node> n = ndev->GetNode ();
1304  NS_ASSERT (n);
1305  uint64_t AnimUid = GetAnimUidFromPacket (p);
1306  if (!WifiPacketIsPending (AnimUid))
1307  {
1308  NS_LOG_WARN ("WifiMacRxTrace: unknown Uid");
1309  return;
1310  }
1312  AnimPacketInfo& pktInfo = m_pendingWifiPackets[AnimUid];
1313  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1314  if (pktrxInfo.IsPhyRxComplete ())
1315  {
1316  NS_LOG_INFO ("MacRxTrace for packet:" << AnimUid << " complete");
1317  OutputWirelessPacket (p, pktInfo, pktrxInfo);
1318  }
1319 
1320 }
1321 void AnimationInterface::WifiPhyRxDropTrace (std::string context,
1323 {
1324 }
1325 
1326 void AnimationInterface::WimaxTxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
1327 {
1328  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1329  return;
1330  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1331  NS_ASSERT (ndev);
1332  Ptr <Node> n = ndev->GetNode ();
1333  NS_ASSERT (n);
1334  gAnimUid++;
1335  NS_LOG_INFO ("WimaxTxTrace for packet:" << gAnimUid);
1336  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1338  AnimByteTag tag;
1339  tag.Set (gAnimUid);
1340  p->AddByteTag (tag);
1341  AddPendingWimaxPacket (gAnimUid, pktinfo);
1342 }
1343 
1344 
1345 void AnimationInterface::WimaxRxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
1346 {
1347  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1348  return;
1349  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1350  NS_ASSERT (ndev);
1351  Ptr <Node> n = ndev->GetNode ();
1352  NS_ASSERT (n);
1353  uint64_t AnimUid = GetAnimUidFromPacket (p);
1354  NS_LOG_INFO ("WimaxRxTrace for packet:" << AnimUid);
1355  NS_ASSERT (WimaxPacketIsPending (AnimUid) == true);
1356  AnimPacketInfo& pktInfo = m_pendingWimaxPackets[AnimUid];
1357  pktInfo.ProcessRxBegin (ndev, Simulator::Now ());
1358  pktInfo.ProcessRxEnd (ndev, Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1360  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1361  OutputWirelessPacket (p, pktInfo, pktrxInfo);
1362 }
1363 
1364 void AnimationInterface::LteTxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
1365 {
1366  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1367  return;
1368  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1369  NS_ASSERT (ndev);
1370  Ptr <Node> n = ndev->GetNode ();
1371  NS_ASSERT (n);
1372  gAnimUid++;
1373  NS_LOG_INFO ("LteTxTrace for packet:" << gAnimUid);
1374  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1376  AnimByteTag tag;
1377  tag.Set (gAnimUid);
1378  p->AddByteTag (tag);
1379  AddPendingLtePacket (gAnimUid, pktinfo);
1380 }
1381 
1382 
1383 void AnimationInterface::LteRxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
1384 {
1385  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1386  return;
1387  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1388  NS_ASSERT (ndev);
1389  Ptr <Node> n = ndev->GetNode ();
1390  NS_ASSERT (n);
1391  uint64_t AnimUid = GetAnimUidFromPacket (p);
1392  NS_LOG_INFO ("LteRxTrace for packet:" << gAnimUid);
1393  if (!LtePacketIsPending (AnimUid))
1394  {
1395  NS_LOG_WARN ("LteRxTrace: unknown Uid");
1396  return;
1397  }
1398  AnimPacketInfo& pktInfo = m_pendingLtePackets[AnimUid];
1399  pktInfo.ProcessRxBegin (ndev, Simulator::Now ());
1400  pktInfo.ProcessRxEnd (ndev, Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1402  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1403  OutputWirelessPacket (p, pktInfo, pktrxInfo);
1404 }
1405 
1407 {
1408  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1409  return;
1410  if (!pb)
1411  {
1412  NS_LOG_WARN ("pb == 0. Not yet supported");
1413  return;
1414  }
1415  context = "/" + context;
1416  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1417  NS_ASSERT (ndev);
1418  Ptr <Node> n = ndev->GetNode ();
1419  NS_ASSERT (n);
1420 
1421  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1422  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1423  i != pbList.end ();
1424  ++i)
1425  {
1426  Ptr <Packet> p = *i;
1427  gAnimUid++;
1428  NS_LOG_INFO ("LteSpectrumPhyTxTrace for packet:" << gAnimUid);
1429  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1431  AnimByteTag tag;
1432  tag.Set (gAnimUid);
1433  p->AddByteTag (tag);
1434  AddPendingLtePacket (gAnimUid, pktinfo);
1435  }
1436 }
1437 
1439 {
1440  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1441  return;
1442  if (!pb)
1443  {
1444  NS_LOG_WARN ("pb == 0. Not yet supported");
1445  return;
1446  }
1447  context = "/" + context;
1448  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1449  NS_ASSERT (ndev);
1450  Ptr <Node> n = ndev->GetNode ();
1451  NS_ASSERT (n);
1452 
1453  std::list <Ptr <Packet> > pbList = pb->GetPackets ();
1454  for (std::list <Ptr <Packet> >::iterator i = pbList.begin ();
1455  i != pbList.end ();
1456  ++i)
1457  {
1458  Ptr <Packet> p = *i;
1459  uint64_t AnimUid = GetAnimUidFromPacket (p);
1460  NS_LOG_INFO ("LteSpectrumPhyRxTrace for packet:" << gAnimUid);
1461  if (!LtePacketIsPending (AnimUid))
1462  {
1463  NS_LOG_WARN ("LteSpectrumPhyRxTrace: unknown Uid");
1464  return;
1465  }
1466  AnimPacketInfo& pktInfo = m_pendingLtePackets[AnimUid];
1467  pktInfo.ProcessRxBegin (ndev, Simulator::Now ());
1468  pktInfo.ProcessRxEnd (ndev, Simulator::Now () + Seconds (0.001), UpdatePosition (n));
1470  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1471  OutputWirelessPacket (p, pktInfo, pktrxInfo);
1472  }
1473 }
1474 
1476 {
1477  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1478  return;
1479  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1480  NS_ASSERT (ndev);
1481  Ptr <Node> n = ndev->GetNode ();
1482  NS_ASSERT (n);
1483  gAnimUid++;
1484  NS_LOG_INFO ("CsmaPhyTxBeginTrace for packet:" << gAnimUid);
1485  AnimByteTag tag;
1486  tag.Set (gAnimUid);
1487  p->AddByteTag (tag);
1488  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1489  AddPendingCsmaPacket (gAnimUid, pktinfo);
1490 
1491 }
1492 
1494 {
1495  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1496  return;
1497  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1498  NS_ASSERT (ndev);
1499  Ptr <Node> n = ndev->GetNode ();
1500  NS_ASSERT (n);
1501  uint64_t AnimUid = GetAnimUidFromPacket (p);
1502  NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << AnimUid);
1503  if (!CsmaPacketIsPending (AnimUid))
1504  {
1505  NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid");
1506  AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
1507  AddPendingCsmaPacket (AnimUid, pktinfo);
1508  NS_LOG_WARN ("Unknown Uid, but adding Csma Packet anyway");
1509  }
1511  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[AnimUid];
1512  pktInfo.m_lbTx = Simulator::Now ().GetSeconds ();
1513 }
1514 
1516 {
1517  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1518  return;
1519  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1520  NS_ASSERT (ndev);
1521  Ptr <Node> n = ndev->GetNode ();
1522  NS_ASSERT (n);
1523  uint64_t AnimUid = GetAnimUidFromPacket (p);
1524  if (!CsmaPacketIsPending (AnimUid))
1525  {
1526  NS_LOG_WARN ("CsmaPhyRxEndTrace: unknown Uid");
1527  return;
1528  }
1530  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[AnimUid];
1531  m_pendingCsmaPackets[AnimUid].ProcessRxBegin (ndev, Simulator::Now ());
1532  pktInfo.ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n));
1533  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << AnimUid);
1534  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1535  if (pktrxInfo.IsPhyRxComplete ())
1536  {
1537  NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << AnimUid << " complete");
1538  OutputCsmaPacket (p, pktInfo, pktrxInfo);
1539  }
1540 }
1541 
1542 
1543 void AnimationInterface::CsmaMacRxTrace (std::string context,
1545 {
1546  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1547  return;
1548  NS_LOG_FUNCTION (this);
1549  Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
1550  NS_ASSERT (ndev);
1551  Ptr <Node> n = ndev->GetNode ();
1552  NS_ASSERT (n);
1553  uint64_t AnimUid = GetAnimUidFromPacket (p);
1554  if (!CsmaPacketIsPending (AnimUid))
1555  {
1556  NS_LOG_WARN ("CsmaMacRxTrace: unknown Uid");
1557  return;
1558  }
1560  AnimPacketInfo& pktInfo = m_pendingCsmaPackets[AnimUid];
1561  AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev);
1562  if (pktrxInfo.IsPhyRxComplete ())
1563  {
1564  NS_LOG_INFO ("MacRxTrace for packet:" << AnimUid << " complete");
1565  OutputCsmaPacket (p, pktInfo, pktrxInfo);
1566  }
1567 }
1568 
1569 
1571 
1572 {
1573  if (!m_started || !IsInTimeWindow () || !m_trackPackets)
1574  return;
1575  Ptr <Node> n = mobility->GetObject <Node> ();
1576  NS_ASSERT (n);
1577  Vector v ;
1578  if (!mobility)
1579  {
1580  v = GetPosition (n);
1581  }
1582  else
1583  {
1584  v = mobility->GetPosition ();
1585  }
1586  UpdatePosition (n,v);
1587  RecalcTopoBounds (v);
1588  std::ostringstream oss;
1589  if (!m_enable3105)
1590  {
1591  oss << GetXMLOpenClose_node (0, n->GetId (), v.x, v.y, nodeColors[n->GetId ()]);
1592  }
1593  else
1594  {
1595  oss << GetXMLOpenCloseUpdateNodePosition (n->GetId (), v.x, v.y);
1596  }
1597  WriteN (oss.str (), m_f);
1598  WriteDummyPacket ();
1599 }
1600 
1602 {
1603  Vector oldLocation = GetPosition (n);
1604  if ((ceil (oldLocation.x) == ceil (newLocation.x)) &&
1605  (ceil (oldLocation.y) == ceil (newLocation.y)))
1606  {
1607 
1608  return false;
1609  }
1610  else
1611  {
1612  return true;
1613  }
1614 }
1615 
1617 {
1618  if (!m_started || !IsInTimeWindow ())
1619  return;
1620  std::vector <Ptr <Node> > MovedNodes = RecalcTopoBounds ();
1621  std::ostringstream oss;
1622  for (uint32_t i = 0; i < MovedNodes.size (); i++)
1623  {
1624  Ptr <Node> n = MovedNodes [i];
1625  NS_ASSERT (n);
1626  Vector v = GetPosition (n);
1627  if (!m_enable3105)
1628  {
1629  oss << GetXMLOpenClose_node (0, n->GetId (), v.x, v.y);
1630  }
1631  else
1632  {
1633  oss << GetXMLOpenCloseUpdateNodePosition (n->GetId () , v.x, v.y);
1634  }
1635  }
1636  if (!m_enable3105)
1637  {
1638  WriteDummyPacket ();
1639  }
1640  else
1641  {
1642  WriteN (oss.str (), m_f);
1643  }
1644  if (!Simulator::IsFinished ())
1645  {
1646  PurgePendingWifi ();
1647  PurgePendingWimax ();
1648  PurgePendingLte ();
1649  PurgePendingCsma ();
1651  }
1652 }
1653 
1654 void AnimationInterface::UpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
1655 {
1656  NS_LOG_INFO ("Setting node image for Node Id:" << nodeId);
1657  if (resourceId > (m_resources.size ()-1))
1658  {
1659  NS_FATAL_ERROR ("Resource Id:" << resourceId << " not found. Did you use AddResource?");
1660  }
1661  std::ostringstream oss;
1662  oss << GetXMLOpenCloseUpdateNodeImage (nodeId, resourceId);
1663  WriteN (oss.str (), m_f);
1664 }
1665 
1666 
1668 {
1669  std::ostringstream oss;
1670  p->Print (oss);
1671  return oss.str ();
1672 }
1673 
1675 {
1676  return m_currentPktCount;
1677 }
1678 
1680 {
1681  const EnergyFractionMap::const_iterator fractionIter = m_nodeEnergyFraction.find (node->GetId ());
1682 
1683  NS_ASSERT (fractionIter != m_nodeEnergyFraction.end ());
1684  return fractionIter->second;
1685 }
1686 
1687 int64_t
1689 {
1690  NS_LOG_FUNCTION (this << stream);
1692  return 1;
1693 }
1694 
1695 // Helper to output a wireless packet.
1696 // For now, only the XML interface is supported
1698 {
1699  std::string typeString = "unknown";
1700  switch (counterType)
1701  {
1702  case UINT32_COUNTER:
1703  {
1704  typeString = "UINT32";
1705  break;
1706  }
1707  case DOUBLE_COUNTER:
1708  {
1709  typeString = "DOUBLE";
1710  break;
1711  }
1712  }
1713  return typeString;
1714 }
1715 
1716 
1718 {
1719  std::string s =
1720  "<information><!-- \n\
1721  Description of attributes:\n\
1722  =========================\n\
1723  anim\n\
1724  * ver = Current version\n\
1725  topology\n\
1726  * minX = minimum X coordinate of the canvas\n\
1727  * minY = minimum Y coordinate of the canvas\n\
1728  * maxX = maximum X coordinate of the canvas\n\
1729  * maxY = maximum Y coordinate of the canvas\n\
1730  node\n\
1731  * id = Node Id\n\
1732  * locX = X coordinate\n\
1733  * locY = Y coordinate\n\
1734  * r = Red component\n\
1735  * g = Green component\n\
1736  * b = Blue component\n\
1737  link\n\
1738  * fromId = From Node Id\n\
1739  * toId = To Node Id\n\
1740  * fd = From Node description (for IP Address)\n\
1741  * td = To Node description (for IP Address)\n\
1742  * ld = Link description (for Bandwidth, delay etc)\n\
1743  linkupdate\n\
1744  * t = Simulation time\n\
1745  * ld = Link description (for Bandwidth, delay etc)\n\
1746  nodeupdate\n\
1747  * t = Simulation time\n\
1748  * descr = Node description\n\
1749  * r = Red component\n\
1750  * g = Green component\n\
1751  * b = Blue component\n\
1752  * visible = Node visibility\n\
1753  * rc = Residual energy (between 0 and 1)\n\
1754  p\n\
1755  * fId = From Node Id\n\
1756  * fbTx = First bit transmit time\n\
1757  * lbTx = Last bit transmit time\n\
1758  * tId = To Node Id\n\
1759  * fbRx = First bit Rx Time\n\
1760  * lbRx = Last bit Rx\n\
1761  * meta-info = Packet meta data\n\
1762  wp\n\
1763  * fId = From Node Id\n\
1764  * fbTx = First bit transmit time\n\
1765  * lbTx = Last bit transmit time\n\
1766  * range = Reception range\n\
1767  * tId = To Node Id\n\
1768  * fbRx = First bit Rx time\n\
1769  * meta-info = Packet meta data\n\
1770  * lbRx = Last bit Rx time-->\n\
1771  </information>\n";
1772 return s;
1773 }
1774 
1776 {
1777  StartNewTraceFile ();
1778  std::ostringstream oss;
1779  uint32_t nodeId = 0;
1780  if (pktInfo.m_txnd)
1781  nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1782  else
1783  nodeId = pktInfo.m_txNodeId;
1784 
1785  double lbTx = pktInfo.firstlastbitDelta + pktInfo.m_fbTx;
1786  uint32_t rxId = pktrxInfo.m_rxnd->GetNode ()->GetId ();
1787 
1788  oss << GetXMLOpenClose_p ("wp", nodeId, pktInfo.m_fbTx, lbTx, rxId,
1789  pktrxInfo.m_fbRx, pktrxInfo.m_lbRx, m_enablePacketMetadata? GetPacketMetadata (p):"");
1790  WriteN (oss.str (), m_f);
1791 }
1792 
1794 {
1795  StartNewTraceFile ();
1796  std::ostringstream oss;
1797  NS_ASSERT (pktInfo.m_txnd);
1798  uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId ();
1799  uint32_t rxId = pktrxInfo.m_rxnd->GetNode ()->GetId ();
1800 
1801  oss << GetXMLOpenClose_p ("p", nodeId, pktInfo.m_fbTx, pktInfo.m_lbTx, rxId,
1802  pktrxInfo.m_fbRx, pktrxInfo.m_lbRx, m_enablePacketMetadata? GetPacketMetadata (p):"");
1803  WriteN (oss.str (), m_f);
1804 }
1805 
1806 void AnimationInterface::SetConstantPosition (Ptr <Node> n, double x, double y, double z)
1807 {
1808  NS_ASSERT (n);
1810  if (hubLoc == 0)
1811  {
1812  hubLoc = CreateObject<ConstantPositionMobilityModel> ();
1813  n->AggregateObject (hubLoc);
1814  }
1815  Vector hubVec (x, y, z);
1816  hubLoc->SetPosition (hubVec);
1817  NS_LOG_INFO ("Node:" << n->GetId () << " Position set to:(" << x << "," << y << "," << z << ")");
1818 
1819 }
1820 
1821 void AnimationInterface::UpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counter)
1822 {
1823  if (nodeCounterId > (m_nodeCounters.size ()-1))
1824  {
1825  NS_FATAL_ERROR ("NodeCounter Id:" << nodeCounterId << " not found. Did you use AddNodeCounter?");
1826  }
1827  std::ostringstream oss;
1828  oss << GetXMLOpenCloseUpdateNodeCounter (nodeCounterId, nodeId, counter);
1829  WriteN (oss.str (), m_f);
1830 }
1831 
1832 void AnimationInterface::SetBackgroundImage (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
1833 {
1834  if ((opacity < 0) || (opacity > 1))
1835  {
1836  NS_FATAL_ERROR ("Opacity must be between 0.0 and 1.0");
1837  }
1838  std::ostringstream oss;
1839  oss << GetXMLOpenCloseUpdateBackground (fileName, x, y, scaleX, scaleY, opacity);
1840  WriteN (oss.str (), m_f);
1841 }
1842 
1843 
1844 void AnimationInterface::SetNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b)
1845 {
1846  if (initialized)
1847  NS_FATAL_ERROR ("SetNodeColor must be used prior to creating the AnimationInterface object");
1848  NS_ASSERT (n);
1849  NS_LOG_INFO ("Setting node color for Node Id:" << n->GetId ());
1850  struct Rgb rgb = {r, g, b};
1851  nodeColors[n->GetId ()] = rgb;
1852 }
1853 
1854 void AnimationInterface::ShowNode (uint32_t nodeId, bool show)
1855 {
1856  NS_ASSERT (NodeList::GetNode (nodeId));
1857  NS_LOG_INFO ("Setting node visibility for Node Id:" << nodeId);
1858  WriteNodeUpdate (nodeId);
1859 }
1860 
1862 {
1863  ShowNode (n, show);
1864 }
1865 
1867 {
1868  std::ostringstream oss;
1869  oss << GetXMLOpenClose_nodeupdate (nodeId);
1870  WriteN (oss.str (), m_f);
1871 }
1872 
1873 void AnimationInterface::UpdateNodeSize (uint32_t nodeId, double width, double height)
1874 {
1875  NodeSize s = { width, height };
1876  m_nodeSizes[nodeId] = s;
1877  std::ostringstream oss;
1878  oss << GetXMLOpenCloseUpdateNodeSize (nodeId, s.width, s.height);
1879  WriteN (oss.str (), m_f);
1880 }
1881 
1882 
1883 void AnimationInterface::UpdateNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b)
1884 {
1885  UpdateNodeColor (n->GetId (), r, g, b);
1886 }
1887 
1888 void AnimationInterface::UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
1889 {
1890  NS_ASSERT (NodeList::GetNode (nodeId));
1891  NS_LOG_INFO ("Setting node color for Node Id:" << nodeId);
1892  struct Rgb rgb = {r, g, b};
1893  nodeColors[nodeId] = rgb;
1894  if (!m_enable3105)
1895  {
1896  WriteNodeUpdate (nodeId);
1897  }
1898  else
1899  {
1900  std::ostringstream oss;
1901  oss << GetXMLOpenCloseUpdateNodeColor (nodeId, r, g, b);
1902  WriteN (oss.str (), m_f);
1903  }
1904 }
1905 
1906 
1907 
1908 void AnimationInterface::SetNodeColor (NodeContainer nc, uint8_t r, uint8_t g, uint8_t b)
1909 {
1910  for (uint32_t i = 0; i < nc.GetN (); ++i)
1911  {
1912  Ptr <Node> n = nc.Get (i);
1913  NS_ASSERT (n);
1914  SetNodeColor (n, r, g, b);
1915  }
1916 }
1917 
1918 
1919 void AnimationInterface::UpdateLinkDescription (uint32_t fromNode, uint32_t toNode,
1920  std::string linkDescription)
1921 {
1922  std::ostringstream oss;
1923  oss << GetXMLOpenClose_linkupdate (fromNode, toNode, linkDescription);
1924  WriteN (oss.str (), m_f);
1925 }
1926 
1928  std::string linkDescription)
1929 {
1930  NS_ASSERT (fromNode);
1931  NS_ASSERT (toNode);
1932  std::ostringstream oss;
1933  oss << GetXMLOpenClose_linkupdate (fromNode->GetId (), toNode->GetId (), linkDescription);
1934  WriteN (oss.str (), m_f);
1935 }
1936 
1937 void AnimationInterface::SetLinkDescription (uint32_t fromNode, uint32_t toNode,
1938  std::string linkDescription,
1939  std::string fromNodeDescription,
1940  std::string toNodeDescription)
1941 {
1942 
1943  P2pLinkNodeIdPair p2pPair;
1944  p2pPair.fromNode = fromNode;
1945  p2pPair.toNode = toNode;
1946  LinkProperties lp = { fromNodeDescription, toNodeDescription, linkDescription };
1947  linkProperties[p2pPair] = lp;
1948  /* DEBUG */
1949  /*
1950  for (std::map <P2pLinkNodeIdPair, LinkProperties>::const_iterator i = linkProperties.begin ();
1951  i != linkProperties.end (); ++i)
1952  {
1953  P2pLinkNodeIdPair ppair = i->first;
1954  LinkProperties l = i->second;
1955  NS_LOG_UNCOND ("A:" << ppair.fromNode << " B:" << ppair.toNode << " ad:" << l.fromNodeDescription << " bd:" << l.toNodeDescription << " ld:" << l.linkDescription);
1956 
1957  }
1958  */
1959 }
1960 
1962  std::string linkDescription,
1963  std::string fromNodeDescription,
1964  std::string toNodeDescription)
1965 {
1966  NS_ASSERT (fromNode);
1967  NS_ASSERT (toNode);
1968  SetLinkDescription (fromNode->GetId (), toNode->GetId (), linkDescription, fromNodeDescription, toNodeDescription);
1969 }
1970 
1971 
1973 {
1974  if (initialized)
1975  NS_FATAL_ERROR ("SetNodeDescription must be used prior to creating the AnimationInterface object");
1976  NS_ASSERT (n);
1977  nodeDescriptions[n->GetId ()] = descr;
1978 }
1979 
1981 {
1982  UpdateNodeDescription (n->GetId (), descr);
1983 }
1984 
1985 void AnimationInterface::UpdateNodeDescription (uint32_t nodeId, std::string descr)
1986 {
1987  NS_ASSERT (NodeList::GetNode (nodeId));
1988  nodeDescriptions[nodeId] = descr;
1989  std::ostringstream oss;
1990  if (!m_enable3105)
1991  {
1992  oss << GetXMLOpenClose_nodeupdate (nodeId);
1993  }
1994  else
1995  {
1996  oss << GetXMLOpenCloseUpdateNodeDescription (nodeId);
1997  }
1998  WriteN (oss.str (), m_f);
1999 }
2000 
2001 
2002 
2004 {
2005  if (initialized)
2006  NS_FATAL_ERROR ("SetNodeDescription must be used prior to creating the AnimationInterface object");
2007  for (uint32_t i = 0; i < nc.GetN (); ++i)
2008  {
2009  Ptr <Node> n = nc.Get (i);
2010  NS_ASSERT (n);
2011  nodeDescriptions[n->GetId ()] = descr;
2012  }
2013 }
2014 
2015 
2016 // XML Private Helpers
2017 
2018 std::string AnimationInterface::GetXMLOpen_anim (uint32_t lp)
2019 {
2020  std::ostringstream oss;
2021  oss <<"<anim ver=\"" << GetNetAnimVersion () << "\">\n";
2022  return oss.str ();
2023 }
2024 
2025 std::string AnimationInterface::GetXMLOpenClose_nodeupdate (uint32_t id, bool visible)
2026 {
2027  std::ostringstream oss;
2028  oss << "<nodeupdate id=\"" << id << "\"";
2029  oss << " t=\"" << Simulator::Now ().GetSeconds () << "\"";
2030  if (visible)
2031  oss << " visible=\"" << 1 << "\"";
2032  else
2033  oss << " visible=\"" << 0 << "\"";
2034  AppendXMLNodeDescription (oss, id);
2035  AppendXMLNodeColor (oss, nodeColors[id]);
2036  AppendXMLRemainingEnergy (oss, id);
2037 
2038  oss <<"/>\n";
2039 
2040  return oss.str ();
2041 
2042 }
2043 
2044 std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp, uint32_t id, double locX, double locY)
2045 {
2046  std::ostringstream oss;
2047  oss <<"<node id=\"" << id << "\"";
2048  AppendXMLNodeDescription (oss, id);
2049  oss << " locX = \"" << locX << "\" " << "locY = \"" << locY << "\"";
2050  AppendXMLRemainingEnergy (oss, id);
2051 
2052  oss <<"/>\n";
2053 
2054  return oss.str ();
2055 }
2056 
2057 std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp, uint32_t id, double locX, double locY, struct Rgb rgb)
2058 {
2059  std::ostringstream oss;
2060  oss <<"<node id = \"" << id << "\"";
2061  AppendXMLNodeDescription (oss, id);
2062  oss << " locX=\"" << locX << "\" " << "locY=\"" << locY << "\"";
2063  AppendXMLNodeColor (oss, rgb);
2064  AppendXMLRemainingEnergy (oss, id);
2065 
2066  oss <<"/>\n";
2067 
2068  return oss.str ();
2069 }
2070 
2071 std::string AnimationInterface::GetXMLOpenClose_linkupdate (uint32_t fromId, uint32_t toId, std::string linkDescription)
2072 {
2073  std::ostringstream oss;
2074  oss << "<linkupdate t=\"" << Simulator::Now ().GetSeconds () << "\""
2075  << " fromId=\"" << fromId
2076  << "\" toId=\"" << toId
2077  << "\" ";
2078 
2079  oss << " ld=\"" << linkDescription << "\""
2080  << " />\n";
2081  return oss.str ();
2082 
2083 }
2084 
2085 std::string AnimationInterface::GetXMLOpenClose_link (uint32_t fromLp, uint32_t fromId, uint32_t toLp, uint32_t toId)
2086 {
2087  std::ostringstream oss;
2088  oss << "<link fromId=\"" << fromId
2089  << "\" toId=\"" << toId
2090  << "\" ";
2091 
2092  LinkProperties lprop ;
2093  lprop.fromNodeDescription = "";
2094  lprop.toNodeDescription = "";
2095  lprop.linkDescription = "";
2096 
2097  P2pLinkNodeIdPair p1 = { fromId, toId };
2098  P2pLinkNodeIdPair p2 = { toId, fromId };
2099  if (linkProperties.find (p1) != linkProperties.end ())
2100  {
2101  lprop = linkProperties[p1];
2102  }
2103  else if (linkProperties.find (p2) != linkProperties.end ())
2104  {
2105  lprop = linkProperties[p2];
2106  }
2107 
2108  oss << " fd=\"" << lprop.fromNodeDescription << "\""
2109  << " td=\"" << lprop.toNodeDescription << "\""
2110  << " ld=\"" << lprop.linkDescription << "\""
2111  << " />\n";
2112  return oss.str ();
2113 }
2114 
2115 
2116 std::string AnimationInterface::GetXMLOpen_packet (uint32_t fromLp, uint32_t fromId, double fbTx, double lbTx, std::string auxInfo)
2117 {
2118  std::ostringstream oss;
2119  oss << std::setprecision (10);
2120  oss << "<p fId=\"" << fromId
2121  << "\" fbTx=\"" << fbTx
2122  << "\" lbTx=\"" << lbTx
2123  << (auxInfo.empty ()?"":"\" aux=\"") << auxInfo.c_str () << "\">";
2124  return oss.str ();
2125 }
2126 
2127 std::string AnimationInterface::GetXMLOpenClose_routing (uint32_t nodeId, std::string routingInfo)
2128 {
2129  std::ostringstream oss;
2130  oss << "<" << "rt" << " t=\"" << Simulator::Now ().GetSeconds () << "\""
2131  << " id=\"" << nodeId << "\""
2132  << " info=\"" << routingInfo.c_str () << "\""
2133  << "/>" << std::endl;
2134  return oss.str ();
2135 }
2136 
2137 std::string AnimationInterface::GetXMLOpenClose_rp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
2138 {
2139  std::ostringstream oss;
2140  oss << "<" << "rp" << " t =\"" << Simulator::Now ().GetSeconds () << "\""
2141  << " id=\"" << nodeId << "\"" << " d=\"" << destination.c_str () << "\""
2142  << " c=\"" << rpElements.size () << "\"" << ">" << std::endl;
2143  for (Ipv4RoutePathElements::const_iterator i = rpElements.begin ();
2144  i != rpElements.end ();
2145  ++i)
2146  {
2147  Ipv4RoutePathElement rpElement = *i;
2148  oss << "<rpe" << " n=\"" << rpElement.nodeId << "\"" << " nH=\"" << rpElement.nextHop.c_str () << "\"" << "/>" << std::endl;
2149  }
2150  oss << "</rp>" << std::endl;
2151  return oss.str ();
2152 }
2153 
2154 
2155 std::string AnimationInterface::GetXMLOpenClose_p (std::string pktType, uint32_t fId, double fbTx, double lbTx,
2156  uint32_t tId, double fbRx, double lbRx, std::string metaInfo,
2157  std::string auxInfo)
2158 {
2159  std::ostringstream oss;
2160  oss << std::setprecision (10);
2161  oss << "<" << pktType << " fId=\"" << fId
2162  << "\" fbTx=\"" << fbTx
2163  << "\" lbTx=\"" << lbTx << "\"";
2164  if (!auxInfo.empty ())
2165  {
2166  oss << " aux=\"" << auxInfo.c_str () << "\"";
2167  }
2168  if (!metaInfo.empty ())
2169  {
2170  oss << " meta-info=\"" << metaInfo.c_str () << "\"";
2171  }
2172  oss << " tId=\"" << tId << "\" fbRx=\"" << fbRx << "\" lbRx=\"" << lbRx << "\">" << std::endl;
2173  return oss.str ();
2174 }
2175 
2176 
2177 
2178 std::string AnimationInterface::GetXMLOpen_wpacket (uint32_t fromLp, uint32_t fromId, double fbTx, double lbTx, double range)
2179 {
2180  std::ostringstream oss;
2181  oss << std::setprecision (10);
2182  oss << "<wpacket fromId=\"" << fromId
2183  << "\" fbTx=\"" << fbTx
2184  << "\" lbTx=\"" << lbTx
2185  << "\" range=\"" << range << "\">" << std::endl;
2186  return oss.str ();
2187 
2188 }
2189 
2190 std::string AnimationInterface::GetXMLOpenClose_rx (uint32_t toLp, uint32_t toId, double fbRx, double lbRx)
2191 {
2192  std::ostringstream oss;
2193  oss << std::setprecision (10);
2194  oss << "<rx toId=\"" << toId
2195  << "\" fbRx=\"" << fbRx
2196  << "\" lbRx=\"" << lbRx
2197  << "\"/>" << std::endl;
2198  return oss.str ();
2199 }
2200 
2201 std::string AnimationInterface::GetXMLOpenClose_meta (std::string metaInfo)
2202 {
2203  std::ostringstream oss;
2204  oss << "<meta info=\""
2205  << metaInfo << "\" />" << std::endl;
2206  return oss.str ();
2207 }
2208 
2209 std::string AnimationInterface::GetXMLOpenCloseAddNodeCounter (uint32_t nodeCounterId, std::string counterName, CounterType counterType)
2210 {
2211  std::ostringstream oss;
2212  oss << "<ncs ncId=\"" << nodeCounterId << "\""
2213  << " n=\"" << counterName << "\""
2214  << " t=\"" << CounterTypeToString (counterType) << "\""
2215  << " />" << std::endl;
2216  return oss.str ();
2217 }
2218 
2219 std::string AnimationInterface::GetXMLOpenCloseAddResource (uint32_t resourceId, std::string resourcePath)
2220 {
2221  std::ostringstream oss;
2222  oss << "<res rid=\"" << resourceId << "\""
2223  << " p=\"" << resourcePath << "\""
2224  << "/>" << std::endl;
2225  return oss.str ();
2226 }
2227 
2228 std::string AnimationInterface::GetXMLOpenCloseUpdateNodeImage (uint32_t nodeId, uint32_t resourceId)
2229 {
2230  std::ostringstream oss;
2231  oss << "<nu p=\"i\""
2232  << " t=\"" << Simulator::Now ().GetSeconds () << "\""
2233  << " id=\"" << nodeId << "\""
2234  << " rid=\"" << resourceId << "\""
2235  << "/>" << std::endl;
2236  return oss.str ();
2237 }
2238 
2239 std::string AnimationInterface::GetXMLOpenCloseUpdateNodeSize (uint32_t nodeId, double width, double height)
2240 {
2241  std::ostringstream oss;
2242  oss << std::setprecision (10);
2243  oss << "<nu p=\"s\""
2244  << " t=\"" << Simulator::Now ().GetSeconds () << "\""
2245  << " id=\"" << nodeId << "\""
2246  << " w=\"" << width << "\""
2247  << " h=\"" << height << "\""
2248  << "/>" << std::endl;
2249  return oss.str ();
2250 }
2251 
2252 std::string AnimationInterface::GetXMLOpenCloseUpdateNodePosition (uint32_t nodeId, double x, double y)
2253 {
2254  std::ostringstream oss;
2255  oss << "<nu p=\"p\""
2256  << " t=\"" << Simulator::Now ().GetSeconds () << "\""
2257  << " id=\"" << nodeId << "\""
2258  << " x=\"" << x << "\""
2259  << " y=\"" << y << "\""
2260  << "/>" << std::endl;
2261  return oss.str ();
2262 }
2263 
2264 std::string AnimationInterface::GetXMLOpenCloseUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
2265 {
2266  std::ostringstream oss;
2267  oss << "<nu p=\"c\""
2268  << " t=\"" << Simulator::Now ().GetSeconds () << "\""
2269  << " id=\"" << nodeId << "\""
2270  << " r=\"" << (uint32_t)r << "\""
2271  << " g=\"" << (uint32_t)g << "\""
2272  << " b=\"" << (uint32_t)b << "\""
2273  << "/>" << std::endl;
2274  return oss.str ();
2275 }
2276 
2278 {
2279  std::ostringstream oss;
2280  oss << "<nu p=\"d\""
2281  << " t=\"" << Simulator::Now ().GetSeconds () << "\""
2282  << " id=\"" << nodeId << "\"";
2283  if (nodeDescriptions.find (nodeId) != nodeDescriptions.end ())
2284  {
2285  oss << " descr=\""<< nodeDescriptions[nodeId] << "\"";
2286  }
2287  else
2288  {
2289  oss << " descr=\"\"";
2290  }
2291 
2292  oss << "/>" << std::endl;
2293  return oss.str ();
2294 }
2295 
2296 
2297 std::string AnimationInterface::GetXMLOpenCloseUpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counterValue)
2298 {
2299  std::ostringstream oss;
2300  oss << "<nc c=\"" << nodeCounterId << "\""
2301  << " i=\"" << nodeId << "\""
2302  << " t=\"" << Simulator::Now ().GetSeconds () << "\""
2303  << " v=\"" << counterValue << "\""
2304  << " />" << std::endl;
2305  return oss.str ();
2306 }
2307 
2308 std::string AnimationInterface::GetXMLOpenCloseUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
2309 {
2310  std::ostringstream oss;
2311  oss << "<bg f=\"" << fileName << "\""
2312  << " x=\"" << x << "\""
2313  << " y=\"" << y << "\""
2314  << " sx=\"" << scaleX << "\""
2315  << " sy=\"" << scaleY << "\""
2316  << " o=\"" << opacity << "\""
2317  << "/>" << std::endl;
2318  return oss.str ();
2319 }
2320 
2321 
2322 std::string AnimationInterface::GetXMLOpenClose_NonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType)
2323 {
2324  std::ostringstream oss;
2325  oss << "<nonp2plinkproperties id=\""
2326  << id << "\""
2327  << " ipv4Address=\"" << ipv4Address << "\""
2328  << " channelType=\"" << channelType << "\""
2329  << "/>" << std::endl;
2330  return oss.str ();
2331 }
2332 
2333 
2334 const std::vector<std::string> AnimationInterface::GetElementsFromContext (const std::string& context) const
2335 {
2336  std::vector <std::string> elements;
2337  size_t pos1=0, pos2;
2338  while (pos1 != context.npos)
2339  {
2340  pos1 = context.find ("/",pos1);
2341  pos2 = context.find ("/",pos1+1);
2342  elements.push_back (context.substr (pos1+1,pos2-(pos1+1)));
2343  pos1 = pos2;
2344  pos2 = context.npos;
2345  }
2346  return elements;
2347 }
2348 
2349 void AnimationInterface::AppendXMLNodeDescription (std::ostream& ostream, uint32_t id) const
2350 {
2351  if (nodeDescriptions.find (id) != nodeDescriptions.end ())
2352  {
2353  ostream << " descr=\""<< nodeDescriptions[id] << "\"";
2354  }
2355  else
2356  {
2357  ostream << " descr=\"\"";
2358  }
2359 }
2360 
2361 void AnimationInterface::AppendXMLNodeColor (std::ostream& ostream, const Rgb& color) const
2362 {
2363  const uint8_t r = color.r;
2364  const uint8_t g = color.g;
2365  const uint8_t b = color.b;
2366 
2367  ostream << " r=\"" << (uint32_t)r << "\" "
2368  << " g=\"" << (uint32_t)g << "\" "
2369  << " b=\"" << (uint32_t)b <<"\" ";
2370 }
2371 
2372 void AnimationInterface::AppendXMLRemainingEnergy (std::ostream& ostream, uint32_t id) const
2373 {
2374  const EnergyFractionMap::const_iterator fractionIter = m_nodeEnergyFraction.find (id);
2375 
2376  if (fractionIter != m_nodeEnergyFraction.end ())
2377  ostream << "rc = \"" << fractionIter->second <<"\" ";
2378  else if (NodeList::GetNode (id)->GetObject<EnergySource>())
2379  ostream << "rc = \"1\" ";
2380 }
2381 
2382 TypeId
2384 {
2385  static TypeId tid = TypeId ("ns3::AnimByteTag")
2386  .SetParent<Tag> ()
2387  .AddConstructor<AnimByteTag> ()
2388  ;
2389  return tid;
2390 }
2391 TypeId
2393 {
2394  return GetTypeId ();
2395 }
2396 
2397 uint32_t
2399 {
2400  return sizeof (uint64_t);
2401 }
2402 void
2404 {
2405  i.WriteU64 (m_AnimUid);
2406 }
2407 void
2409 {
2410  m_AnimUid = i.ReadU64 ();
2411 }
2412 void
2413 AnimByteTag::Print (std::ostream &os) const
2414 {
2415  os << "AnimUid=" << m_AnimUid;
2416 }
2417 void
2418 AnimByteTag::Set (uint64_t AnimUid)
2419 {
2420  m_AnimUid = AnimUid;
2421 }
2422 
2423 uint64_t
2424 AnimByteTag::Get (void) const
2425 {
2426  return m_AnimUid;
2427 }
2428 
2429 
2430 } // 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)
void UpdateNodeImage(uint32_t nodeId, uint32_t resourceId)
Helper function to update the image of a node.
bool WifiPacketIsPending(uint64_t AnimUid)
double x
x coordinate of vector
Definition: vector.h:49
void CsmaMacRxTrace(std::string context, Ptr< const Packet > p)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
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)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
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:246
std::vector< Ptr< Node > > RecalcTopoBounds()
void AddPendingWifiPacket(uint64_t AnimUid, AnimPacketInfo &)
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
bool LtePacketIsPending(uint64_t AnimUid)
Ipv4Address GetLocal(void) const
Get the local address.
std::string GetIpv4Address(Ptr< NetDevice > nd)
std::string CounterTypeToString(CounterType counterType)
void WriteU64(uint64_t v)
Definition: tag-buffer.cc:102
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:240
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.
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)
Ptr< LteEnbPhy > GetPhy(void) const
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)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
std::string GetXMLClose(std::string name)
void WifiMacRxTrace(std::string context, Ptr< const Packet > p)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
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)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:223
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
A structure to store the width and height of a node`.
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 &)
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:825
void UpdateNodeSize(uint32_t nodeId, double width, double height)
Helper function to update the size of a node.
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
Print the packet contents.
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
void ProcessRxBegin(Ptr< const NetDevice > nd, const Time &fbRx)
Process RxBegin notifications.
void ResetAnimWriteCallback()
Reset the write callback function.
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
double GetSeconds(void) const
Definition: nstime.h:272
void SetBackgroundImage(std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
Helper function to set the background image.
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="")
void UpdateNodeCounter(uint32_t nodeCounterId, uint32_t nodeId, double counter)
Helper function to update a node's counter referenced by the nodeCounterId.
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:552
void SetRandomPosition(bool setRandPos)
Set random position if a Mobility Model does not exists for the node.
uint32_t AddNodeCounter(std::string counterName, CounterType counterType)
Setup a node counter.
~AnimationInterface()
Destructor for the animator interface.
EnergyFractionMap m_nodeEnergyFraction
void SkipPacketTracing()
Do not trace packets.
double startTime
static Iterator End(void)
Definition: node-list.cc:234
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:134
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1242
ByteTagIterator GetByteTagIterator(void) const
Retiurns an iterator over the set of byte tags included in this packet.
Definition: packet.cc:818
std::map< uint64_t, AnimPacketInfo > m_pendingLtePackets
std::string GetXMLOpenCloseUpdateNodeImage(uint32_t nodeId, uint32_t resourceId)
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.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
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
std::string GetXMLOpenCloseUpdateNodePosition(uint32_t nodeId, double x, double y)
static std::map< uint32_t, Rgb > nodeColors
std::map< uint32_t, NodeSize > m_nodeSizes
void WifiPhyTxDropTrace(std::string context, Ptr< const Packet > p)
void AggregateObject(Ptr< Object > other)
Definition: object.cc:242
Ipv4Address GetGateway(void) const
Definition: ipv4-route.cc:70
std::string GetXMLOpenCloseUpdateNodeColor(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
#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::vector< std::string > m_resources
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:76
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:142
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
uint32_t AddResource(std::string resourcePath)
Add a resource such as the path to an image file.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Definition: node-list.h:44
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
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionaly.
an EUI-48 address
Definition: mac48-address.h:41
std::string GetXMLOpenCloseUpdateNodeDescription(uint32_t nodeId)
AnimationInterface(const std::string filename, bool enable3105=true, uint64_t maxPktsPerFile=MAX_PKTS_PER_TRACE_FILE)
Constructor.
double y
y coordinate of vector
Definition: vector.h:53
void EnablePacketMetadata(bool enable=true)
Enable Packet metadata.
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)
std::string GetXMLOpenCloseUpdateNodeSize(uint32_t nodeId, double width, double height)
std::string GetXMLOpenCloseAddResource(uint32_t resourceId, std::string resourcePath)
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:106
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)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:203
std::string GetMacAddress(Ptr< NetDevice > nd)
static Iterator Begin(void)
Definition: node-list.cc:228
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
std::string GetXMLOpenCloseAddNodeCounter(uint32_t counterId, std::string counterName, CounterType counterType)
A network Node.
Definition: node.h:55
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:213
std::string GetXMLOpenClose_rp(uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
std::string GetXMLOpenCloseUpdateNodeCounter(uint32_t counterId, uint32_t nodeId, double value)
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)
std::string GetXMLOpenCloseUpdateBackground(std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
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:362
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
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
std::string GetXMLOpenClose_link(uint32_t fromLp, uint32_t fromId, uint32_t toLp, uint32_t toId)
std::vector< std::string > m_nodeCounters
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.