--- a/src/netanim/doc/animation.rst Wed Sep 30 22:24:08 2015 +0200
+++ b/src/netanim/doc/animation.rst Thu Oct 01 07:59:09 2015 -0700
@@ -235,7 +235,7 @@
anim.UpdateNodeCounter (89, 7, 3.4);
With the above statement, AnimationInterface sets the counter with Id == 89, associated with Node 7 with the value 3.4.
-The counter with Id 89 is obtained using AnimationInterface::AddNodeCounter. An example usage for this is in src/netanim/examples/resources_demo.cc.
+The counter with Id 89 is obtained using AnimationInterface::AddNodeCounter. An example usage for this is in src/netanim/examples/resource-counters.cc.
Step 2: Loading the XML in NetAnim
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/examples/colors-link-description.cc Thu Oct 01 07:59:09 2015 -0700
@@ -0,0 +1,161 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: John Abraham <[email protected]>
+ */
+
+#include <iostream>
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/internet-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/netanim-module.h"
+#include "ns3/applications-module.h"
+#include "ns3/point-to-point-layout-module.h"
+
+using namespace ns3;
+
+AnimationInterface * pAnim = 0;
+
+struct rgb {
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+};
+
+struct rgb colors [] = {
+ { 255, 0, 0 }, // Red
+ { 0, 255, 0 }, // Blue
+ { 0, 0, 255 } // Green
+ };
+
+void modify ()
+{
+ std::ostringstream oss;
+ oss << "Update:" << Simulator::Now ().GetSeconds ();
+ pAnim->UpdateLinkDescription (0, 1, oss.str ());
+ pAnim->UpdateLinkDescription (0, 2, oss.str ());
+ pAnim->UpdateLinkDescription (0, 3, oss.str ());
+ pAnim->UpdateLinkDescription (0, 4, oss.str ());
+ pAnim->UpdateLinkDescription (0, 5, oss.str ());
+ pAnim->UpdateLinkDescription (0, 6, oss.str ());
+ pAnim->UpdateLinkDescription (1, 7, oss.str ());
+ pAnim->UpdateLinkDescription (1, 8, oss.str ());
+ pAnim->UpdateLinkDescription (1, 9, oss.str ());
+ pAnim->UpdateLinkDescription (1, 10, oss.str ());
+ pAnim->UpdateLinkDescription (1, 11, oss.str ());
+
+ // Every update change the node description for node 2
+ std::ostringstream node0Oss;
+ node0Oss << "-----Node:" << Simulator::Now ().GetSeconds ();
+ pAnim->UpdateNodeDescription (2, node0Oss.str ());
+
+ // Every update change the color for node 4
+ static uint32_t index = 0;
+ index++;
+ if (index == 3)
+ index = 0;
+ struct rgb color = colors[index];
+ for (uint32_t nodeId = 4; nodeId < 12; ++nodeId)
+ pAnim->UpdateNodeColor (nodeId, color.r, color.g, color.b);
+
+
+ if (Simulator::Now ().GetSeconds () < 10) // This is important or the simulation
+ // will run endlessly
+ Simulator::Schedule (Seconds (1), modify);
+
+}
+
+int main (int argc, char *argv[])
+{
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s"));
+
+ uint32_t nLeftLeaf = 5;
+ uint32_t nRightLeaf = 5;
+ uint32_t nLeaf = 0; // If non-zero, number of both left and right
+ std::string animFile = "dynamic_linknode.xml" ; // Name of file for animation output
+
+ CommandLine cmd;
+ cmd.AddValue ("nLeftLeaf", "Number of left side leaf nodes", nLeftLeaf);
+ cmd.AddValue ("nRightLeaf","Number of right side leaf nodes", nRightLeaf);
+ cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf);
+ cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
+
+ cmd.Parse (argc,argv);
+ if (nLeaf > 0)
+ {
+ nLeftLeaf = nLeaf;
+ nRightLeaf = nLeaf;
+ }
+
+ // Create the point-to-point link helpers
+ PointToPointHelper pointToPointRouter;
+ pointToPointRouter.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
+ pointToPointRouter.SetChannelAttribute ("Delay", StringValue ("1ms"));
+ PointToPointHelper pointToPointLeaf;
+ pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
+ pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms"));
+
+ PointToPointDumbbellHelper d (nLeftLeaf, pointToPointLeaf,
+ nRightLeaf, pointToPointLeaf,
+ pointToPointRouter);
+
+ // Install Stack
+ InternetStackHelper stack;
+ d.InstallStack (stack);
+
+ // Assign IP Addresses
+ d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
+ Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"),
+ Ipv4AddressHelper ("10.3.1.0", "255.255.255.0"));
+
+ d.BoundingBox (1, 1, 100, 100);
+ // Install on/off app on all right side nodes
+ OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
+ clientHelper.SetAttribute
+ ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
+ clientHelper.SetAttribute
+ ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
+ ApplicationContainer clientApps;
+
+ for (uint32_t i = 0; i < d.RightCount (); ++i)
+ {
+ // Create an on/off app sending packets to the same leaf right side
+ AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), 1000));
+ clientHelper.SetAttribute ("Remote", remoteAddress);
+ clientApps.Add (clientHelper.Install (d.GetRight (i)));
+ }
+
+ clientApps.Start (Seconds (0.0));
+ clientApps.Stop (Seconds (10.0));
+
+ // Set the bounding box for animation
+
+
+ // Create the animation object and configure for specified output
+ pAnim = new AnimationInterface (animFile);
+ Simulator::Schedule (Seconds (1), modify);
+
+ // Set up the acutal simulation
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ Simulator::Run ();
+ std::cout << "Animation Trace file created:" << animFile.c_str ()<< std::endl;
+ Simulator::Destroy ();
+ delete pAnim;
+ return 0;
+}
--- a/src/netanim/examples/dynamic_linknode.cc Wed Sep 30 22:24:08 2015 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,161 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: John Abraham <[email protected]>
- */
-
-#include <iostream>
-
-#include "ns3/core-module.h"
-#include "ns3/network-module.h"
-#include "ns3/internet-module.h"
-#include "ns3/point-to-point-module.h"
-#include "ns3/netanim-module.h"
-#include "ns3/applications-module.h"
-#include "ns3/point-to-point-layout-module.h"
-
-using namespace ns3;
-
-AnimationInterface * pAnim = 0;
-
-struct rgb {
- uint8_t r;
- uint8_t g;
- uint8_t b;
-};
-
-struct rgb colors [] = {
- { 255, 0, 0 }, // Red
- { 0, 255, 0 }, // Blue
- { 0, 0, 255 } // Green
- };
-
-void modify ()
-{
- std::ostringstream oss;
- oss << "Update:" << Simulator::Now ().GetSeconds ();
- pAnim->UpdateLinkDescription (0, 1, oss.str ());
- pAnim->UpdateLinkDescription (0, 2, oss.str ());
- pAnim->UpdateLinkDescription (0, 3, oss.str ());
- pAnim->UpdateLinkDescription (0, 4, oss.str ());
- pAnim->UpdateLinkDescription (0, 5, oss.str ());
- pAnim->UpdateLinkDescription (0, 6, oss.str ());
- pAnim->UpdateLinkDescription (1, 7, oss.str ());
- pAnim->UpdateLinkDescription (1, 8, oss.str ());
- pAnim->UpdateLinkDescription (1, 9, oss.str ());
- pAnim->UpdateLinkDescription (1, 10, oss.str ());
- pAnim->UpdateLinkDescription (1, 11, oss.str ());
-
- // Every update change the node description for node 2
- std::ostringstream node0Oss;
- node0Oss << "-----Node:" << Simulator::Now ().GetSeconds ();
- pAnim->UpdateNodeDescription (2, node0Oss.str ());
-
- // Every update change the color for node 4
- static uint32_t index = 0;
- index++;
- if (index == 3)
- index = 0;
- struct rgb color = colors[index];
- for (uint32_t nodeId = 4; nodeId < 12; ++nodeId)
- pAnim->UpdateNodeColor (nodeId, color.r, color.g, color.b);
-
-
- if (Simulator::Now ().GetSeconds () < 10) // This is important or the simulation
- // will run endlessly
- Simulator::Schedule (Seconds (1), modify);
-
-}
-
-int main (int argc, char *argv[])
-{
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s"));
-
- uint32_t nLeftLeaf = 5;
- uint32_t nRightLeaf = 5;
- uint32_t nLeaf = 0; // If non-zero, number of both left and right
- std::string animFile = "dynamic_linknode.xml" ; // Name of file for animation output
-
- CommandLine cmd;
- cmd.AddValue ("nLeftLeaf", "Number of left side leaf nodes", nLeftLeaf);
- cmd.AddValue ("nRightLeaf","Number of right side leaf nodes", nRightLeaf);
- cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf);
- cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
-
- cmd.Parse (argc,argv);
- if (nLeaf > 0)
- {
- nLeftLeaf = nLeaf;
- nRightLeaf = nLeaf;
- }
-
- // Create the point-to-point link helpers
- PointToPointHelper pointToPointRouter;
- pointToPointRouter.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
- pointToPointRouter.SetChannelAttribute ("Delay", StringValue ("1ms"));
- PointToPointHelper pointToPointLeaf;
- pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
- pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms"));
-
- PointToPointDumbbellHelper d (nLeftLeaf, pointToPointLeaf,
- nRightLeaf, pointToPointLeaf,
- pointToPointRouter);
-
- // Install Stack
- InternetStackHelper stack;
- d.InstallStack (stack);
-
- // Assign IP Addresses
- d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
- Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"),
- Ipv4AddressHelper ("10.3.1.0", "255.255.255.0"));
-
- d.BoundingBox (1, 1, 100, 100);
- // Install on/off app on all right side nodes
- OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
- clientHelper.SetAttribute
- ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
- clientHelper.SetAttribute
- ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
- ApplicationContainer clientApps;
-
- for (uint32_t i = 0; i < d.RightCount (); ++i)
- {
- // Create an on/off app sending packets to the same leaf right side
- AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), 1000));
- clientHelper.SetAttribute ("Remote", remoteAddress);
- clientApps.Add (clientHelper.Install (d.GetRight (i)));
- }
-
- clientApps.Start (Seconds (0.0));
- clientApps.Stop (Seconds (10.0));
-
- // Set the bounding box for animation
-
-
- // Create the animation object and configure for specified output
- pAnim = new AnimationInterface (animFile);
- Simulator::Schedule (Seconds (1), modify);
-
- // Set up the acutal simulation
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- Simulator::Run ();
- std::cout << "Animation Trace file created:" << animFile.c_str ()<< std::endl;
- Simulator::Destroy ();
- delete pAnim;
- return 0;
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/examples/resources-counters.cc Thu Oct 01 07:59:09 2015 -0700
@@ -0,0 +1,199 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: John Abraham <[email protected]>
+ */
+
+#include <iostream>
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/internet-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/netanim-module.h"
+#include "ns3/applications-module.h"
+#include "ns3/point-to-point-layout-module.h"
+
+using namespace ns3;
+
+AnimationInterface * pAnim = 0;
+
+struct rgb {
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+};
+
+struct rgb colors [] = {
+ { 255, 0, 0 }, // Red
+ { 0, 255, 0 }, // Blue
+ { 0, 0, 255 } // Green
+ };
+
+uint32_t resourceId1;
+uint32_t resourceId2;
+uint32_t nodeCounterIdUint32;
+uint32_t nodeCounterIdDouble1;
+uint32_t nodeCounterIdDouble2;
+
+void modify ()
+{
+ std::ostringstream oss;
+ oss << "Update:" << Simulator::Now ().GetSeconds ();
+ pAnim->UpdateLinkDescription (0, 1, oss.str ());
+ pAnim->UpdateLinkDescription (0, 2, oss.str ());
+ pAnim->UpdateLinkDescription (0, 3, oss.str ());
+ pAnim->UpdateLinkDescription (0, 4, oss.str ());
+ pAnim->UpdateLinkDescription (0, 5, oss.str ());
+ pAnim->UpdateLinkDescription (0, 6, oss.str ());
+ pAnim->UpdateLinkDescription (1, 7, oss.str ());
+ pAnim->UpdateLinkDescription (1, 8, oss.str ());
+ pAnim->UpdateLinkDescription (1, 9, oss.str ());
+ pAnim->UpdateLinkDescription (1, 10, oss.str ());
+ pAnim->UpdateLinkDescription (1, 11, oss.str ());
+
+ // Every update change the node description for node 2
+ std::ostringstream node0Oss;
+ node0Oss << "-----Node:" << Simulator::Now ().GetSeconds ();
+ pAnim->UpdateNodeDescription (2, node0Oss.str ());
+ static double size = 2;
+ static uint32_t currentResourceId = resourceId1;
+ pAnim->UpdateNodeSize (2, size, size);
+ pAnim->UpdateNodeImage (3, currentResourceId);
+ size *= 1.1;
+ if (size > 20)
+ size = 1;
+ pAnim->UpdateNodeSize (3, 10, 10);
+ if (currentResourceId == resourceId1)
+ currentResourceId = resourceId2;
+ else
+ currentResourceId = resourceId1;
+
+ // Every update change the color for node 4
+ static uint32_t index = 0;
+ index++;
+ if (index == 3)
+ index = 0;
+ struct rgb color = colors[index];
+ for (uint32_t nodeId = 4; nodeId < 12; ++nodeId)
+ pAnim->UpdateNodeColor (nodeId, color.r, color.g, color.b);
+
+ // Update Node Counter for node 0 and node 5, use some random number between 0 to 1000 for value
+ Ptr <UniformRandomVariable> rv = CreateObject<UniformRandomVariable> ();
+ pAnim->UpdateNodeCounter (nodeCounterIdUint32, 0, rv->GetValue (0, 1000));
+ pAnim->UpdateNodeCounter (nodeCounterIdDouble1, 0, rv->GetValue (100.0, 200.0));
+ pAnim->UpdateNodeCounter (nodeCounterIdDouble2, 0, rv->GetValue (300.0, 400.0));
+ pAnim->UpdateNodeCounter (nodeCounterIdUint32, 5, rv->GetValue (0, 1000));
+ pAnim->UpdateNodeCounter (nodeCounterIdDouble1, 5, rv->GetValue (100.0, 200.0));
+ pAnim->UpdateNodeCounter (nodeCounterIdDouble2, 5, rv->GetValue (300.0, 400.0));
+
+ if (Simulator::Now ().GetSeconds () < 10) // This is important or the simulation
+ // will run endlessly
+ Simulator::Schedule (Seconds (0.1), modify);
+
+}
+
+int main (int argc, char *argv[])
+{
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s"));
+
+ uint32_t nLeftLeaf = 5;
+ uint32_t nRightLeaf = 5;
+ uint32_t nLeaf = 0; // If non-zero, number of both left and right
+ std::string animFile = "resources_demo.xml" ; // Name of file for animation output
+
+ CommandLine cmd;
+ cmd.AddValue ("nLeftLeaf", "Number of left side leaf nodes", nLeftLeaf);
+ cmd.AddValue ("nRightLeaf","Number of right side leaf nodes", nRightLeaf);
+ cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf);
+ cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
+
+ cmd.Parse (argc,argv);
+ if (nLeaf > 0)
+ {
+ nLeftLeaf = nLeaf;
+ nRightLeaf = nLeaf;
+ }
+
+ // Create the point-to-point link helpers
+ PointToPointHelper pointToPointRouter;
+ pointToPointRouter.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
+ pointToPointRouter.SetChannelAttribute ("Delay", StringValue ("1ms"));
+ PointToPointHelper pointToPointLeaf;
+ pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
+ pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms"));
+
+ PointToPointDumbbellHelper d (nLeftLeaf, pointToPointLeaf,
+ nRightLeaf, pointToPointLeaf,
+ pointToPointRouter);
+
+ // Install Stack
+ InternetStackHelper stack;
+ d.InstallStack (stack);
+
+ // Assign IP Addresses
+ d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
+ Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"),
+ Ipv4AddressHelper ("10.3.1.0", "255.255.255.0"));
+
+ d.BoundingBox (1, 1, 100, 100);
+ // Install on/off app on all right side nodes
+ OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
+ clientHelper.SetAttribute
+ ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
+ clientHelper.SetAttribute
+ ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
+ ApplicationContainer clientApps;
+
+ for (uint32_t i = 0; i < d.RightCount (); ++i)
+ {
+ // Create an on/off app sending packets to the same leaf right side
+ AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), 1000));
+ clientHelper.SetAttribute ("Remote", remoteAddress);
+ clientApps.Add (clientHelper.Install (d.GetRight (i)));
+ }
+
+ clientApps.Start (Seconds (0.0));
+ clientApps.Stop (Seconds (5.0));
+
+ // Set the bounding box for animation
+
+
+ // Create the animation object and configure for specified output
+ pAnim = new AnimationInterface (animFile);
+ // Provide the absolute path to the resource
+ resourceId1 = pAnim->AddResource ("/Users/john/ns3/netanim-3.105/ns-3-logo1.png");
+ resourceId2 = pAnim->AddResource ("/Users/john/ns3/netanim-3.105/ns-3-logo2.png");
+ pAnim->SetBackgroundImage ("/Users/john/ns3/netanim-3.105/ns-3-background.png", 0, 0, 0.2, 0.2, 0.1);
+
+
+ // Add a node counter
+ nodeCounterIdUint32 = pAnim->AddNodeCounter ("Uint32 Counter", AnimationInterface::UINT32_COUNTER);
+ nodeCounterIdDouble1 = pAnim->AddNodeCounter ("Double Counter 1", AnimationInterface::DOUBLE_COUNTER);
+ nodeCounterIdDouble2 = pAnim->AddNodeCounter ("Double Counter 2", AnimationInterface::DOUBLE_COUNTER);
+
+ Simulator::Schedule (Seconds (0.1), modify);
+
+ // Set up the acutal simulation
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ Simulator::Run ();
+ std::cout << "Animation Trace file created:" << animFile.c_str ()<< std::endl;
+ Simulator::Destroy ();
+ delete pAnim;
+ return 0;
+}
+
--- a/src/netanim/examples/resources_demo.cc Wed Sep 30 22:24:08 2015 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,199 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: John Abraham <[email protected]>
- */
-
-#include <iostream>
-
-#include "ns3/core-module.h"
-#include "ns3/network-module.h"
-#include "ns3/internet-module.h"
-#include "ns3/point-to-point-module.h"
-#include "ns3/netanim-module.h"
-#include "ns3/applications-module.h"
-#include "ns3/point-to-point-layout-module.h"
-
-using namespace ns3;
-
-AnimationInterface * pAnim = 0;
-
-struct rgb {
- uint8_t r;
- uint8_t g;
- uint8_t b;
-};
-
-struct rgb colors [] = {
- { 255, 0, 0 }, // Red
- { 0, 255, 0 }, // Blue
- { 0, 0, 255 } // Green
- };
-
-uint32_t resourceId1;
-uint32_t resourceId2;
-uint32_t nodeCounterIdUint32;
-uint32_t nodeCounterIdDouble1;
-uint32_t nodeCounterIdDouble2;
-
-void modify ()
-{
- std::ostringstream oss;
- oss << "Update:" << Simulator::Now ().GetSeconds ();
- pAnim->UpdateLinkDescription (0, 1, oss.str ());
- pAnim->UpdateLinkDescription (0, 2, oss.str ());
- pAnim->UpdateLinkDescription (0, 3, oss.str ());
- pAnim->UpdateLinkDescription (0, 4, oss.str ());
- pAnim->UpdateLinkDescription (0, 5, oss.str ());
- pAnim->UpdateLinkDescription (0, 6, oss.str ());
- pAnim->UpdateLinkDescription (1, 7, oss.str ());
- pAnim->UpdateLinkDescription (1, 8, oss.str ());
- pAnim->UpdateLinkDescription (1, 9, oss.str ());
- pAnim->UpdateLinkDescription (1, 10, oss.str ());
- pAnim->UpdateLinkDescription (1, 11, oss.str ());
-
- // Every update change the node description for node 2
- std::ostringstream node0Oss;
- node0Oss << "-----Node:" << Simulator::Now ().GetSeconds ();
- pAnim->UpdateNodeDescription (2, node0Oss.str ());
- static double size = 2;
- static uint32_t currentResourceId = resourceId1;
- pAnim->UpdateNodeSize (2, size, size);
- pAnim->UpdateNodeImage (3, currentResourceId);
- size *= 1.1;
- if (size > 20)
- size = 1;
- pAnim->UpdateNodeSize (3, 10, 10);
- if (currentResourceId == resourceId1)
- currentResourceId = resourceId2;
- else
- currentResourceId = resourceId1;
-
- // Every update change the color for node 4
- static uint32_t index = 0;
- index++;
- if (index == 3)
- index = 0;
- struct rgb color = colors[index];
- for (uint32_t nodeId = 4; nodeId < 12; ++nodeId)
- pAnim->UpdateNodeColor (nodeId, color.r, color.g, color.b);
-
- // Update Node Counter for node 0 and node 5, use some random number between 0 to 1000 for value
- Ptr <UniformRandomVariable> rv = CreateObject<UniformRandomVariable> ();
- pAnim->UpdateNodeCounter (nodeCounterIdUint32, 0, rv->GetValue (0, 1000));
- pAnim->UpdateNodeCounter (nodeCounterIdDouble1, 0, rv->GetValue (100.0, 200.0));
- pAnim->UpdateNodeCounter (nodeCounterIdDouble2, 0, rv->GetValue (300.0, 400.0));
- pAnim->UpdateNodeCounter (nodeCounterIdUint32, 5, rv->GetValue (0, 1000));
- pAnim->UpdateNodeCounter (nodeCounterIdDouble1, 5, rv->GetValue (100.0, 200.0));
- pAnim->UpdateNodeCounter (nodeCounterIdDouble2, 5, rv->GetValue (300.0, 400.0));
-
- if (Simulator::Now ().GetSeconds () < 10) // This is important or the simulation
- // will run endlessly
- Simulator::Schedule (Seconds (0.1), modify);
-
-}
-
-int main (int argc, char *argv[])
-{
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s"));
-
- uint32_t nLeftLeaf = 5;
- uint32_t nRightLeaf = 5;
- uint32_t nLeaf = 0; // If non-zero, number of both left and right
- std::string animFile = "resources_demo.xml" ; // Name of file for animation output
-
- CommandLine cmd;
- cmd.AddValue ("nLeftLeaf", "Number of left side leaf nodes", nLeftLeaf);
- cmd.AddValue ("nRightLeaf","Number of right side leaf nodes", nRightLeaf);
- cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf);
- cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
-
- cmd.Parse (argc,argv);
- if (nLeaf > 0)
- {
- nLeftLeaf = nLeaf;
- nRightLeaf = nLeaf;
- }
-
- // Create the point-to-point link helpers
- PointToPointHelper pointToPointRouter;
- pointToPointRouter.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
- pointToPointRouter.SetChannelAttribute ("Delay", StringValue ("1ms"));
- PointToPointHelper pointToPointLeaf;
- pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
- pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms"));
-
- PointToPointDumbbellHelper d (nLeftLeaf, pointToPointLeaf,
- nRightLeaf, pointToPointLeaf,
- pointToPointRouter);
-
- // Install Stack
- InternetStackHelper stack;
- d.InstallStack (stack);
-
- // Assign IP Addresses
- d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
- Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"),
- Ipv4AddressHelper ("10.3.1.0", "255.255.255.0"));
-
- d.BoundingBox (1, 1, 100, 100);
- // Install on/off app on all right side nodes
- OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
- clientHelper.SetAttribute
- ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
- clientHelper.SetAttribute
- ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
- ApplicationContainer clientApps;
-
- for (uint32_t i = 0; i < d.RightCount (); ++i)
- {
- // Create an on/off app sending packets to the same leaf right side
- AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), 1000));
- clientHelper.SetAttribute ("Remote", remoteAddress);
- clientApps.Add (clientHelper.Install (d.GetRight (i)));
- }
-
- clientApps.Start (Seconds (0.0));
- clientApps.Stop (Seconds (5.0));
-
- // Set the bounding box for animation
-
-
- // Create the animation object and configure for specified output
- pAnim = new AnimationInterface (animFile);
- // Provide the absolute path to the resource
- resourceId1 = pAnim->AddResource ("/Users/john/ns3/netanim-3.105/ns-3-logo1.png");
- resourceId2 = pAnim->AddResource ("/Users/john/ns3/netanim-3.105/ns-3-logo2.png");
- pAnim->SetBackgroundImage ("/Users/john/ns3/netanim-3.105/ns-3-background.png", 0, 0, 0.2, 0.2, 0.1);
-
-
- // Add a node counter
- nodeCounterIdUint32 = pAnim->AddNodeCounter ("Uint32 Counter", AnimationInterface::UINT32_COUNTER);
- nodeCounterIdDouble1 = pAnim->AddNodeCounter ("Double Counter 1", AnimationInterface::DOUBLE_COUNTER);
- nodeCounterIdDouble2 = pAnim->AddNodeCounter ("Double Counter 2", AnimationInterface::DOUBLE_COUNTER);
-
- Simulator::Schedule (Seconds (0.1), modify);
-
- // Set up the acutal simulation
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- Simulator::Run ();
- std::cout << "Animation Trace file created:" << animFile.c_str ()<< std::endl;
- Simulator::Destroy ();
- delete pAnim;
- return 0;
-}
-
--- a/src/netanim/examples/wscript Wed Sep 30 22:24:08 2015 +0200
+++ b/src/netanim/examples/wscript Thu Oct 01 07:59:09 2015 -0700
@@ -21,10 +21,10 @@
['netanim', 'internet', 'mobility', 'applications', 'uan'])
obj.source = 'uan-animation.cc'
- obj = bld.create_ns3_program('dynamic_linknode',
+ obj = bld.create_ns3_program('colors-link-description',
['netanim', 'applications', 'point-to-point-layout'])
- obj.source = 'dynamic_linknode.cc'
+ obj.source = 'colors-link-description.cc'
- obj = bld.create_ns3_program('resources_demo',
+ obj = bld.create_ns3_program('resources-counters',
['netanim', 'applications', 'point-to-point-layout'])
- obj.source = 'resources_demo.cc'
+ obj.source = 'resources-counters.cc'
--- a/src/netanim/model/animation-interface.cc Wed Sep 30 22:24:08 2015 +0200
+++ b/src/netanim/model/animation-interface.cc Thu Oct 01 07:59:09 2015 -0700
@@ -1997,13 +1997,46 @@
template <typename T>
void
-AnimationInterface::AnimXmlElement::AddAttribute (std::string attribute, T value)
+AnimationInterface::AnimXmlElement::AddAttribute (std::string attribute, T value, bool xmlEscape)
{
std::ostringstream oss;
oss << std::setprecision (10);
oss << value;
m_elementString += attribute.c_str ();
- m_elementString += "=\"" + oss.str () + "\" ";
+ if (xmlEscape)
+ {
+ m_elementString += "=\"";
+ std::string valueStr = oss.str ();
+ for (std::string::iterator it = valueStr.begin (); it != valueStr.end (); ++it)
+ {
+ switch (*it)
+ {
+ case '&':
+ m_elementString += "&";
+ break;
+ case '\"':
+ m_elementString += """;
+ break;
+ case '\'':
+ m_elementString += "'";
+ break;
+ case '<':
+ m_elementString += "<";
+ break;
+ case '>':
+ m_elementString += ">";
+ break;
+ default:
+ m_elementString += *it;
+ break;
+ }
+ }
+ m_elementString += "\" ";
+ }
+ else
+ {
+ m_elementString += "=\"" + oss.str () + "\" ";
+ }
}
void
@@ -2102,7 +2135,7 @@
element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
element.AddAttribute ("fromId", fromId);
element.AddAttribute ("toId", toId);
- element.AddAttribute ("ld", linkDescription);
+ element.AddAttribute ("ld", linkDescription, true);
element.CloseElement ();
WriteN (element.GetElementString (), m_f);
}
@@ -2130,9 +2163,9 @@
lprop = m_linkProperties[p2];
}
- element.AddAttribute ("fd", lprop.fromNodeDescription);
- element.AddAttribute ("td", lprop.toNodeDescription);
- element.AddAttribute ("ld", lprop.linkDescription);
+ element.AddAttribute ("fd", lprop.fromNodeDescription, true);
+ element.AddAttribute ("td", lprop.toNodeDescription, true);
+ element.AddAttribute ("ld", lprop.linkDescription, true);
element.CloseElement ();
WriteN (element.GetElementString (), m_f);
}
@@ -2143,7 +2176,7 @@
AnimXmlElement element ("rt");
element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
element.AddAttribute ("id", nodeId);
- element.AddAttribute ("info", routingInfo.c_str ());
+ element.AddAttribute ("info", routingInfo.c_str (), true);
element.CloseElement ();
WriteN (element.GetElementString (), m_routingF);
}
@@ -2184,7 +2217,7 @@
element.AddAttribute ("fbTx", fbTx);
if (!metaInfo.empty ())
{
- element.AddAttribute ("meta-info", metaInfo.c_str ());
+ element.AddAttribute ("meta-info", metaInfo.c_str (), true);
}
element.CloseElement ();
WriteN (element.GetElementString (), m_f);
@@ -2212,7 +2245,7 @@
element.AddAttribute ("lbTx", lbTx);
if (!metaInfo.empty ())
{
- element.AddAttribute ("meta-info", metaInfo.c_str ());
+ element.AddAttribute ("meta-info", metaInfo.c_str (), true);
}
element.AddAttribute ("tId", tId);
element.AddAttribute ("fbRx", fbRx);
@@ -2303,7 +2336,7 @@
element.AddAttribute ("id", nodeId);
if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ())
{
- element.AddAttribute ("descr", m_nodeDescriptions[nodeId]);
+ element.AddAttribute ("descr", m_nodeDescriptions[nodeId], true);
}
element.CloseElement ();
WriteN (element.GetElementString (), m_f);
--- a/src/netanim/model/animation-interface.h Wed Sep 30 22:24:08 2015 +0200
+++ b/src/netanim/model/animation-interface.h Thu Oct 01 07:59:09 2015 -0700
@@ -520,7 +520,7 @@
public:
AnimXmlElement (std::string tagName, bool emptyElement=true);
template <typename T>
- void AddAttribute (std::string attribute, T value);
+ void AddAttribute (std::string attribute, T value, bool xmlEscape=false);
void Close ();
void CloseElement ();
void CloseTag ();