2007-02-19 12:22:20 +01:00
|
|
|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
2007-02-02 00:04:48 -08:00
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
|
*
|
|
|
|
|
* ns-2 simple.tcl script (ported from ns-2)
|
|
|
|
|
* Originally authored by Steve McCanne, 12/19/1996
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Port of ns-2/tcl/ex/simple.tcl to ns-3
|
2007-03-07 22:45:17 -08:00
|
|
|
//
|
|
|
|
|
// Network topology
|
|
|
|
|
//
|
|
|
|
|
// n0
|
|
|
|
|
// \ 5 Mb/s, 2ms
|
|
|
|
|
// \ 1.5Mb/s, 10ms
|
|
|
|
|
// n2 -------------------------n3
|
|
|
|
|
// /
|
|
|
|
|
// / 5 Mb/s, 2ms
|
|
|
|
|
// n1
|
|
|
|
|
//
|
2007-07-27 13:07:36 -07:00
|
|
|
// - all links are point-to-point links with indicated one-way BW/delay
|
2007-03-07 22:45:17 -08:00
|
|
|
// - CBR/UDP flows from n0 to n3, and from n3 to n1
|
|
|
|
|
// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
|
|
|
|
|
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
|
2007-03-27 23:14:31 -07:00
|
|
|
// (i.e., DataRate of 448,000 bps)
|
2007-03-07 22:45:17 -08:00
|
|
|
// - DropTail queues
|
2007-07-27 13:07:36 -07:00
|
|
|
// - Tracing of queues and packet receptions to file
|
|
|
|
|
// "simple-point-to-point.tr"
|
2007-02-02 00:04:48 -08:00
|
|
|
|
2007-02-19 00:44:05 -08:00
|
|
|
#include <iostream>
|
2007-03-19 07:02:14 -07:00
|
|
|
#include <fstream>
|
2007-02-19 00:44:05 -08:00
|
|
|
#include <string>
|
2007-02-22 09:40:46 +01:00
|
|
|
#include <cassert>
|
2007-02-19 00:44:05 -08:00
|
|
|
|
2007-04-26 11:36:05 -04:00
|
|
|
#include "ns3/command-line.h"
|
|
|
|
|
#include "ns3/default-value.h"
|
2007-05-09 13:26:21 -04:00
|
|
|
#include "ns3/ptr.h"
|
2007-06-12 11:04:00 +02:00
|
|
|
#include "ns3/random-variable.h"
|
2007-02-22 09:40:46 +01:00
|
|
|
|
2007-02-15 21:54:16 -08:00
|
|
|
#include "ns3/simulator.h"
|
2007-02-15 21:56:24 -08:00
|
|
|
#include "ns3/nstime.h"
|
2007-03-25 15:33:24 -07:00
|
|
|
#include "ns3/data-rate.h"
|
2007-02-22 09:40:46 +01:00
|
|
|
|
2007-03-28 19:26:58 +02:00
|
|
|
#include "ns3/ascii-trace.h"
|
2007-03-29 23:24:10 +02:00
|
|
|
#include "ns3/pcap-trace.h"
|
2007-02-15 22:27:33 -08:00
|
|
|
#include "ns3/internet-node.h"
|
2007-07-27 20:26:36 +02:00
|
|
|
#include "ns3/point-to-point-channel.h"
|
|
|
|
|
#include "ns3/point-to-point-net-device.h"
|
2007-02-18 23:29:05 -08:00
|
|
|
#include "ns3/ipv4-address.h"
|
2007-07-30 13:29:36 +02:00
|
|
|
#include "ns3/inet-socket-address.h"
|
2007-06-04 18:25:43 +02:00
|
|
|
#include "ns3/ipv4.h"
|
2007-04-30 16:23:10 +02:00
|
|
|
#include "ns3/socket.h"
|
2007-02-19 00:44:05 -08:00
|
|
|
#include "ns3/ipv4-route.h"
|
2007-07-27 20:26:36 +02:00
|
|
|
#include "ns3/point-to-point-topology.h"
|
2007-03-21 23:17:11 -07:00
|
|
|
#include "ns3/onoff-application.h"
|
2007-03-19 00:40:44 -07:00
|
|
|
|
2007-02-02 00:04:48 -08:00
|
|
|
using namespace ns3;
|
|
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
|
{
|
2007-05-04 11:50:02 -07:00
|
|
|
|
|
|
|
|
// Users may find it convenient to turn on explicit debugging
|
|
|
|
|
// for selected modules; the below lines suggest how to do this
|
2007-08-22 12:02:42 -04:00
|
|
|
// remember to add #include "ns3/debug.h" before enabling these
|
2007-05-04 12:17:14 -07:00
|
|
|
#if 0
|
2007-03-27 15:41:08 -07:00
|
|
|
DebugComponentEnable("Object");
|
2007-03-18 03:43:49 -07:00
|
|
|
DebugComponentEnable("Queue");
|
|
|
|
|
DebugComponentEnable("DropTailQueue");
|
|
|
|
|
DebugComponentEnable("Channel");
|
2007-03-25 07:13:03 -07:00
|
|
|
DebugComponentEnable("PointToPointChannel");
|
|
|
|
|
DebugComponentEnable("PointToPointNetDevice");
|
2007-03-18 03:43:49 -07:00
|
|
|
#endif
|
2007-03-19 07:02:14 -07:00
|
|
|
|
2007-05-04 11:50:02 -07:00
|
|
|
// Set up some default values for the simulation. Use the Bind()
|
|
|
|
|
// technique to tell the system what subclass of Queue to use,
|
|
|
|
|
// and what the queue limit is
|
|
|
|
|
|
|
|
|
|
// The below Bind command tells the queue factory which class to
|
|
|
|
|
// instantiate, when the queue factory is invoked in the topology code
|
2007-08-08 16:41:59 +02:00
|
|
|
DefaultValue::Bind ("Queue", "DropTailQueue");
|
2007-05-14 11:12:29 +02:00
|
|
|
|
2007-08-08 16:41:59 +02:00
|
|
|
DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
|
|
|
|
|
DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s");
|
2007-05-04 11:50:02 -07:00
|
|
|
|
2007-08-08 16:41:59 +02:00
|
|
|
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
|
2007-05-04 11:50:02 -07:00
|
|
|
|
|
|
|
|
// Allow the user to override any of the defaults and the above
|
|
|
|
|
// Bind()s at run-time, via command-line arguments
|
|
|
|
|
CommandLine::Parse (argc, argv);
|
2007-03-25 17:47:59 -07:00
|
|
|
|
2007-05-04 11:50:02 -07:00
|
|
|
// Here, we will explicitly create four nodes. In more sophisticated
|
|
|
|
|
// topologies, we could configure a node factory.
|
2007-06-04 16:32:37 +02:00
|
|
|
Ptr<Node> n0 = Create<InternetNode> ();
|
|
|
|
|
Ptr<Node> n1 = Create<InternetNode> ();
|
|
|
|
|
Ptr<Node> n2 = Create<InternetNode> ();
|
|
|
|
|
Ptr<Node> n3 = Create<InternetNode> ();
|
2007-03-19 22:27:22 -07:00
|
|
|
|
2007-05-04 11:50:02 -07:00
|
|
|
// We create the channels first without any IP addressing information
|
2007-05-10 20:19:26 +02:00
|
|
|
Ptr<PointToPointChannel> channel0 =
|
2007-05-02 11:43:22 +02:00
|
|
|
PointToPointTopology::AddPointToPointLink (
|
2007-05-04 12:17:14 -07:00
|
|
|
n0, n2, DataRate(5000000), MilliSeconds(2));
|
|
|
|
|
|
2007-05-10 20:19:26 +02:00
|
|
|
Ptr<PointToPointChannel> channel1 =
|
2007-05-02 11:43:22 +02:00
|
|
|
PointToPointTopology::AddPointToPointLink (
|
2007-05-04 12:17:14 -07:00
|
|
|
n1, n2, DataRate(5000000), MilliSeconds(2));
|
|
|
|
|
|
2007-05-10 20:19:26 +02:00
|
|
|
Ptr<PointToPointChannel> channel2 =
|
2007-05-02 11:43:22 +02:00
|
|
|
PointToPointTopology::AddPointToPointLink (
|
2007-05-04 12:17:14 -07:00
|
|
|
n2, n3, DataRate(1500000), MilliSeconds(10));
|
2007-02-21 17:58:14 +01:00
|
|
|
|
2007-05-04 12:17:14 -07:00
|
|
|
// Later, we add IP addresses.
|
|
|
|
|
PointToPointTopology::AddIpv4Addresses (
|
|
|
|
|
channel0, n0, Ipv4Address("10.1.1.1"),
|
|
|
|
|
n2, Ipv4Address("10.1.1.2"));
|
|
|
|
|
|
|
|
|
|
PointToPointTopology::AddIpv4Addresses (
|
|
|
|
|
channel1, n1, Ipv4Address("10.1.2.1"),
|
|
|
|
|
n2, Ipv4Address("10.1.2.2"));
|
|
|
|
|
|
|
|
|
|
PointToPointTopology::AddIpv4Addresses (
|
|
|
|
|
channel2, n2, Ipv4Address("10.1.3.1"),
|
|
|
|
|
n3, Ipv4Address("10.1.3.2"));
|
|
|
|
|
|
2007-05-12 15:31:40 -07:00
|
|
|
// Finally, we add static routes. These three steps (Channel and
|
|
|
|
|
// NetDevice creation, IP Address assignment, and routing) are
|
|
|
|
|
// separated because there may be a need to postpone IP Address
|
|
|
|
|
// assignment (emulation) or modify to use dynamic routing
|
|
|
|
|
PointToPointTopology::AddIpv4Routes(n0, n2, channel0);
|
|
|
|
|
PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
|
|
|
|
|
PointToPointTopology::AddIpv4Routes(n2, n3, channel2);
|
|
|
|
|
|
2007-05-04 12:17:14 -07:00
|
|
|
|
2007-03-27 23:14:31 -07:00
|
|
|
// Create the OnOff application to send UDP datagrams of size
|
|
|
|
|
// 210 bytes at a rate of 448 Kb/s
|
2007-06-04 16:32:37 +02:00
|
|
|
Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
|
2007-05-02 15:07:33 +02:00
|
|
|
n0,
|
2007-07-30 14:07:39 +02:00
|
|
|
InetSocketAddress ("10.1.3.2", 80),
|
2007-06-06 10:54:58 +02:00
|
|
|
"Udp",
|
2007-03-27 23:14:31 -07:00
|
|
|
ConstantVariable(1),
|
2007-05-14 11:12:29 +02:00
|
|
|
ConstantVariable(0));
|
2007-03-27 23:14:31 -07:00
|
|
|
// Start the application
|
2007-05-13 09:46:38 +02:00
|
|
|
ooff->Start(Seconds(1.0));
|
|
|
|
|
ooff->Stop (Seconds(10.0));
|
2007-03-27 23:14:31 -07:00
|
|
|
|
|
|
|
|
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
|
2007-06-04 16:32:37 +02:00
|
|
|
ooff = Create<OnOffApplication> (
|
2007-05-02 15:07:33 +02:00
|
|
|
n3,
|
2007-07-30 14:07:39 +02:00
|
|
|
InetSocketAddress ("10.1.2.1", 80),
|
2007-06-06 10:54:58 +02:00
|
|
|
"Udp",
|
2007-03-27 23:14:31 -07:00
|
|
|
ConstantVariable(1),
|
2007-05-14 11:12:29 +02:00
|
|
|
ConstantVariable(0));
|
2007-03-27 23:14:31 -07:00
|
|
|
// Start the application
|
2007-05-13 09:46:38 +02:00
|
|
|
ooff->Start(Seconds(1.1));
|
|
|
|
|
ooff->Stop (Seconds(10.0));
|
2007-02-21 17:58:14 +01:00
|
|
|
|
|
|
|
|
// Here, finish off packet routing configuration
|
2007-03-27 23:14:31 -07:00
|
|
|
// This will likely set by some global StaticRouting object in the future
|
2007-06-04 18:25:43 +02:00
|
|
|
Ptr<Ipv4> ipv4;
|
|
|
|
|
ipv4 = n0->QueryInterface<Ipv4> (Ipv4::iid);
|
2007-05-03 00:31:04 +02:00
|
|
|
ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1);
|
2007-06-04 18:25:43 +02:00
|
|
|
ipv4 = n3->QueryInterface<Ipv4> (Ipv4::iid);
|
2007-05-03 00:31:04 +02:00
|
|
|
ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1);
|
2007-05-09 14:50:14 -04:00
|
|
|
|
2007-03-27 23:14:31 -07:00
|
|
|
// Configure tracing of all enqueue, dequeue, and NetDevice receive events
|
2007-07-27 13:07:36 -07:00
|
|
|
// Trace output will be sent to the simple-point-to-point.tr file
|
|
|
|
|
AsciiTrace asciitrace ("simple-point-to-point.tr");
|
2007-05-04 12:17:14 -07:00
|
|
|
asciitrace.TraceAllQueues ();
|
|
|
|
|
asciitrace.TraceAllNetDeviceRx ();
|
|
|
|
|
|
|
|
|
|
// Also configure some tcpdump traces; each interface will be traced
|
2007-07-27 13:07:36 -07:00
|
|
|
// The output files will be named
|
|
|
|
|
// simple-point-to-point.pcap-<nodeId>-<interfaceId>
|
2007-05-12 15:36:41 -07:00
|
|
|
// and can be read by the "tcpdump -r" command (use "-tt" option to
|
|
|
|
|
// display timestamps correctly)
|
2007-07-27 13:07:36 -07:00
|
|
|
PcapTrace pcaptrace ("simple-point-to-point.pcap");
|
2007-05-04 12:17:14 -07:00
|
|
|
pcaptrace.TraceAllIp ();
|
2007-03-18 14:06:51 -07:00
|
|
|
|
2007-02-21 17:58:14 +01:00
|
|
|
Simulator::Run ();
|
2007-02-02 00:04:48 -08:00
|
|
|
|
2007-02-21 17:58:14 +01:00
|
|
|
Simulator::Destroy ();
|
2007-02-02 00:04:48 -08:00
|
|
|
}
|