Files
ns-3-dev/examples/mpi/simple-distributed.cc
T
Tom Henderson 9a8a5f06e4 Merge node and common modules into new network module
--HG--
rename : src/node/ipv4-address-generator.cc => src/internet-stack/ipv4-address-generator.cc
rename : src/node/ipv4-address-generator.h => src/internet-stack/ipv4-address-generator.h
rename : src/node/ipv4-header.cc => src/internet-stack/ipv4-header.cc
rename : src/node/ipv4-header.h => src/internet-stack/ipv4-header.h
rename : src/node/ipv4-interface-address.cc => src/internet-stack/ipv4-interface-address.cc
rename : src/node/ipv4-interface-address.h => src/internet-stack/ipv4-interface-address.h
rename : src/node/ipv4-raw-socket-factory.cc => src/internet-stack/ipv4-raw-socket-factory.cc
rename : src/node/ipv4-raw-socket-factory.h => src/internet-stack/ipv4-raw-socket-factory.h
rename : src/node/ipv4-route.cc => src/internet-stack/ipv4-route.cc
rename : src/node/ipv4-route.h => src/internet-stack/ipv4-route.h
rename : src/node/ipv4-routing-protocol.cc => src/internet-stack/ipv4-routing-protocol.cc
rename : src/node/ipv4-routing-protocol.h => src/internet-stack/ipv4-routing-protocol.h
rename : src/node/ipv4.cc => src/internet-stack/ipv4.cc
rename : src/node/ipv4.h => src/internet-stack/ipv4.h
rename : src/node/ipv6-header.cc => src/internet-stack/ipv6-header.cc
rename : src/node/ipv6-header.h => src/internet-stack/ipv6-header.h
rename : src/node/ipv6-interface-address.cc => src/internet-stack/ipv6-interface-address.cc
rename : src/node/ipv6-interface-address.h => src/internet-stack/ipv6-interface-address.h
rename : src/node/ipv6-raw-socket-factory.cc => src/internet-stack/ipv6-raw-socket-factory.cc
rename : src/node/ipv6-raw-socket-factory.h => src/internet-stack/ipv6-raw-socket-factory.h
rename : src/node/ipv6-route.cc => src/internet-stack/ipv6-route.cc
rename : src/node/ipv6-route.h => src/internet-stack/ipv6-route.h
rename : src/node/ipv6-routing-protocol.cc => src/internet-stack/ipv6-routing-protocol.cc
rename : src/node/ipv6-routing-protocol.h => src/internet-stack/ipv6-routing-protocol.h
rename : src/node/ipv6.cc => src/internet-stack/ipv6.cc
rename : src/node/ipv6.h => src/internet-stack/ipv6.h
rename : src/node/tcp-socket-factory.cc => src/internet-stack/tcp-socket-factory.cc
rename : src/node/tcp-socket-factory.h => src/internet-stack/tcp-socket-factory.h
rename : src/node/tcp-socket.cc => src/internet-stack/tcp-socket.cc
rename : src/node/tcp-socket.h => src/internet-stack/tcp-socket.h
rename : src/node/udp-socket-factory.cc => src/internet-stack/udp-socket-factory.cc
rename : src/node/udp-socket-factory.h => src/internet-stack/udp-socket-factory.h
rename : src/node/udp-socket.cc => src/internet-stack/udp-socket.cc
rename : src/node/udp-socket.h => src/internet-stack/udp-socket.h
rename : src/helper/application-container.cc => src/network/helper/application-container.cc
rename : src/helper/application-container.h => src/network/helper/application-container.h
rename : src/helper/net-device-container.cc => src/network/helper/net-device-container.cc
rename : src/helper/net-device-container.h => src/network/helper/net-device-container.h
rename : src/helper/node-container.cc => src/network/helper/node-container.cc
rename : src/helper/node-container.h => src/network/helper/node-container.h
rename : src/helper/packet-socket-helper.cc => src/network/helper/packet-socket-helper.cc
rename : src/helper/packet-socket-helper.h => src/network/helper/packet-socket-helper.h
rename : src/node/address.cc => src/network/model/address.cc
rename : src/node/address.h => src/network/model/address.h
rename : src/node/application.cc => src/network/model/application.cc
rename : src/node/application.h => src/network/model/application.h
rename : src/common/buffer.cc => src/network/model/buffer.cc
rename : src/common/buffer.h => src/network/model/buffer.h
rename : src/common/byte-tag-list.cc => src/network/model/byte-tag-list.cc
rename : src/common/byte-tag-list.h => src/network/model/byte-tag-list.h
rename : src/node/channel-list.cc => src/network/model/channel-list.cc
rename : src/node/channel-list.h => src/network/model/channel-list.h
rename : src/node/channel.cc => src/network/model/channel.cc
rename : src/node/channel.h => src/network/model/channel.h
rename : src/common/chunk.cc => src/network/model/chunk.cc
rename : src/common/chunk.h => src/network/model/chunk.h
rename : src/common/header.cc => src/network/model/header.cc
rename : src/common/header.h => src/network/model/header.h
rename : src/node/net-device.cc => src/network/model/net-device.cc
rename : src/node/net-device.h => src/network/model/net-device.h
rename : src/common/nix-vector.cc => src/network/model/nix-vector.cc
rename : src/common/nix-vector.h => src/network/model/nix-vector.h
rename : src/node/node-list.cc => src/network/model/node-list.cc
rename : src/node/node-list.h => src/network/model/node-list.h
rename : src/node/node.cc => src/network/model/node.cc
rename : src/node/node.h => src/network/model/node.h
rename : src/common/packet-metadata.cc => src/network/model/packet-metadata.cc
rename : src/common/packet-metadata.h => src/network/model/packet-metadata.h
rename : src/common/packet-tag-list.cc => src/network/model/packet-tag-list.cc
rename : src/common/packet-tag-list.h => src/network/model/packet-tag-list.h
rename : src/common/packet.cc => src/network/model/packet.cc
rename : src/common/packet.h => src/network/model/packet.h
rename : src/node/socket-factory.cc => src/network/model/socket-factory.cc
rename : src/node/socket-factory.h => src/network/model/socket-factory.h
rename : src/node/socket.cc => src/network/model/socket.cc
rename : src/node/socket.h => src/network/model/socket.h
rename : src/common/tag-buffer.cc => src/network/model/tag-buffer.cc
rename : src/common/tag-buffer.h => src/network/model/tag-buffer.h
rename : src/common/tag.cc => src/network/model/tag.cc
rename : src/common/tag.h => src/network/model/tag.h
rename : src/common/trailer.cc => src/network/model/trailer.cc
rename : src/common/trailer.h => src/network/model/trailer.h
rename : src/common/buffer-test.cc => src/network/test/buffer-test.cc
rename : src/common/known.pcap => src/network/test/known.pcap
rename : src/common/packet-metadata-test.cc => src/network/test/packet-metadata-test.cc
rename : src/node/packetbb-test-suite.cc => src/network/test/packetbb-test-suite.cc
rename : src/common/pcap-file-test-suite.cc => src/network/test/pcap-file-test-suite.cc
rename : src/node/address-utils.cc => src/network/utils/address-utils.cc
rename : src/node/address-utils.h => src/network/utils/address-utils.h
rename : src/common/data-rate.cc => src/network/utils/data-rate.cc
rename : src/common/data-rate.h => src/network/utils/data-rate.h
rename : src/node/drop-tail-queue.cc => src/network/utils/drop-tail-queue.cc
rename : src/node/drop-tail-queue.h => src/network/utils/drop-tail-queue.h
rename : src/common/error-model.cc => src/network/utils/error-model.cc
rename : src/common/error-model.h => src/network/utils/error-model.h
rename : src/node/ethernet-header.cc => src/network/utils/ethernet-header.cc
rename : src/node/ethernet-header.h => src/network/utils/ethernet-header.h
rename : src/node/ethernet-trailer.cc => src/network/utils/ethernet-trailer.cc
rename : src/node/ethernet-trailer.h => src/network/utils/ethernet-trailer.h
rename : src/node/inet-socket-address.cc => src/network/utils/inet-socket-address.cc
rename : src/node/inet-socket-address.h => src/network/utils/inet-socket-address.h
rename : src/node/inet6-socket-address.cc => src/network/utils/inet6-socket-address.cc
rename : src/node/inet6-socket-address.h => src/network/utils/inet6-socket-address.h
rename : src/node/ipv4-address.cc => src/network/utils/ipv4-address.cc
rename : src/node/ipv4-address.h => src/network/utils/ipv4-address.h
rename : src/node/ipv6-address.cc => src/network/utils/ipv6-address.cc
rename : src/node/ipv6-address.h => src/network/utils/ipv6-address.h
rename : src/node/llc-snap-header.cc => src/network/utils/llc-snap-header.cc
rename : src/node/llc-snap-header.h => src/network/utils/llc-snap-header.h
rename : src/node/mac48-address.cc => src/network/utils/mac48-address.cc
rename : src/node/mac48-address.h => src/network/utils/mac48-address.h
rename : src/node/mac64-address.cc => src/network/utils/mac64-address.cc
rename : src/node/mac64-address.h => src/network/utils/mac64-address.h
rename : src/common/output-stream-wrapper.cc => src/network/utils/output-stream-wrapper.cc
rename : src/common/output-stream-wrapper.h => src/network/utils/output-stream-wrapper.h
rename : src/common/packet-burst.cc => src/network/utils/packet-burst.cc
rename : src/common/packet-burst.h => src/network/utils/packet-burst.h
rename : src/node/packet-socket-address.cc => src/network/utils/packet-socket-address.cc
rename : src/node/packet-socket-address.h => src/network/utils/packet-socket-address.h
rename : src/node/packet-socket-factory.cc => src/network/utils/packet-socket-factory.cc
rename : src/node/packet-socket-factory.h => src/network/utils/packet-socket-factory.h
rename : src/node/packet-socket.cc => src/network/utils/packet-socket.cc
rename : src/node/packet-socket.h => src/network/utils/packet-socket.h
rename : src/node/packetbb.cc => src/network/utils/packetbb.cc
rename : src/node/packetbb.h => src/network/utils/packetbb.h
rename : src/common/pcap-file-wrapper.cc => src/network/utils/pcap-file-wrapper.cc
rename : src/common/pcap-file-wrapper.h => src/network/utils/pcap-file-wrapper.h
rename : src/common/pcap-file.cc => src/network/utils/pcap-file.cc
rename : src/common/pcap-file.h => src/network/utils/pcap-file.h
rename : src/node/phy-mac.h => src/network/utils/phy-mac.h
rename : src/node/queue.cc => src/network/utils/queue.cc
rename : src/node/queue.h => src/network/utils/queue.h
rename : src/node/radiotap-header.cc => src/network/utils/radiotap-header.cc
rename : src/node/radiotap-header.h => src/network/utils/radiotap-header.h
rename : src/common/sequence-number.cc => src/network/utils/sequence-number.cc
rename : src/common/sequence-number.h => src/network/utils/sequence-number.h
rename : src/common/sgi-hashmap.h => src/network/utils/sgi-hashmap.h
rename : src/node/simple-channel.cc => src/network/utils/simple-channel.cc
rename : src/node/simple-channel.h => src/network/utils/simple-channel.h
rename : src/node/simple-net-device.cc => src/network/utils/simple-net-device.cc
rename : src/node/simple-net-device.h => src/network/utils/simple-net-device.h
rename : src/node/waf => src/network/waf
rename : src/node/wscript => src/network/wscript
2011-02-21 09:11:37 -08:00

