Add netanim module
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -4,22 +4,12 @@ def build(bld):
|
||||
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)
|
||||
|
||||
|
||||
121
src/netanim/examples/dumbbell-animation.cc
Normal file
121
src/netanim/examples/dumbbell-animation.cc
Normal file
@@ -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<riley@ece.gatech.edu>
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
||||
109
src/netanim/examples/grid-animation.cc
Normal file
109
src/netanim/examples/grid-animation.cc
Normal file
@@ -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 <jpelkey@gatech.edu>
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
||||
137
src/netanim/examples/star-animation.cc
Normal file
137
src/netanim/examples/star-animation.cc
Normal file
@@ -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;
|
||||
}
|
||||
1
src/netanim/examples/waf
vendored
Normal file
1
src/netanim/examples/waf
vendored
Normal file
@@ -0,0 +1 @@
|
||||
exec "`dirname "$0"`"/../../waf "$@"
|
||||
14
src/netanim/examples/wscript
Normal file
14
src/netanim/examples/wscript
Normal file
@@ -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'
|
||||
1
src/netanim/waf
vendored
Executable file
1
src/netanim/waf
vendored
Executable file
@@ -0,0 +1 @@
|
||||
exec "`dirname "$0"`"/../../waf "$@"
|
||||
31
src/netanim/wscript
Normal file
31
src/netanim/wscript
Normal file
@@ -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)
|
||||
|
||||
@@ -10,9 +10,6 @@ def build(bld):
|
||||
'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 @@ def build(bld):
|
||||
'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',
|
||||
]
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ all_modules = (
|
||||
'mobility',
|
||||
'wifi',
|
||||
'helper',
|
||||
'netanim',
|
||||
'stats',
|
||||
'uan',
|
||||
'spectrum',
|
||||
@@ -79,7 +80,7 @@ def configure(conf):
|
||||
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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user