--- a/examples/animation/dumbbell-animation.cc Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,121 +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: George F. Riley<[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/helper-module.h"
-#include "ns3/applications-module.h"
-#include "ns3/ipv4-global-routing-helper.h"
-
-using namespace ns3;
-
-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
- uint16_t port = 0; // If non zero, port to bind to for anim connection
- std::string animFile; // 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 ("port", "Port Number for Remote Animation", port);
- 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"));
-
- // Install on/off app on all right side nodes
- OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
- clientHelper.SetAttribute
- ("OnTime", RandomVariableValue (UniformVariable (0, 1)));
- clientHelper.SetAttribute
- ("OffTime", RandomVariableValue (UniformVariable (0, 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
- d.BoundingBox (1, 1, 10, 10);
-
- // Create the animation object and configure for specified output
- AnimationInterface anim;
- if (port > 0)
- {
- anim.SetServerPort (port);
- }
- else if (!animFile.empty ())
- {
- anim.SetOutputFile (animFile);
- }
- anim.StartAnimation ();
-
- // Set up the acutal simulation
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- std::cout << "Running the simulation" << std::endl;
- Simulator::Run ();
- std::cout << "Destroying the simulation" << std::endl;
- Simulator::Destroy ();
- std::cout << "Stopping the animation" << std::endl;
- anim.StopAnimation();
- return 0;
-}
--- a/examples/animation/grid-animation.cc Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +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: Josh Pelkey <[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/helper-module.h"
-#include "ns3/applications-module.h"
-#include "ns3/ipv4-global-routing-helper.h"
-
-using namespace ns3;
-
-int main (int argc, char *argv[])
-{
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s"));
-
- uint32_t xSize = 5;
- uint32_t ySize = 5;
- uint16_t port = 0;
- std::string animFile;
-
- CommandLine cmd;
- cmd.AddValue ("xSize", "Number of rows of nodes", xSize);
- cmd.AddValue ("ySize", "Number of columns of nodes", ySize);
- cmd.AddValue ("port", "Port Number for Remote Animation", port);
- cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
-
- cmd.Parse (argc,argv);
- if (xSize < 1 || ySize < 1 || (xSize < 2 && ySize < 2))
- {
- NS_FATAL_ERROR ("Need more nodes for grid.");
- }
-
- PointToPointHelper pointToPoint;
- pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
-
- // Create Grid
- PointToPointGridHelper grid (xSize, ySize, pointToPoint);
-
- // Install stack on Grid
- InternetStackHelper stack;
- grid.InstallStack (stack);
-
- // Assign Addresses to Grid
- grid.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
- Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"));
-
-
- OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
- clientHelper.SetAttribute
- ("OnTime", RandomVariableValue (ConstantVariable (1)));
- clientHelper.SetAttribute
- ("OffTime", RandomVariableValue (ConstantVariable (0)));
- ApplicationContainer clientApps;
-
- // Create an on/off app sending packets
- AddressValue remoteAddress (InetSocketAddress (grid.GetIpv4Address (xSize-1,ySize-1), 1000));
- clientHelper.SetAttribute ("Remote", remoteAddress);
- clientApps.Add (clientHelper.Install (grid.GetNode (0,0)));
-
- clientApps.Start (Seconds (0.0));
- clientApps.Stop (Seconds (1.5));
-
- // Set the bounding box for animation
- grid.BoundingBox (1, 1, 10, 10);
-
- // Create the animation object and configure for specified output
- AnimationInterface anim;
- if (port > 0)
- {
- anim.SetServerPort (port);
- }
- else if (!animFile.empty ())
- {
- anim.SetOutputFile (animFile);
- }
- anim.StartAnimation ();
-
- // Set up the actual simulation
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- std::cout << "Running the simulation" << std::endl;
- Simulator::Run ();
- std::cout << "Destroying the simulation" << std::endl;
- Simulator::Destroy ();
- std::cout << "Stopping the animation" << std::endl;
- anim.StopAnimation();
- return 0;
-}
--- a/examples/animation/star-animation.cc Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +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
- *
- */
-
-#include "ns3/core-module.h"
-#include "ns3/network-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/internet-module.h"
-#include "ns3/point-to-point-module.h"
-#include "ns3/applications-module.h"
-#include "ns3/ipv4-global-routing-helper.h"
-
-// Network topology (default)
-//
-// n2 n3 n4 .
-// \ | / .
-// \|/ .
-// n1--- n0---n5 .
-// /|\ .
-// / | \ .
-// n8 n7 n6 .
-//
-
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("StarAnimation");
-
-int
-main (int argc, char *argv[])
-{
-
- //
- // Set up some default values for the simulation.
- //
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));
-
- // ??? try and stick 15kb/s into the data rate
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"));
-
- //
- // Default number of nodes in the star. Overridable by command line argument.
- //
- uint32_t nSpokes = 8;
- uint32_t animPort = 0;
- std::string animFile;
-
- CommandLine cmd;
- cmd.AddValue("nSpokes", "Number of spoke nodes to place in the star", nSpokes);
- cmd.AddValue ("animPort", "Port Number for Remote Animation", animPort);
- cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
-
- cmd.Parse (argc, argv);
-
- NS_LOG_INFO ("Build star topology.");
- PointToPointHelper pointToPoint;
- pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
- PointToPointStarHelper star (nSpokes, pointToPoint);
-
- NS_LOG_INFO ("Install internet stack on all nodes.");
- InternetStackHelper internet;
- star.InstallStack (internet);
-
- NS_LOG_INFO ("Assign IP Addresses.");
- star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"));
-
- NS_LOG_INFO ("Create applications.");
- //
- // Create a packet sink on the star "hub" to receive packets.
- //
- uint16_t port = 50000;
- Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
- PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
- ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ());
- hubApp.Start (Seconds (1.0));
- hubApp.Stop (Seconds (10.0));
-
- //
- // Create OnOff applications to send TCP to the hub, one on each spoke node.
- //
- OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
- onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-
- ApplicationContainer spokeApps;
-
- for (uint32_t i = 0; i < star.SpokeCount (); ++i)
- {
- AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i), port));
- onOffHelper.SetAttribute ("Remote", remoteAddress);
- spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i)));
- }
- spokeApps.Start (Seconds (1.0));
- spokeApps.Stop (Seconds (10.0));
-
- NS_LOG_INFO ("Enable static global routing.");
- //
- // Turn on global static routing so we can actually be routed across the star.
- //
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- // Set the bounding box for animation
- star.BoundingBox (1, 1, 10, 10);
-
- // Create the animation object and configure for specified output
- AnimationInterface anim;
- if (animPort > 0)
- {
- anim.SetServerPort (animPort);
- }
- else if (!animFile.empty ())
- {
- anim.SetOutputFile (animFile);
- }
- anim.StartAnimation ();
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-
- return 0;
-}
--- a/examples/animation/waf Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-exec "`dirname "$0"`"/../../waf "$@"
--- a/examples/animation/wscript Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
-
-def build(bld):
- obj = bld.create_ns3_program('dumbbell-animation',
- ['point-to-point', 'internet'])
- obj.source = 'dumbbell-animation.cc'
-
- obj = bld.create_ns3_program('grid-animation',
- ['point-to-point', 'internet'])
- obj.source = 'grid-animation.cc'
-
- obj = bld.create_ns3_program('star-animation',
- ['point-to-point', 'internet'])
- obj.source = 'star-animation.cc'
--- a/examples/tcp/star.cc Sat Mar 05 09:33:25 2011 +0000
+++ b/examples/tcp/star.cc Sat Mar 05 10:51:26 2011 -0800
@@ -17,7 +17,7 @@
#include "ns3/core-module.h"
#include "ns3/network-module.h"
-#include "ns3/helper-module.h"
+#include "ns3/netanim-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
--- a/src/aodv/examples/aodv.cc Sat Mar 05 09:33:25 2011 +0000
+++ b/src/aodv/examples/aodv.cc Sat Mar 05 10:51:26 2011 -0800
@@ -23,7 +23,7 @@
#include "ns3/aodv-module.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
-#include "ns3/helper-module.h"
+#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
--- a/src/helper/animation-interface.cc Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,202 +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: George F. Riley<[email protected]>
- */
-
-// Interface between ns3 and the network animator
-
-#include <stdio.h>
-#include <sstream>
-
-#include "ns3/net-anim-config.h"
-
-// Socket related includes
-#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H)
-#include <sys/socket.h>
-#include <netinet/in.h>
-#else
-#include <fcntl.h>
-#endif
-
-// ns3 includes
-#include "ns3/animation-interface.h"
-#include "ns3/channel.h"
-#include "ns3/config.h"
-#include "ns3/node.h"
-#include "ns3/canvas-location.h"
-#include "ns3/packet.h"
-#include "ns3/simulator.h"
-
-using namespace std;
-
-NS_LOG_COMPONENT_DEFINE ("AnimationInterface");
-
-namespace ns3 {
-
-AnimationInterface::AnimationInterface ()
- : m_fHandle (STDOUT_FILENO), m_model (0)
-{
-}
-
-AnimationInterface::~AnimationInterface ()
-{
-}
-
-bool AnimationInterface::SetOutputFile (const std::string& fn)
-{
- FILE* f = fopen (fn.c_str (), "w");
- if (!f)
- {
- return false; // Can't open
- }
- m_fHandle = fileno (f); // Set the file handle
- return true;
-}
-
-bool AnimationInterface::SetServerPort (uint16_t port)
-{
-#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H)
- int s = socket (AF_INET, SOCK_STREAM, 0);
- struct sockaddr_in addr;
- addr.sin_family = AF_INET;
- addr.sin_port = htons (port);
- addr.sin_addr.s_addr = htonl (INADDR_ANY);
- if (bind (s, (struct sockaddr*)&addr, sizeof (addr)) < 0)
- {
- NS_LOG_WARN ("Can't bind to port " << port << ", exiting.");
- return false;
- }
- listen (s, 1);
- NS_LOG_INFO ("Waiting for animator connection");
- // Now wait for the animator to connect in
- m_fHandle = accept (s, 0, 0);
- NS_LOG_INFO ("Got animator connection from remote");
- // set the linger socket option
- int t = 1;
- setsockopt (s, SOL_SOCKET, SO_LINGER, &t, sizeof(t));
- return true;
-#endif
- return false; // never reached unless the above is disabled
- // which is done to support a platform like MinGW
-}
-
-void AnimationInterface::StartAnimation ()
-{
- // Dump the topology
- for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
- {
- Ptr<Node> n = *i;
- Ptr<CanvasLocation> loc = n->GetObject<CanvasLocation> ();
- if (loc)
- {
- // Location exists, dump it
- Vector v = loc->GetLocation ();
- ostringstream oss;
- oss << "0.0 N " << n->GetId ()
- << " " << v.x << " " << v.y << endl;
- WriteN (m_fHandle, oss.str ().c_str (), oss.str ().length ());
- }
- }
- // Now dump the p2p links
- for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
- {
- Ptr<Node> n = *i;
- uint32_t n1Id = n->GetId ();
- uint32_t nDev = n->GetNDevices (); // Number of devices
- for (uint32_t i = 0; i < nDev; ++i)
- {
- Ptr<NetDevice> dev = n->GetDevice (i);
- Ptr<Channel> ch = dev->GetChannel ();
- if (!ch)
- {
- continue; // No channel, can't be p2p device
- }
- string channelType = ch->GetInstanceTypeId ().GetName ();
- if (channelType == string ("ns3::PointToPointChannel"))
- { // Since these are duplex links, we only need to dump
- // if srcid < dstid
- uint32_t nChDev = ch->GetNDevices ();
- for (uint32_t j = 0; j < nChDev; ++j)
- {
- Ptr<NetDevice> chDev = ch->GetDevice (j);
- uint32_t n2Id = chDev->GetNode ()->GetId ();
- if (n1Id < n2Id)
- { // ouptut the p2p link
- ostringstream oss;
- oss << "0.0 L " << n1Id << " " << n2Id << endl;
- WriteN (m_fHandle, oss.str ().c_str (),
- oss.str ().length ());
- }
- }
- }
- else
- {
- NS_FATAL_ERROR ("Net animation currently only supports point-to-point links.");
- }
- }
- }
-
- // Connect the callback for packet tx events
- Config::Connect ("/ChannelList/*/TxRxPointToPoint",
- MakeCallback (&AnimationInterface::DevTxTrace, this));
-}
-
-void AnimationInterface::StopAnimation ()
-{
- if (m_fHandle > 0)
- {
- close (m_fHandle);
- }
-}
-
-
-// Private methods
-int AnimationInterface::WriteN (int h, const char* data, uint32_t count)
-{ // Write count bytes to h from data
- uint32_t nLeft = count;
- const char* p = data;
- uint32_t written = 0;
-
- while (nLeft)
- {
- int n = write (h, p, nLeft);
- if (n <= 0)
- {
- return written;
- }
- written += n;
- nLeft -= n;
- p += n;
- }
- return written;
-}
-
-void AnimationInterface::DevTxTrace (std::string context, Ptr<const Packet> p,
- Ptr<NetDevice> tx, Ptr<NetDevice> rx,
- Time txTime, Time rxTime)
-{
- Time now = Simulator::Now ();
- ostringstream oss;
- oss << now.GetSeconds() << " P "
- << tx->GetNode ()->GetId () << " "
- << rx->GetNode ()->GetId () << " "
- << (now + txTime).GetSeconds () << " " // last bit tx time
- << (now + rxTime - txTime).GetSeconds() << " " // first bit rx time
- << (now + rxTime).GetSeconds () << endl; // last bit rx time
- WriteN (m_fHandle, oss.str ().c_str (), oss.str ().length ());
-}
-
-} // namespace ns3
--- a/src/helper/animation-interface.h Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +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: George F. Riley<[email protected]>
- */
-
-// Interface between ns3 and the network animator
-
-#ifndef ANIMATION_INTERFACE__H
-#define ANIMATION_INTERFACE__H
-
-#include <string>
-
-#include "ns3/ptr.h"
-#include "ns3/net-device.h"
-#include "ns3/nstime.h"
-#include "ns3/log.h"
-#include "ns3/node-list.h"
-
-
-namespace ns3 {
-class NetModel;
-
-/**
- * \brief Interface to network animator
- *
- * Provides functions that facilitate communications with an
- * external or internal network animator.
- */
-class AnimationInterface
-{
-public:
-/**
- * @brief Construct the animator interface. No arguments needed.
- */
- AnimationInterface ();
-/**
- * @brief Destructor for the animator interface.
- */
- ~AnimationInterface ();
-/**
- * @brief Specify that animation commands are to be written
- * to the specified output file.
- *
- * This call is used to write the animation information to a text
- * file that can later be used as input to the network animator tool.
- *
- * @param fn The name of the output file.
- * @returns true if successful open.
- */
- bool SetOutputFile (const std::string& fn);
-
-/**
- * @brief Specify that animation commands are to be written to
- * a socket.
- *
- * This call is used to set the ns3 process in server mode, waiting
- * for a TCP connection from the animator. This call will not
- * return until the animator connects in, or if the bind to the
- * specified port fails.
- *
- * @param port Port number to bind to.
- * @returns true if connection created, false if bind failed.
- */
- bool SetServerPort (uint16_t port);
-
-/**
- * @brief Writes the topology information and sets up the appropriate
- * animation packet tx callback
- *
- * Writes the topology information to the appropriate output, depending
- * on prior calls to SetOutputFile, SetServerPort, or SetInternalAnimation.
- * Then creates the callbacks needed for the animator to start processing
- * packets.
- *
- */
- void StartAnimation ();
-
-/**
- * @brief Closes the interface to the animator.
- *
- */
- void StopAnimation ();
-
-
-private:
- // Packet tx animation callback
- void DevTxTrace (std::string context, Ptr<const Packet> p,
- Ptr<NetDevice> tx, Ptr<NetDevice> rx,
- Time txTime, Time rxTime);
- // Write specified amount of data to the specified handle
- int WriteN (int, const char*, uint32_t);
-private:
- int m_fHandle; // File handle for output (-1 if none)
- NetModel* m_model; // If non nil, points to the internal network model
- // for the interlan animator
-};
-}
-#endif
-
--- a/src/helper/canvas-location.cc Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 Georgia Institute of Technology
- *
- * 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: George Riley<[email protected]>
- */
-
-#include "canvas-location.h"
-
-namespace ns3 {
-
-NS_OBJECT_ENSURE_REGISTERED (CanvasLocation);
-
-TypeId
-CanvasLocation::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::CanvasLocation")
- .SetParent<Object> ()
- .AddAttribute ("Location", "The current location on the canvas.",
- TypeId::ATTR_SET | TypeId::ATTR_GET,
- VectorValue (Vector (0.0, 0.0, 0.0)),
- MakeVectorAccessor (&CanvasLocation::SetLocation,
- &CanvasLocation::GetLocation),
- MakeVectorChecker ())
- ;
- return tid;
-}
-
-CanvasLocation::CanvasLocation ()
-{}
-
-CanvasLocation::~CanvasLocation ()
-{}
-
-Vector
-CanvasLocation::GetLocation (void) const
-{
- return m_location;
-}
-
-void
-CanvasLocation::SetLocation (const Vector &location)
-{
- m_location = location;
-}
-
-} // namespace ns3
--- a/src/helper/canvas-location.h Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 Georgia Institute of Technology
- *
- * 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: George Riley<[email protected]>
- */
-#ifndef CANVAS_LOCATION_H
-#define CANVAS_LOCATION_H
-
-#include "ns3/object.h"
-#include "ns3/traced-callback.h"
-#include "ns3/vector.h"
-
-namespace ns3 {
-
-/**
- * \brief Keep track of the current location of an object
- *
- * This can be used anytime a logical node location is needed
- * (as opposed to a physical location used by the wireless PHY
- * layer to calculate path loss). One potential use of
- * this is by the animator to determine where to position the
- * node icon on the animation display. Location units are
- * arbitrary and dimensionless. In the case of use by the
- * animator they dimensions are in pixels.
- */
-class CanvasLocation : public Object
-{
-public:
- static TypeId GetTypeId (void);
- CanvasLocation ();
- virtual ~CanvasLocation ();
-
- /**
- * \returns the current location
- */
- Vector GetLocation (void) const;
- /**
- * \param location the location to set.
- */
- void SetLocation (const Vector &location);
-private:
- Vector m_location;
-};
-
-}; // namespace ns3
-
-#endif /* CANVAS_LOCATION_H */
--- a/src/helper/wscript Sat Mar 05 09:33:25 2011 +0000
+++ b/src/helper/wscript Sat Mar 05 10:51:26 2011 -0800
@@ -4,22 +4,12 @@
helper = bld.create_ns3_module('helper', ['mobility', 'network', 'internet', 'wifi', 'point-to-point', 'spectrum'])
helper.source = [
'athstats-helper.cc',
- 'animation-interface.cc',
- 'canvas-location.cc',
]
headers = bld.new_task_gen('ns3header')
headers.module = 'helper'
headers.source = [
'athstats-helper.h',
- 'animation-interface.h',
- 'canvas-location.h',
]
env = bld.env_of_name('default')
-
-def configure(conf):
- conf.check(header_name='sys/socket.h', define_name='HAVE_SYS_SOCKET_H')
- conf.check(header_name='netinet/in.h', define_name='HAVE_NETINET_IN_H')
- conf.write_config_header('ns3/net-anim-config.h', top=True)
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/examples/dumbbell-animation.cc Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,121 @@
+/* -*- 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: George F. Riley<[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/ipv4-global-routing-helper.h"
+
+using namespace ns3;
+
+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
+ uint16_t port = 0; // If non zero, port to bind to for anim connection
+ std::string animFile; // 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 ("port", "Port Number for Remote Animation", port);
+ 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"));
+
+ // Install on/off app on all right side nodes
+ OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
+ clientHelper.SetAttribute
+ ("OnTime", RandomVariableValue (UniformVariable (0, 1)));
+ clientHelper.SetAttribute
+ ("OffTime", RandomVariableValue (UniformVariable (0, 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
+ d.BoundingBox (1, 1, 10, 10);
+
+ // Create the animation object and configure for specified output
+ AnimationInterface anim;
+ if (port > 0)
+ {
+ anim.SetServerPort (port);
+ }
+ else if (!animFile.empty ())
+ {
+ anim.SetOutputFile (animFile);
+ }
+ anim.StartAnimation ();
+
+ // Set up the acutal simulation
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ std::cout << "Running the simulation" << std::endl;
+ Simulator::Run ();
+ std::cout << "Destroying the simulation" << std::endl;
+ Simulator::Destroy ();
+ std::cout << "Stopping the animation" << std::endl;
+ anim.StopAnimation();
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/examples/grid-animation.cc Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,109 @@
+/* -*- 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: Josh Pelkey <[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/ipv4-global-routing-helper.h"
+
+using namespace ns3;
+
+int main (int argc, char *argv[])
+{
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s"));
+
+ uint32_t xSize = 5;
+ uint32_t ySize = 5;
+ uint16_t port = 0;
+ std::string animFile;
+
+ CommandLine cmd;
+ cmd.AddValue ("xSize", "Number of rows of nodes", xSize);
+ cmd.AddValue ("ySize", "Number of columns of nodes", ySize);
+ cmd.AddValue ("port", "Port Number for Remote Animation", port);
+ cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
+
+ cmd.Parse (argc,argv);
+ if (xSize < 1 || ySize < 1 || (xSize < 2 && ySize < 2))
+ {
+ NS_FATAL_ERROR ("Need more nodes for grid.");
+ }
+
+ PointToPointHelper pointToPoint;
+ pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+
+ // Create Grid
+ PointToPointGridHelper grid (xSize, ySize, pointToPoint);
+
+ // Install stack on Grid
+ InternetStackHelper stack;
+ grid.InstallStack (stack);
+
+ // Assign Addresses to Grid
+ grid.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
+ Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"));
+
+
+ OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
+ clientHelper.SetAttribute
+ ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ clientHelper.SetAttribute
+ ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ ApplicationContainer clientApps;
+
+ // Create an on/off app sending packets
+ AddressValue remoteAddress (InetSocketAddress (grid.GetIpv4Address (xSize-1,ySize-1), 1000));
+ clientHelper.SetAttribute ("Remote", remoteAddress);
+ clientApps.Add (clientHelper.Install (grid.GetNode (0,0)));
+
+ clientApps.Start (Seconds (0.0));
+ clientApps.Stop (Seconds (1.5));
+
+ // Set the bounding box for animation
+ grid.BoundingBox (1, 1, 10, 10);
+
+ // Create the animation object and configure for specified output
+ AnimationInterface anim;
+ if (port > 0)
+ {
+ anim.SetServerPort (port);
+ }
+ else if (!animFile.empty ())
+ {
+ anim.SetOutputFile (animFile);
+ }
+ anim.StartAnimation ();
+
+ // Set up the actual simulation
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ std::cout << "Running the simulation" << std::endl;
+ Simulator::Run ();
+ std::cout << "Destroying the simulation" << std::endl;
+ Simulator::Destroy ();
+ std::cout << "Stopping the animation" << std::endl;
+ anim.StopAnimation();
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/examples/star-animation.cc Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,137 @@
+/* -*- 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
+ *
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/netanim-module.h"
+#include "ns3/internet-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/applications-module.h"
+#include "ns3/ipv4-global-routing-helper.h"
+
+// Network topology (default)
+//
+// n2 n3 n4 .
+// \ | / .
+// \|/ .
+// n1--- n0---n5 .
+// /|\ .
+// / | \ .
+// n8 n7 n6 .
+//
+
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("StarAnimation");
+
+int
+main (int argc, char *argv[])
+{
+
+ //
+ // Set up some default values for the simulation.
+ //
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));
+
+ // ??? try and stick 15kb/s into the data rate
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"));
+
+ //
+ // Default number of nodes in the star. Overridable by command line argument.
+ //
+ uint32_t nSpokes = 8;
+ uint32_t animPort = 0;
+ std::string animFile;
+
+ CommandLine cmd;
+ cmd.AddValue("nSpokes", "Number of spoke nodes to place in the star", nSpokes);
+ cmd.AddValue ("animPort", "Port Number for Remote Animation", animPort);
+ cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
+
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Build star topology.");
+ PointToPointHelper pointToPoint;
+ pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ PointToPointStarHelper star (nSpokes, pointToPoint);
+
+ NS_LOG_INFO ("Install internet stack on all nodes.");
+ InternetStackHelper internet;
+ star.InstallStack (internet);
+
+ NS_LOG_INFO ("Assign IP Addresses.");
+ star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"));
+
+ NS_LOG_INFO ("Create applications.");
+ //
+ // Create a packet sink on the star "hub" to receive packets.
+ //
+ uint16_t port = 50000;
+ Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
+ PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
+ ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ());
+ hubApp.Start (Seconds (1.0));
+ hubApp.Stop (Seconds (10.0));
+
+ //
+ // Create OnOff applications to send TCP to the hub, one on each spoke node.
+ //
+ OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
+ onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer spokeApps;
+
+ for (uint32_t i = 0; i < star.SpokeCount (); ++i)
+ {
+ AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i), port));
+ onOffHelper.SetAttribute ("Remote", remoteAddress);
+ spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i)));
+ }
+ spokeApps.Start (Seconds (1.0));
+ spokeApps.Stop (Seconds (10.0));
+
+ NS_LOG_INFO ("Enable static global routing.");
+ //
+ // Turn on global static routing so we can actually be routed across the star.
+ //
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ // Set the bounding box for animation
+ star.BoundingBox (1, 1, 10, 10);
+
+ // Create the animation object and configure for specified output
+ AnimationInterface anim;
+ if (animPort > 0)
+ {
+ anim.SetServerPort (animPort);
+ }
+ else if (!animFile.empty ())
+ {
+ anim.SetOutputFile (animFile);
+ }
+ anim.StartAnimation ();
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/examples/waf Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/examples/wscript Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,14 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('dumbbell-animation',
+ ['netanim'])
+ obj.source = 'dumbbell-animation.cc'
+
+ obj = bld.create_ns3_program('grid-animation',
+ ['netanim'])
+ obj.source = 'grid-animation.cc'
+
+ obj = bld.create_ns3_program('star-animation',
+ ['netanim'])
+ obj.source = 'star-animation.cc'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/helper/point-to-point-dumbbell-helper.cc Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,267 @@
+/* -*- 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: George F. Riley<[email protected]>
+ */
+
+// Implement an object to create a dumbbell topology.
+
+#include <iostream>
+#include <sstream>
+
+// ns3 includes
+#include "ns3/animation-interface.h"
+#include "ns3/point-to-point-dumbbell-helper.h"
+#include "ns3/canvas-location.h"
+
+#include "ns3/node-list.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/vector.h"
+
+NS_LOG_COMPONENT_DEFINE("PointToPointDumbbellHelper");
+
+namespace ns3 {
+
+PointToPointDumbbellHelper::PointToPointDumbbellHelper (uint32_t nLeftLeaf,
+ PointToPointHelper leftHelper,
+ uint32_t nRightLeaf,
+ PointToPointHelper rightHelper,
+ PointToPointHelper bottleneckHelper)
+{
+ // Create the bottleneck routers
+ m_routers.Create (2);
+ // Create the leaf nodes
+ m_leftLeaf.Create (nLeftLeaf);
+ m_rightLeaf.Create (nRightLeaf);
+
+ // Add the link connecting routers
+ m_routerDevices = bottleneckHelper.Install (m_routers);
+ // Add the left side links
+ for (uint32_t i = 0; i < nLeftLeaf; ++i)
+ {
+ NetDeviceContainer c = leftHelper.Install (m_routers.Get (0),
+ m_leftLeaf.Get (i));
+ m_leftRouterDevices.Add (c.Get (0));
+ m_leftLeafDevices.Add (c.Get(1));
+ }
+ // Add the right side links
+ for (uint32_t i = 0; i < nRightLeaf; ++i)
+ {
+ NetDeviceContainer c = rightHelper.Install (m_routers.Get (1),
+ m_rightLeaf.Get (i));
+ m_rightRouterDevices.Add (c.Get (0));
+ m_rightLeafDevices.Add (c.Get (1));
+ }
+}
+
+PointToPointDumbbellHelper::~PointToPointDumbbellHelper ()
+{}
+
+Ptr<Node> PointToPointDumbbellHelper::GetLeft () const
+{ // Get the left side bottleneck router
+ return m_routers.Get (0);
+}
+
+Ptr<Node> PointToPointDumbbellHelper::GetLeft (uint32_t i) const
+{ // Get the i'th left side leaf
+ return m_leftLeaf.Get (i);
+}
+
+Ptr<Node> PointToPointDumbbellHelper::GetRight () const
+{ // Get the right side bottleneck router
+ return m_routers.Get (1);
+}
+
+Ptr<Node> PointToPointDumbbellHelper::GetRight (uint32_t i) const
+{ // Get the i'th right side leaf
+ return m_rightLeaf.Get (i);
+}
+
+Ipv4Address PointToPointDumbbellHelper::GetLeftIpv4Address (uint32_t i) const
+{
+ return m_leftLeafInterfaces.GetAddress (i);
+}
+
+Ipv4Address PointToPointDumbbellHelper::GetRightIpv4Address (uint32_t i) const
+{
+ return m_rightLeafInterfaces.GetAddress (i);
+}
+
+uint32_t PointToPointDumbbellHelper::LeftCount () const
+{ // Number of left side nodes
+ return m_leftLeaf.GetN ();
+}
+
+uint32_t PointToPointDumbbellHelper::RightCount () const
+{ // Number of right side nodes
+ return m_rightLeaf.GetN ();
+}
+
+void PointToPointDumbbellHelper::InstallStack (InternetStackHelper stack)
+{
+ stack.Install (m_routers);
+ stack.Install (m_leftLeaf);
+ stack.Install (m_rightLeaf);
+}
+
+void PointToPointDumbbellHelper::AssignIpv4Addresses (Ipv4AddressHelper leftIp,
+ Ipv4AddressHelper rightIp,
+ Ipv4AddressHelper routerIp)
+{
+ // Assign the router network
+ m_routerInterfaces = routerIp.Assign (m_routerDevices);
+ // Assign to left side
+ for (uint32_t i = 0; i < LeftCount (); ++i)
+ {
+ NetDeviceContainer ndc;
+ ndc.Add (m_leftLeafDevices.Get (i));
+ ndc.Add (m_leftRouterDevices.Get (i));
+ Ipv4InterfaceContainer ifc = leftIp.Assign(ndc);
+ m_leftLeafInterfaces.Add (ifc.Get (0));
+ m_leftRouterInterfaces.Add (ifc.Get (1));
+ leftIp.NewNetwork ();
+ }
+ // Assign to right side
+ for (uint32_t i = 0; i < RightCount (); ++i)
+ {
+ NetDeviceContainer ndc;
+ ndc.Add (m_rightLeafDevices.Get (i));
+ ndc.Add (m_rightRouterDevices.Get (i));
+ Ipv4InterfaceContainer ifc = rightIp.Assign (ndc);
+ m_rightLeafInterfaces.Add (ifc.Get (0));
+ m_rightRouterInterfaces.Add (ifc.Get (1));
+ rightIp.NewNetwork ();
+ }
+}
+
+
+void PointToPointDumbbellHelper::BoundingBox (double ulx, double uly, // Upper left x/y
+ double lrx, double lry) // Lower right y
+{
+ double xDist;
+ double yDist;
+ if (lrx > ulx)
+ {
+ xDist = lrx - ulx;
+ }
+ else
+ {
+ xDist = ulx - lrx;
+ }
+ if (lry > uly)
+ {
+ yDist = lry - uly;
+ }
+ else
+ {
+ yDist = uly - lry;
+ }
+
+ double xAdder = xDist / 3.0;
+ double thetaL = M_PI / (LeftCount () + 1.0);
+ double thetaR = M_PI / (RightCount () + 1.0);
+
+ // Place the left router
+ Ptr<Node> lr = GetLeft ();
+ Ptr<CanvasLocation> loc = lr->GetObject<CanvasLocation> ();
+ if (loc == 0)
+ {
+ loc = CreateObject<CanvasLocation> ();
+ lr->AggregateObject (loc);
+ }
+ Vector lrl (ulx + xAdder, uly + yDist/2.0, 0);
+ loc->SetLocation (lrl);
+
+ // Place the right router
+ Ptr<Node> rr = GetRight ();
+ loc = rr->GetObject<CanvasLocation> ();
+ if (loc == 0)
+ {
+ loc = CreateObject<CanvasLocation> ();
+ rr->AggregateObject (loc);
+ }
+ Vector rrl (ulx + xAdder * 2, uly + yDist/2.0, 0); // Right router location
+ loc->SetLocation (rrl);
+
+ // Place the left leaf nodes
+ double theta = -M_PI_2 + thetaL;
+ for (uint32_t l = 0; l < LeftCount (); ++l)
+ {
+ // Make them in a circular pattern to make all line lengths the same
+ // Special case when theta = 0, to be sure we get a straight line
+ if ((LeftCount () % 2) == 1)
+ { // Count is odd, see if we are in middle
+ if (l == (LeftCount () / 2))
+ {
+ theta = 0.0;
+ }
+ }
+ Ptr<Node> ln = GetLeft (l);
+ loc = ln->GetObject<CanvasLocation> ();
+ if (loc == 0)
+ {
+ loc = CreateObject<CanvasLocation> ();
+ ln->AggregateObject (loc);
+ }
+ Vector lnl (lrl.x - cos (theta) * xAdder,
+ lrl.y + sin (theta) * xAdder, 0); // Left Node Location
+ // Insure did not exceed bounding box
+ if (lnl.y < uly)
+ {
+ lnl.y = uly; // Set to upper right y
+ }
+ if (lnl.y > lry)
+ {
+ lnl.y = lry; // Set to lower right y
+ }
+ loc->SetLocation (lnl);
+ theta += thetaL;
+ }
+ // Place the right nodes
+ theta = -M_PI_2 + thetaR;
+ for (uint32_t r = 0; r < RightCount (); ++r)
+ {
+ // Special case when theta = 0, to be sure we get a straight line
+ if ((RightCount () % 2) == 1)
+ { // Count is odd, see if we are in middle
+ if (r == (RightCount () / 2))
+ {
+ theta = 0.0;
+ }
+ }
+ Ptr<Node> rn = GetRight (r);
+ loc = rn->GetObject<CanvasLocation> ();
+ if (loc == 0)
+ {
+ loc = CreateObject<CanvasLocation> ();
+ rn->AggregateObject (loc);
+ }
+ Vector rnl (rrl.x + cos (theta) * xAdder, // Right node location
+ rrl.y + sin (theta) * xAdder, 0);
+ // Insure did not exceed bounding box
+ if (rnl.y < uly)
+ {
+ rnl.y = uly; // Set to upper right y
+ }
+ if (rnl.y > lry)
+ {
+ rnl.y = lry; // Set to lower right y
+ }
+ loc->SetLocation (rnl);
+ theta += thetaR;
+ }
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/helper/point-to-point-dumbbell-helper.h Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,160 @@
+/* -*- 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: George F. Riley<[email protected]>
+ */
+
+// Define an object to create a dumbbell topology.
+
+#ifndef POINT_TO_POINT_DUMBBELL_HELPER_H
+#define POINT_TO_POINT_DUMBBELL_HELPER_H
+
+#include <string>
+
+#include "point-to-point-helper.h"
+#include "ipv4-address-helper.h"
+#include "internet-stack-helper.h"
+#include "ipv4-interface-container.h"
+
+namespace ns3 {
+
+/**
+ * \brief A helper to make it easier to create a dumbbell topology
+ * with p2p links
+ */
+class PointToPointDumbbellHelper
+{
+public:
+ /**
+ * Create a PointToPointDumbbellHelper in order to easily create
+ * dumbbell topologies using p2p links
+ *
+ * \param nLeftLeaf number of left side leaf nodes in the dumbbell
+ *
+ * \param leftHelper PointToPointHelper used to install the links
+ * between the left leaf nodes and the left-most
+ * router
+ *
+ * \param nRightLeaf number of right side leaf nodes in the dumbbell
+ *
+ * \param rightHelper PointToPointHelper used to install the links
+ * between the right leaf nodes and the right-most
+ * router
+ *
+ * \param bottleneckHelper PointToPointHelper used to install the link
+ * between the inner-routers, usually known as
+ * the bottleneck link
+ */
+ PointToPointDumbbellHelper (uint32_t nLeftLeaf,
+ PointToPointHelper leftHelper,
+ uint32_t nRightLeaf,
+ PointToPointHelper rightHelper,
+ PointToPointHelper bottleneckHelper);
+
+ ~PointToPointDumbbellHelper ();
+
+public:
+ /**
+ * \returns pointer to the node of the left side bottleneck
+ * router
+ */
+ Ptr<Node> GetLeft () const;
+
+ /**
+ * \returns pointer to the i'th left side leaf node
+ */
+ Ptr<Node> GetLeft (uint32_t i) const;
+
+ /**
+ * \returns pointer to the node of the right side bottleneck
+ * router
+ */
+ Ptr<Node> GetRight () const;
+
+ /**
+ * \returns pointer to the i'th left side leaf node
+ */
+ Ptr<Node> GetRight (uint32_t i) const;
+
+ /**
+ * \returns an Ipv4Address of the i'th left leaf
+ */
+ Ipv4Address GetLeftIpv4Address (uint32_t i ) const; // Get left leaf address
+
+ /**
+ * \returns an Ipv4Address of the i'th right leaf
+ */
+ Ipv4Address GetRightIpv4Address (uint32_t i) const; // Get right leaf address
+
+ /**
+ * \returns total number of left side leaf nodes
+ */
+ uint32_t LeftCount () const;
+
+ /**
+ * \returns total number of right side leaf nodes
+ */
+ uint32_t RightCount () const;
+
+ /**
+ * \param stack an InternetStackHelper which is used to install
+ * on every node in the dumbbell
+ */
+ void InstallStack (InternetStackHelper stack);
+
+ /**
+ * \param leftIp Ipv4AddressHelper to assign Ipv4 addresses to the
+ * interfaces on the left side of the dumbbell
+ *
+ * \param rightIp Ipv4AddressHelper to assign Ipv4 addresses to the
+ * interfaces on the right side of the dumbbell
+ *
+ * \param routerIp Ipv4AddressHelper to assign Ipv4 addresses to the
+ * interfaces on the bottleneck link
+ */
+ void AssignIpv4Addresses (Ipv4AddressHelper leftIp,
+ Ipv4AddressHelper rightIp,
+ Ipv4AddressHelper routerIp);
+
+ /**
+ * Sets up the node canvas locations for every node in the dumbbell.
+ * This is needed for use with the animation interface
+ *
+ * \param ulx upper left x value
+ * \param uly upper left y value
+ * \param lrx lower right x value
+ * \param lry lower right y value
+ */
+ void BoundingBox (double ulx, double uly, double lrx, double lry);
+
+private:
+ NodeContainer m_leftLeaf;
+ NetDeviceContainer m_leftLeafDevices;
+ NodeContainer m_rightLeaf;
+ NetDeviceContainer m_rightLeafDevices;
+ NodeContainer m_routers;
+ NetDeviceContainer m_routerDevices; // just two connecting the routers
+ NetDeviceContainer m_leftRouterDevices;
+ NetDeviceContainer m_rightRouterDevices;
+ Ipv4InterfaceContainer m_leftLeafInterfaces;
+ Ipv4InterfaceContainer m_leftRouterInterfaces;
+ Ipv4InterfaceContainer m_rightLeafInterfaces;
+ Ipv4InterfaceContainer m_rightRouterInterfaces;
+ Ipv4InterfaceContainer m_routerInterfaces;
+};
+
+} // namespace ns3
+
+#endif /* POINT_TO_POINT_DUMBBELL_HELPER_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/helper/point-to-point-grid-helper.cc Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,216 @@
+/* -*- 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: Josh Pelkey <[email protected]>
+ */
+
+#include "ns3/point-to-point-grid-helper.h"
+#include "ns3/animation-interface.h"
+#include "ns3/internet-stack-helper.h"
+#include "ns3/point-to-point-helper.h"
+#include "ns3/canvas-location.h"
+#include "ns3/string.h"
+#include "ns3/vector.h"
+#include "ns3/log.h"
+
+NS_LOG_COMPONENT_DEFINE("PointToPointGridHelper");
+
+namespace ns3 {
+
+PointToPointGridHelper::PointToPointGridHelper (uint32_t nRows,
+ uint32_t nCols,
+ PointToPointHelper pointToPoint)
+ : m_xSize (nCols), m_ySize (nRows)
+{
+ // Bounds check
+ if (m_xSize < 1 || m_ySize < 1 || (m_xSize < 2 && m_ySize < 2))
+ {
+ NS_FATAL_ERROR ("Need more nodes for grid.");
+ }
+
+ InternetStackHelper stack;
+
+ for (uint32_t y = 0; y < nRows; ++y)
+ {
+ NodeContainer rowNodes;
+ NetDeviceContainer rowDevices;
+ NetDeviceContainer colDevices;
+
+ for (uint32_t x = 0; x < nCols; ++x)
+ {
+ rowNodes.Create (1);
+
+ // install p2p links across the row
+ if (x > 0)
+ {
+ rowDevices.Add (pointToPoint.
+ Install (rowNodes.Get (x-1), rowNodes.Get (x)));
+ }
+
+ // install vertical p2p links
+ if (y > 0)
+ {
+ colDevices.Add(pointToPoint.
+ Install ((m_nodes.at (y-1)).Get (x), rowNodes.Get (x)));
+ }
+ }
+
+ m_nodes.push_back (rowNodes);
+ m_rowDevices.push_back (rowDevices);
+
+ if (y > 0)
+ m_colDevices.push_back (colDevices);
+ }
+}
+
+PointToPointGridHelper::~PointToPointGridHelper ()
+{}
+
+void
+PointToPointGridHelper::InstallStack (InternetStackHelper stack)
+{
+ for (uint32_t i = 0; i < m_nodes.size (); ++i)
+ {
+ NodeContainer rowNodes = m_nodes[i];
+ for (uint32_t j = 0; j < rowNodes.GetN (); ++j)
+ {
+ stack.Install (rowNodes.Get (j));
+ }
+ }
+}
+
+void
+PointToPointGridHelper::AssignIpv4Addresses (Ipv4AddressHelper rowIp, Ipv4AddressHelper colIp)
+{
+ // Assign addresses to all row devices in the grid.
+ // These devices are stored in a vector. Each row
+ // of the grid has all the row devices in one entry
+ // of the vector. These entries come in pairs.
+ for (uint32_t i = 0; i < m_rowDevices.size (); ++i)
+ {
+ Ipv4InterfaceContainer rowInterfaces;
+ NetDeviceContainer rowContainer = m_rowDevices[i];
+ for (uint32_t j = 0; j < rowContainer.GetN (); j+=2)
+ {
+ rowInterfaces.Add (rowIp.Assign (rowContainer.Get (j)));
+ rowInterfaces.Add (rowIp.Assign (rowContainer.Get (j+1)));
+ rowIp.NewNetwork ();
+ }
+ m_rowInterfaces.push_back (rowInterfaces);
+ }
+
+ // Assign addresses to all col devices in the grid.
+ // These devices are stored in a vector. Each col
+ // of the grid has all the col devices in one entry
+ // of the vector. These entries come in pairs.
+ for (uint32_t i = 0; i < m_colDevices.size (); ++i)
+ {
+ Ipv4InterfaceContainer colInterfaces;
+ NetDeviceContainer colContainer = m_colDevices[i];
+ for (uint32_t j = 0; j < colContainer.GetN (); j+=2)
+ {
+ colInterfaces.Add (colIp.Assign (colContainer.Get (j)));
+ colInterfaces.Add (colIp.Assign (colContainer.Get (j+1)));
+ colIp.NewNetwork ();
+ }
+ m_colInterfaces.push_back (colInterfaces);
+ }
+}
+
+void
+PointToPointGridHelper::BoundingBox (double ulx, double uly,
+ double lrx, double lry)
+{
+ double xDist;
+ double yDist;
+ if (lrx > ulx)
+ {
+ xDist = lrx - ulx;
+ }
+ else
+ {
+ xDist = ulx - lrx;
+ }
+ if (lry > uly)
+ {
+ yDist = lry - uly;
+ }
+ else
+ {
+ yDist = uly - lry;
+ }
+ double xAdder = xDist / m_xSize;
+ double yAdder = yDist / m_ySize;
+ double yLoc = yDist / 2;
+ for (uint32_t i = 0; i < m_ySize; ++i)
+ {
+ double xLoc = xDist / 2;
+ for (uint32_t j = 0; j < m_xSize; ++j)
+ {
+ Ptr<Node> node = GetNode (i, j);
+ Ptr<CanvasLocation> loc = node->GetObject<CanvasLocation> ();
+ if (loc ==0)
+ {
+ loc = CreateObject<CanvasLocation> ();
+ node->AggregateObject (loc);
+ }
+ Vector locVec (xLoc, yLoc, 0);
+ loc->SetLocation (locVec);
+
+ xLoc += xAdder;
+ }
+ yLoc += yAdder;
+ }
+}
+
+Ptr<Node>
+PointToPointGridHelper::GetNode (uint32_t row, uint32_t col)
+{
+ if (row > m_nodes.size () - 1 ||
+ col > m_nodes.at (row).GetN () - 1)
+ {
+ NS_FATAL_ERROR ("Index out of bounds in PointToPointGridHelper::GetNode.");
+ }
+
+ return (m_nodes.at (row)).Get (col);
+}
+
+Ipv4Address
+PointToPointGridHelper::GetIpv4Address (uint32_t row, uint32_t col)
+{
+ if (row > m_nodes.size () - 1 ||
+ col > m_nodes.at (row).GetN () - 1)
+ {
+ NS_FATAL_ERROR ("Index out of bounds in PointToPointGridHelper::GetIpv4Address.");
+ }
+
+ // Right now this just gets one of the addresses of the
+ // specified node. The exact device can't be specified.
+ // If you picture the grid, the address returned is the
+ // address of the left (row) device of all nodes, with
+ // the exception of the left-most nodes in the grid;
+ // in which case the right (row) device address is
+ // returned
+ if (col == 0)
+ {
+ return (m_rowInterfaces.at (row)).GetAddress (0);
+ }
+ else
+ {
+ return (m_rowInterfaces.at (row)).GetAddress ((2*col)-1);
+ }
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/helper/point-to-point-grid-helper.h Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,125 @@
+/* -*- 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: Josh Pelkey <[email protected]>
+ */
+
+#ifndef POINT_TO_POINT_GRID_HELPER_H
+#define POINT_TO_POINT_GRID_HELPER_H
+
+#include <vector>
+
+#include "internet-stack-helper.h"
+#include "point-to-point-helper.h"
+#include "ipv4-address-helper.h"
+#include "ipv4-interface-container.h"
+#include "net-device-container.h"
+
+namespace ns3 {
+
+/**
+ * \brief A helper to make it easier to create a grid topology
+ * with p2p links
+ */
+class PointToPointGridHelper
+{
+public:
+ /**
+ * Create a PointToPointGridHelper in order to easily create
+ * grid topologies using p2p links
+ *
+ * \param nRows total number of rows in the grid
+ *
+ * \param nCols total number of colums in the grid
+ *
+ * \param pointToPoint the PointToPointHelper which is used
+ * to connect all of the nodes together
+ * in the grid
+ */
+ PointToPointGridHelper (uint32_t nRows,
+ uint32_t nCols,
+ PointToPointHelper pointToPoint);
+
+ ~PointToPointGridHelper ();
+
+ /**
+ * \param row the row address of the node desired
+ *
+ * \param col the column address of the node desired
+ *
+ * \returns a pointer to the node specified by the
+ * (row, col) address
+ */
+ Ptr<Node> GetNode (uint32_t row, uint32_t col);
+
+ /**
+ * This returns an Ipv4 address at the node specified by
+ * the (row, col) address. Technically, a node will have
+ * multiple interfaces in the grid; therefore, it also has
+ * multiple Ipv4 addresses. This method only returns one of
+ * the addresses. If you picture the grid, the address returned
+ * is the left row device of all the nodes, except the left-most
+ * grid nodes, which returns the right row device.
+ *
+ * \param row the row address of the node desired
+ *
+ * \param col the column address of the node desired
+ *
+ * \returns Ipv4Address of one of the interfaces of the node
+ * specified by the (row, col) address
+ */
+ Ipv4Address GetIpv4Address (uint32_t row, uint32_t col);
+
+ /**
+ * \param stack an InternetStackHelper which is used to install
+ * on every node in the grid
+ */
+ void InstallStack (InternetStackHelper stack);
+
+ /**
+ * Assigns Ipv4 addresses to all the row and column interfaces
+ *
+ * \param rowIp the Ipv4AddressHelper used to assign Ipv4 addresses
+ * to all of the row interfaces in the grid
+ *
+ * \param colIp the Ipv4AddressHelper used to assign Ipv4 addresses
+ * to all of the row interfaces in the grid
+ */
+ void AssignIpv4Addresses (Ipv4AddressHelper rowIp, Ipv4AddressHelper colIp);
+
+ /**
+ * Sets up the node canvas locations for every node in the grid.
+ * This is needed for use with the animation interface
+ *
+ * \param ulx upper left x value
+ * \param uly upper left y value
+ * \param lrx lower right x value
+ * \param lry lower right y value
+ */
+ void BoundingBox (double ulx, double uly, double lrx, double lry);
+
+private:
+ uint32_t m_xSize;
+ uint32_t m_ySize;
+ std::vector<NetDeviceContainer> m_rowDevices;
+ std::vector<NetDeviceContainer> m_colDevices;
+ std::vector<Ipv4InterfaceContainer> m_rowInterfaces;
+ std::vector<Ipv4InterfaceContainer> m_colInterfaces;
+ std::vector<NodeContainer> m_nodes;
+};
+
+} // namespace ns3
+
+#endif /* POINT_TO_POINT_GRID_HELPER_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/helper/point-to-point-star-helper.cc Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,159 @@
+/* -*- 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
+ */
+
+#include <iostream>
+#include <sstream>
+
+// ns3 includes
+#include "ns3/animation-interface.h"
+#include "ns3/point-to-point-star-helper.h"
+#include "ns3/canvas-location.h"
+
+#include "ns3/node-list.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/vector.h"
+
+NS_LOG_COMPONENT_DEFINE("PointToPointStarHelper");
+
+namespace ns3 {
+
+PointToPointStarHelper::PointToPointStarHelper (uint32_t numSpokes,
+ PointToPointHelper p2pHelper)
+{
+ m_hub.Create (1);
+ m_spokes.Create (numSpokes);
+
+ for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
+ {
+ NetDeviceContainer nd = p2pHelper.Install (m_hub.Get (0), m_spokes.Get (i));
+ m_hubDevices.Add (nd.Get (0));
+ m_spokeDevices.Add (nd.Get (1));
+ }
+}
+
+PointToPointStarHelper::~PointToPointStarHelper ()
+{}
+
+Ptr<Node>
+PointToPointStarHelper::GetHub () const
+{
+ return m_hub.Get (0);
+}
+
+Ptr<Node>
+PointToPointStarHelper::GetSpokeNode (uint32_t i) const
+{
+ return m_spokes.Get (i);
+}
+
+Ipv4Address
+PointToPointStarHelper::GetHubIpv4Address (uint32_t i) const
+{
+ return m_hubInterfaces.GetAddress (i);
+}
+
+Ipv4Address
+PointToPointStarHelper::GetSpokeIpv4Address (uint32_t i) const
+{
+ return m_spokeInterfaces.GetAddress (i);
+}
+
+uint32_t
+PointToPointStarHelper::SpokeCount () const
+{
+ return m_spokes.GetN ();
+}
+
+void
+PointToPointStarHelper::InstallStack (InternetStackHelper stack)
+{
+ stack.Install (m_hub);
+ stack.Install (m_spokes);
+}
+
+void
+PointToPointStarHelper::AssignIpv4Addresses (Ipv4AddressHelper address)
+{
+ for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
+ {
+ m_hubInterfaces.Add (address.Assign (m_hubDevices.Get (i)));
+ m_spokeInterfaces.Add (address.Assign (m_spokeDevices.Get (i)));
+ address.NewNetwork ();
+ }
+}
+
+void
+PointToPointStarHelper::BoundingBox (double ulx, double uly,
+ double lrx, double lry)
+{
+ double xDist;
+ double yDist;
+ if (lrx > ulx)
+ {
+ xDist = lrx - ulx;
+ }
+ else
+ {
+ xDist = ulx - lrx;
+ }
+ if (lry > uly)
+ {
+ yDist = lry - uly;
+ }
+ else
+ {
+ yDist = uly - lry;
+ }
+
+ // Place the hub
+ Ptr<Node> hub = m_hub.Get (0);
+ Ptr<CanvasLocation> hubLoc = hub->GetObject<CanvasLocation> ();
+ if (hubLoc == 0)
+ {
+ hubLoc = CreateObject<CanvasLocation> ();
+ hub->AggregateObject (hubLoc);
+ }
+ Vector hubVec (ulx + xDist/2.0, uly + yDist/2.0, 0);
+ hubLoc->SetLocation (hubVec);
+
+ double spokeDist;
+ if (xDist > yDist)
+ {
+ spokeDist = yDist/4.0;
+ }
+ else
+ {
+ spokeDist = xDist/4.0;
+ }
+
+ double theta = 2*M_PI/m_spokes.GetN ();
+ for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
+ {
+ Ptr<Node> spokeNode = m_spokes.Get (i);
+ Ptr<CanvasLocation> spokeLoc = spokeNode->GetObject<CanvasLocation> ();
+ if (spokeLoc == 0)
+ {
+ spokeLoc = CreateObject<CanvasLocation> ();
+ spokeNode->AggregateObject (spokeLoc);
+ }
+ Vector spokeVec (hubVec.x + cos (theta*i) * spokeDist,
+ hubVec.y + sin (theta*i) * spokeDist,
+ 0);
+ spokeLoc->SetLocation (spokeVec);
+ }
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/helper/point-to-point-star-helper.h Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,122 @@
+/* -*- 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
+ */
+
+// Define an object to create a dumbbell topology.
+
+#ifndef POINT_TO_POINT_STAR_HELPER_H
+#define POINT_TO_POINT_STAR_HELPER_H
+
+#include <string>
+
+#include "point-to-point-helper.h"
+#include "ipv4-address-helper.h"
+#include "internet-stack-helper.h"
+#include "ipv4-interface-container.h"
+
+namespace ns3 {
+
+/**
+ * \brief A helper to make it easier to create a star topology
+ * with PointToPoint links
+ */
+class PointToPointStarHelper
+{
+public:
+ /**
+ * Create a PointToPointStarHelper in order to easily create
+ * star topologies using p2p links
+ *
+ * \param numSpokes the number of links attached to
+ * the hub node, creating a total of
+ * numSpokes + 1 nodes
+ *
+ * \param p2pHelper the link helper for p2p links,
+ * used to link nodes together
+ */
+ PointToPointStarHelper (uint32_t numSpokes,
+ PointToPointHelper p2pHelper);
+
+ ~PointToPointStarHelper ();
+
+public:
+ /**
+ * \returns a node pointer to the hub node in the
+ * star, i.e., the center node
+ */
+ Ptr<Node> GetHub () const;
+
+ /**
+ * \param i an index into the spokes of the star
+ *
+ * \returns a node pointer to the node at the indexed spoke
+ */
+ Ptr<Node> GetSpokeNode (uint32_t i) const;
+
+ /**
+ * \param i index into the hub interfaces
+ *
+ * \returns Ipv4Address according to indexed hub interface
+ */
+ Ipv4Address GetHubIpv4Address (uint32_t i) const;
+
+ /**
+ * \param i index into the spoke interfaces
+ *
+ * \returns Ipv4Address according to indexed spoke interface
+ */
+ Ipv4Address GetSpokeIpv4Address (uint32_t i) const;
+
+ /**
+ * \returns the total number of spokes in the star
+ */
+ uint32_t SpokeCount () const;
+
+ /**
+ * \param stack an InternetStackHelper which is used to install
+ * on every node in the star
+ */
+ void InstallStack (InternetStackHelper stack);
+
+ /**
+ * \param address an Ipv4AddressHelper which is used to install
+ * Ipv4 addresses on all the node interfaces in
+ * the star
+ */
+ void AssignIpv4Addresses (Ipv4AddressHelper address);
+
+ /**
+ * Sets up the node canvas locations for every node in the star.
+ * This is needed for use with the animation interface
+ *
+ * \param ulx upper left x value
+ * \param uly upper left y value
+ * \param lrx lower right x value
+ * \param lry lower right y value
+ */
+ void BoundingBox (double ulx, double uly, double lrx, double lry);
+
+private:
+ NodeContainer m_hub;
+ NetDeviceContainer m_hubDevices;
+ NodeContainer m_spokes;
+ NetDeviceContainer m_spokeDevices;
+ Ipv4InterfaceContainer m_hubInterfaces;
+ Ipv4InterfaceContainer m_spokeInterfaces;
+};
+
+} // namespace ns3
+
+#endif /* POINT_TO_POINT_STAR_HELPER_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/model/animation-interface.cc Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,202 @@
+/* -*- 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: George F. Riley<[email protected]>
+ */
+
+// Interface between ns3 and the network animator
+
+#include <stdio.h>
+#include <sstream>
+
+#include "ns3/net-anim-config.h"
+
+// Socket related includes
+#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H)
+#include <sys/socket.h>
+#include <netinet/in.h>
+#else
+#include <fcntl.h>
+#endif
+
+// ns3 includes
+#include "ns3/animation-interface.h"
+#include "ns3/channel.h"
+#include "ns3/config.h"
+#include "ns3/node.h"
+#include "ns3/canvas-location.h"
+#include "ns3/packet.h"
+#include "ns3/simulator.h"
+
+using namespace std;
+
+NS_LOG_COMPONENT_DEFINE ("AnimationInterface");
+
+namespace ns3 {
+
+AnimationInterface::AnimationInterface ()
+ : m_fHandle (STDOUT_FILENO), m_model (0)
+{
+}
+
+AnimationInterface::~AnimationInterface ()
+{
+}
+
+bool AnimationInterface::SetOutputFile (const std::string& fn)
+{
+ FILE* f = fopen (fn.c_str (), "w");
+ if (!f)
+ {
+ return false; // Can't open
+ }
+ m_fHandle = fileno (f); // Set the file handle
+ return true;
+}
+
+bool AnimationInterface::SetServerPort (uint16_t port)
+{
+#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H)
+ int s = socket (AF_INET, SOCK_STREAM, 0);
+ struct sockaddr_in addr;
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons (port);
+ addr.sin_addr.s_addr = htonl (INADDR_ANY);
+ if (bind (s, (struct sockaddr*)&addr, sizeof (addr)) < 0)
+ {
+ NS_LOG_WARN ("Can't bind to port " << port << ", exiting.");
+ return false;
+ }
+ listen (s, 1);
+ NS_LOG_INFO ("Waiting for animator connection");
+ // Now wait for the animator to connect in
+ m_fHandle = accept (s, 0, 0);
+ NS_LOG_INFO ("Got animator connection from remote");
+ // set the linger socket option
+ int t = 1;
+ setsockopt (s, SOL_SOCKET, SO_LINGER, &t, sizeof(t));
+ return true;
+#endif
+ return false; // never reached unless the above is disabled
+ // which is done to support a platform like MinGW
+}
+
+void AnimationInterface::StartAnimation ()
+{
+ // Dump the topology
+ for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
+ {
+ Ptr<Node> n = *i;
+ Ptr<CanvasLocation> loc = n->GetObject<CanvasLocation> ();
+ if (loc)
+ {
+ // Location exists, dump it
+ Vector v = loc->GetLocation ();
+ ostringstream oss;
+ oss << "0.0 N " << n->GetId ()
+ << " " << v.x << " " << v.y << endl;
+ WriteN (m_fHandle, oss.str ().c_str (), oss.str ().length ());
+ }
+ }
+ // Now dump the p2p links
+ for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
+ {
+ Ptr<Node> n = *i;
+ uint32_t n1Id = n->GetId ();
+ uint32_t nDev = n->GetNDevices (); // Number of devices
+ for (uint32_t i = 0; i < nDev; ++i)
+ {
+ Ptr<NetDevice> dev = n->GetDevice (i);
+ Ptr<Channel> ch = dev->GetChannel ();
+ if (!ch)
+ {
+ continue; // No channel, can't be p2p device
+ }
+ string channelType = ch->GetInstanceTypeId ().GetName ();
+ if (channelType == string ("ns3::PointToPointChannel"))
+ { // Since these are duplex links, we only need to dump
+ // if srcid < dstid
+ uint32_t nChDev = ch->GetNDevices ();
+ for (uint32_t j = 0; j < nChDev; ++j)
+ {
+ Ptr<NetDevice> chDev = ch->GetDevice (j);
+ uint32_t n2Id = chDev->GetNode ()->GetId ();
+ if (n1Id < n2Id)
+ { // ouptut the p2p link
+ ostringstream oss;
+ oss << "0.0 L " << n1Id << " " << n2Id << endl;
+ WriteN (m_fHandle, oss.str ().c_str (),
+ oss.str ().length ());
+ }
+ }
+ }
+ else
+ {
+ NS_FATAL_ERROR ("Net animation currently only supports point-to-point links.");
+ }
+ }
+ }
+
+ // Connect the callback for packet tx events
+ Config::Connect ("/ChannelList/*/TxRxPointToPoint",
+ MakeCallback (&AnimationInterface::DevTxTrace, this));
+}
+
+void AnimationInterface::StopAnimation ()
+{
+ if (m_fHandle > 0)
+ {
+ close (m_fHandle);
+ }
+}
+
+
+// Private methods
+int AnimationInterface::WriteN (int h, const char* data, uint32_t count)
+{ // Write count bytes to h from data
+ uint32_t nLeft = count;
+ const char* p = data;
+ uint32_t written = 0;
+
+ while (nLeft)
+ {
+ int n = write (h, p, nLeft);
+ if (n <= 0)
+ {
+ return written;
+ }
+ written += n;
+ nLeft -= n;
+ p += n;
+ }
+ return written;
+}
+
+void AnimationInterface::DevTxTrace (std::string context, Ptr<const Packet> p,
+ Ptr<NetDevice> tx, Ptr<NetDevice> rx,
+ Time txTime, Time rxTime)
+{
+ Time now = Simulator::Now ();
+ ostringstream oss;
+ oss << now.GetSeconds() << " P "
+ << tx->GetNode ()->GetId () << " "
+ << rx->GetNode ()->GetId () << " "
+ << (now + txTime).GetSeconds () << " " // last bit tx time
+ << (now + rxTime - txTime).GetSeconds() << " " // first bit rx time
+ << (now + rxTime).GetSeconds () << endl; // last bit rx time
+ WriteN (m_fHandle, oss.str ().c_str (), oss.str ().length ());
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/model/animation-interface.h Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,112 @@
+/* -*- 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: George F. Riley<[email protected]>
+ */
+
+// Interface between ns3 and the network animator
+
+#ifndef ANIMATION_INTERFACE__H
+#define ANIMATION_INTERFACE__H
+
+#include <string>
+
+#include "ns3/ptr.h"
+#include "ns3/net-device.h"
+#include "ns3/nstime.h"
+#include "ns3/log.h"
+#include "ns3/node-list.h"
+
+
+namespace ns3 {
+class NetModel;
+
+/**
+ * \brief Interface to network animator
+ *
+ * Provides functions that facilitate communications with an
+ * external or internal network animator.
+ */
+class AnimationInterface
+{
+public:
+/**
+ * @brief Construct the animator interface. No arguments needed.
+ */
+ AnimationInterface ();
+/**
+ * @brief Destructor for the animator interface.
+ */
+ ~AnimationInterface ();
+/**
+ * @brief Specify that animation commands are to be written
+ * to the specified output file.
+ *
+ * This call is used to write the animation information to a text
+ * file that can later be used as input to the network animator tool.
+ *
+ * @param fn The name of the output file.
+ * @returns true if successful open.
+ */
+ bool SetOutputFile (const std::string& fn);
+
+/**
+ * @brief Specify that animation commands are to be written to
+ * a socket.
+ *
+ * This call is used to set the ns3 process in server mode, waiting
+ * for a TCP connection from the animator. This call will not
+ * return until the animator connects in, or if the bind to the
+ * specified port fails.
+ *
+ * @param port Port number to bind to.
+ * @returns true if connection created, false if bind failed.
+ */
+ bool SetServerPort (uint16_t port);
+
+/**
+ * @brief Writes the topology information and sets up the appropriate
+ * animation packet tx callback
+ *
+ * Writes the topology information to the appropriate output, depending
+ * on prior calls to SetOutputFile, SetServerPort, or SetInternalAnimation.
+ * Then creates the callbacks needed for the animator to start processing
+ * packets.
+ *
+ */
+ void StartAnimation ();
+
+/**
+ * @brief Closes the interface to the animator.
+ *
+ */
+ void StopAnimation ();
+
+
+private:
+ // Packet tx animation callback
+ void DevTxTrace (std::string context, Ptr<const Packet> p,
+ Ptr<NetDevice> tx, Ptr<NetDevice> rx,
+ Time txTime, Time rxTime);
+ // Write specified amount of data to the specified handle
+ int WriteN (int, const char*, uint32_t);
+private:
+ int m_fHandle; // File handle for output (-1 if none)
+ NetModel* m_model; // If non nil, points to the internal network model
+ // for the interlan animator
+};
+}
+#endif
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/model/canvas-location.cc Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 Georgia Institute of Technology
+ *
+ * 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: George Riley<[email protected]>
+ */
+
+#include "canvas-location.h"
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (CanvasLocation);
+
+TypeId
+CanvasLocation::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::CanvasLocation")
+ .SetParent<Object> ()
+ .AddAttribute ("Location", "The current location on the canvas.",
+ TypeId::ATTR_SET | TypeId::ATTR_GET,
+ VectorValue (Vector (0.0, 0.0, 0.0)),
+ MakeVectorAccessor (&CanvasLocation::SetLocation,
+ &CanvasLocation::GetLocation),
+ MakeVectorChecker ())
+ ;
+ return tid;
+}
+
+CanvasLocation::CanvasLocation ()
+{}
+
+CanvasLocation::~CanvasLocation ()
+{}
+
+Vector
+CanvasLocation::GetLocation (void) const
+{
+ return m_location;
+}
+
+void
+CanvasLocation::SetLocation (const Vector &location)
+{
+ m_location = location;
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/model/canvas-location.h Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 Georgia Institute of Technology
+ *
+ * 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: George Riley<[email protected]>
+ */
+#ifndef CANVAS_LOCATION_H
+#define CANVAS_LOCATION_H
+
+#include "ns3/object.h"
+#include "ns3/traced-callback.h"
+#include "ns3/vector.h"
+
+namespace ns3 {
+
+/**
+ * \brief Keep track of the current location of an object
+ *
+ * This can be used anytime a logical node location is needed
+ * (as opposed to a physical location used by the wireless PHY
+ * layer to calculate path loss). One potential use of
+ * this is by the animator to determine where to position the
+ * node icon on the animation display. Location units are
+ * arbitrary and dimensionless. In the case of use by the
+ * animator they dimensions are in pixels.
+ */
+class CanvasLocation : public Object
+{
+public:
+ static TypeId GetTypeId (void);
+ CanvasLocation ();
+ virtual ~CanvasLocation ();
+
+ /**
+ * \returns the current location
+ */
+ Vector GetLocation (void) const;
+ /**
+ * \param location the location to set.
+ */
+ void SetLocation (const Vector &location);
+private:
+ Vector m_location;
+};
+
+}; // namespace ns3
+
+#endif /* CANVAS_LOCATION_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/waf Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/netanim/wscript Sat Mar 05 10:51:26 2011 -0800
@@ -0,0 +1,31 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ module = bld.create_ns3_module('netanim', ['internet', 'point-to-point'])
+ module.includes = '.'
+ module.source = [
+ 'model/animation-interface.cc',
+ 'model/canvas-location.cc',
+ 'helper/point-to-point-dumbbell-helper.cc',
+ 'helper/point-to-point-grid-helper.cc',
+ 'helper/point-to-point-star-helper.cc',
+ ]
+
+ headers = bld.new_task_gen('ns3header')
+ headers.module = 'netanim'
+ headers.source = [
+ 'model/animation-interface.h',
+ 'model/canvas-location.h',
+ 'helper/point-to-point-dumbbell-helper.h',
+ 'helper/point-to-point-grid-helper.h',
+ 'helper/point-to-point-star-helper.h',
+ ]
+
+ if (bld.env['ENABLE_EXAMPLES']):
+ bld.add_subdirs('examples')
+
+def configure(conf):
+ conf.check(header_name='sys/socket.h', define_name='HAVE_SYS_SOCKET_H')
+ conf.check(header_name='netinet/in.h', define_name='HAVE_NETINET_IN_H')
+ conf.write_config_header('ns3/net-anim-config.h', top=True)
+
--- a/src/point-to-point/helper/point-to-point-dumbbell-helper.cc Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,267 +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: George F. Riley<[email protected]>
- */
-
-// Implement an object to create a dumbbell topology.
-
-#include <iostream>
-#include <sstream>
-
-// ns3 includes
-#include "ns3/animation-interface.h"
-#include "ns3/point-to-point-dumbbell-helper.h"
-#include "ns3/canvas-location.h"
-
-#include "ns3/node-list.h"
-#include "ns3/point-to-point-net-device.h"
-#include "ns3/vector.h"
-
-NS_LOG_COMPONENT_DEFINE("PointToPointDumbbellHelper");
-
-namespace ns3 {
-
-PointToPointDumbbellHelper::PointToPointDumbbellHelper (uint32_t nLeftLeaf,
- PointToPointHelper leftHelper,
- uint32_t nRightLeaf,
- PointToPointHelper rightHelper,
- PointToPointHelper bottleneckHelper)
-{
- // Create the bottleneck routers
- m_routers.Create (2);
- // Create the leaf nodes
- m_leftLeaf.Create (nLeftLeaf);
- m_rightLeaf.Create (nRightLeaf);
-
- // Add the link connecting routers
- m_routerDevices = bottleneckHelper.Install (m_routers);
- // Add the left side links
- for (uint32_t i = 0; i < nLeftLeaf; ++i)
- {
- NetDeviceContainer c = leftHelper.Install (m_routers.Get (0),
- m_leftLeaf.Get (i));
- m_leftRouterDevices.Add (c.Get (0));
- m_leftLeafDevices.Add (c.Get(1));
- }
- // Add the right side links
- for (uint32_t i = 0; i < nRightLeaf; ++i)
- {
- NetDeviceContainer c = rightHelper.Install (m_routers.Get (1),
- m_rightLeaf.Get (i));
- m_rightRouterDevices.Add (c.Get (0));
- m_rightLeafDevices.Add (c.Get (1));
- }
-}
-
-PointToPointDumbbellHelper::~PointToPointDumbbellHelper ()
-{}
-
-Ptr<Node> PointToPointDumbbellHelper::GetLeft () const
-{ // Get the left side bottleneck router
- return m_routers.Get (0);
-}
-
-Ptr<Node> PointToPointDumbbellHelper::GetLeft (uint32_t i) const
-{ // Get the i'th left side leaf
- return m_leftLeaf.Get (i);
-}
-
-Ptr<Node> PointToPointDumbbellHelper::GetRight () const
-{ // Get the right side bottleneck router
- return m_routers.Get (1);
-}
-
-Ptr<Node> PointToPointDumbbellHelper::GetRight (uint32_t i) const
-{ // Get the i'th right side leaf
- return m_rightLeaf.Get (i);
-}
-
-Ipv4Address PointToPointDumbbellHelper::GetLeftIpv4Address (uint32_t i) const
-{
- return m_leftLeafInterfaces.GetAddress (i);
-}
-
-Ipv4Address PointToPointDumbbellHelper::GetRightIpv4Address (uint32_t i) const
-{
- return m_rightLeafInterfaces.GetAddress (i);
-}
-
-uint32_t PointToPointDumbbellHelper::LeftCount () const
-{ // Number of left side nodes
- return m_leftLeaf.GetN ();
-}
-
-uint32_t PointToPointDumbbellHelper::RightCount () const
-{ // Number of right side nodes
- return m_rightLeaf.GetN ();
-}
-
-void PointToPointDumbbellHelper::InstallStack (InternetStackHelper stack)
-{
- stack.Install (m_routers);
- stack.Install (m_leftLeaf);
- stack.Install (m_rightLeaf);
-}
-
-void PointToPointDumbbellHelper::AssignIpv4Addresses (Ipv4AddressHelper leftIp,
- Ipv4AddressHelper rightIp,
- Ipv4AddressHelper routerIp)
-{
- // Assign the router network
- m_routerInterfaces = routerIp.Assign (m_routerDevices);
- // Assign to left side
- for (uint32_t i = 0; i < LeftCount (); ++i)
- {
- NetDeviceContainer ndc;
- ndc.Add (m_leftLeafDevices.Get (i));
- ndc.Add (m_leftRouterDevices.Get (i));
- Ipv4InterfaceContainer ifc = leftIp.Assign(ndc);
- m_leftLeafInterfaces.Add (ifc.Get (0));
- m_leftRouterInterfaces.Add (ifc.Get (1));
- leftIp.NewNetwork ();
- }
- // Assign to right side
- for (uint32_t i = 0; i < RightCount (); ++i)
- {
- NetDeviceContainer ndc;
- ndc.Add (m_rightLeafDevices.Get (i));
- ndc.Add (m_rightRouterDevices.Get (i));
- Ipv4InterfaceContainer ifc = rightIp.Assign (ndc);
- m_rightLeafInterfaces.Add (ifc.Get (0));
- m_rightRouterInterfaces.Add (ifc.Get (1));
- rightIp.NewNetwork ();
- }
-}
-
-
-void PointToPointDumbbellHelper::BoundingBox (double ulx, double uly, // Upper left x/y
- double lrx, double lry) // Lower right y
-{
- double xDist;
- double yDist;
- if (lrx > ulx)
- {
- xDist = lrx - ulx;
- }
- else
- {
- xDist = ulx - lrx;
- }
- if (lry > uly)
- {
- yDist = lry - uly;
- }
- else
- {
- yDist = uly - lry;
- }
-
- double xAdder = xDist / 3.0;
- double thetaL = M_PI / (LeftCount () + 1.0);
- double thetaR = M_PI / (RightCount () + 1.0);
-
- // Place the left router
- Ptr<Node> lr = GetLeft ();
- Ptr<CanvasLocation> loc = lr->GetObject<CanvasLocation> ();
- if (loc == 0)
- {
- loc = CreateObject<CanvasLocation> ();
- lr->AggregateObject (loc);
- }
- Vector lrl (ulx + xAdder, uly + yDist/2.0, 0);
- loc->SetLocation (lrl);
-
- // Place the right router
- Ptr<Node> rr = GetRight ();
- loc = rr->GetObject<CanvasLocation> ();
- if (loc == 0)
- {
- loc = CreateObject<CanvasLocation> ();
- rr->AggregateObject (loc);
- }
- Vector rrl (ulx + xAdder * 2, uly + yDist/2.0, 0); // Right router location
- loc->SetLocation (rrl);
-
- // Place the left leaf nodes
- double theta = -M_PI_2 + thetaL;
- for (uint32_t l = 0; l < LeftCount (); ++l)
- {
- // Make them in a circular pattern to make all line lengths the same
- // Special case when theta = 0, to be sure we get a straight line
- if ((LeftCount () % 2) == 1)
- { // Count is odd, see if we are in middle
- if (l == (LeftCount () / 2))
- {
- theta = 0.0;
- }
- }
- Ptr<Node> ln = GetLeft (l);
- loc = ln->GetObject<CanvasLocation> ();
- if (loc == 0)
- {
- loc = CreateObject<CanvasLocation> ();
- ln->AggregateObject (loc);
- }
- Vector lnl (lrl.x - cos (theta) * xAdder,
- lrl.y + sin (theta) * xAdder, 0); // Left Node Location
- // Insure did not exceed bounding box
- if (lnl.y < uly)
- {
- lnl.y = uly; // Set to upper right y
- }
- if (lnl.y > lry)
- {
- lnl.y = lry; // Set to lower right y
- }
- loc->SetLocation (lnl);
- theta += thetaL;
- }
- // Place the right nodes
- theta = -M_PI_2 + thetaR;
- for (uint32_t r = 0; r < RightCount (); ++r)
- {
- // Special case when theta = 0, to be sure we get a straight line
- if ((RightCount () % 2) == 1)
- { // Count is odd, see if we are in middle
- if (r == (RightCount () / 2))
- {
- theta = 0.0;
- }
- }
- Ptr<Node> rn = GetRight (r);
- loc = rn->GetObject<CanvasLocation> ();
- if (loc == 0)
- {
- loc = CreateObject<CanvasLocation> ();
- rn->AggregateObject (loc);
- }
- Vector rnl (rrl.x + cos (theta) * xAdder, // Right node location
- rrl.y + sin (theta) * xAdder, 0);
- // Insure did not exceed bounding box
- if (rnl.y < uly)
- {
- rnl.y = uly; // Set to upper right y
- }
- if (rnl.y > lry)
- {
- rnl.y = lry; // Set to lower right y
- }
- loc->SetLocation (rnl);
- theta += thetaR;
- }
-}
-
-} // namespace ns3
--- a/src/point-to-point/helper/point-to-point-dumbbell-helper.h Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,160 +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: George F. Riley<[email protected]>
- */
-
-// Define an object to create a dumbbell topology.
-
-#ifndef POINT_TO_POINT_DUMBBELL_HELPER_H
-#define POINT_TO_POINT_DUMBBELL_HELPER_H
-
-#include <string>
-
-#include "point-to-point-helper.h"
-#include "ipv4-address-helper.h"
-#include "internet-stack-helper.h"
-#include "ipv4-interface-container.h"
-
-namespace ns3 {
-
-/**
- * \brief A helper to make it easier to create a dumbbell topology
- * with p2p links
- */
-class PointToPointDumbbellHelper
-{
-public:
- /**
- * Create a PointToPointDumbbellHelper in order to easily create
- * dumbbell topologies using p2p links
- *
- * \param nLeftLeaf number of left side leaf nodes in the dumbbell
- *
- * \param leftHelper PointToPointHelper used to install the links
- * between the left leaf nodes and the left-most
- * router
- *
- * \param nRightLeaf number of right side leaf nodes in the dumbbell
- *
- * \param rightHelper PointToPointHelper used to install the links
- * between the right leaf nodes and the right-most
- * router
- *
- * \param bottleneckHelper PointToPointHelper used to install the link
- * between the inner-routers, usually known as
- * the bottleneck link
- */
- PointToPointDumbbellHelper (uint32_t nLeftLeaf,
- PointToPointHelper leftHelper,
- uint32_t nRightLeaf,
- PointToPointHelper rightHelper,
- PointToPointHelper bottleneckHelper);
-
- ~PointToPointDumbbellHelper ();
-
-public:
- /**
- * \returns pointer to the node of the left side bottleneck
- * router
- */
- Ptr<Node> GetLeft () const;
-
- /**
- * \returns pointer to the i'th left side leaf node
- */
- Ptr<Node> GetLeft (uint32_t i) const;
-
- /**
- * \returns pointer to the node of the right side bottleneck
- * router
- */
- Ptr<Node> GetRight () const;
-
- /**
- * \returns pointer to the i'th left side leaf node
- */
- Ptr<Node> GetRight (uint32_t i) const;
-
- /**
- * \returns an Ipv4Address of the i'th left leaf
- */
- Ipv4Address GetLeftIpv4Address (uint32_t i ) const; // Get left leaf address
-
- /**
- * \returns an Ipv4Address of the i'th right leaf
- */
- Ipv4Address GetRightIpv4Address (uint32_t i) const; // Get right leaf address
-
- /**
- * \returns total number of left side leaf nodes
- */
- uint32_t LeftCount () const;
-
- /**
- * \returns total number of right side leaf nodes
- */
- uint32_t RightCount () const;
-
- /**
- * \param stack an InternetStackHelper which is used to install
- * on every node in the dumbbell
- */
- void InstallStack (InternetStackHelper stack);
-
- /**
- * \param leftIp Ipv4AddressHelper to assign Ipv4 addresses to the
- * interfaces on the left side of the dumbbell
- *
- * \param rightIp Ipv4AddressHelper to assign Ipv4 addresses to the
- * interfaces on the right side of the dumbbell
- *
- * \param routerIp Ipv4AddressHelper to assign Ipv4 addresses to the
- * interfaces on the bottleneck link
- */
- void AssignIpv4Addresses (Ipv4AddressHelper leftIp,
- Ipv4AddressHelper rightIp,
- Ipv4AddressHelper routerIp);
-
- /**
- * Sets up the node canvas locations for every node in the dumbbell.
- * This is needed for use with the animation interface
- *
- * \param ulx upper left x value
- * \param uly upper left y value
- * \param lrx lower right x value
- * \param lry lower right y value
- */
- void BoundingBox (double ulx, double uly, double lrx, double lry);
-
-private:
- NodeContainer m_leftLeaf;
- NetDeviceContainer m_leftLeafDevices;
- NodeContainer m_rightLeaf;
- NetDeviceContainer m_rightLeafDevices;
- NodeContainer m_routers;
- NetDeviceContainer m_routerDevices; // just two connecting the routers
- NetDeviceContainer m_leftRouterDevices;
- NetDeviceContainer m_rightRouterDevices;
- Ipv4InterfaceContainer m_leftLeafInterfaces;
- Ipv4InterfaceContainer m_leftRouterInterfaces;
- Ipv4InterfaceContainer m_rightLeafInterfaces;
- Ipv4InterfaceContainer m_rightRouterInterfaces;
- Ipv4InterfaceContainer m_routerInterfaces;
-};
-
-} // namespace ns3
-
-#endif /* POINT_TO_POINT_DUMBBELL_HELPER_H */
--- a/src/point-to-point/helper/point-to-point-grid-helper.cc Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,216 +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: Josh Pelkey <[email protected]>
- */
-
-#include "ns3/point-to-point-grid-helper.h"
-#include "ns3/animation-interface.h"
-#include "ns3/internet-stack-helper.h"
-#include "ns3/point-to-point-helper.h"
-#include "ns3/canvas-location.h"
-#include "ns3/string.h"
-#include "ns3/vector.h"
-#include "ns3/log.h"
-
-NS_LOG_COMPONENT_DEFINE("PointToPointGridHelper");
-
-namespace ns3 {
-
-PointToPointGridHelper::PointToPointGridHelper (uint32_t nRows,
- uint32_t nCols,
- PointToPointHelper pointToPoint)
- : m_xSize (nCols), m_ySize (nRows)
-{
- // Bounds check
- if (m_xSize < 1 || m_ySize < 1 || (m_xSize < 2 && m_ySize < 2))
- {
- NS_FATAL_ERROR ("Need more nodes for grid.");
- }
-
- InternetStackHelper stack;
-
- for (uint32_t y = 0; y < nRows; ++y)
- {
- NodeContainer rowNodes;
- NetDeviceContainer rowDevices;
- NetDeviceContainer colDevices;
-
- for (uint32_t x = 0; x < nCols; ++x)
- {
- rowNodes.Create (1);
-
- // install p2p links across the row
- if (x > 0)
- {
- rowDevices.Add (pointToPoint.
- Install (rowNodes.Get (x-1), rowNodes.Get (x)));
- }
-
- // install vertical p2p links
- if (y > 0)
- {
- colDevices.Add(pointToPoint.
- Install ((m_nodes.at (y-1)).Get (x), rowNodes.Get (x)));
- }
- }
-
- m_nodes.push_back (rowNodes);
- m_rowDevices.push_back (rowDevices);
-
- if (y > 0)
- m_colDevices.push_back (colDevices);
- }
-}
-
-PointToPointGridHelper::~PointToPointGridHelper ()
-{}
-
-void
-PointToPointGridHelper::InstallStack (InternetStackHelper stack)
-{
- for (uint32_t i = 0; i < m_nodes.size (); ++i)
- {
- NodeContainer rowNodes = m_nodes[i];
- for (uint32_t j = 0; j < rowNodes.GetN (); ++j)
- {
- stack.Install (rowNodes.Get (j));
- }
- }
-}
-
-void
-PointToPointGridHelper::AssignIpv4Addresses (Ipv4AddressHelper rowIp, Ipv4AddressHelper colIp)
-{
- // Assign addresses to all row devices in the grid.
- // These devices are stored in a vector. Each row
- // of the grid has all the row devices in one entry
- // of the vector. These entries come in pairs.
- for (uint32_t i = 0; i < m_rowDevices.size (); ++i)
- {
- Ipv4InterfaceContainer rowInterfaces;
- NetDeviceContainer rowContainer = m_rowDevices[i];
- for (uint32_t j = 0; j < rowContainer.GetN (); j+=2)
- {
- rowInterfaces.Add (rowIp.Assign (rowContainer.Get (j)));
- rowInterfaces.Add (rowIp.Assign (rowContainer.Get (j+1)));
- rowIp.NewNetwork ();
- }
- m_rowInterfaces.push_back (rowInterfaces);
- }
-
- // Assign addresses to all col devices in the grid.
- // These devices are stored in a vector. Each col
- // of the grid has all the col devices in one entry
- // of the vector. These entries come in pairs.
- for (uint32_t i = 0; i < m_colDevices.size (); ++i)
- {
- Ipv4InterfaceContainer colInterfaces;
- NetDeviceContainer colContainer = m_colDevices[i];
- for (uint32_t j = 0; j < colContainer.GetN (); j+=2)
- {
- colInterfaces.Add (colIp.Assign (colContainer.Get (j)));
- colInterfaces.Add (colIp.Assign (colContainer.Get (j+1)));
- colIp.NewNetwork ();
- }
- m_colInterfaces.push_back (colInterfaces);
- }
-}
-
-void
-PointToPointGridHelper::BoundingBox (double ulx, double uly,
- double lrx, double lry)
-{
- double xDist;
- double yDist;
- if (lrx > ulx)
- {
- xDist = lrx - ulx;
- }
- else
- {
- xDist = ulx - lrx;
- }
- if (lry > uly)
- {
- yDist = lry - uly;
- }
- else
- {
- yDist = uly - lry;
- }
- double xAdder = xDist / m_xSize;
- double yAdder = yDist / m_ySize;
- double yLoc = yDist / 2;
- for (uint32_t i = 0; i < m_ySize; ++i)
- {
- double xLoc = xDist / 2;
- for (uint32_t j = 0; j < m_xSize; ++j)
- {
- Ptr<Node> node = GetNode (i, j);
- Ptr<CanvasLocation> loc = node->GetObject<CanvasLocation> ();
- if (loc ==0)
- {
- loc = CreateObject<CanvasLocation> ();
- node->AggregateObject (loc);
- }
- Vector locVec (xLoc, yLoc, 0);
- loc->SetLocation (locVec);
-
- xLoc += xAdder;
- }
- yLoc += yAdder;
- }
-}
-
-Ptr<Node>
-PointToPointGridHelper::GetNode (uint32_t row, uint32_t col)
-{
- if (row > m_nodes.size () - 1 ||
- col > m_nodes.at (row).GetN () - 1)
- {
- NS_FATAL_ERROR ("Index out of bounds in PointToPointGridHelper::GetNode.");
- }
-
- return (m_nodes.at (row)).Get (col);
-}
-
-Ipv4Address
-PointToPointGridHelper::GetIpv4Address (uint32_t row, uint32_t col)
-{
- if (row > m_nodes.size () - 1 ||
- col > m_nodes.at (row).GetN () - 1)
- {
- NS_FATAL_ERROR ("Index out of bounds in PointToPointGridHelper::GetIpv4Address.");
- }
-
- // Right now this just gets one of the addresses of the
- // specified node. The exact device can't be specified.
- // If you picture the grid, the address returned is the
- // address of the left (row) device of all nodes, with
- // the exception of the left-most nodes in the grid;
- // in which case the right (row) device address is
- // returned
- if (col == 0)
- {
- return (m_rowInterfaces.at (row)).GetAddress (0);
- }
- else
- {
- return (m_rowInterfaces.at (row)).GetAddress ((2*col)-1);
- }
-}
-
-} // namespace ns3
--- a/src/point-to-point/helper/point-to-point-grid-helper.h Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,125 +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: Josh Pelkey <[email protected]>
- */
-
-#ifndef POINT_TO_POINT_GRID_HELPER_H
-#define POINT_TO_POINT_GRID_HELPER_H
-
-#include <vector>
-
-#include "internet-stack-helper.h"
-#include "point-to-point-helper.h"
-#include "ipv4-address-helper.h"
-#include "ipv4-interface-container.h"
-#include "net-device-container.h"
-
-namespace ns3 {
-
-/**
- * \brief A helper to make it easier to create a grid topology
- * with p2p links
- */
-class PointToPointGridHelper
-{
-public:
- /**
- * Create a PointToPointGridHelper in order to easily create
- * grid topologies using p2p links
- *
- * \param nRows total number of rows in the grid
- *
- * \param nCols total number of colums in the grid
- *
- * \param pointToPoint the PointToPointHelper which is used
- * to connect all of the nodes together
- * in the grid
- */
- PointToPointGridHelper (uint32_t nRows,
- uint32_t nCols,
- PointToPointHelper pointToPoint);
-
- ~PointToPointGridHelper ();
-
- /**
- * \param row the row address of the node desired
- *
- * \param col the column address of the node desired
- *
- * \returns a pointer to the node specified by the
- * (row, col) address
- */
- Ptr<Node> GetNode (uint32_t row, uint32_t col);
-
- /**
- * This returns an Ipv4 address at the node specified by
- * the (row, col) address. Technically, a node will have
- * multiple interfaces in the grid; therefore, it also has
- * multiple Ipv4 addresses. This method only returns one of
- * the addresses. If you picture the grid, the address returned
- * is the left row device of all the nodes, except the left-most
- * grid nodes, which returns the right row device.
- *
- * \param row the row address of the node desired
- *
- * \param col the column address of the node desired
- *
- * \returns Ipv4Address of one of the interfaces of the node
- * specified by the (row, col) address
- */
- Ipv4Address GetIpv4Address (uint32_t row, uint32_t col);
-
- /**
- * \param stack an InternetStackHelper which is used to install
- * on every node in the grid
- */
- void InstallStack (InternetStackHelper stack);
-
- /**
- * Assigns Ipv4 addresses to all the row and column interfaces
- *
- * \param rowIp the Ipv4AddressHelper used to assign Ipv4 addresses
- * to all of the row interfaces in the grid
- *
- * \param colIp the Ipv4AddressHelper used to assign Ipv4 addresses
- * to all of the row interfaces in the grid
- */
- void AssignIpv4Addresses (Ipv4AddressHelper rowIp, Ipv4AddressHelper colIp);
-
- /**
- * Sets up the node canvas locations for every node in the grid.
- * This is needed for use with the animation interface
- *
- * \param ulx upper left x value
- * \param uly upper left y value
- * \param lrx lower right x value
- * \param lry lower right y value
- */
- void BoundingBox (double ulx, double uly, double lrx, double lry);
-
-private:
- uint32_t m_xSize;
- uint32_t m_ySize;
- std::vector<NetDeviceContainer> m_rowDevices;
- std::vector<NetDeviceContainer> m_colDevices;
- std::vector<Ipv4InterfaceContainer> m_rowInterfaces;
- std::vector<Ipv4InterfaceContainer> m_colInterfaces;
- std::vector<NodeContainer> m_nodes;
-};
-
-} // namespace ns3
-
-#endif /* POINT_TO_POINT_GRID_HELPER_H */
--- a/src/point-to-point/helper/point-to-point-star-helper.cc Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,159 +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
- */
-
-#include <iostream>
-#include <sstream>
-
-// ns3 includes
-#include "ns3/animation-interface.h"
-#include "ns3/point-to-point-star-helper.h"
-#include "ns3/canvas-location.h"
-
-#include "ns3/node-list.h"
-#include "ns3/point-to-point-net-device.h"
-#include "ns3/vector.h"
-
-NS_LOG_COMPONENT_DEFINE("PointToPointStarHelper");
-
-namespace ns3 {
-
-PointToPointStarHelper::PointToPointStarHelper (uint32_t numSpokes,
- PointToPointHelper p2pHelper)
-{
- m_hub.Create (1);
- m_spokes.Create (numSpokes);
-
- for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
- {
- NetDeviceContainer nd = p2pHelper.Install (m_hub.Get (0), m_spokes.Get (i));
- m_hubDevices.Add (nd.Get (0));
- m_spokeDevices.Add (nd.Get (1));
- }
-}
-
-PointToPointStarHelper::~PointToPointStarHelper ()
-{}
-
-Ptr<Node>
-PointToPointStarHelper::GetHub () const
-{
- return m_hub.Get (0);
-}
-
-Ptr<Node>
-PointToPointStarHelper::GetSpokeNode (uint32_t i) const
-{
- return m_spokes.Get (i);
-}
-
-Ipv4Address
-PointToPointStarHelper::GetHubIpv4Address (uint32_t i) const
-{
- return m_hubInterfaces.GetAddress (i);
-}
-
-Ipv4Address
-PointToPointStarHelper::GetSpokeIpv4Address (uint32_t i) const
-{
- return m_spokeInterfaces.GetAddress (i);
-}
-
-uint32_t
-PointToPointStarHelper::SpokeCount () const
-{
- return m_spokes.GetN ();
-}
-
-void
-PointToPointStarHelper::InstallStack (InternetStackHelper stack)
-{
- stack.Install (m_hub);
- stack.Install (m_spokes);
-}
-
-void
-PointToPointStarHelper::AssignIpv4Addresses (Ipv4AddressHelper address)
-{
- for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
- {
- m_hubInterfaces.Add (address.Assign (m_hubDevices.Get (i)));
- m_spokeInterfaces.Add (address.Assign (m_spokeDevices.Get (i)));
- address.NewNetwork ();
- }
-}
-
-void
-PointToPointStarHelper::BoundingBox (double ulx, double uly,
- double lrx, double lry)
-{
- double xDist;
- double yDist;
- if (lrx > ulx)
- {
- xDist = lrx - ulx;
- }
- else
- {
- xDist = ulx - lrx;
- }
- if (lry > uly)
- {
- yDist = lry - uly;
- }
- else
- {
- yDist = uly - lry;
- }
-
- // Place the hub
- Ptr<Node> hub = m_hub.Get (0);
- Ptr<CanvasLocation> hubLoc = hub->GetObject<CanvasLocation> ();
- if (hubLoc == 0)
- {
- hubLoc = CreateObject<CanvasLocation> ();
- hub->AggregateObject (hubLoc);
- }
- Vector hubVec (ulx + xDist/2.0, uly + yDist/2.0, 0);
- hubLoc->SetLocation (hubVec);
-
- double spokeDist;
- if (xDist > yDist)
- {
- spokeDist = yDist/4.0;
- }
- else
- {
- spokeDist = xDist/4.0;
- }
-
- double theta = 2*M_PI/m_spokes.GetN ();
- for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
- {
- Ptr<Node> spokeNode = m_spokes.Get (i);
- Ptr<CanvasLocation> spokeLoc = spokeNode->GetObject<CanvasLocation> ();
- if (spokeLoc == 0)
- {
- spokeLoc = CreateObject<CanvasLocation> ();
- spokeNode->AggregateObject (spokeLoc);
- }
- Vector spokeVec (hubVec.x + cos (theta*i) * spokeDist,
- hubVec.y + sin (theta*i) * spokeDist,
- 0);
- spokeLoc->SetLocation (spokeVec);
- }
-}
-
-} // namespace ns3
--- a/src/point-to-point/helper/point-to-point-star-helper.h Sat Mar 05 09:33:25 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,122 +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
- */
-
-// Define an object to create a dumbbell topology.
-
-#ifndef POINT_TO_POINT_STAR_HELPER_H
-#define POINT_TO_POINT_STAR_HELPER_H
-
-#include <string>
-
-#include "point-to-point-helper.h"
-#include "ipv4-address-helper.h"
-#include "internet-stack-helper.h"
-#include "ipv4-interface-container.h"
-
-namespace ns3 {
-
-/**
- * \brief A helper to make it easier to create a star topology
- * with PointToPoint links
- */
-class PointToPointStarHelper
-{
-public:
- /**
- * Create a PointToPointStarHelper in order to easily create
- * star topologies using p2p links
- *
- * \param numSpokes the number of links attached to
- * the hub node, creating a total of
- * numSpokes + 1 nodes
- *
- * \param p2pHelper the link helper for p2p links,
- * used to link nodes together
- */
- PointToPointStarHelper (uint32_t numSpokes,
- PointToPointHelper p2pHelper);
-
- ~PointToPointStarHelper ();
-
-public:
- /**
- * \returns a node pointer to the hub node in the
- * star, i.e., the center node
- */
- Ptr<Node> GetHub () const;
-
- /**
- * \param i an index into the spokes of the star
- *
- * \returns a node pointer to the node at the indexed spoke
- */
- Ptr<Node> GetSpokeNode (uint32_t i) const;
-
- /**
- * \param i index into the hub interfaces
- *
- * \returns Ipv4Address according to indexed hub interface
- */
- Ipv4Address GetHubIpv4Address (uint32_t i) const;
-
- /**
- * \param i index into the spoke interfaces
- *
- * \returns Ipv4Address according to indexed spoke interface
- */
- Ipv4Address GetSpokeIpv4Address (uint32_t i) const;
-
- /**
- * \returns the total number of spokes in the star
- */
- uint32_t SpokeCount () const;
-
- /**
- * \param stack an InternetStackHelper which is used to install
- * on every node in the star
- */
- void InstallStack (InternetStackHelper stack);
-
- /**
- * \param address an Ipv4AddressHelper which is used to install
- * Ipv4 addresses on all the node interfaces in
- * the star
- */
- void AssignIpv4Addresses (Ipv4AddressHelper address);
-
- /**
- * Sets up the node canvas locations for every node in the star.
- * This is needed for use with the animation interface
- *
- * \param ulx upper left x value
- * \param uly upper left y value
- * \param lrx lower right x value
- * \param lry lower right y value
- */
- void BoundingBox (double ulx, double uly, double lrx, double lry);
-
-private:
- NodeContainer m_hub;
- NetDeviceContainer m_hubDevices;
- NodeContainer m_spokes;
- NetDeviceContainer m_spokeDevices;
- Ipv4InterfaceContainer m_hubInterfaces;
- Ipv4InterfaceContainer m_spokeInterfaces;
-};
-
-} // namespace ns3
-
-#endif /* POINT_TO_POINT_STAR_HELPER_H */
--- a/src/point-to-point/wscript Sat Mar 05 09:33:25 2011 +0000
+++ b/src/point-to-point/wscript Sat Mar 05 10:51:26 2011 -0800
@@ -10,9 +10,6 @@
'model/point-to-point-test.cc',
'model/ppp-header.cc',
'helper/point-to-point-helper.cc',
- 'helper/point-to-point-grid-helper.cc',
- 'helper/point-to-point-dumbbell-helper.cc',
- 'helper/point-to-point-star-helper.cc',
]
headers = bld.new_task_gen('ns3header')
headers.module = 'point-to-point'
@@ -22,8 +19,5 @@
'model/point-to-point-remote-channel.h',
'model/ppp-header.h',
'helper/point-to-point-helper.h',
- 'helper/point-to-point-grid-helper.h',
- 'helper/point-to-point-dumbbell-helper.h',
- 'helper/point-to-point-star-helper.h',
]
--- a/src/wscript Sat Mar 05 09:33:25 2011 +0000
+++ b/src/wscript Sat Mar 05 10:51:26 2011 -0800
@@ -38,6 +38,7 @@
'mobility',
'wifi',
'helper',
+ 'netanim',
'stats',
'uan',
'spectrum',
@@ -79,7 +80,7 @@
conf.sub_config('tap-bridge')
conf.sub_config('contrib')
conf.sub_config('internet')
- conf.sub_config('helper')
+ conf.sub_config('netanim')
conf.sub_config('test')
conf.sub_config('click')