249 lines
8.1 KiB
C++

/* -*- 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
*
*
* TestDistributed creates a dumbbell topology and logically splits it in
* half. The left half is placed on logical processor 0 and the right half
* is placed on logical processor 1.
*
* ------- -------
* RANK 0 RANK 1
* ------- | -------
* |
* n0 ---------| | |---------- n6
* | | |
* n1 -------\ | | | /------- n7
* n4 ----------|---------- n5
* n2 -------/ | | | \------- n8
* | | |
* n3 ---------| | |---------- n9
*
*
* OnOff clients are placed on each left leaf node. Each right leaf node
* is a packet sink for a left leaf node. As a packet travels from one
* logical processor to another (the link between n4 and n5), MPI messages
* are passed containing the serialized packet. The message is then
* deserialized into a new packet and sent on as normal.
*
* One packet is sent from each left leaf node. The packet sinks on the
* right leaf nodes output logging information when they receive the packet.
*/
#include "ns3/core-module.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/helper-module.h"
#include "ns3/mpi-interface.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-list-routing-helper.h"
#ifdef NS3_MPI
#include <mpi.h>
#endif
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("SimpleDistributed");
int
main (int argc, char *argv[])
{
#ifdef NS3_MPI
// Distributed simulation setup
MpiInterface::Enable (&argc, &argv);
GlobalValue::Bind ("SimulatorImplementationType",
StringValue ("ns3::DistributedSimulatorImpl"));
LogComponentEnable ("PacketSink", LOG_LEVEL_INFO);
uint32_t systemId = MpiInterface::GetSystemId ();
uint32_t systemCount = MpiInterface::GetSize ();
// Check for valid distributed parameters.
// Must have 2 and only 2 Logical Processors (LPs)
if (systemCount != 2)
{
std::cout << "This simulation requires 2 and only 2 logical processors." << std::endl;
return 1;
}
// Some default values
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("1Mbps"));
Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (512));
bool nix = true;
// Parse command line
CommandLine cmd;
cmd.AddValue ("nix", "Enable the use of nix-vector or global routing", nix);
cmd.Parse (argc, argv);
// Create leaf nodes on left with system id 0
NodeContainer leftLeafNodes;
leftLeafNodes.Create (4, 0);
// Create router nodes. Left router
// with system id 0, right router with
// system id 1
NodeContainer routerNodes;
Ptr<Node> routerNode1 = CreateObject<Node> (0);
Ptr<Node> routerNode2 = CreateObject<Node> (1);
routerNodes.Add (routerNode1);
routerNodes.Add (routerNode2);
// Create leaf nodes on left with system id 1
NodeContainer rightLeafNodes;
rightLeafNodes.Create (4, 1);
PointToPointHelper routerLink;
routerLink.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
routerLink.SetChannelAttribute ("Delay", StringValue ("5ms"));
PointToPointHelper leafLink;
leafLink.SetDeviceAttribute ("DataRate", StringValue ("1Mbps"));
leafLink.SetChannelAttribute ("Delay", StringValue ("2ms"));
// Add link connecting routers
NetDeviceContainer routerDevices;
routerDevices = routerLink.Install (routerNodes);
// Add links for left side leaf nodes to left router
NetDeviceContainer leftRouterDevices;
NetDeviceContainer leftLeafDevices;
for (uint32_t i = 0; i < 4; ++i)
{
NetDeviceContainer temp = leafLink.Install (leftLeafNodes.Get (i), routerNodes.Get (0));
leftLeafDevices.Add (temp.Get (0));
leftRouterDevices.Add (temp.Get (1));
}
// Add links for right side leaf nodes to right router
NetDeviceContainer rightRouterDevices;
NetDeviceContainer rightLeafDevices;
for (uint32_t i = 0; i < 4; ++i)
{
NetDeviceContainer temp = leafLink.Install (rightLeafNodes.Get (i), routerNodes.Get (1));
rightLeafDevices.Add (temp.Get (0));
rightRouterDevices.Add (temp.Get (1));
}
InternetStackHelper stack;
Ipv4NixVectorHelper nixRouting;
Ipv4StaticRoutingHelper staticRouting;
Ipv4ListRoutingHelper list;
list.Add (staticRouting, 0);
list.Add (nixRouting, 10);
if (nix)
{
stack.SetRoutingHelper (list);
}
stack.InstallAll ();
Ipv4InterfaceContainer routerInterfaces;
Ipv4InterfaceContainer leftLeafInterfaces;
Ipv4InterfaceContainer leftRouterInterfaces;
Ipv4InterfaceContainer rightLeafInterfaces;
Ipv4InterfaceContainer rightRouterInterfaces;
Ipv4AddressHelper leftAddress;
leftAddress.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4AddressHelper routerAddress;
routerAddress.SetBase ("10.2.1.0", "255.255.255.0");
Ipv4AddressHelper rightAddress;
rightAddress.SetBase ("10.3.1.0", "255.255.255.0");
// Router-to-Router interfaces
routerInterfaces = routerAddress.Assign (routerDevices);
// Left interfaces
for (uint32_t i = 0; i < 4; ++i)
{
NetDeviceContainer ndc;
ndc.Add (leftLeafDevices.Get (i));
ndc.Add (leftRouterDevices.Get (i));
Ipv4InterfaceContainer ifc = leftAddress.Assign (ndc);
leftLeafInterfaces.Add (ifc.Get (0));
leftRouterInterfaces.Add (ifc.Get (1));
leftAddress.NewNetwork ();
}
// Right interfaces
for (uint32_t i = 0; i < 4; ++i)
{
NetDeviceContainer ndc;
ndc.Add (rightLeafDevices.Get (i));
ndc.Add (rightRouterDevices.Get (i));
Ipv4InterfaceContainer ifc = rightAddress.Assign (ndc);
rightLeafInterfaces.Add (ifc.Get (0));
rightRouterInterfaces.Add (ifc.Get (1));
rightAddress.NewNetwork ();
}
if (!nix)
{
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
}
// Create a packet sink on the right leafs to receive packets from left leafs
uint16_t port = 50000;
if (systemId == 1)
{
Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", sinkLocalAddress);
ApplicationContainer sinkApp;
for (uint32_t i = 0; i < 4; ++i)
{
sinkApp.Add (sinkHelper.Install (rightLeafNodes.Get (i)));
}
sinkApp.Start (Seconds (1.0));
sinkApp.Stop (Seconds (5));
}
// Create the OnOff applications to send
if (systemId == 0)
{
OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
clientHelper.SetAttribute
("OnTime", RandomVariableValue (ConstantVariable (1)));
clientHelper.SetAttribute
("OffTime", RandomVariableValue (ConstantVariable (0)));
ApplicationContainer clientApps;
for (uint32_t i = 0; i < 4; ++i)
{
AddressValue remoteAddress
(InetSocketAddress (rightLeafInterfaces.GetAddress (i), port));
clientHelper.SetAttribute ("Remote", remoteAddress);
clientApps.Add (clientHelper.Install (leftLeafNodes.Get (i)));
}
clientApps.Start (Seconds (1.0));
clientApps.Stop (Seconds (5));
}
Simulator::Stop (Seconds (5));
Simulator::Run ();
Simulator::Destroy ();
return 0;
#else
NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in");
#endif
}