1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/mpi/Makefile Mon Nov 02 10:49:39 2009 -0500
1.3 @@ -0,0 +1,32 @@
1.4 +# #################################################################
1.5 +#
1.6 +# !!!!IMPORTANT!!!! <----------------------------------------REALLY
1.7 +# Change the NS3BASE below to the path of your base ns-3
1.8 +# folder as well as the CXX to the path to mpic++
1.9 +#
1.10 +# #################################################################
1.11 +
1.12 +NS3BASE = /home/user/repos/ns-3-distributed
1.13 +CXX = /usr/bin/mpic++
1.14 +CXXFLAGS = -g -Wall -I$(NS3BASE)/build/debug -DNS3_MPI
1.15 +LDFLAGS = -g -L$(NS3BASE)/build/debug -lns3
1.16 +all: nms-udp-nix test-distributed
1.17 +
1.18 +nms-udp-nix: nms-udp-nix.o
1.19 + @echo Linking
1.20 + $(CXX) -o nms-udp-nix nms-udp-nix.o $(LDFLAGS)
1.21 +
1.22 +nms-udp-nix.o: nms-udp-nix.cc
1.23 + $(CXX) -c $(CXXFLAGS) nms-udp-nix.cc
1.24 +
1.25 +test-distributed: test-distributed.o
1.26 + @echo Linking
1.27 + $(CXX) -o test-distributed test-distributed.o $(LDFLAGS)
1.28 +
1.29 +test-distributed.o: test-distributed.cc
1.30 + $(CXX) -c $(CXXFLAGS) test-distributed.cc
1.31 +
1.32 +clean:
1.33 + @rm -f nms-udp-nix nms-udp-nix.o test-distributed test-distributed.o
1.34 + @echo Cleaned
1.35 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/mpi/README Mon Nov 02 10:49:39 2009 -0500
2.3 @@ -0,0 +1,80 @@
2.4 +###########################################################
2.5 +# Steps for building ns-3 with MPI and running the example
2.6 +# programs
2.7 +###########################################################
2.8 +
2.9 +##############################
2.10 +# Before building ns-3 with waf
2.11 +
2.12 +1) Ensure that MPI is installed, as well as mpic++. In Ubuntu
2.13 + repositories, these are openmpi-bin, openmpi-common,
2.14 + openmpi-doc, libopenmpi-dev
2.15 +
2.16 +2) Set the CXX environment variable to the path of mpic++.
2.17 + In bash: export CXX=/usr/bin/mpic++
2.18 + Note: Change the path to your actual path to mpic++
2.19 +
2.20 +3) Configure ns-3 with the --with-mpi option
2.21 + ./waf -d debug configure --with-mpi
2.22 + Ensure that MPI is enabled by checking the
2.23 + Optional features shown from the output of
2.24 + configure.
2.25 +
2.26 +4) Build ns-3 with the --with-mpi option
2.27 + ./waf -d debug --with-mpi
2.28 + Note: You can choose debug or optimized here
2.29 +
2.30 +Notes: If you already built ns-3 without MPI, or without the
2.31 + CXX environment variable set correctly, you must re-build.
2.32 + ./waf distclean
2.33 + Start over at step 1.
2.34 +
2.35 +##############################
2.36 +# After building ns-3 with waf
2.37 +
2.38 +1) Change directories into examples/mpi
2.39 +
2.40 +2) Several environment variables must be set
2.41 + before building the examples:
2.42 +
2.43 + - LD_LIBRARY_PATH should be set to the debug
2.44 + directory in ns-3, as well as the openmpi library
2.45 + Ex: export 'LD_LIBRARY_PATH=/home/user/repos/ns-3-distributed/build/debug:/usr/lib/openmpi/1.2.7-gcc/lib'
2.46 + **NOTE** Do not just copy and paste here. Make sure that these point to the proper directories
2.47 +
2.48 + - CXX (should already be set, per above)
2.49 +
2.50 + - PATH should also contain a path to mpic++ and mpirun.
2.51 + This is likely already taken care of, but if you get
2.52 + errors that mpirun or mpic++ can't be found, make sure
2.53 + this path is set (or type the full path when trying to
2.54 + use these programs).
2.55 +
2.56 +3) Edit the Makefile in the examples/mpi directory. The
2.57 + NS3BASE and CXX lines should be changed. NS3BASE is the
2.58 + path to ns-3 that you have just built. CXX is to mpic++
2.59 +
2.60 +4) Build the programs with make.
2.61 +
2.62 +5) The programs are now ready to run with mpirun. Here are
2.63 + a few examples:
2.64 +
2.65 + mpirun -np 2 ./test-distributed
2.66 + mpirun -np 4 -machinefile mpihosts ./nms-udp-nix --LAN=2 --CN=2 --NIX=1
2.67 +
2.68 + ** NOTE: The np switch is the number of LPs to use. The machinefile
2.69 + switch is which machines to use. This can simply contain
2.70 + something like:
2.71 +
2.72 + localhost
2.73 + localhost
2.74 + localhost
2.75 + ...
2.76 +
2.77 + Or if you have a cluster of machines, you can name them.
2.78 +
2.79 +6) If you get an error trying to run, you've probably missed setting a path.
2.80 + Make sure that you changed the paths in the Makefile. Make sure that
2.81 + LD_LIBRARY_PATH and CXX are set correctly.
2.82 +
2.83 +7) You made it. Have fun!
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/examples/mpi/nms-udp-nix.cc Mon Nov 02 10:49:39 2009 -0500
3.3 @@ -0,0 +1,526 @@
3.4 +// DARPA NMS Campus Network Model
3.5 +// - This topology replicates the original NMS Campus Network model
3.6 +// with the exception of chord links (which were never utilized in the
3.7 +// original model)
3.8 +// - Link Bandwidths and Delays may not be the same as the original
3.9 +// specifications
3.10 +//
3.11 +// (c)2009, GTech Systems, Inc. - Alfred Park <park@gtech-systems.com>
3.12 +//
3.13 +// Modified for distributed simulation by Josh Pelkey <jpelkey@gatech.edu>
3.14 +
3.15 +// for timing functions
3.16 +#include <cstdlib>
3.17 +#include <sys/time.h>
3.18 +#include <fstream>
3.19 +
3.20 +#include "ns3/core-module.h"
3.21 +#include "ns3/simulator-module.h"
3.22 +#include "ns3/node-module.h"
3.23 +#include "ns3/helper-module.h"
3.24 +#include "ns3/global-routing-module.h"
3.25 +#include "ns3/onoff-application.h"
3.26 +#include "ns3/packet-sink.h"
3.27 +#include "ns3/point-to-point-net-device.h"
3.28 +
3.29 +#ifdef NS3_MPI
3.30 +#include <mpi.h>
3.31 +#endif
3.32 +
3.33 +using namespace std;
3.34 +using namespace ns3;
3.35 +
3.36 +typedef struct timeval TIMER_TYPE;
3.37 +#define TIMER_NOW(_t) gettimeofday(&_t,NULL);
3.38 +#define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec*1e-6)
3.39 +#define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS(_t1)-TIMER_SECONDS(_t2))
3.40 +
3.41 +NS_LOG_COMPONENT_DEFINE ("CampusNetworkModel");
3.42 +
3.43 +int
3.44 +main (int argc, char *argv[])
3.45 +{
3.46 + // Enable MPI with the command line arguments
3.47 + MPIInterface::Enable(&argc, &argv);
3.48 +
3.49 + TIMER_TYPE t0, t1, t2;
3.50 + TIMER_NOW(t0);
3.51 + cout << " ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << endl;
3.52 +
3.53 + //RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
3.54 +
3.55 + GlobalValue::Bind("SimulatorImplementationType",
3.56 + StringValue("ns3::DistributedSimulatorImpl"));
3.57 +
3.58 + uint32_t rank = MPIInterface::Rank();;
3.59 + uint32_t systemCount = MPIInterface::Size ();
3.60 +
3.61 + uint32_t nCN = 2, nLANClients = 42;
3.62 + int single = 0; // non zero if use a single flow only
3.63 + int nBytes = 500000; // Bytes for each on/off app
3.64 + bool nix = true;
3.65 +
3.66 + CommandLine cmd;
3.67 + cmd.AddValue("CN", "Number of total CNs [2]", nCN);
3.68 + cmd.AddValue("LAN", "Number of nodes per LAN [42]", nLANClients);
3.69 + cmd.AddValue("single", "1 if use single flow", single);
3.70 + cmd.AddValue("nBytes", "Number of bytes for each on/off app", nBytes);
3.71 + cmd.AddValue("NIX", "Toggle the use of nix-vector or global routing", nix);
3.72 + cmd.Parse(argc,argv);
3.73 +
3.74 + if (nCN < 2) {
3.75 + cout << "Number of total CNs (" << nCN << ") lower than minimum of 2"
3.76 + << endl;
3.77 + return 1;
3.78 + }
3.79 + if (systemCount > nCN) {
3.80 + cout << "Number of total CNs (" << nCN << ") should be >= systemCount ("
3.81 + << systemCount << ")." << endl;
3.82 + return 1;
3.83 + }
3.84 + cout << "Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << endl;
3.85 +
3.86 + NodeContainer nodes_net0[nCN][3], nodes_net1[nCN][6], nodes_netLR[nCN],
3.87 + nodes_net2[nCN][14], nodes_net2LAN[nCN][7][nLANClients],
3.88 + nodes_net3[nCN][9], nodes_net3LAN[nCN][5][nLANClients];
3.89 + PointToPointHelper p2p_2gb200ms, p2p_1gb5ms, p2p_100mb1ms;
3.90 + InternetStackHelper stack;
3.91 + Ipv4InterfaceContainer ifs, ifs0[nCN][3], ifs1[nCN][6], ifs2[nCN][14],
3.92 + ifs3[nCN][9], ifs2LAN[nCN][7][nLANClients],
3.93 + ifs3LAN[nCN][5][nLANClients];
3.94 + Ipv4AddressHelper address;
3.95 + std::ostringstream oss;
3.96 + p2p_1gb5ms.SetDeviceAttribute("DataRate", StringValue("1Gbps"));
3.97 + p2p_1gb5ms.SetChannelAttribute("Delay", StringValue("5ms"));
3.98 + p2p_2gb200ms.SetDeviceAttribute("DataRate", StringValue("2Gbps"));
3.99 + p2p_2gb200ms.SetChannelAttribute("Delay", StringValue("200ms"));
3.100 + p2p_100mb1ms.SetDeviceAttribute("DataRate", StringValue("100Mbps"));
3.101 + p2p_100mb1ms.SetChannelAttribute("Delay", StringValue("1ms"));
3.102 +
3.103 + Ipv4NixVectorHelper nixRouting;
3.104 + Ipv4StaticRoutingHelper staticRouting;
3.105 +
3.106 + Ipv4ListRoutingHelper list;
3.107 + list.Add (staticRouting, 0);
3.108 + list.Add (nixRouting, 10);
3.109 +
3.110 + if (nix)
3.111 + {
3.112 + stack.SetRoutingHelper (list);
3.113 + }
3.114 +
3.115 + // Create Campus Networks
3.116 + for (uint32_t z = 0; z < nCN; ++z) {
3.117 + cout << "Creating Campus Network " << z << ":" << endl;
3.118 + // Create Net0
3.119 + cout << " SubNet [ 0";
3.120 + for (int i = 0; i < 3; ++i) {
3.121 + Ptr<Node> node = CreateObject<Node> (z%systemCount);
3.122 + nodes_net0[z][i].Add (node);
3.123 + stack.Install(nodes_net0[z][i]);
3.124 + }
3.125 + nodes_net0[z][0].Add(nodes_net0[z][1].Get(0));
3.126 + nodes_net0[z][1].Add(nodes_net0[z][2].Get(0));
3.127 + nodes_net0[z][2].Add(nodes_net0[z][0].Get(0));
3.128 + NetDeviceContainer ndc0[3];
3.129 + for (int i = 0; i < 3; ++i) {
3.130 + ndc0[i] = p2p_1gb5ms.Install(nodes_net0[z][i]);
3.131 + }
3.132 + // Create Net1
3.133 + cout << " 1";
3.134 + for (int i = 0; i < 6; ++i) {
3.135 + Ptr<Node> node = CreateObject<Node> (z%systemCount);
3.136 + nodes_net1[z][i].Add (node);
3.137 + stack.Install(nodes_net1[z][i]);
3.138 + }
3.139 + nodes_net1[z][0].Add(nodes_net1[z][1].Get(0));
3.140 + nodes_net1[z][2].Add(nodes_net1[z][0].Get(0));
3.141 + nodes_net1[z][3].Add(nodes_net1[z][0].Get(0));
3.142 + nodes_net1[z][4].Add(nodes_net1[z][1].Get(0));
3.143 + nodes_net1[z][5].Add(nodes_net1[z][1].Get(0));
3.144 + NetDeviceContainer ndc1[6];
3.145 + for (int i = 0; i < 6; ++i) {
3.146 + if (i == 1) continue;
3.147 + ndc1[i] = p2p_1gb5ms.Install(nodes_net1[z][i]);
3.148 + }
3.149 + // Connect Net0 <-> Net1
3.150 + NodeContainer net0_1;
3.151 + net0_1.Add(nodes_net0[z][2].Get(0));
3.152 + net0_1.Add(nodes_net1[z][0].Get(0));
3.153 + NetDeviceContainer ndc0_1;
3.154 + ndc0_1 = p2p_1gb5ms.Install(net0_1);
3.155 + oss.str("");
3.156 + oss << 10 + z << ".1.252.0";
3.157 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.158 + ifs = address.Assign(ndc0_1);
3.159 + // Create Net2
3.160 + cout << " 2";
3.161 + for (int i = 0; i < 14; ++i) {
3.162 + Ptr<Node> node = CreateObject<Node> (z%systemCount);
3.163 + nodes_net2[z][i].Add (node);
3.164 + stack.Install(nodes_net2[z][i]);
3.165 + }
3.166 + nodes_net2[z][0].Add(nodes_net2[z][1].Get(0));
3.167 + nodes_net2[z][2].Add(nodes_net2[z][0].Get(0));
3.168 + nodes_net2[z][1].Add(nodes_net2[z][3].Get(0));
3.169 + nodes_net2[z][3].Add(nodes_net2[z][2].Get(0));
3.170 + nodes_net2[z][4].Add(nodes_net2[z][2].Get(0));
3.171 + nodes_net2[z][5].Add(nodes_net2[z][3].Get(0));
3.172 + nodes_net2[z][6].Add(nodes_net2[z][5].Get(0));
3.173 + nodes_net2[z][7].Add(nodes_net2[z][2].Get(0));
3.174 + nodes_net2[z][8].Add(nodes_net2[z][3].Get(0));
3.175 + nodes_net2[z][9].Add(nodes_net2[z][4].Get(0));
3.176 + nodes_net2[z][10].Add(nodes_net2[z][5].Get(0));
3.177 + nodes_net2[z][11].Add(nodes_net2[z][6].Get(0));
3.178 + nodes_net2[z][12].Add(nodes_net2[z][6].Get(0));
3.179 + nodes_net2[z][13].Add(nodes_net2[z][6].Get(0));
3.180 + NetDeviceContainer ndc2[14];
3.181 + for (int i = 0; i < 14; ++i) {
3.182 + ndc2[i] = p2p_1gb5ms.Install(nodes_net2[z][i]);
3.183 + }
3.184 + NetDeviceContainer ndc2LAN[7][nLANClients];
3.185 + for (int i = 0; i < 7; ++i) {
3.186 + oss.str("");
3.187 + oss << 10 + z << ".4." << 15 + i << ".0";
3.188 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.189 + for (uint32_t j = 0; j < nLANClients; ++j) {
3.190 + Ptr<Node> node = CreateObject<Node> (z%systemCount);
3.191 + nodes_net2LAN[z][i][j].Add (node);
3.192 + stack.Install(nodes_net2LAN[z][i][j]);
3.193 + nodes_net2LAN[z][i][j].Add(nodes_net2[z][i+7].Get(0));
3.194 + ndc2LAN[i][j] = p2p_100mb1ms.Install(nodes_net2LAN[z][i][j]);
3.195 + ifs2LAN[z][i][j] = address.Assign(ndc2LAN[i][j]);
3.196 + }
3.197 + }
3.198 + // Create Net3
3.199 + cout << " 3 ]" << endl;
3.200 + for (int i = 0; i < 9; ++i) {
3.201 + Ptr<Node> node = CreateObject<Node> (z%systemCount);
3.202 + nodes_net3[z][i].Add (node);
3.203 + stack.Install(nodes_net3[z][i]);
3.204 + }
3.205 + nodes_net3[z][0].Add(nodes_net3[z][1].Get(0));
3.206 + nodes_net3[z][1].Add(nodes_net3[z][2].Get(0));
3.207 + nodes_net3[z][2].Add(nodes_net3[z][3].Get(0));
3.208 + nodes_net3[z][3].Add(nodes_net3[z][1].Get(0));
3.209 + nodes_net3[z][4].Add(nodes_net3[z][0].Get(0));
3.210 + nodes_net3[z][5].Add(nodes_net3[z][0].Get(0));
3.211 + nodes_net3[z][6].Add(nodes_net3[z][2].Get(0));
3.212 + nodes_net3[z][7].Add(nodes_net3[z][3].Get(0));
3.213 + nodes_net3[z][8].Add(nodes_net3[z][3].Get(0));
3.214 + NetDeviceContainer ndc3[9];
3.215 + for (int i = 0; i < 9; ++i) {
3.216 + ndc3[i] = p2p_1gb5ms.Install(nodes_net3[z][i]);
3.217 + }
3.218 + NetDeviceContainer ndc3LAN[5][nLANClients];
3.219 + for (int i = 0; i < 5; ++i) {
3.220 + oss.str("");
3.221 + oss << 10 + z << ".5." << 10 + i << ".0";
3.222 + address.SetBase(oss.str().c_str(), "255.255.255.255");
3.223 + for (uint32_t j = 0; j < nLANClients; ++j) {
3.224 + Ptr<Node> node = CreateObject<Node> (z%systemCount);
3.225 + nodes_net3LAN[z][i][j].Add (node);
3.226 + stack.Install(nodes_net3LAN[z][i][j]);
3.227 + nodes_net3LAN[z][i][j].Add(nodes_net3[z][i+4].Get(0));
3.228 + ndc3LAN[i][j] = p2p_100mb1ms.Install(nodes_net3LAN[z][i][j]);
3.229 + ifs3LAN[z][i][j] = address.Assign(ndc3LAN[i][j]);
3.230 + }
3.231 + }
3.232 + cout << " Connecting Subnets..." << endl;
3.233 + // Create Lone Routers (Node 4 & 5)
3.234 + Ptr<Node> node1 = CreateObject<Node> (z%systemCount);
3.235 + Ptr<Node> node2 = CreateObject<Node> (z%systemCount);
3.236 + nodes_netLR[z].Add (node1);
3.237 + nodes_netLR[z].Add (node2);
3.238 + stack.Install(nodes_netLR[z]);
3.239 + NetDeviceContainer ndcLR;
3.240 + ndcLR = p2p_1gb5ms.Install(nodes_netLR[z]);
3.241 + // Connect Net2/Net3 through Lone Routers to Net0
3.242 + NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
3.243 + net0_4.Add(nodes_netLR[z].Get(0));
3.244 + net0_4.Add(nodes_net0[z][0].Get(0));
3.245 + net0_5.Add(nodes_netLR[z].Get(1));
3.246 + net0_5.Add(nodes_net0[z][1].Get(0));
3.247 + net2_4a.Add(nodes_netLR[z].Get(0));
3.248 + net2_4a.Add(nodes_net2[z][0].Get(0));
3.249 + net2_4b.Add(nodes_netLR[z].Get(1));
3.250 + net2_4b.Add(nodes_net2[z][1].Get(0));
3.251 + net3_5a.Add(nodes_netLR[z].Get(1));
3.252 + net3_5a.Add(nodes_net3[z][0].Get(0));
3.253 + net3_5b.Add(nodes_netLR[z].Get(1));
3.254 + net3_5b.Add(nodes_net3[z][1].Get(0));
3.255 + NetDeviceContainer ndc0_4, ndc0_5, ndc2_4a, ndc2_4b, ndc3_5a, ndc3_5b;
3.256 + ndc0_4 = p2p_1gb5ms.Install(net0_4);
3.257 + oss.str("");
3.258 + oss << 10 + z << ".1.253.0";
3.259 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.260 + ifs = address.Assign(ndc0_4);
3.261 + ndc0_5 = p2p_1gb5ms.Install(net0_5);
3.262 + oss.str("");
3.263 + oss << 10 + z << ".1.254.0";
3.264 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.265 + ifs = address.Assign(ndc0_5);
3.266 + ndc2_4a = p2p_1gb5ms.Install(net2_4a);
3.267 + oss.str("");
3.268 + oss << 10 + z << ".4.253.0";
3.269 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.270 + ifs = address.Assign(ndc2_4a);
3.271 + ndc2_4b = p2p_1gb5ms.Install(net2_4b);
3.272 + oss.str("");
3.273 + oss << 10 + z << ".4.254.0";
3.274 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.275 + ifs = address.Assign(ndc2_4b);
3.276 + ndc3_5a = p2p_1gb5ms.Install(net3_5a);
3.277 + oss.str("");
3.278 + oss << 10 + z << ".5.253.0";
3.279 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.280 + ifs = address.Assign(ndc3_5a);
3.281 + ndc3_5b = p2p_1gb5ms.Install(net3_5b);
3.282 + oss.str("");
3.283 + oss << 10 + z << ".5.254.0";
3.284 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.285 + ifs = address.Assign(ndc3_5b);
3.286 + // Assign IP addresses
3.287 + cout << " Assigning IP addresses..." << endl;
3.288 + for (int i = 0; i < 3; ++i) {
3.289 + oss.str("");
3.290 + oss << 10 + z << ".1." << 1 + i << ".0";
3.291 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.292 + ifs0[z][i] = address.Assign(ndc0[i]);
3.293 + }
3.294 + for (int i = 0; i < 6; ++i) {
3.295 + if (i == 1) continue;
3.296 + oss.str("");
3.297 + oss << 10 + z << ".2." << 1 + i << ".0";
3.298 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.299 + ifs1[z][i] = address.Assign(ndc1[i]);
3.300 + }
3.301 + oss.str("");
3.302 + oss << 10 + z << ".3.1.0";
3.303 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.304 + ifs = address.Assign(ndcLR);
3.305 + for (int i = 0; i < 14; ++i) {
3.306 + oss.str("");
3.307 + oss << 10 + z << ".4." << 1 + i << ".0";
3.308 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.309 + ifs2[z][i] = address.Assign(ndc2[i]);
3.310 + }
3.311 + for (int i = 0; i < 9; ++i) {
3.312 + oss.str("");
3.313 + oss << 10 + z << ".5." << 1 + i << ".0";
3.314 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.315 + ifs3[z][i] = address.Assign(ndc3[i]);
3.316 + }
3.317 + }
3.318 + // Create Ring Links
3.319 + if (nCN > 1) {
3.320 + cout << "Forming Ring Topology..." << endl;
3.321 + NodeContainer nodes_ring[nCN];
3.322 + for (uint32_t z = 0; z < nCN-1; ++z) {
3.323 + nodes_ring[z].Add(nodes_net0[z][0].Get(0));
3.324 + nodes_ring[z].Add(nodes_net0[z+1][0].Get(0));
3.325 + }
3.326 + nodes_ring[nCN-1].Add(nodes_net0[nCN-1][0].Get(0));
3.327 + nodes_ring[nCN-1].Add(nodes_net0[0][0].Get(0));
3.328 + NetDeviceContainer ndc_ring[nCN];
3.329 + for (uint32_t z = 0; z < nCN; ++z) {
3.330 + ndc_ring[z] = p2p_2gb200ms.Install(nodes_ring[z]);
3.331 + oss.str("");
3.332 + oss << "254.1." << z + 1 << ".0";
3.333 + address.SetBase(oss.str().c_str(), "255.255.255.0");
3.334 + ifs = address.Assign(ndc_ring[z]);
3.335 + }
3.336 + }
3.337 +
3.338 + // Create Traffic Flows
3.339 + cout << "Creating TCP Traffic Flows:" << endl;
3.340 + Config::SetDefault("ns3::OnOffApplication::MaxBytes", UintegerValue(nBytes));
3.341 + Config::SetDefault("ns3::OnOffApplication::OnTime",
3.342 + RandomVariableValue(ConstantVariable(1)));
3.343 + Config::SetDefault("ns3::OnOffApplication::OffTime",
3.344 + RandomVariableValue(ConstantVariable(0)));
3.345 + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (512));
3.346 +
3.347 +
3.348 + if (single)
3.349 + {
3.350 + cout << "Using single flow." << endl;
3.351 +
3.352 + if (rank == 0)
3.353 + {
3.354 + PacketSinkHelper sinkHelper("ns3::TcpSocketFactory",
3.355 + InetSocketAddress(Ipv4Address::GetAny(),
3.356 + 9999));
3.357 + ApplicationContainer sinkApp = sinkHelper.Install(
3.358 + nodes_net1[0][2].Get(0));
3.359 + sinkApp.Start(Seconds(100.0));
3.360 +
3.361 + OnOffHelper client("ns3::TcpSocketFactory", Address());
3.362 + AddressValue remoteAddress(InetSocketAddress(
3.363 + ifs1[0][2].GetAddress(0), 9999));
3.364 + cout << "Remote Address is " << ifs1[0][2].GetAddress(0) << endl;
3.365 + client.SetAttribute("Remote", remoteAddress);
3.366 +
3.367 + ApplicationContainer clientApp;
3.368 + clientApp.Add(client.Install(nodes_net2LAN[0][0][0].Get(0)));
3.369 + clientApp.Start(Seconds(100));
3.370 + }
3.371 + }
3.372 + else
3.373 + {
3.374 + UniformVariable urng;
3.375 + int r1;
3.376 + double r2;
3.377 + for (uint32_t z = 0; z < nCN; ++z) {
3.378 + uint32_t x = z + 1;
3.379 + if (z == nCN - 1) {
3.380 + x = 0;
3.381 + }
3.382 + // Subnet 2 LANs
3.383 + cout << " Campus Network " << z << " Flows [ Net2 ";
3.384 + for (int i = 0; i < 7; ++i) {
3.385 + for (uint32_t j = 0; j < nLANClients; ++j) {
3.386 + // Sinks
3.387 + if (systemCount == 1)
3.388 + {
3.389 + PacketSinkHelper sinkHelper("ns3::TcpSocketFactory",
3.390 + InetSocketAddress(Ipv4Address::GetAny(), 9999));
3.391 + ApplicationContainer sinkApp = sinkHelper.Install(
3.392 + nodes_net2LAN[z][i][j].Get(0));
3.393 + sinkApp.Start(Seconds(100.0));
3.394 + }
3.395 + else if (rank == z%systemCount)
3.396 + {
3.397 + PacketSinkHelper sinkHelper("ns3::TcpSocketFactory",
3.398 + InetSocketAddress(Ipv4Address::GetAny(), 9999));
3.399 + ApplicationContainer sinkApp = sinkHelper.Install(
3.400 + nodes_net2LAN[z][i][j].Get(0));
3.401 + sinkApp.Start(Seconds(100.0));
3.402 + }
3.403 + // Sources
3.404 + if (systemCount == 1)
3.405 + {
3.406 + r1 = 2 + (int)(4 * urng.GetValue());
3.407 + r2 = 100 + (10 * urng.GetValue());;
3.408 + OnOffHelper client("ns3::TcpSocketFactory", Address());
3.409 + AddressValue remoteAddress(InetSocketAddress(
3.410 + ifs2LAN[z][i][j].GetAddress(0), 9999));
3.411 + client.SetAttribute("Remote", remoteAddress);
3.412 + ApplicationContainer clientApp;
3.413 + clientApp.Add(client.Install(nodes_net1[x][r1].Get(0)));
3.414 + clientApp.Start(Seconds(r2));
3.415 + }
3.416 + else if (rank == x%systemCount)
3.417 + {
3.418 + r1 = 2 + (int)(4 * urng.GetValue());
3.419 + r2 = 100 + (10 * urng.GetValue());;
3.420 + OnOffHelper client("ns3::TcpSocketFactory", Address());
3.421 + AddressValue remoteAddress(InetSocketAddress(
3.422 + ifs2LAN[z][i][j].GetAddress(0), 9999));
3.423 + client.SetAttribute("Remote", remoteAddress);
3.424 + ApplicationContainer clientApp;
3.425 + clientApp.Add(client.Install(nodes_net1[x][r1].Get(0)));
3.426 + clientApp.Start(Seconds(r2));
3.427 + }
3.428 + }
3.429 + }
3.430 + // Subnet 3 LANs
3.431 + cout << "Net3 ]" << endl;
3.432 + for (int i = 0; i < 5; ++i) {
3.433 + for (uint32_t j = 0; j < nLANClients; ++j) {
3.434 + // Sinks
3.435 + if (systemCount == 1)
3.436 + {
3.437 + PacketSinkHelper sinkHelper("ns3::TcpSocketFactory",
3.438 + InetSocketAddress(Ipv4Address::GetAny(), 9999));
3.439 + ApplicationContainer sinkApp = sinkHelper.Install(
3.440 + nodes_net3LAN[z][i][j].Get(0));
3.441 + sinkApp.Start(Seconds(100.0));
3.442 + }
3.443 + else if (rank == z%systemCount)
3.444 + {
3.445 + PacketSinkHelper sinkHelper("ns3::TcpSocketFactory",
3.446 + InetSocketAddress(Ipv4Address::GetAny(), 9999));
3.447 + ApplicationContainer sinkApp = sinkHelper.Install(
3.448 + nodes_net3LAN[z][i][j].Get(0));
3.449 + sinkApp.Start(Seconds(100.0));
3.450 + }
3.451 + // Sources
3.452 + if (systemCount == 1)
3.453 + {
3.454 + r1 = 2 + (int)(4 * urng.GetValue());
3.455 + r2 = 100 + (10 * urng.GetValue());;
3.456 + OnOffHelper client("ns3::TcpSocketFactory", Address());
3.457 + AddressValue remoteAddress(InetSocketAddress(
3.458 + ifs2LAN[z][i][j].GetAddress(0), 9999));
3.459 + client.SetAttribute("Remote", remoteAddress);
3.460 + ApplicationContainer clientApp;
3.461 + clientApp.Add(client.Install(nodes_net1[x][r1].Get(0)));
3.462 + clientApp.Start(Seconds(r2));
3.463 + }
3.464 + else if (rank == x%systemCount)
3.465 + {
3.466 + r1 = 2 + (int)(4 * urng.GetValue());
3.467 + r2 = 100 + (10 * urng.GetValue());;
3.468 + OnOffHelper client("ns3::TcpSocketFactory", Address());
3.469 + AddressValue remoteAddress(InetSocketAddress(
3.470 + ifs2LAN[z][i][j].GetAddress(0), 9999));
3.471 + client.SetAttribute("Remote", remoteAddress);
3.472 + ApplicationContainer clientApp;
3.473 + clientApp.Add(client.Install(nodes_net1[x][r1].Get(0)));
3.474 + clientApp.Start(Seconds(r2));
3.475 + }
3.476 + }
3.477 + }
3.478 + }
3.479 + }
3.480 +
3.481 + cout << "Created " << NodeList::GetNNodes() << " nodes." << endl;
3.482 + TIMER_TYPE routingStart;
3.483 + TIMER_NOW(routingStart);
3.484 +
3.485 + if (nix)
3.486 + {
3.487 + cout << "Using Nix-vectors..." << endl;
3.488 + }
3.489 + else
3.490 + {
3.491 + // Calculate routing tables
3.492 + cout << "Populating Routing tables..." << endl;
3.493 + Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
3.494 + }
3.495 +
3.496 + TIMER_TYPE routingEnd;
3.497 + TIMER_NOW(routingEnd);
3.498 + cout << "Routing tables population took "
3.499 + << TIMER_DIFF(routingEnd, routingStart) << endl;
3.500 +#if 1
3.501 + oss.str("");
3.502 + oss << "nms_udp_nix_rank" << rank << ".tr";
3.503 + std::ofstream ascii;
3.504 + ascii.open(oss.str().c_str());
3.505 + PointToPointHelper::EnableAsciiAll(ascii);
3.506 + CsmaHelper::EnableAsciiAll(ascii);
3.507 +#endif
3.508 +
3.509 +#if 0
3.510 + PointToPointHelper::EnablePcapAll("nms_p2p");
3.511 + CsmaHelper::EnablePcapAll("nms_csma");
3.512 +#endif
3.513 +
3.514 + cout << "Running simulator..." << endl;
3.515 + TIMER_NOW(t1);
3.516 + Simulator::Stop(Seconds(102.0));
3.517 + Simulator::Run();
3.518 + TIMER_NOW(t2);
3.519 + cout << "Simulator finished." << endl;
3.520 + Simulator::Destroy();
3.521 +
3.522 + double d1 = TIMER_DIFF(t1, t0), d2 = TIMER_DIFF(t2, t1);
3.523 + cout << "-----" << endl << "Runtime Stats:" << endl;
3.524 + cout << "Simulator init time: " << d1 << endl;
3.525 + cout << "Simulator run time: " << d2 << endl;
3.526 + cout << "Total elapsed time: " << d1+d2 << endl;
3.527 + return 0;
3.528 +}
3.529 +
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/examples/mpi/test-distributed.cc Mon Nov 02 10:49:39 2009 -0500
4.3 @@ -0,0 +1,254 @@
4.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
4.5 +/*
4.6 + * This program is free software; you can redistribute it and/or modify
4.7 + * it under the terms of the GNU General Public License version 2 as
4.8 + * published by the Free Software Foundation;
4.9 + *
4.10 + * This program is distributed in the hope that it will be useful,
4.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.13 + * GNU General Public License for more details.
4.14 + *
4.15 + * You should have received a copy of the GNU General Public License
4.16 + * along with this program; if not, write to the Free Software
4.17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4.18 + *
4.19 + *
4.20 + * TestDistributed creates a dumbbell topology and logically splits it in
4.21 + * half. The left half is placed on logical processor 0 and the right half
4.22 + * is placed on logical processor 1.
4.23 + *
4.24 + * ------- -------
4.25 + * RANK 0 RANK 1
4.26 + * ------- | -------
4.27 + * |
4.28 + * n0 ---------| | |---------- n6
4.29 + * | | |
4.30 + * n1 -------\ | | | /------- n7
4.31 + * n4 ----------|---------- n5
4.32 + * n2 -------/ | | | \------- n8
4.33 + * | | |
4.34 + * n3 ---------| | |---------- n9
4.35 + *
4.36 + *
4.37 + * OnOff clients are placed on each left leaf node. Each right leaf node
4.38 + * is a packet sink for a left leaf node. As a packet travels from one
4.39 + * logical processor to another (the link between n4 and n5), MPI messages
4.40 + * are passed containing the serialized packet. The message is then
4.41 + * deserialized into a new packet and sent on as normal.
4.42 + *
4.43 + * One packet is sent from each left leaf node. The packet sinks on the
4.44 + * right leaf nodes output logging information when they receive the packet.
4.45 + */
4.46 +
4.47 +#include "ns3/core-module.h"
4.48 +#include "ns3/simulator-module.h"
4.49 +#include "ns3/node-module.h"
4.50 +#include "ns3/helper-module.h"
4.51 +
4.52 +#ifdef NS3_MPI
4.53 +#include <mpi.h>
4.54 +#endif
4.55 +
4.56 +using namespace ns3;
4.57 +
4.58 +NS_LOG_COMPONENT_DEFINE ("TestDistributed");
4.59 +
4.60 +int
4.61 +main (int argc, char *argv[])
4.62 +{
4.63 +#ifdef NS3_MPI
4.64 + // Distributed simulation setup
4.65 + MPIInterface::Enable(&argc, &argv);
4.66 + GlobalValue::Bind("SimulatorImplementationType",
4.67 + StringValue("ns3::DistributedSimulatorImpl"));
4.68 +
4.69 + LogComponentEnable("PacketSink", LOG_LEVEL_INFO);
4.70 +
4.71 + uint32_t rank = MPIInterface::Rank();;
4.72 + uint32_t systemCount = MPIInterface::Size ();
4.73 +
4.74 + // Check for valid distributed parameters.
4.75 + // Must have 2 and only 2 LPs
4.76 + if (systemCount != 2)
4.77 + {
4.78 + std::cout << "This simulation requires 2 and only 2 logical processors." << std::endl;
4.79 + return 1;
4.80 + }
4.81 +
4.82 + // Some default values
4.83 + Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
4.84 + Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("1Mbps"));
4.85 + Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (512));
4.86 + bool nix = true;
4.87 +
4.88 + // Parse command line
4.89 + CommandLine cmd;
4.90 + cmd.AddValue("nix", "Toggle the use of nix-vector or global routing", nix);
4.91 + cmd.Parse (argc, argv);
4.92 +
4.93 + // Create leaf nodes on left with
4.94 + // rank 0
4.95 + NodeContainer leftLeafNodes;
4.96 + for (uint32_t i = 0; i < 4; ++i)
4.97 + {
4.98 + Ptr<Node> node = CreateObject<Node> (0);
4.99 + leftLeafNodes.Add (node);
4.100 + }
4.101 +
4.102 + // Create router nodes. Left router
4.103 + // with rank 0, right router with
4.104 + // rank 1
4.105 + NodeContainer routerNodes;
4.106 + Ptr<Node> routerNode1 = CreateObject<Node> (0);
4.107 + Ptr<Node> routerNode2 = CreateObject<Node> (1);
4.108 + routerNodes.Add (routerNode1);
4.109 + routerNodes.Add (routerNode2);
4.110 +
4.111 + // Create right nodes on left with
4.112 + // rank 1
4.113 + NodeContainer rightLeafNodes;
4.114 + for (uint32_t i = 0; i < 4; ++i)
4.115 + {
4.116 + Ptr<Node> node = CreateObject<Node> (1);
4.117 + rightLeafNodes.Add (node);
4.118 + }
4.119 +
4.120 + PointToPointHelper routerLink;
4.121 + routerLink.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
4.122 + routerLink.SetChannelAttribute ("Delay", StringValue ("5ms"));
4.123 +
4.124 + PointToPointHelper leafLink;
4.125 + leafLink.SetDeviceAttribute ("DataRate", StringValue ("1Mbps"));
4.126 + leafLink.SetChannelAttribute ("Delay", StringValue ("2ms"));
4.127 +
4.128 + // Add link connecting routers
4.129 + NetDeviceContainer routerDevices;
4.130 + routerDevices = routerLink.Install (routerNodes);
4.131 +
4.132 + // Add links for left side links
4.133 + NetDeviceContainer leftRouterDevices;
4.134 + NetDeviceContainer leftLeafDevices;
4.135 + for (uint32_t i = 0; i < 4; ++i)
4.136 + {
4.137 + NetDeviceContainer temp = leafLink.Install (leftLeafNodes.Get (i), routerNodes.Get (0));
4.138 + leftLeafDevices.Add (temp.Get (0));
4.139 + leftRouterDevices.Add (temp.Get (1));
4.140 + }
4.141 +
4.142 + // Add links for right side links
4.143 + NetDeviceContainer rightRouterDevices;
4.144 + NetDeviceContainer rightLeafDevices;
4.145 + for (uint32_t i = 0; i < 4; ++i)
4.146 + {
4.147 + NetDeviceContainer temp = leafLink.Install (rightLeafNodes.Get (i), routerNodes.Get (1));
4.148 + rightLeafDevices.Add (temp.Get (0));
4.149 + rightRouterDevices.Add (temp.Get (1));
4.150 + }
4.151 +
4.152 + InternetStackHelper stack;
4.153 + Ipv4NixVectorHelper nixRouting;
4.154 + Ipv4StaticRoutingHelper staticRouting;
4.155 +
4.156 + Ipv4ListRoutingHelper list;
4.157 + list.Add (staticRouting, 0);
4.158 + list.Add (nixRouting, 10);
4.159 +
4.160 + if (nix)
4.161 + {
4.162 + stack.SetRoutingHelper (list);
4.163 + }
4.164 +
4.165 + stack.InstallAll ();
4.166 +
4.167 + Ipv4InterfaceContainer routerInterfaces;
4.168 + Ipv4InterfaceContainer leftLeafInterfaces;
4.169 + Ipv4InterfaceContainer leftRouterInterfaces;
4.170 + Ipv4InterfaceContainer rightLeafInterfaces;
4.171 + Ipv4InterfaceContainer rightRouterInterfaces;
4.172 +
4.173 + Ipv4AddressHelper leftAddress;
4.174 + leftAddress.SetBase ("10.1.1.0", "255.255.255.0");
4.175 +
4.176 + Ipv4AddressHelper routerAddress;
4.177 + routerAddress.SetBase ("10.2.1.0", "255.255.255.0");
4.178 +
4.179 + Ipv4AddressHelper rightAddress;
4.180 + rightAddress.SetBase ("10.3.1.0", "255.255.255.0");
4.181 +
4.182 + // Router-to-Router interfaces
4.183 + routerInterfaces = routerAddress.Assign (routerDevices);
4.184 +
4.185 + // Left interfaces
4.186 + for (uint32_t i = 0; i < 4; ++i)
4.187 + {
4.188 + NetDeviceContainer ndc;
4.189 + ndc.Add (leftLeafDevices.Get (i));
4.190 + ndc.Add (leftRouterDevices.Get (i));
4.191 + Ipv4InterfaceContainer ifc = leftAddress.Assign (ndc);
4.192 + leftLeafInterfaces.Add (ifc.Get (0));
4.193 + leftRouterInterfaces.Add (ifc.Get (1));
4.194 + leftAddress.NewNetwork ();
4.195 + }
4.196 +
4.197 + // Right interfaces
4.198 + for (uint32_t i = 0; i < 4; ++i)
4.199 + {
4.200 + NetDeviceContainer ndc;
4.201 + ndc.Add (rightLeafDevices.Get (i));
4.202 + ndc.Add (rightRouterDevices.Get (i));
4.203 + Ipv4InterfaceContainer ifc = rightAddress.Assign (ndc);
4.204 + rightLeafInterfaces.Add (ifc.Get (0));
4.205 + rightRouterInterfaces.Add (ifc.Get (1));
4.206 + rightAddress.NewNetwork ();
4.207 + }
4.208 +
4.209 + if (!nix)
4.210 + {
4.211 + Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
4.212 + }
4.213 +
4.214 + // Create a packet sink on the right leafs to receive packets from left leafs
4.215 + uint16_t port = 50000;
4.216 + if (rank == 1)
4.217 + {
4.218 + Address sinkLocalAddress(InetSocketAddress (Ipv4Address::GetAny (), port));
4.219 + PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", sinkLocalAddress);
4.220 + ApplicationContainer sinkApp;
4.221 + for (uint32_t i = 0; i < 4; ++i)
4.222 + {
4.223 + sinkApp.Add (sinkHelper.Install (rightLeafNodes.Get (i)));
4.224 + }
4.225 + sinkApp.Start (Seconds (1.0));
4.226 + sinkApp.Stop (Seconds (5));
4.227 + }
4.228 +
4.229 + // Create the OnOff applications to send
4.230 + if (rank == 0)
4.231 + {
4.232 + OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
4.233 + clientHelper.SetAttribute
4.234 + ("OnTime", RandomVariableValue (ConstantVariable (1)));
4.235 + clientHelper.SetAttribute
4.236 + ("OffTime", RandomVariableValue (ConstantVariable (0)));
4.237 +
4.238 + ApplicationContainer clientApps;
4.239 + for(uint32_t i = 0; i < 4; ++i)
4.240 + {
4.241 + AddressValue remoteAddress
4.242 + (InetSocketAddress (rightLeafInterfaces.GetAddress (i), port));
4.243 + clientHelper.SetAttribute ("Remote", remoteAddress);
4.244 + clientApps.Add(clientHelper.Install (leftLeafNodes.Get (i)));
4.245 + }
4.246 + clientApps.Start (Seconds (1.0));
4.247 + clientApps.Stop (Seconds (5));
4.248 + }
4.249 +
4.250 + Simulator::Stop (Seconds (5));
4.251 + Simulator::Run ();
4.252 + Simulator::Destroy ();
4.253 + return 0;
4.254 +#else
4.255 + NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in");
4.256 +#endif
4.257 +}
5.1 --- a/examples/nix-simple.cc Tue Oct 27 15:16:38 2009 -0400
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,114 +0,0 @@
5.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
5.5 -/*
5.6 - * This program is free software; you can redistribute it and/or modify
5.7 - * it under the terms of the GNU General Public License version 2 as
5.8 - * published by the Free Software Foundation;
5.9 - *
5.10 - * This program is distributed in the hope that it will be useful,
5.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.13 - * GNU General Public License for more details.
5.14 - *
5.15 - * You should have received a copy of the GNU General Public License
5.16 - * along with this program; if not, write to the Free Software
5.17 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5.18 - */
5.19 -
5.20 -#include "ns3/core-module.h"
5.21 -#include "ns3/simulator-module.h"
5.22 -#include "ns3/node-module.h"
5.23 -#include "ns3/helper-module.h"
5.24 -
5.25 -/*
5.26 - * Simple point to point links:
5.27 - *
5.28 - * n0 -- n1 -- n2 -- n3
5.29 - *
5.30 - * n0 has UdpEchoClient
5.31 - * n3 has UdpEchoServer
5.32 - *
5.33 - * n0 IP: 10.1.1.1
5.34 - * n1 IP: 10.1.1.2, 10.1.2.1
5.35 - * n2 IP: 10.1.2.2, 10.1.3.1
5.36 - * n3 IP: 10.1.3.2
5.37 - *
5.38 - */
5.39 -
5.40 -using namespace ns3;
5.41 -
5.42 -NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
5.43 -
5.44 - int
5.45 -main (int argc, char *argv[])
5.46 -{
5.47 - LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
5.48 - LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
5.49 -
5.50 - NodeContainer nodes12;
5.51 - nodes12.Create (2);
5.52 -
5.53 - NodeContainer nodes23;
5.54 - nodes23.Add (nodes12.Get (1));
5.55 - nodes23.Create (1);
5.56 -
5.57 - NodeContainer nodes34;
5.58 - nodes34.Add(nodes23.Get (1));
5.59 - nodes34.Create (1);
5.60 -
5.61 - PointToPointHelper pointToPoint;
5.62 - pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
5.63 - pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
5.64 -
5.65 - NodeContainer allNodes = NodeContainer (nodes12, nodes23.Get (1), nodes34.Get (1));
5.66 -
5.67 - // NixHelper to install nix-vector routing
5.68 - // on all nodes
5.69 - Ipv4NixVectorHelper nixRouting;
5.70 - Ipv4StaticRoutingHelper staticRouting;
5.71 -
5.72 - Ipv4ListRoutingHelper list;
5.73 - list.Add (staticRouting, 0);
5.74 - list.Add (nixRouting, 10);
5.75 -
5.76 - InternetStackHelper stack;
5.77 - stack.SetRoutingHelper (list);
5.78 - stack.Install (allNodes);
5.79 -
5.80 - NetDeviceContainer devices12;
5.81 - NetDeviceContainer devices23;
5.82 - NetDeviceContainer devices34;
5.83 - devices12 = pointToPoint.Install (nodes12);
5.84 - devices23 = pointToPoint.Install (nodes23);
5.85 - devices34 = pointToPoint.Install (nodes34);
5.86 -
5.87 - Ipv4AddressHelper address1;
5.88 - address1.SetBase ("10.1.1.0", "255.255.255.0");
5.89 - Ipv4AddressHelper address2;
5.90 - address2.SetBase ("10.1.2.0", "255.255.255.0");
5.91 - Ipv4AddressHelper address3;
5.92 - address3.SetBase ("10.1.3.0", "255.255.255.0");
5.93 -
5.94 - address1.Assign (devices12);
5.95 - address2.Assign (devices23);
5.96 - Ipv4InterfaceContainer interfaces = address3.Assign (devices34);
5.97 -
5.98 - UdpEchoServerHelper echoServer (9);
5.99 -
5.100 - ApplicationContainer serverApps = echoServer.Install (nodes34.Get (1));
5.101 - serverApps.Start (Seconds (1.0));
5.102 - serverApps.Stop (Seconds (10.0));
5.103 -
5.104 - UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
5.105 - echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
5.106 - echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
5.107 - echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
5.108 -
5.109 - ApplicationContainer clientApps = echoClient.Install (nodes12.Get (0));
5.110 - clientApps.Start (Seconds (2.0));
5.111 - clientApps.Stop (Seconds (10.0));
5.112 -
5.113 -
5.114 - Simulator::Run ();
5.115 - Simulator::Destroy ();
5.116 - return 0;
5.117 -}
6.1 --- a/examples/nms-p2p-nix.cc Tue Oct 27 15:16:38 2009 -0400
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,458 +0,0 @@
6.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
6.5 -// DARPA NMS Campus Network Model
6.6 -//
6.7 -// - This topology replicates the original NMS Campus Network model
6.8 -// with the exception of chord links (which were never utilized in the
6.9 -// original model)
6.10 -// - Link Bandwidths and Delays may not be the same as the original
6.11 -// specifications
6.12 -//
6.13 -// (c)2009, GTech Systems, Inc. - Alfred Park <park@gtech-systems.com>
6.14 -
6.15 -// for timing functions
6.16 -#include <cstdlib>
6.17 -#include <sys/time.h>
6.18 -#include <fstream>
6.19 -
6.20 -#include "ns3/core-module.h"
6.21 -#include "ns3/simulator-module.h"
6.22 -#include "ns3/node-module.h"
6.23 -#include "ns3/helper-module.h"
6.24 -#include "ns3/global-routing-module.h"
6.25 -#include "ns3/onoff-application.h"
6.26 -#include "ns3/packet-sink.h"
6.27 -#include "ns3/point-to-point-net-device.h"
6.28 -#include "ns3/simulator.h"
6.29 -
6.30 -using namespace std;
6.31 -using namespace ns3;
6.32 -
6.33 -typedef struct timeval TIMER_TYPE;
6.34 -#define TIMER_NOW(_t) gettimeofday(&_t,NULL);
6.35 -#define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec*1e-6)
6.36 -#define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS(_t1)-TIMER_SECONDS(_t2))
6.37 -
6.38 -NS_LOG_COMPONENT_DEFINE ("CampusNetworkModel");
6.39 -
6.40 -void Progress ()
6.41 -{
6.42 - Time now = Simulator::Now ();
6.43 - Simulator::Schedule (Seconds (0.1), Progress);
6.44 -}
6.45 -
6.46 -int
6.47 -main (int argc, char *argv[])
6.48 -{
6.49 - //Config::SetDefault ("ns3::Simulator::SchedulerType", StringValue ("ns3::CalendarScheduler"));
6.50 - TIMER_TYPE t0, t1, t2;
6.51 - TIMER_NOW(t0);
6.52 - cout << " ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << endl;
6.53 - LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
6.54 -
6.55 - //RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
6.56 -
6.57 - int nCN = 2, nLANClients = 42;
6.58 - bool nix = true;
6.59 -
6.60 - CommandLine cmd;
6.61 - cmd.AddValue ("CN", "Number of total CNs [2]", nCN);
6.62 - cmd.AddValue ("LAN", "Number of nodes per LAN [42]", nLANClients);
6.63 - cmd.AddValue ("NIX", "Toggle nix-vector routing", nix);
6.64 - cmd.Parse (argc,argv);
6.65 -
6.66 - if (nCN < 2)
6.67 - {
6.68 - cout << "Number of total CNs (" << nCN << ") lower than minimum of 2"
6.69 - << endl;
6.70 - return 1;
6.71 - }
6.72 -
6.73 - cout << "Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << endl;
6.74 -
6.75 - NodeContainer nodes_net0[nCN][3], nodes_net1[nCN][6], nodes_netLR[nCN],
6.76 - nodes_net2[nCN][14], nodes_net2LAN[nCN][7][nLANClients],
6.77 - nodes_net3[nCN][9], nodes_net3LAN[nCN][5][nLANClients];
6.78 - PointToPointHelper p2p_2gb200ms, p2p_1gb5ms, p2p_100mb1ms;
6.79 - InternetStackHelper stack;
6.80 - Ipv4InterfaceContainer ifs, ifs0[nCN][3], ifs1[nCN][6], ifs2[nCN][14],
6.81 - ifs3[nCN][9], ifs2LAN[nCN][7][nLANClients],
6.82 - ifs3LAN[nCN][5][nLANClients];
6.83 - Ipv4AddressHelper address;
6.84 - std::ostringstream oss;
6.85 - p2p_1gb5ms.SetDeviceAttribute ("DataRate", StringValue ("1Gbps"));
6.86 - p2p_1gb5ms.SetChannelAttribute ("Delay", StringValue ("5ms"));
6.87 - p2p_2gb200ms.SetDeviceAttribute ("DataRate", StringValue ("2Gbps"));
6.88 - p2p_2gb200ms.SetChannelAttribute ("Delay", StringValue ("200ms"));
6.89 - p2p_100mb1ms.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
6.90 - p2p_100mb1ms.SetChannelAttribute ("Delay", StringValue ("1ms"));
6.91 -
6.92 - // Setup NixVector Routing
6.93 - Ipv4NixVectorHelper nixRouting;
6.94 - Ipv4StaticRoutingHelper staticRouting;
6.95 -
6.96 - Ipv4ListRoutingHelper list;
6.97 - list.Add (staticRouting, 0);
6.98 - list.Add (nixRouting, 10);
6.99 -
6.100 - if (nix)
6.101 - {
6.102 - stack.SetRoutingHelper (list);
6.103 - }
6.104 -
6.105 - // Create Campus Networks
6.106 - for (int z = 0; z < nCN; ++z)
6.107 - {
6.108 - cout << "Creating Campus Network " << z << ":" << endl;
6.109 - // Create Net0
6.110 - cout << " SubNet [ 0";
6.111 - for (int i = 0; i < 3; ++i)
6.112 - {
6.113 - nodes_net0[z][i].Create (1);
6.114 - stack.Install (nodes_net0[z][i]);
6.115 - }
6.116 - nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
6.117 - nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
6.118 - nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
6.119 - NetDeviceContainer ndc0[3];
6.120 - for (int i = 0; i < 3; ++i)
6.121 - {
6.122 - ndc0[i] = p2p_1gb5ms.Install (nodes_net0[z][i]);
6.123 - }
6.124 - // Create Net1
6.125 - cout << " 1";
6.126 - for (int i = 0; i < 6; ++i)
6.127 - {
6.128 - nodes_net1[z][i].Create (1);
6.129 - stack.Install (nodes_net1[z][i]);
6.130 - }
6.131 - nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
6.132 - nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
6.133 - nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
6.134 - nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
6.135 - nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
6.136 - NetDeviceContainer ndc1[6];
6.137 - for (int i = 0; i < 6; ++i)
6.138 - {
6.139 - if (i == 1)
6.140 - {
6.141 - continue;
6.142 - }
6.143 - ndc1[i] = p2p_1gb5ms.Install (nodes_net1[z][i]);
6.144 - }
6.145 - // Connect Net0 <-> Net1
6.146 - NodeContainer net0_1;
6.147 - net0_1.Add (nodes_net0[z][2].Get (0));
6.148 - net0_1.Add (nodes_net1[z][0].Get (0));
6.149 - NetDeviceContainer ndc0_1;
6.150 - ndc0_1 = p2p_1gb5ms.Install (net0_1);
6.151 - oss.str("");
6.152 - oss << 10 + z << ".1.252.0";
6.153 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.154 - ifs = address.Assign (ndc0_1);
6.155 - // Create Net2
6.156 - cout << " 2";
6.157 - for (int i = 0; i < 14; ++i)
6.158 - {
6.159 - nodes_net2[z][i].Create (1);
6.160 - stack.Install (nodes_net2[z][i]);
6.161 - }
6.162 - nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
6.163 - nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
6.164 - nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
6.165 - nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
6.166 - nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
6.167 - nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
6.168 - nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
6.169 - nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
6.170 - nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
6.171 - nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
6.172 - nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
6.173 - nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
6.174 - nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
6.175 - nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
6.176 - NetDeviceContainer ndc2[14];
6.177 - for (int i = 0; i < 14; ++i)
6.178 - {
6.179 - ndc2[i] = p2p_1gb5ms.Install (nodes_net2[z][i]);
6.180 - }
6.181 - NetDeviceContainer ndc2LAN[7][nLANClients];
6.182 - for (int i = 0; i < 7; ++i)
6.183 - {
6.184 - oss.str ("");
6.185 - oss << 10 + z << ".4." << 15 + i << ".0";
6.186 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.187 - for (int j = 0; j < nLANClients; ++j)
6.188 - {
6.189 - nodes_net2LAN[z][i][j].Create (1);
6.190 - stack.Install (nodes_net2LAN[z][i][j]);
6.191 - nodes_net2LAN[z][i][j].Add (nodes_net2[z][i+7].Get (0));
6.192 - ndc2LAN[i][j] = p2p_100mb1ms.Install (nodes_net2LAN[z][i][j]);
6.193 - ifs2LAN[z][i][j] = address.Assign (ndc2LAN[i][j]);
6.194 - }
6.195 - }
6.196 - // Create Net3
6.197 - cout << " 3 ]" << endl;
6.198 - for (int i = 0; i < 9; ++i)
6.199 - {
6.200 - nodes_net3[z][i].Create (1);
6.201 - stack.Install(nodes_net3[z][i]);
6.202 - }
6.203 - nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
6.204 - nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
6.205 - nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
6.206 - nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
6.207 - nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
6.208 - nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
6.209 - nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
6.210 - nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
6.211 - nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
6.212 - NetDeviceContainer ndc3[9];
6.213 - for (int i = 0; i < 9; ++i)
6.214 - {
6.215 - ndc3[i] = p2p_1gb5ms.Install (nodes_net3[z][i]);
6.216 - }
6.217 - NetDeviceContainer ndc3LAN[5][nLANClients];
6.218 - for (int i = 0; i < 5; ++i)
6.219 - {
6.220 - oss.str ("");
6.221 - oss << 10 + z << ".5." << 10 + i << ".0";
6.222 - address.SetBase (oss.str ().c_str (), "255.255.255.255");
6.223 - for (int j = 0; j < nLANClients; ++j)
6.224 - {
6.225 - nodes_net3LAN[z][i][j].Create (1);
6.226 - stack.Install (nodes_net3LAN[z][i][j]);
6.227 - nodes_net3LAN[z][i][j].Add (nodes_net3[z][i+4].Get (0));
6.228 - ndc3LAN[i][j] = p2p_100mb1ms.Install (nodes_net3LAN[z][i][j]);
6.229 - ifs3LAN[z][i][j] = address.Assign (ndc3LAN[i][j]);
6.230 - }
6.231 - }
6.232 - cout << " Connecting Subnets..." << endl;
6.233 - // Create Lone Routers (Node 4 & 5)
6.234 - nodes_netLR[z].Create (2);
6.235 - stack.Install (nodes_netLR[z]);
6.236 - NetDeviceContainer ndcLR;
6.237 - ndcLR = p2p_1gb5ms.Install (nodes_netLR[z]);
6.238 - // Connect Net2/Net3 through Lone Routers to Net0
6.239 - NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
6.240 - net0_4.Add (nodes_netLR[z].Get (0));
6.241 - net0_4.Add (nodes_net0[z][0].Get (0));
6.242 - net0_5.Add (nodes_netLR[z].Get (1));
6.243 - net0_5.Add (nodes_net0[z][1].Get (0));
6.244 - net2_4a.Add (nodes_netLR[z].Get (0));
6.245 - net2_4a.Add (nodes_net2[z][0].Get (0));
6.246 - net2_4b.Add (nodes_netLR[z].Get (1));
6.247 - net2_4b.Add (nodes_net2[z][1].Get (0));
6.248 - net3_5a.Add (nodes_netLR[z].Get (1));
6.249 - net3_5a.Add (nodes_net3[z][0].Get (0));
6.250 - net3_5b.Add (nodes_netLR[z].Get (1));
6.251 - net3_5b.Add (nodes_net3[z][1].Get (0));
6.252 - NetDeviceContainer ndc0_4, ndc0_5, ndc2_4a, ndc2_4b, ndc3_5a, ndc3_5b;
6.253 - ndc0_4 = p2p_1gb5ms.Install (net0_4);
6.254 - oss.str ("");
6.255 - oss << 10 + z << ".1.253.0";
6.256 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.257 - ifs = address.Assign (ndc0_4);
6.258 - ndc0_5 = p2p_1gb5ms.Install (net0_5);
6.259 - oss.str ("");
6.260 - oss << 10 + z << ".1.254.0";
6.261 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.262 - ifs = address.Assign (ndc0_5);
6.263 - ndc2_4a = p2p_1gb5ms.Install (net2_4a);
6.264 - oss.str ("");
6.265 - oss << 10 + z << ".4.253.0";
6.266 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.267 - ifs = address.Assign (ndc2_4a);
6.268 - ndc2_4b = p2p_1gb5ms.Install (net2_4b);
6.269 - oss.str ("");
6.270 - oss << 10 + z << ".4.254.0";
6.271 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.272 - ifs = address.Assign (ndc2_4b);
6.273 - ndc3_5a = p2p_1gb5ms.Install (net3_5a);
6.274 - oss.str ("");
6.275 - oss << 10 + z << ".5.253.0";
6.276 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.277 - ifs = address.Assign (ndc3_5a);
6.278 - ndc3_5b = p2p_1gb5ms.Install (net3_5b);
6.279 - oss.str ("");
6.280 - oss << 10 + z << ".5.254.0";
6.281 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.282 - ifs = address.Assign (ndc3_5b);
6.283 - // Assign IP addresses
6.284 - cout << " Assigning IP addresses..." << endl;
6.285 - for (int i = 0; i < 3; ++i)
6.286 - {
6.287 - oss.str ("");
6.288 - oss << 10 + z << ".1." << 1 + i << ".0";
6.289 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.290 - ifs0[z][i] = address.Assign (ndc0[i]);
6.291 - }
6.292 - for (int i = 0; i < 6; ++i)
6.293 - {
6.294 - if (i == 1)
6.295 - {
6.296 - continue;
6.297 - }
6.298 - oss.str ("");
6.299 - oss << 10 + z << ".2." << 1 + i << ".0";
6.300 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.301 - ifs1[z][i] = address.Assign (ndc1[i]);
6.302 - }
6.303 - oss.str ("");
6.304 - oss << 10 + z << ".3.1.0";
6.305 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.306 - ifs = address.Assign (ndcLR);
6.307 - for (int i = 0; i < 14; ++i)
6.308 - {
6.309 - oss.str ("");
6.310 - oss << 10 + z << ".4." << 1 + i << ".0";
6.311 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.312 - ifs2[z][i] = address.Assign (ndc2[i]);
6.313 - }
6.314 - for (int i = 0; i < 9; ++i)
6.315 - {
6.316 - oss.str ("");
6.317 - oss << 10 + z << ".5." << 1 + i << ".0";
6.318 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.319 - ifs3[z][i] = address.Assign (ndc3[i]);
6.320 - }
6.321 - }
6.322 - // Create Ring Links
6.323 - if (nCN > 1)
6.324 - {
6.325 - cout << "Forming Ring Topology..." << endl;
6.326 - NodeContainer nodes_ring[nCN];
6.327 - for (int z = 0; z < nCN-1; ++z)
6.328 - {
6.329 - nodes_ring[z].Add (nodes_net0[z][0].Get (0));
6.330 - nodes_ring[z].Add (nodes_net0[z+1][0].Get (0));
6.331 - }
6.332 - nodes_ring[nCN-1].Add (nodes_net0[nCN-1][0].Get (0));
6.333 - nodes_ring[nCN-1].Add (nodes_net0[0][0].Get (0));
6.334 - NetDeviceContainer ndc_ring[nCN];
6.335 - for (int z = 0; z < nCN; ++z)
6.336 - {
6.337 - ndc_ring[z] = p2p_2gb200ms.Install (nodes_ring[z]);
6.338 - oss.str ("");
6.339 - oss << "254.1." << z + 1 << ".0";
6.340 - address.SetBase (oss.str ().c_str (), "255.255.255.0");
6.341 - ifs = address.Assign (ndc_ring[z]);
6.342 - }
6.343 - }
6.344 -
6.345 - // Create Traffic Flows
6.346 - cout << "Creating TCP Traffic Flows:" << endl;
6.347 - Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (500000));
6.348 - Config::SetDefault ("ns3::OnOffApplication::OnTime",
6.349 - RandomVariableValue (ConstantVariable (1)));
6.350 - Config::SetDefault ("ns3::OnOffApplication::OffTime",
6.351 - RandomVariableValue (ConstantVariable (0)));
6.352 - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (512));
6.353 -
6.354 - UniformVariable urng;
6.355 - int r1;
6.356 - double r2;
6.357 - for (int z = 0; z < nCN; ++z)
6.358 - {
6.359 - int x = z + 1;
6.360 - if (z == nCN - 1)
6.361 - {
6.362 - x = 0;
6.363 - }
6.364 - // Subnet 2 LANs
6.365 - cout << " Campus Network " << z << " Flows [ Net2 ";
6.366 - for (int i = 0; i < 7; ++i)
6.367 - {
6.368 - for (int j = 0; j < nLANClients; ++j)
6.369 - {
6.370 - // Sinks
6.371 - PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
6.372 - InetSocketAddress (Ipv4Address::GetAny (), 9999));
6.373 - ApplicationContainer sinkApp = sinkHelper.Install (
6.374 - nodes_net2LAN[z][i][j].Get (0));
6.375 - sinkApp.Start (Seconds (100.0));
6.376 - // Sources
6.377 - r1 = 2 + (int)(4 * urng.GetValue ());
6.378 - r2 = 100 + (10 * urng.GetValue ());;
6.379 - OnOffHelper client ("ns3::TcpSocketFactory", Address ());
6.380 - AddressValue remoteAddress(InetSocketAddress (
6.381 - ifs2LAN[z][i][j].GetAddress (0), 9999));
6.382 - client.SetAttribute ("Remote", remoteAddress);
6.383 - ApplicationContainer clientApp;
6.384 - clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
6.385 - clientApp.Start (Seconds (r2));
6.386 - }
6.387 - }
6.388 - // Subnet 3 LANs
6.389 - cout << "Net3 ]" << endl;
6.390 - for (int i = 0; i < 5; ++i)
6.391 - {
6.392 - for (int j = 0; j < nLANClients; ++j)
6.393 - {
6.394 - // Sinks
6.395 - PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
6.396 - InetSocketAddress (Ipv4Address::GetAny (), 9999));
6.397 - ApplicationContainer sinkApp = sinkHelper.Install (
6.398 - nodes_net3LAN[z][i][j].Get (0));
6.399 - sinkApp.Start (Seconds (100.0));
6.400 - // Sources
6.401 - r1 = 2 + (int)(4 * urng.GetValue ());
6.402 - r2 = 100 + (10 * urng.GetValue ());;
6.403 - OnOffHelper client ("ns3::TcpSocketFactory", Address ());
6.404 - AddressValue remoteAddress (InetSocketAddress (
6.405 - ifs2LAN[z][i][j].GetAddress (0), 9999));
6.406 - client.SetAttribute ("Remote", remoteAddress);
6.407 - ApplicationContainer clientApp;
6.408 - clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
6.409 - clientApp.Start (Seconds (r2));
6.410 - }
6.411 - }
6.412 - }
6.413 -
6.414 - cout << "Created " << NodeList::GetNNodes () << " nodes." << endl;
6.415 - TIMER_TYPE routingStart;
6.416 - TIMER_NOW (routingStart);
6.417 -
6.418 - if (nix)
6.419 - {
6.420 - // Calculate routing tables
6.421 - cout << "Using Nix-vectors..." << endl;
6.422 - }
6.423 - else
6.424 - {
6.425 - // Calculate routing tables
6.426 - cout << "Populating Global Static Routing Tables..." << endl;
6.427 - Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
6.428 - }
6.429 -
6.430 - TIMER_TYPE routingEnd;
6.431 - TIMER_NOW (routingEnd);
6.432 - cout << "Routing tables population took "
6.433 - << TIMER_DIFF (routingEnd, routingStart) << endl;
6.434 -#if 0
6.435 - std::ofstream ascii;
6.436 - ascii.open("nms_p2p_nix.tr");
6.437 - PointToPointHelper::EnableAsciiAll(ascii);
6.438 - CsmaHelper::EnableAsciiAll(ascii);
6.439 -#endif
6.440 -
6.441 -#if 0
6.442 - PointToPointHelper::EnablePcapAll("nms_p2p");
6.443 - CsmaHelper::EnablePcapAll("nms_csma");
6.444 -#endif
6.445 -
6.446 - Simulator::ScheduleNow (Progress);
6.447 - cout << "Running simulator..." << endl;
6.448 - TIMER_NOW (t1);
6.449 - Simulator::Stop (Seconds (200.0));
6.450 - Simulator::Run ();
6.451 - TIMER_NOW (t2);
6.452 - cout << "Simulator finished." << endl;
6.453 - Simulator::Destroy ();
6.454 -
6.455 - double d1 = TIMER_DIFF (t1, t0), d2 = TIMER_DIFF (t2, t1);
6.456 - cout << "-----" << endl << "Runtime Stats:" << endl;
6.457 - cout << "Simulator init time: " << d1 << endl;
6.458 - cout << "Simulator run time: " << d2 << endl;
6.459 - cout << "Total elapsed time: " << d1+d2 << endl;
6.460 - return 0;
6.461 -}
7.1 --- a/src/common/packet-metadata.cc Tue Oct 27 15:16:38 2009 -0400
7.2 +++ b/src/common/packet-metadata.cc Mon Nov 02 10:49:39 2009 -0500
7.3 @@ -1202,18 +1202,6 @@
7.4 return totalSize;
7.5 }
7.6
7.7 -void
7.8 -PacketMetadata::SetNixVector (Ptr<NixVector> nixVector)
7.9 -{
7.10 - m_nixVector = nixVector;
7.11 -}
7.12 -
7.13 -Ptr<NixVector>
7.14 -PacketMetadata::GetNixVector (void) const
7.15 -{
7.16 - return m_nixVector;
7.17 -}
7.18 -
7.19
7.20 } // namespace ns3
7.21
8.1 --- a/src/common/packet-metadata.h Tue Oct 27 15:16:38 2009 -0400
8.2 +++ b/src/common/packet-metadata.h Mon Nov 02 10:49:39 2009 -0500
8.3 @@ -26,7 +26,6 @@
8.4 #include "ns3/assert.h"
8.5 #include "ns3/type-id.h"
8.6 #include "buffer.h"
8.7 -#include "nix-vector.h"
8.8
8.9 namespace ns3 {
8.10
8.11 @@ -156,9 +155,6 @@
8.12 uint32_t GetUid (void) const;
8.13 uint32_t GetMpiRank (void) const;
8.14
8.15 - void SetNixVector (Ptr<NixVector>);
8.16 - Ptr<NixVector> GetNixVector (void) const;
8.17 -
8.18 uint32_t GetSerializedSize (void) const;
8.19 void Serialize (Buffer::Iterator i, uint32_t size) const;
8.20 uint32_t Deserialize (Buffer::Iterator i);
8.21 @@ -305,7 +301,6 @@
8.22 uint16_t m_used;
8.23 uint32_t m_mpiRank;
8.24 uint32_t m_packetUid;
8.25 - Ptr<NixVector> m_nixVector;
8.26 };
8.27
8.28 }; // namespace ns3
8.29 @@ -318,8 +313,7 @@
8.30 m_tail (0xffff),
8.31 m_used (0),
8.32 m_mpiRank (0),
8.33 - m_packetUid (uid),
8.34 - m_nixVector (0)
8.35 + m_packetUid (uid)
8.36 {
8.37 memset (m_data->m_data, 0xff, 4);
8.38 if (size > 0)
8.39 @@ -333,8 +327,7 @@
8.40 m_tail (0xffff),
8.41 m_used (0),
8.42 m_mpiRank (mpiRank),
8.43 - m_packetUid (uid),
8.44 - m_nixVector (0)
8.45 + m_packetUid (uid)
8.46 {
8.47 memset (m_data->m_data, 0xff, 4);
8.48 if (size > 0)
8.49 @@ -348,8 +341,7 @@
8.50 m_tail (o.m_tail),
8.51 m_used (o.m_used),
8.52 m_mpiRank (o.m_mpiRank),
8.53 - m_packetUid (o.m_packetUid),
8.54 - m_nixVector (o.m_nixVector)
8.55 + m_packetUid (o.m_packetUid)
8.56 {
8.57 NS_ASSERT (m_data != 0);
8.58 m_data->m_count++;
8.59 @@ -375,7 +367,6 @@
8.60 m_used = o.m_used;
8.61 m_mpiRank = o.m_mpiRank;
8.62 m_packetUid = o.m_packetUid;
8.63 - m_nixVector = o.m_nixVector;
8.64 return *this;
8.65 }
8.66 PacketMetadata::~PacketMetadata ()
9.1 --- a/src/common/packet.cc Tue Oct 27 15:16:38 2009 -0400
9.2 +++ b/src/common/packet.cc Mon Nov 02 10:49:39 2009 -0500
9.3 @@ -620,6 +620,7 @@
9.4 m_metadata.Serialize (writeBuffer.Begin (), metaReserve);
9.5
9.6 // write Tags
9.7 + //XXX
9.8 //reserve = m_tags.GetSerializedSize ();
9.9 //buffer.AddAtStart (reserve);
9.10 //m_tags.Serialize (buffer.Begin (), reserve);
9.11 @@ -648,15 +649,6 @@
9.12 writeBuffer.AddAtStart (4);
9.13 writeBuffer.Begin ().WriteU32 (GetUid ());
9.14
9.15 - // Some debugging
9.16 - const uint8_t *pointer = writeBuffer.PeekData ();
9.17 - for (uint32_t i = 0; i < writeBuffer.GetSize (); i+=4)
9.18 - {
9.19 - std::cout << (uint32_t)*pointer << std::endl;
9.20 - pointer += 4;
9.21 - }
9.22 - std::cout << "------------" << std::endl;
9.23 -
9.24 return writeBuffer;
9.25 }
9.26
9.27 @@ -664,14 +656,6 @@
9.28 Packet::DeserializeForMpi (Buffer buffer)
9.29 {
9.30 NS_LOG_FUNCTION (this);
9.31 - // Some debugging
9.32 - const uint8_t *pointer = buffer.PeekData ();
9.33 - for (uint32_t i = 0; i < buffer.GetSize (); i+=4)
9.34 - {
9.35 - std::cout << (uint32_t)*pointer << std::endl;
9.36 - pointer += 4;
9.37 - }
9.38 - std::cout << "------------" << std::endl;
9.39
9.40 // uid and rank have already been stripped
9.41 // off immediately before calling this
10.1 --- a/src/common/packet.h Tue Oct 27 15:16:38 2009 -0400
10.2 +++ b/src/common/packet.h Mon Nov 02 10:49:39 2009 -0500
10.3 @@ -430,9 +430,9 @@
10.4 * for MPI.
10.5 *
10.6 * This method will trigger calls to the Serialize and GetSerializedSize
10.7 - * methods of Nix-vector, metadata, and each tag stored in this packet.
10.8 - * The returned buffer will _not_ contain zero-byte data, only the
10.9 - * number of bytes of zero-byte data.
10.10 + * methods of Nix-vector, metadata, and each tag (unimplemented) stored
10.11 + * in this packet. The returned buffer will _not_ contain zero-byte data,
10.12 + * only the number of bytes of zero-byte data.
10.13 *
10.14 * This method will typically be used by distributed MPI simulations where
10.15 * the simulated system is partitioned and each partition runs on
10.16 @@ -448,7 +448,8 @@
10.17 * calling SerializeForMpi.
10.18 *
10.19 * This method will trigger calls to the Deserialize method
10.20 - * of the nix-vector, metadata, and each tag stored in this packet.
10.21 + * of the nix-vector, metadata, and each tag (unimplemented)
10.22 + * stored in this packet.
10.23 *
10.24 * This method will typically be used by parallel simulations where
10.25 * the simulated system is partitioned and each partition runs on
11.1 --- a/src/node/node.h Tue Oct 27 15:16:38 2009 -0400
11.2 +++ b/src/node/node.h Mon Nov 02 10:49:39 2009 -0500
11.3 @@ -82,7 +82,7 @@
11.4 * \param sid - the system id for parallel simulations associated
11.5 * to this node.
11.6 */
11.7 - void SetSystemId (uint32_t);
11.8 + void SetSystemId (uint32_t sid);
11.9
11.10 /**
11.11 * \returns the system id for parallel simulations associated
12.1 --- a/src/simulator/distributed-simulator-impl.cc Tue Oct 27 15:16:38 2009 -0400
12.2 +++ b/src/simulator/distributed-simulator-impl.cc Mon Nov 02 10:49:39 2009 -0500
12.3 @@ -59,9 +59,9 @@
12.4 DistributedSimulatorImpl::DistributedSimulatorImpl ()
12.5 {
12.6 #ifdef NS3_MPI
12.7 - //MPIInterface::Enable ();
12.8 m_myId = MPIInterface::Rank ();
12.9 m_systemCount = MPIInterface::Size ();
12.10 +
12.11 // Allocate the LBTS message buffer
12.12 m_pLBTS = new LBTSMessage[m_systemCount];
12.13 m_grantedTime = Seconds (0);
13.1 --- a/src/simulator/mpi-interface.cc Tue Oct 27 15:16:38 2009 -0400
13.2 +++ b/src/simulator/mpi-interface.cc Mon Nov 02 10:49:39 2009 -0500
13.3 @@ -52,7 +52,8 @@
13.4 char** MPIInterface::m_pRxBuffers;
13.5 #endif
13.6
13.7 -uint32_t MPIInterface::Rank ()
13.8 +uint32_t
13.9 +MPIInterface::Rank ()
13.10 {
13.11 if (!m_initialized)
13.12 {
13.13 @@ -62,7 +63,8 @@
13.14 return rank;
13.15 }
13.16
13.17 -uint32_t MPIInterface::Size ()
13.18 +uint32_t
13.19 +MPIInterface::Size ()
13.20 {
13.21 if (!m_initialized)
13.22 {
13.23 @@ -72,7 +74,8 @@
13.24 return size;
13.25 }
13.26
13.27 -bool MPIInterface::IsEnabled ()
13.28 +bool
13.29 +MPIInterface::IsEnabled ()
13.30 {
13.31 if (!m_initialized)
13.32 {
13.33 @@ -82,22 +85,8 @@
13.34 return m_enabled;
13.35 }
13.36
13.37 -/*void MPIInterface::Enable ()
13.38 -{
13.39 - if (m_enabled) return;
13.40 -#ifdef NS3_MPI
13.41 - int argc = 1;
13.42 - char test[5] = "test";
13.43 - char* argv1[2] = {
13.44 - test, 0 };
13.45 - char** argv = argv1;
13.46 - Enable (&argc, &argv);
13.47 -#else
13.48 - NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in");
13.49 -#endif
13.50 -} */
13.51 -
13.52 -void MPIInterface::Enable (int* pargc, char*** pargv)
13.53 +void
13.54 +MPIInterface::Enable (int* pargc, char*** pargv)
13.55 {
13.56 #ifdef NS3_MPI
13.57 // Initialize the MPI interface
13.58 @@ -121,7 +110,8 @@
13.59 #endif
13.60 }
13.61
13.62 -void MPIInterface::SendPacket (Ptr<Packet> p, const Time& rxTime, uint32_t node, uint32_t dev)
13.63 +void
13.64 +MPIInterface::SendPacket (Ptr<Packet> p, const Time& rxTime, uint32_t node, uint32_t dev)
13.65 {
13.66 #ifdef NS3_MPI
13.67 SentBuffer sendBuf;
13.68 @@ -150,7 +140,8 @@
13.69 #endif
13.70 }
13.71
13.72 -void MPIInterface::ReceiveMessages ()
13.73 +void
13.74 +MPIInterface::ReceiveMessages ()
13.75 { // Poll the non-block reads to see if data arrived
13.76 #ifdef NS3_MPI
13.77 while (true)
13.78 @@ -216,7 +207,8 @@
13.79 #endif
13.80 }
13.81
13.82 -void MPIInterface::TestSendComplete ()
13.83 +void
13.84 +MPIInterface::TestSendComplete ()
13.85 {
13.86 #ifdef NS3_MPI
13.87 list<SentBuffer>::iterator i = m_pendingTx.begin ();
14.1 --- a/src/simulator/mpi-interface.h Tue Oct 27 15:16:38 2009 -0400
14.2 +++ b/src/simulator/mpi-interface.h Mon Nov 02 10:49:39 2009 -0500
14.3 @@ -55,8 +55,8 @@
14.4 static uint32_t Rank(); // Get the MPI Rank
14.5 static uint32_t Size(); // Get the MPI Size (number of systems)
14.6 static bool IsEnabled(); // True if using MPI
14.7 - //static void Enable(); // Called by distributed simulator constructor
14.8 static void Enable(int*, char***); // Called by ns3 main program
14.9 +
14.10 // Serialize and send a packet to the specified node and net device
14.11 static void SendPacket(Ptr<Packet>, const Time&, uint32_t, uint32_t);
14.12 static void ReceiveMessages(); // Check for received messages complete
15.1 --- a/wscript Tue Oct 27 15:16:38 2009 -0400
15.2 +++ b/wscript Mon Nov 02 10:49:39 2009 -0500
15.3 @@ -282,19 +282,6 @@
15.4 if Options.options.build_profile == 'debug':
15.5 env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE')
15.6 env.append_value('CXXDEFINES', 'NS3_LOG_ENABLE')
15.7 - if Options.options.with_mpi:
15.8 - conf.find_program('mpic++', var='MPI')
15.9 - if conf.env['MPI'] and os.getenv('CXX') != conf.env['MPI']:
15.10 - conf.report_optional_feature("mpi", "MPI Support", False, ("CXX Path should be %s" % conf.env['MPI']))
15.11 - else:
15.12 - if conf.env['MPI']:
15.13 - env.append_value('CXXDEFINES', 'NS3_MPI')
15.14 - conf.report_optional_feature("mpi", "MPI Support", True, '')
15.15 - os.environ['COMPILER_CXX'] = conf.env['MPI']
15.16 - else:
15.17 - conf.report_optional_feature("mpi", "MPI Support", False, 'mpic++ not found')
15.18 - else:
15.19 - conf.report_optional_feature("mpi", "MPI Support", False, 'option --with-mpi not selected')
15.20
15.21 env['PLATFORM'] = sys.platform
15.22
15.23 @@ -322,6 +309,23 @@
15.24 if Options.options.enable_modules:
15.25 conf.env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in
15.26 Options.options.enable_modules.split(',')]
15.27 + # for MPI
15.28 + conf.find_program('mpic++', var='MPI')
15.29 + if Options.options.with_mpi and conf.env['MPI'] and os.getenv('CXX') != conf.env['MPI']:
15.30 + conf.report_optional_feature("mpi", "MPI Support", False, ("CXX Path should be %s" % conf.env['MPI']))
15.31 + msg = ("Attempted to compile with MPI; however, CXX environment variable not set\n"
15.32 + "It should be set to the path of mpic++ (" + conf.env['MPI'] + ")")
15.33 + raise Utils.WafError(msg)
15.34 + else:
15.35 + if Options.options.with_mpi and conf.env['MPI']:
15.36 + env.append_value('CXXDEFINES', 'NS3_MPI')
15.37 + conf.report_optional_feature("mpi", "MPI Support", True, '')
15.38 + os.environ['COMPILER_CXX'] = conf.env['MPI']
15.39 + else:
15.40 + if Options.options.with_mpi:
15.41 + conf.report_optional_feature("mpi", "MPI Support", False, 'mpic++ not found')
15.42 + else:
15.43 + conf.report_optional_feature("mpi", "MPI Support", False, 'option --with-mpi not selected')
15.44
15.45 # for suid bits
15.46 conf.find_program('sudo', var='SUDO')
15.47 @@ -392,6 +396,7 @@
15.48 conf.env.append_value('CXXDEFINES', "ENABLE_GSL")
15.49 conf.env.append_value('CCDEFINES', "ENABLE_GSL")
15.50
15.51 +
15.52 # Write a summary of optional features status
15.53 print "---- Summary of optional NS-3 features:"
15.54 for (name, caption, was_enabled, reason_not_enabled) in conf.env['NS3_OPTIONAL_FEATURES']: