2008-04-08 23:12:19 -07:00
|
|
|
/* -*- 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
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//
|
2017-02-06 20:31:02 +01:00
|
|
|
// This ns-3 example demonstrates the use of helper functions to ease
|
2010-12-01 22:13:26 +00:00
|
|
|
// the construction of simulation scenarios.
|
2017-02-06 20:31:02 +01:00
|
|
|
//
|
2008-04-08 23:12:19 -07:00
|
|
|
// The simulation topology consists of a mixed wired and wireless
|
|
|
|
|
// scenario in which a hierarchical mobility model is used.
|
|
|
|
|
//
|
|
|
|
|
// The simulation layout consists of N backbone routers interconnected
|
|
|
|
|
// by an ad hoc wifi network.
|
|
|
|
|
// Each backbone router also has a local 802.11 network and is connected
|
|
|
|
|
// to a local LAN. An additional set of (K-1) nodes are connected to
|
|
|
|
|
// this backbone. Finally, a local LAN is connected to each router
|
2010-12-01 22:13:26 +00:00
|
|
|
// on the backbone, with L-1 additional hosts.
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
|
|
|
|
// The nodes are populated with TCP/IP stacks, and OLSR unicast routing
|
|
|
|
|
// on the backbone. An example UDP transfer is shown. The simulator
|
|
|
|
|
// be configured to output tcpdumps or traces from different nodes.
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// +--------------------------------------------------------+
|
|
|
|
|
// | |
|
2017-02-06 20:31:02 +01:00
|
|
|
// | 802.11 ad hoc, ns-2 mobility |
|
2008-04-08 23:12:19 -07:00
|
|
|
// | |
|
|
|
|
|
// +--------------------------------------------------------+
|
|
|
|
|
// | o o o (N backbone routers) |
|
|
|
|
|
// +--------+ +--------+
|
|
|
|
|
// wired LAN | mobile | wired LAN | mobile |
|
|
|
|
|
// -----------| router | -----------| router |
|
|
|
|
|
// --------- ---------
|
|
|
|
|
// | |
|
|
|
|
|
// +----------------+ +----------------+
|
|
|
|
|
// | 802.11 | | 802.11 |
|
2008-12-30 21:51:36 -08:00
|
|
|
// | infra net | | infra net |
|
2008-04-08 23:12:19 -07:00
|
|
|
// | K-1 hosts | | K-1 hosts |
|
|
|
|
|
// +----------------+ +----------------+
|
|
|
|
|
//
|
2008-12-30 21:51:36 -08:00
|
|
|
// We'll send data from the first wired LAN node on the first wired LAN
|
|
|
|
|
// to the last wireless STA on the last infrastructure net, thereby
|
|
|
|
|
// causing packets to traverse CSMA to adhoc to infrastructure links
|
2017-02-06 20:31:02 +01:00
|
|
|
//
|
2008-12-30 21:51:36 -08:00
|
|
|
// Note that certain mobility patterns may cause packet forwarding
|
2017-02-06 20:31:02 +01:00
|
|
|
// to fail (if nodes become disconnected)
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
#include "ns3/core-module.h"
|
2011-03-02 13:42:28 -08:00
|
|
|
#include "ns3/applications-module.h"
|
2008-04-08 23:12:19 -07:00
|
|
|
#include "ns3/mobility-module.h"
|
|
|
|
|
#include "ns3/wifi-module.h"
|
2011-03-03 19:54:57 +00:00
|
|
|
#include "ns3/csma-module.h"
|
2010-10-25 21:43:38 +01:00
|
|
|
#include "ns3/olsr-helper.h"
|
2011-04-26 15:18:32 -07:00
|
|
|
#include "ns3/internet-module.h"
|
2014-05-04 18:46:44 -07:00
|
|
|
#include "ns3/netanim-module.h"
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
using namespace ns3;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Define logging keyword for this file
|
|
|
|
|
//
|
|
|
|
|
NS_LOG_COMPONENT_DEFINE ("MixedWireless");
|
|
|
|
|
|
|
|
|
|
//
|
2008-12-30 13:18:56 -08:00
|
|
|
// This function will be used below as a trace sink, if the command-line
|
|
|
|
|
// argument or default value "useCourseChangeCallback" is set to true
|
2017-02-06 20:31:02 +01:00
|
|
|
//
|
2008-04-08 23:12:19 -07:00
|
|
|
static void
|
|
|
|
|
CourseChangeCallback (std::string path, Ptr<const MobilityModel> model)
|
|
|
|
|
{
|
|
|
|
|
Vector position = model->GetPosition ();
|
|
|
|
|
std::cout << "CourseChange " << path << " x=" << position.x << ", y=" << position.y << ", z=" << position.z << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 20:31:02 +01:00
|
|
|
int
|
2008-04-08 23:12:19 -07:00
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
//
|
2017-02-06 20:31:02 +01:00
|
|
|
// First, we declare and initialize a few local variables that control some
|
2008-04-08 23:12:19 -07:00
|
|
|
// simulation parameters.
|
|
|
|
|
//
|
|
|
|
|
uint32_t backboneNodes = 10;
|
2014-05-04 18:37:17 -07:00
|
|
|
uint32_t infraNodes = 2;
|
|
|
|
|
uint32_t lanNodes = 2;
|
2014-05-04 17:59:01 -07:00
|
|
|
uint32_t stopTime = 20;
|
2008-12-30 13:18:56 -08:00
|
|
|
bool useCourseChangeCallback = false;
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Simulation defaults are typically set next, before command line
|
|
|
|
|
// arguments are parsed.
|
|
|
|
|
//
|
2014-05-04 17:59:01 -07:00
|
|
|
Config::SetDefault ("ns3::OnOffApplication::PacketSize", StringValue ("1472"));
|
|
|
|
|
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("100kb/s"));
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// For convenience, we add the local variables to the command line argument
|
2017-02-06 20:31:02 +01:00
|
|
|
// system so that they can be overridden with flags such as
|
2008-04-08 23:12:19 -07:00
|
|
|
// "--backboneNodes=20"
|
|
|
|
|
//
|
|
|
|
|
CommandLine cmd;
|
2011-05-22 23:18:47 -07:00
|
|
|
cmd.AddValue ("backboneNodes", "number of backbone nodes", backboneNodes);
|
2008-04-08 23:12:19 -07:00
|
|
|
cmd.AddValue ("infraNodes", "number of leaf nodes", infraNodes);
|
2011-05-22 23:18:47 -07:00
|
|
|
cmd.AddValue ("lanNodes", "number of LAN nodes", lanNodes);
|
|
|
|
|
cmd.AddValue ("stopTime", "simulation stop time (seconds)", stopTime);
|
|
|
|
|
cmd.AddValue ("useCourseChangeCallback", "whether to enable course change tracing", useCourseChangeCallback);
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// The system global variables and the local values added to the argument
|
|
|
|
|
// system can be overridden by command line arguments by using this call.
|
|
|
|
|
//
|
|
|
|
|
cmd.Parse (argc, argv);
|
|
|
|
|
|
2014-05-04 17:59:01 -07:00
|
|
|
if (stopTime < 10)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Use a simulation stop time >= 10 seconds" << std::endl;
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
// //
|
|
|
|
|
// Construct the backbone //
|
|
|
|
|
// //
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Create a container to manage the nodes of the adhoc (backbone) network.
|
|
|
|
|
// Later we'll create the rest of the nodes we'll need.
|
|
|
|
|
//
|
|
|
|
|
NodeContainer backbone;
|
|
|
|
|
backbone.Create (backboneNodes);
|
|
|
|
|
//
|
2017-02-06 20:31:02 +01:00
|
|
|
// Create the backbone wifi net devices and install them into the nodes in
|
2008-04-08 23:12:19 -07:00
|
|
|
// our container
|
|
|
|
|
//
|
2008-12-30 12:14:54 -08:00
|
|
|
WifiHelper wifi;
|
2016-02-05 21:48:25 +01:00
|
|
|
WifiMacHelper mac;
|
2009-04-24 10:01:41 +02:00
|
|
|
mac.SetType ("ns3::AdhocWifiMac");
|
2008-12-30 12:14:54 -08:00
|
|
|
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
|
2010-06-16 10:55:13 +01:00
|
|
|
"DataMode", StringValue ("OfdmRate54Mbps"));
|
2008-11-04 14:06:34 +01:00
|
|
|
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
|
|
|
|
|
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
|
|
|
|
|
wifiPhy.SetChannel (wifiChannel.Create ());
|
2009-04-24 10:01:41 +02:00
|
|
|
NetDeviceContainer backboneDevices = wifi.Install (wifiPhy, mac, backbone);
|
2009-06-26 15:34:16 +02:00
|
|
|
|
|
|
|
|
// We enable OLSR (which will be consulted at a higher priority than
|
|
|
|
|
// the global routing) on the backbone ad hoc nodes
|
|
|
|
|
NS_LOG_INFO ("Enabling OLSR routing on all backbone nodes");
|
|
|
|
|
OlsrHelper olsr;
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
|
|
|
|
// Add the IPv4 protocol stack to the nodes in our container
|
|
|
|
|
//
|
|
|
|
|
InternetStackHelper internet;
|
2011-05-12 21:49:50 -07:00
|
|
|
internet.SetRoutingHelper (olsr); // has effect on the next Install ()
|
2008-04-08 23:12:19 -07:00
|
|
|
internet.Install (backbone);
|
2009-06-26 15:34:16 +02:00
|
|
|
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
|
|
|
|
// Assign IPv4 addresses to the device drivers (actually to the associated
|
|
|
|
|
// IPv4 interfaces) we just created.
|
|
|
|
|
//
|
|
|
|
|
Ipv4AddressHelper ipAddrs;
|
|
|
|
|
ipAddrs.SetBase ("192.168.0.0", "255.255.255.0");
|
|
|
|
|
ipAddrs.Assign (backboneDevices);
|
|
|
|
|
|
|
|
|
|
//
|
2017-02-06 20:31:02 +01:00
|
|
|
// The ad-hoc network nodes need a mobility model so we aggregate one to
|
2010-12-01 22:13:26 +00:00
|
|
|
// each of the nodes we just finished building.
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
|
|
|
|
MobilityHelper mobility;
|
2014-05-04 18:37:17 -07:00
|
|
|
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
|
|
|
|
|
"MinX", DoubleValue (20.0),
|
|
|
|
|
"MinY", DoubleValue (20.0),
|
|
|
|
|
"DeltaX", DoubleValue (20.0),
|
|
|
|
|
"DeltaY", DoubleValue (20.0),
|
|
|
|
|
"GridWidth", UintegerValue (5),
|
|
|
|
|
"LayoutType", StringValue ("RowFirst"));
|
2008-04-08 23:12:19 -07:00
|
|
|
mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
|
2014-05-04 18:37:17 -07:00
|
|
|
"Bounds", RectangleValue (Rectangle (-500, 500, -500, 500)),
|
2012-08-15 14:28:33 -07:00
|
|
|
"Speed", StringValue ("ns3::ConstantRandomVariable[Constant=2]"),
|
|
|
|
|
"Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.2]"));
|
2008-04-22 22:08:53 -07:00
|
|
|
mobility.Install (backbone);
|
2008-04-08 23:12:19 -07:00
|
|
|
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
// //
|
|
|
|
|
// Construct the LANs //
|
|
|
|
|
// //
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
// Reset the address base-- all of the CSMA networks will be in
|
|
|
|
|
// the "172.16 address space
|
|
|
|
|
ipAddrs.SetBase ("172.16.0.0", "255.255.255.0");
|
|
|
|
|
|
2008-04-13 15:46:17 -07:00
|
|
|
|
2008-04-08 23:12:19 -07:00
|
|
|
for (uint32_t i = 0; i < backboneNodes; ++i)
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_INFO ("Configuring local area network for backbone node " << i);
|
|
|
|
|
//
|
2008-04-13 15:46:17 -07:00
|
|
|
// Create a container to manage the nodes of the LAN. We need
|
|
|
|
|
// two containers here; one with all of the new nodes, and one
|
|
|
|
|
// with all of the nodes including new and existing nodes
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
2008-04-13 15:46:17 -07:00
|
|
|
NodeContainer newLanNodes;
|
|
|
|
|
newLanNodes.Create (lanNodes - 1);
|
|
|
|
|
// Now, create the container with all nodes on this link
|
|
|
|
|
NodeContainer lan (backbone.Get (i), newLanNodes);
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
2017-02-06 20:31:02 +01:00
|
|
|
// Create the CSMA net devices and install them into the nodes in our
|
2008-04-08 23:12:19 -07:00
|
|
|
// collection.
|
|
|
|
|
//
|
|
|
|
|
CsmaHelper csma;
|
2017-02-06 20:31:02 +01:00
|
|
|
csma.SetChannelAttribute ("DataRate",
|
2010-12-01 22:13:26 +00:00
|
|
|
DataRateValue (DataRate (5000000)));
|
2008-07-03 15:44:54 -07:00
|
|
|
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
|
2008-04-08 23:12:19 -07:00
|
|
|
NetDeviceContainer lanDevices = csma.Install (lan);
|
|
|
|
|
//
|
2008-04-13 15:46:17 -07:00
|
|
|
// Add the IPv4 protocol stack to the new LAN nodes
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
2008-04-13 15:46:17 -07:00
|
|
|
internet.Install (newLanNodes);
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
2017-02-06 20:31:02 +01:00
|
|
|
// Assign IPv4 addresses to the device drivers (actually to the
|
2008-04-08 23:12:19 -07:00
|
|
|
// associated IPv4 interfaces) we just created.
|
|
|
|
|
//
|
|
|
|
|
ipAddrs.Assign (lanDevices);
|
|
|
|
|
//
|
|
|
|
|
// Assign a new network prefix for the next LAN, according to the
|
|
|
|
|
// network mask initialized above
|
|
|
|
|
//
|
|
|
|
|
ipAddrs.NewNetwork ();
|
2014-05-04 18:37:17 -07:00
|
|
|
//
|
|
|
|
|
// The new LAN nodes need a mobility model so we aggregate one
|
|
|
|
|
// to each of the nodes we just finished building.
|
|
|
|
|
//
|
|
|
|
|
MobilityHelper mobilityLan;
|
2017-02-06 20:31:02 +01:00
|
|
|
Ptr<ListPositionAllocator> subnetAlloc =
|
2014-05-04 18:37:17 -07:00
|
|
|
CreateObject<ListPositionAllocator> ();
|
|
|
|
|
for (uint32_t j = 0; j < newLanNodes.GetN (); ++j)
|
|
|
|
|
{
|
2017-02-06 20:31:02 +01:00
|
|
|
subnetAlloc->Add (Vector (0.0, j * 10 + 10, 0.0));
|
2014-05-04 18:37:17 -07:00
|
|
|
}
|
|
|
|
|
mobilityLan.PushReferenceMobilityModel (backbone.Get (i));
|
|
|
|
|
mobilityLan.SetPositionAllocator (subnetAlloc);
|
|
|
|
|
mobilityLan.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
|
|
|
|
|
mobilityLan.Install (newLanNodes);
|
2008-04-08 23:12:19 -07:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
// //
|
|
|
|
|
// Construct the mobile networks //
|
|
|
|
|
// //
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
// Reset the address base-- all of the 802.11 networks will be in
|
|
|
|
|
// the "10.0" address space
|
|
|
|
|
ipAddrs.SetBase ("10.0.0.0", "255.255.255.0");
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < backboneNodes; ++i)
|
|
|
|
|
{
|
|
|
|
|
NS_LOG_INFO ("Configuring wireless network for backbone node " << i);
|
|
|
|
|
//
|
2008-04-13 15:46:17 -07:00
|
|
|
// Create a container to manage the nodes of the LAN. We need
|
|
|
|
|
// two containers here; one with all of the new nodes, and one
|
|
|
|
|
// with all of the nodes including new and existing nodes
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
2008-12-30 21:51:36 -08:00
|
|
|
NodeContainer stas;
|
|
|
|
|
stas.Create (infraNodes - 1);
|
2008-04-13 15:46:17 -07:00
|
|
|
// Now, create the container with all nodes on this link
|
2008-12-30 21:51:36 -08:00
|
|
|
NodeContainer infra (backbone.Get (i), stas);
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
2008-12-30 21:51:36 -08:00
|
|
|
// Create an infrastructure network
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
2016-02-05 21:48:25 +01:00
|
|
|
WifiHelper wifiInfra;
|
|
|
|
|
WifiMacHelper macInfra;
|
2008-11-04 14:06:34 +01:00
|
|
|
wifiPhy.SetChannel (wifiChannel.Create ());
|
2008-12-30 21:51:36 -08:00
|
|
|
// Create unique ssids for these networks
|
2011-05-22 23:18:47 -07:00
|
|
|
std::string ssidString ("wifi-infra");
|
2008-12-30 21:51:36 -08:00
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << i;
|
2011-05-22 23:18:47 -07:00
|
|
|
ssidString += ss.str ();
|
2008-12-30 21:51:36 -08:00
|
|
|
Ssid ssid = Ssid (ssidString);
|
|
|
|
|
wifiInfra.SetRemoteStationManager ("ns3::ArfWifiManager");
|
|
|
|
|
// setup stas
|
2010-12-02 07:51:34 +00:00
|
|
|
macInfra.SetType ("ns3::StaWifiMac",
|
2016-07-02 11:48:13 +02:00
|
|
|
"Ssid", SsidValue (ssid));
|
2009-04-24 10:01:41 +02:00
|
|
|
NetDeviceContainer staDevices = wifiInfra.Install (wifiPhy, macInfra, stas);
|
2008-12-30 21:51:36 -08:00
|
|
|
// setup ap.
|
2010-12-02 07:51:34 +00:00
|
|
|
macInfra.SetType ("ns3::ApWifiMac",
|
2014-05-04 17:59:01 -07:00
|
|
|
"Ssid", SsidValue (ssid),
|
2017-02-06 20:31:02 +01:00
|
|
|
"BeaconInterval", TimeValue (Seconds (2.5)));
|
2009-04-24 10:01:41 +02:00
|
|
|
NetDeviceContainer apDevices = wifiInfra.Install (wifiPhy, macInfra, backbone.Get (i));
|
2008-12-30 21:51:36 -08:00
|
|
|
// Collect all of these new devices
|
|
|
|
|
NetDeviceContainer infraDevices (apDevices, staDevices);
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
// Add the IPv4 protocol stack to the nodes in our container
|
|
|
|
|
//
|
2008-12-30 21:51:36 -08:00
|
|
|
internet.Install (stas);
|
2008-04-08 23:12:19 -07:00
|
|
|
//
|
|
|
|
|
// Assign IPv4 addresses to the device drivers (actually to the associated
|
|
|
|
|
// IPv4 interfaces) we just created.
|
|
|
|
|
//
|
|
|
|
|
ipAddrs.Assign (infraDevices);
|
|
|
|
|
//
|
2017-02-06 20:31:02 +01:00
|
|
|
// Assign a new network prefix for each mobile network, according to
|
2008-04-08 23:12:19 -07:00
|
|
|
// the network mask initialized above
|
|
|
|
|
//
|
|
|
|
|
ipAddrs.NewNetwork ();
|
|
|
|
|
//
|
2017-02-06 20:31:02 +01:00
|
|
|
// The new wireless nodes need a mobility model so we aggregate one
|
2008-04-08 23:12:19 -07:00
|
|
|
// to each of the nodes we just finished building.
|
|
|
|
|
//
|
2017-02-06 20:31:02 +01:00
|
|
|
Ptr<ListPositionAllocator> subnetAlloc =
|
2008-04-08 23:12:19 -07:00
|
|
|
CreateObject<ListPositionAllocator> ();
|
|
|
|
|
for (uint32_t j = 0; j < infra.GetN (); ++j)
|
|
|
|
|
{
|
|
|
|
|
subnetAlloc->Add (Vector (0.0, j, 0.0));
|
|
|
|
|
}
|
|
|
|
|
mobility.PushReferenceMobilityModel (backbone.Get (i));
|
|
|
|
|
mobility.SetPositionAllocator (subnetAlloc);
|
|
|
|
|
mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
|
2008-12-30 21:51:36 -08:00
|
|
|
"Bounds", RectangleValue (Rectangle (-10, 10, -10, 10)),
|
2012-08-15 14:28:33 -07:00
|
|
|
"Speed", StringValue ("ns3::ConstantRandomVariable[Constant=3]"),
|
|
|
|
|
"Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.4]"));
|
2014-05-04 18:37:17 -07:00
|
|
|
mobility.Install (stas);
|
2008-04-08 23:12:19 -07:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
// //
|
|
|
|
|
// Application configuration //
|
|
|
|
|
// //
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
// Create the OnOff application to send UDP datagrams of size
|
2008-12-30 21:51:36 -08:00
|
|
|
// 210 bytes at a rate of 10 Kb/s, between two nodes
|
|
|
|
|
// We'll send data from the first wired LAN node on the first wired LAN
|
|
|
|
|
// to the last wireless STA on the last infrastructure net, thereby
|
|
|
|
|
// causing packets to traverse CSMA to adhoc to infrastructure links
|
|
|
|
|
|
2008-04-08 23:12:19 -07:00
|
|
|
NS_LOG_INFO ("Create Applications.");
|
|
|
|
|
uint16_t port = 9; // Discard port (RFC 863)
|
|
|
|
|
|
2008-12-30 21:51:36 -08:00
|
|
|
// Let's make sure that the user does not define too few nodes
|
|
|
|
|
// to make this example work. We need lanNodes > 1 and infraNodes > 1
|
|
|
|
|
NS_ASSERT (lanNodes > 1 && infraNodes > 1);
|
|
|
|
|
// We want the source to be the first node created outside of the backbone
|
|
|
|
|
// Conveniently, the variable "backboneNodes" holds this node index value
|
2010-12-01 22:13:26 +00:00
|
|
|
Ptr<Node> appSource = NodeList::GetNode (backboneNodes);
|
|
|
|
|
// We want the sink to be the last node created in the topology.
|
2017-02-06 20:31:02 +01:00
|
|
|
uint32_t lastNodeIndex = backboneNodes + backboneNodes * (lanNodes - 1) + backboneNodes * (infraNodes - 1) - 1;
|
2010-12-01 22:13:26 +00:00
|
|
|
Ptr<Node> appSink = NodeList::GetNode (lastNodeIndex);
|
2008-12-30 21:51:36 -08:00
|
|
|
// Let's fetch the IP address of the last node, which is on Ipv4Interface 1
|
2011-05-22 23:18:47 -07:00
|
|
|
Ipv4Address remoteAddr = appSink->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ();
|
2008-04-08 23:12:19 -07:00
|
|
|
|
2017-02-06 20:31:02 +01:00
|
|
|
OnOffHelper onoff ("ns3::UdpSocketFactory",
|
2008-04-08 23:12:19 -07:00
|
|
|
Address (InetSocketAddress (remoteAddr, port)));
|
2012-08-23 16:00:17 -07:00
|
|
|
|
2008-04-08 23:12:19 -07:00
|
|
|
ApplicationContainer apps = onoff.Install (appSource);
|
2014-05-04 17:59:01 -07:00
|
|
|
apps.Start (Seconds (3));
|
|
|
|
|
apps.Stop (Seconds (stopTime - 1));
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
// Create a packet sink to receive these packets
|
2017-02-06 20:31:02 +01:00
|
|
|
PacketSinkHelper sink ("ns3::UdpSocketFactory",
|
2008-04-08 23:12:19 -07:00
|
|
|
InetSocketAddress (Ipv4Address::GetAny (), port));
|
|
|
|
|
apps = sink.Install (appSink);
|
2014-05-04 17:59:01 -07:00
|
|
|
apps.Start (Seconds (3));
|
2008-04-08 23:12:19 -07:00
|
|
|
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
// //
|
|
|
|
|
// Tracing configuration //
|
|
|
|
|
// //
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
NS_LOG_INFO ("Configure Tracing.");
|
2014-05-04 17:59:01 -07:00
|
|
|
CsmaHelper csma;
|
2010-01-22 12:44:53 -08:00
|
|
|
|
2014-05-04 17:59:01 -07:00
|
|
|
//
|
|
|
|
|
// Let's set up some ns-2-like ascii traces, using another helper class
|
|
|
|
|
//
|
|
|
|
|
AsciiTraceHelper ascii;
|
|
|
|
|
Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream ("mixed-wireless.tr");
|
|
|
|
|
wifiPhy.EnableAsciiAll (stream);
|
|
|
|
|
csma.EnableAsciiAll (stream);
|
|
|
|
|
internet.EnableAsciiIpv4All (stream);
|
|
|
|
|
|
|
|
|
|
// Csma captures in non-promiscuous mode
|
|
|
|
|
csma.EnablePcapAll ("mixed-wireless", false);
|
|
|
|
|
// pcap captures on the backbone wifi devices
|
|
|
|
|
wifiPhy.EnablePcap ("mixed-wireless", backboneDevices, false);
|
|
|
|
|
// pcap trace on the application data sink
|
|
|
|
|
wifiPhy.EnablePcap ("mixed-wireless", appSink->GetId (), 0);
|
2008-04-08 23:12:19 -07:00
|
|
|
|
2008-12-30 13:18:56 -08:00
|
|
|
if (useCourseChangeCallback == true)
|
|
|
|
|
{
|
|
|
|
|
Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", MakeCallback (&CourseChangeCallback));
|
|
|
|
|
}
|
2008-05-15 11:25:17 -07:00
|
|
|
|
2014-05-04 18:46:44 -07:00
|
|
|
AnimationInterface anim ("mixed-wireless.xml");
|
|
|
|
|
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
// //
|
|
|
|
|
// Run simulation //
|
|
|
|
|
// //
|
2017-02-06 20:31:02 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-08 23:12:19 -07:00
|
|
|
|
|
|
|
|
NS_LOG_INFO ("Run Simulation.");
|
2008-05-29 11:45:57 +01:00
|
|
|
Simulator::Stop (Seconds (stopTime));
|
2010-12-01 22:13:26 +00:00
|
|
|
Simulator::Run ();
|
2008-04-08 23:12:19 -07:00
|
|
|
Simulator::Destroy ();
|
|
|
|
|
}
|