2007-10-08 20:51:21 -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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ns3/log.h"
|
|
|
|
|
#include "ns3/ptr.h"
|
|
|
|
|
#include "ns3/internet-node.h"
|
|
|
|
|
#include "ns3/point-to-point-channel.h"
|
|
|
|
|
#include "ns3/mac48-address.h"
|
|
|
|
|
#include "ns3/point-to-point-net-device.h"
|
|
|
|
|
#include "ns3/udp-echo-client.h"
|
|
|
|
|
#include "ns3/udp-echo-server.h"
|
|
|
|
|
#include "ns3/simulator.h"
|
|
|
|
|
#include "ns3/nstime.h"
|
|
|
|
|
#include "ns3/ascii-trace.h"
|
|
|
|
|
#include "ns3/pcap-trace.h"
|
|
|
|
|
#include "ns3/global-route-manager.h"
|
2008-02-27 00:05:23 +01:00
|
|
|
#include "ns3/inet-socket-address.h"
|
|
|
|
|
#include "ns3/uinteger.h"
|
2007-10-08 20:51:21 -07:00
|
|
|
|
2007-11-15 18:56:34 -08:00
|
|
|
#include "point-to-point-ipv4-topology.h"
|
|
|
|
|
|
2007-10-09 18:02:32 -07:00
|
|
|
NS_LOG_COMPONENT_DEFINE ("StarSimulation");
|
2007-10-08 20:51:21 -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 ("StarSimulation", LOG_LEVEL_INFO);
|
2007-10-08 20:51:21 -07:00
|
|
|
|
2007-10-09 18:02:32 -07:00
|
|
|
NS_LOG_INFO ("Star Topology Simulation");
|
2007-10-08 20:51:21 -07:00
|
|
|
|
2008-01-02 09:09:24 +01:00
|
|
|
Ptr<Node> n0 = CreateObject<InternetNode> ();
|
|
|
|
|
Ptr<Node> n1 = CreateObject<InternetNode> ();
|
|
|
|
|
Ptr<Node> n2 = CreateObject<InternetNode> ();
|
|
|
|
|
Ptr<Node> n3 = CreateObject<InternetNode> ();
|
|
|
|
|
Ptr<Node> n4 = CreateObject<InternetNode> ();
|
|
|
|
|
Ptr<Node> n5 = CreateObject<InternetNode> ();
|
|
|
|
|
Ptr<Node> n6 = CreateObject<InternetNode> ();
|
2007-10-08 20:51:21 -07:00
|
|
|
|
|
|
|
|
Ptr<PointToPointChannel> link01 =
|
|
|
|
|
PointToPointIpv4Topology::CreateChannel (DataRate (38400),
|
|
|
|
|
MilliSeconds (20));
|
|
|
|
|
|
|
|
|
|
uint32_t nd01 = PointToPointIpv4Topology::AddNetDevice (n0,
|
|
|
|
|
link01);
|
|
|
|
|
|
|
|
|
|
Ptr<PointToPointChannel> link02 =
|
|
|
|
|
PointToPointIpv4Topology::CreateChannel (DataRate (38400),
|
|
|
|
|
MilliSeconds (20));
|
|
|
|
|
|
|
|
|
|
uint32_t nd02 = PointToPointIpv4Topology::AddNetDevice (n0,
|
|
|
|
|
link02);
|
|
|
|
|
|
|
|
|
|
Ptr<PointToPointChannel> link03 =
|
|
|
|
|
PointToPointIpv4Topology::CreateChannel (DataRate (38400),
|
|
|
|
|
MilliSeconds (20));
|
|
|
|
|
|
|
|
|
|
uint32_t nd03 = PointToPointIpv4Topology::AddNetDevice (n0,
|
|
|
|
|
link03);
|
|
|
|
|
|
|
|
|
|
Ptr<PointToPointChannel> link04 =
|
|
|
|
|
PointToPointIpv4Topology::CreateChannel (DataRate (38400),
|
|
|
|
|
MilliSeconds (20));
|
|
|
|
|
|
|
|
|
|
uint32_t nd04 = PointToPointIpv4Topology::AddNetDevice (n0,
|
|
|
|
|
link04);
|
|
|
|
|
|
|
|
|
|
Ptr<PointToPointChannel> link05 =
|
|
|
|
|
PointToPointIpv4Topology::CreateChannel (DataRate (38400),
|
|
|
|
|
MilliSeconds (20));
|
|
|
|
|
|
|
|
|
|
uint32_t nd05 = PointToPointIpv4Topology::AddNetDevice (n0,
|
|
|
|
|
link05);
|
|
|
|
|
|
|
|
|
|
Ptr<PointToPointChannel> link06 =
|
|
|
|
|
PointToPointIpv4Topology::CreateChannel (DataRate (38400),
|
|
|
|
|
MilliSeconds (20));
|
|
|
|
|
|
2007-10-08 22:00:04 -07:00
|
|
|
uint32_t nd06 = PointToPointIpv4Topology::AddNetDevice (n0, link06);
|
|
|
|
|
|
|
|
|
|
uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, link01);
|
|
|
|
|
uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, link02);
|
|
|
|
|
uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, link03);
|
|
|
|
|
uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, link04);
|
|
|
|
|
uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, link05);
|
|
|
|
|
uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, link06);
|
2007-10-08 20:51:21 -07:00
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n0, nd01, "10.1.1.1",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n1, nd1, "10.1.1.2",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n0, nd02, "10.1.2.1",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n2, nd2, "10.1.2.2",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n0, nd03, "10.1.3.1",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n3, nd3, "10.1.2.2",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n0, nd04, "10.1.4.1",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n4, nd4, "10.1.4.2",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n0, nd05, "10.1.5.1",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n5, nd5, "10.1.5.2",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n0, nd06, "10.1.6.1",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
PointToPointIpv4Topology::AddAddress (n6, nd6, "10.1.6.2",
|
|
|
|
|
"255.255.255.252");
|
|
|
|
|
|
|
|
|
|
uint16_t port = 7;
|
|
|
|
|
|
2008-02-27 00:05:23 +01:00
|
|
|
Ptr<UdpEchoClient> client =
|
2008-03-13 11:10:38 -07:00
|
|
|
CreateObject<UdpEchoClient> ("RemoteIpv4", Ipv4Address ("10.1.1.2"),
|
|
|
|
|
"RemotePort", Uinteger (port),
|
|
|
|
|
"MaxPackets", Uinteger (1),
|
|
|
|
|
"Interval", Seconds(1.),
|
|
|
|
|
"PacketSize", Uinteger (1024));
|
2008-02-27 00:05:23 +01:00
|
|
|
n0->AddApplication (client);
|
|
|
|
|
|
|
|
|
|
Ptr<UdpEchoServer> server =
|
2008-03-13 11:10:38 -07:00
|
|
|
CreateObject<UdpEchoServer> ("Port", Uinteger (port));
|
2008-02-27 00:05:23 +01:00
|
|
|
n1->AddApplication (server);
|
2007-10-08 20:51:21 -07:00
|
|
|
|
|
|
|
|
server->Start(Seconds(1.));
|
|
|
|
|
client->Start(Seconds(2.));
|
|
|
|
|
|
|
|
|
|
server->Stop (Seconds(10.));
|
|
|
|
|
client->Stop (Seconds(10.));
|
|
|
|
|
|
|
|
|
|
AsciiTrace asciitrace ("tutorial.tr");
|
|
|
|
|
asciitrace.TraceAllQueues ();
|
|
|
|
|
asciitrace.TraceAllNetDeviceRx ();
|
|
|
|
|
|
|
|
|
|
Simulator::Run ();
|
|
|
|
|
Simulator::Destroy ();
|
|
|
|
|
}
|