2007-10-08 22:00:04 -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 11:07:19 -07:00
|
|
|
#include <fstream>
|
2007-10-08 22:00:04 -07:00
|
|
|
|
2008-03-31 11:07:19 -07:00
|
|
|
#include "ns3/core-module.h"
|
|
|
|
|
#include "ns3/node-module.h"
|
|
|
|
|
#include "ns3/helper-module.h"
|
|
|
|
|
#include "ns3/simulator-module.h"
|
|
|
|
|
#include "ns3/global-route-manager.h"
|
2007-11-15 18:56:34 -08:00
|
|
|
|
2007-10-09 18:02:32 -07:00
|
|
|
NS_LOG_COMPONENT_DEFINE ("StarRoutingSimulation");
|
2007-10-08 22:00:04 -07:00
|
|
|
|
|
|
|
|
using namespace ns3;
|
|
|
|
|
|
|
|
|
|
// Network topology
|
|
|
|
|
//
|
|
|
|
|
// n3 n2
|
|
|
|
|
// | /
|
|
|
|
|
// | /
|
|
|
|
|
// n4 --- n0 --- n1
|
|
|
|
|
// / |
|
|
|
|
|
// / |
|
|
|
|
|
// n5 n6
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
2007-10-09 18:02:32 -07:00
|
|
|
LogComponentEnable ("StarRoutingSimulation", LOG_LEVEL_INFO);
|
2007-10-08 22:00:04 -07:00
|
|
|
|
2007-10-09 18:02:32 -07:00
|
|
|
NS_LOG_INFO ("Star Topology with Routing Simulation");
|
2007-10-08 22:00:04 -07:00
|
|
|
|
2008-03-31 11:07:19 -07:00
|
|
|
NodeContainer n;
|
|
|
|
|
n.Create (7);
|
|
|
|
|
NodeContainer n01 = NodeContainer (n.Get (0), n.Get (1));
|
|
|
|
|
NodeContainer n02 = NodeContainer (n.Get (0), n.Get (2));
|
|
|
|
|
NodeContainer n03 = NodeContainer (n.Get (0), n.Get (3));
|
|
|
|
|
NodeContainer n04 = NodeContainer (n.Get (0), n.Get (4));
|
|
|
|
|
NodeContainer n05 = NodeContainer (n.Get (0), n.Get (5));
|
|
|
|
|
NodeContainer n06 = NodeContainer (n.Get (0), n.Get (6));
|
|
|
|
|
|
|
|
|
|
InternetStackHelper internet;
|
2008-04-07 10:38:37 -07:00
|
|
|
internet.Install (n);
|
2008-03-31 11:07:19 -07:00
|
|
|
|
|
|
|
|
PointToPointHelper p2p;
|
2008-06-07 10:38:39 -07:00
|
|
|
p2p.SetDeviceParameter ("DataRate", StringValue ("38400bps"));
|
2008-04-17 13:42:25 -07:00
|
|
|
p2p.SetChannelParameter ("Delay", StringValue ("20ms"));
|
2008-03-31 11:07:19 -07:00
|
|
|
|
2008-04-07 10:38:37 -07:00
|
|
|
NetDeviceContainer d01 = p2p.Install (n01);
|
|
|
|
|
NetDeviceContainer d02 = p2p.Install (n02);
|
|
|
|
|
NetDeviceContainer d03 = p2p.Install (n03);
|
|
|
|
|
NetDeviceContainer d04 = p2p.Install (n04);
|
|
|
|
|
NetDeviceContainer d05 = p2p.Install (n05);
|
|
|
|
|
NetDeviceContainer d06 = p2p.Install (n06);
|
2008-03-31 11:07:19 -07:00
|
|
|
|
|
|
|
|
Ipv4AddressHelper ipv4;
|
|
|
|
|
ipv4.SetBase ("10.1.1.0", "255.255.255.252");
|
2008-04-07 10:41:21 -07:00
|
|
|
Ipv4InterfaceContainer i01 = ipv4.Assign (d01);
|
2008-03-31 11:07:19 -07:00
|
|
|
ipv4.SetBase ("10.1.2.0", "255.255.255.252");
|
2008-04-07 10:41:21 -07:00
|
|
|
Ipv4InterfaceContainer i02 = ipv4.Assign (d02);
|
2008-03-31 11:07:19 -07:00
|
|
|
ipv4.SetBase ("10.1.3.0", "255.255.255.252");
|
2008-04-07 10:41:21 -07:00
|
|
|
Ipv4InterfaceContainer i03 = ipv4.Assign (d03);
|
2008-03-31 11:07:19 -07:00
|
|
|
ipv4.SetBase ("10.1.4.0", "255.255.255.252");
|
2008-04-07 10:41:21 -07:00
|
|
|
Ipv4InterfaceContainer i04 = ipv4.Assign (d04);
|
2008-03-31 11:07:19 -07:00
|
|
|
ipv4.SetBase ("10.1.5.0", "255.255.255.252");
|
2008-04-07 10:41:21 -07:00
|
|
|
Ipv4InterfaceContainer i05 = ipv4.Assign (d05);
|
2008-03-31 11:07:19 -07:00
|
|
|
ipv4.SetBase ("10.1.6.0", "255.255.255.252");
|
2008-04-07 10:41:21 -07:00
|
|
|
Ipv4InterfaceContainer i06 = ipv4.Assign (d06);
|
2007-10-08 22:00:04 -07:00
|
|
|
|
|
|
|
|
uint16_t port = 7;
|
|
|
|
|
|
2008-03-31 11:07:19 -07:00
|
|
|
UdpEchoServerHelper server;
|
|
|
|
|
server.SetPort (port);
|
2008-04-07 10:38:37 -07:00
|
|
|
ApplicationContainer apps = server.Install (n.Get (1));
|
2008-03-31 11:07:19 -07:00
|
|
|
apps.Start (Seconds (1.0));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
|
|
|
|
|
|
|
|
|
UdpEchoClientHelper client;
|
|
|
|
|
client.SetRemote (i01.GetAddress (1), port);
|
2008-04-17 13:42:25 -07:00
|
|
|
client.SetAppAttribute ("MaxPackets", UintegerValue (1));
|
|
|
|
|
client.SetAppAttribute ("Interval", StringValue ("1s"));
|
|
|
|
|
client.SetAppAttribute ("PacketSize", UintegerValue (1024));
|
2008-04-07 10:38:37 -07:00
|
|
|
apps = client.Install (n.Get (0));
|
2008-03-31 11:07:19 -07:00
|
|
|
apps.Start (Seconds (2.0));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
2007-10-08 22:00:04 -07:00
|
|
|
|
|
|
|
|
GlobalRouteManager::PopulateRoutingTables ();
|
|
|
|
|
|
2008-03-31 11:07:19 -07:00
|
|
|
std::ofstream ascii;
|
|
|
|
|
ascii.open ("tutorial.tr");
|
2008-04-22 21:18:04 -07:00
|
|
|
PointToPointHelper::EnableAsciiAll (ascii);
|
2008-03-31 11:07:19 -07:00
|
|
|
|
2007-10-08 22:00:04 -07:00
|
|
|
Simulator::Run ();
|
|
|
|
|
Simulator::Destroy ();
|
|
|
|
|
}
|