2007-09-26 19:55:09 -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
|
|
|
|
|
*/
|
|
|
|
|
|
2008-03-31 13:10:17 -07:00
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
#include "ns3/core-module.h"
|
|
|
|
|
#include "ns3/node-module.h"
|
|
|
|
|
#include "ns3/helper-module.h"
|
|
|
|
|
#include "ns3/simulator-module.h"
|
2007-09-26 19:55:09 -07:00
|
|
|
#include "ns3/global-route-manager.h"
|
2008-03-31 13:10:17 -07:00
|
|
|
|
2007-09-26 19:55:09 -07:00
|
|
|
|
2007-10-02 15:34:00 -07:00
|
|
|
NS_LOG_COMPONENT_DEFINE ("DumbbellSimulation");
|
2007-09-26 19:55:09 -07:00
|
|
|
|
|
|
|
|
using namespace ns3;
|
|
|
|
|
|
|
|
|
|
// Network topology
|
|
|
|
|
//
|
|
|
|
|
// point to point
|
|
|
|
|
// +--------------+
|
|
|
|
|
// | |
|
|
|
|
|
// n0 n1 n2 n3 n4 n5 n6 n7
|
|
|
|
|
// | | | | | | | |
|
|
|
|
|
// ================ ================
|
2007-10-02 15:34:00 -07:00
|
|
|
// lan1 lan2
|
2007-09-26 19:55:09 -07:00
|
|
|
//
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
2007-10-02 15:34:00 -07:00
|
|
|
LogComponentEnable ("DumbbellSimulation", LOG_LEVEL_INFO);
|
2007-09-26 19:55:09 -07:00
|
|
|
|
2007-10-02 15:34:00 -07:00
|
|
|
NS_LOG_INFO ("Dumbbell Topology Simulation");
|
2007-10-09 18:02:32 -07:00
|
|
|
//
|
|
|
|
|
// Create the lan on the left side of the dumbbell.
|
|
|
|
|
//
|
2008-03-31 13:10:17 -07:00
|
|
|
NodeContainer lan1;
|
|
|
|
|
lan1.Create (4);
|
2007-09-26 19:55:09 -07:00
|
|
|
|
2008-03-31 13:10:17 -07:00
|
|
|
InternetStackHelper internet;
|
2008-04-07 10:38:37 -07:00
|
|
|
internet.Install (lan1);
|
2007-09-26 19:55:09 -07:00
|
|
|
|
2008-03-31 13:10:17 -07:00
|
|
|
CsmaHelper csma;
|
2008-06-07 10:38:39 -07:00
|
|
|
csma.SetChannelParameter ("DataRate", StringValue ("10Mbps"));
|
2008-04-17 13:42:25 -07:00
|
|
|
csma.SetChannelParameter ("Delay", StringValue ("2ms"));
|
2008-04-07 10:38:37 -07:00
|
|
|
NetDeviceContainer dev1 = csma.Install (lan1);
|
2008-03-31 13:10:17 -07:00
|
|
|
Ipv4AddressHelper ipv4;
|
|
|
|
|
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
|
2008-04-07 10:41:21 -07:00
|
|
|
Ipv4InterfaceContainer i1 = ipv4.Assign (dev1);
|
2007-09-26 19:55:09 -07:00
|
|
|
|
|
|
|
|
|
2007-10-09 18:02:32 -07:00
|
|
|
//
|
|
|
|
|
// Create the lan on the right side of the dumbbell.
|
|
|
|
|
//
|
2008-03-31 13:10:17 -07:00
|
|
|
NodeContainer lan2;
|
|
|
|
|
lan2.Create (4);
|
2008-04-07 10:38:37 -07:00
|
|
|
internet.Install (lan2);
|
2007-09-26 19:55:09 -07:00
|
|
|
|
2008-04-07 10:38:37 -07:00
|
|
|
NetDeviceContainer dev2 = csma.Install (lan2);
|
2008-03-31 13:10:17 -07:00
|
|
|
ipv4.SetBase ("10.1.2.0", "255.255.255.0");
|
2008-04-07 10:41:21 -07:00
|
|
|
Ipv4InterfaceContainer i2 = ipv4.Assign (dev2);
|
2007-09-26 19:55:09 -07:00
|
|
|
|
|
|
|
|
|
2007-10-09 18:02:32 -07:00
|
|
|
//
|
|
|
|
|
// Create the point-to-point link to connect the two lans.
|
|
|
|
|
//
|
2008-03-31 13:10:17 -07:00
|
|
|
NodeContainer backbone = NodeContainer (lan1.Get (3), lan2.Get (0));
|
|
|
|
|
PointToPointHelper p2p;
|
2008-06-07 10:38:39 -07:00
|
|
|
p2p.SetChannelParameter ("DataRate", StringValue ("38400bps"));
|
2008-04-17 13:42:25 -07:00
|
|
|
p2p.SetChannelParameter ("Delay", StringValue ("20ms"));
|
2008-04-07 10:38:37 -07:00
|
|
|
NetDeviceContainer dev3 = p2p.Install (backbone);
|
2008-03-31 13:10:17 -07:00
|
|
|
ipv4.SetBase ("10.1.3.0", "255.255.255.0");
|
2008-04-07 10:41:21 -07:00
|
|
|
ipv4.Assign (dev3);
|
2007-09-26 19:55:09 -07:00
|
|
|
|
2007-10-09 18:02:32 -07:00
|
|
|
//
|
|
|
|
|
// Create data flows across the link:
|
|
|
|
|
// n0 ==> n4 ==> n0
|
|
|
|
|
// n1 ==> n5 ==> n1
|
|
|
|
|
// n2 ==> n6 ==> n2
|
|
|
|
|
// n3 ==> n7 ==> n3
|
|
|
|
|
//
|
2007-09-26 19:55:09 -07:00
|
|
|
uint16_t port = 7;
|
|
|
|
|
|
2008-03-31 13:10:17 -07:00
|
|
|
UdpEchoClientHelper client;
|
|
|
|
|
client.SetRemote (i2.GetAddress (0), port);
|
2008-04-17 13:42:25 -07:00
|
|
|
client.SetAppAttribute ("MaxPackets", UintegerValue (100));
|
|
|
|
|
client.SetAppAttribute ("Interval", StringValue ("10ms"));
|
|
|
|
|
client.SetAppAttribute ("PacketSize", UintegerValue (1024));
|
2008-04-07 10:38:37 -07:00
|
|
|
ApplicationContainer apps = client.Install (lan1.Get (0));
|
2008-03-31 13:10:17 -07:00
|
|
|
apps.Start (Seconds(2.));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
|
|
|
|
|
|
|
|
|
client.SetRemote (i2.GetAddress (1), port);
|
2008-04-07 10:38:37 -07:00
|
|
|
apps = client.Install (lan1.Get (1));
|
2008-03-31 13:10:17 -07:00
|
|
|
apps.Start (Seconds(2.1));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
|
|
|
|
|
|
|
|
|
client.SetRemote (i2.GetAddress (2), port);
|
2008-04-07 10:38:37 -07:00
|
|
|
apps = client.Install (lan1.Get (2));
|
2008-03-31 13:10:17 -07:00
|
|
|
apps.Start (Seconds(2.2));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
|
|
|
|
|
|
|
|
|
client.SetRemote (i2.GetAddress (3), port);
|
2008-04-07 10:38:37 -07:00
|
|
|
apps = client.Install (lan1.Get (3));
|
2008-03-31 13:10:17 -07:00
|
|
|
apps.Start (Seconds(2.3));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UdpEchoServerHelper server;
|
|
|
|
|
server.SetPort (port);
|
2008-04-07 10:38:37 -07:00
|
|
|
apps = server.Install (lan2.Get (0));
|
2008-03-31 13:10:17 -07:00
|
|
|
apps.Start (Seconds (1.0));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
2008-04-07 10:38:37 -07:00
|
|
|
apps = server.Install (lan2.Get (1));
|
2008-03-31 13:10:17 -07:00
|
|
|
apps.Start (Seconds (1.0));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
2008-04-07 10:38:37 -07:00
|
|
|
apps = server.Install (lan2.Get (2));
|
2008-03-31 13:10:17 -07:00
|
|
|
apps.Start (Seconds (1.0));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
2008-04-07 10:38:37 -07:00
|
|
|
apps = server.Install (lan2.Get (3));
|
2008-03-31 13:10:17 -07:00
|
|
|
apps.Start (Seconds (1.0));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
2007-09-26 19:55:09 -07:00
|
|
|
|
|
|
|
|
GlobalRouteManager::PopulateRoutingTables ();
|
|
|
|
|
|
2008-03-31 13:10:17 -07:00
|
|
|
std::ofstream os;
|
|
|
|
|
os.open ("tutorial.tr");
|
2008-04-22 21:18:04 -07:00
|
|
|
PointToPointHelper::EnableAsciiAll (os);
|
|
|
|
|
CsmaHelper::EnableAsciiAll (os);
|
2008-03-31 13:10:17 -07:00
|
|
|
|
2008-04-22 21:18:04 -07:00
|
|
|
PointToPointHelper::EnablePcapAll ("tutorial");
|
|
|
|
|
CsmaHelper::EnablePcapAll ("tutorial");
|
2008-03-31 13:10:17 -07:00
|
|
|
|
2007-09-26 19:55:09 -07:00
|
|
|
Simulator::Run ();
|
|
|
|
|
Simulator::Destroy ();
|
|
|
|
|
}
|