#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/netanim-module.h"
#include "ns3/ptr.h"
#include "ns3/packet.h"
#include "ns3/header.h"
#include <iostream>
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
#include "ns3/pcap-file.h"
using namespace ns3;
int
main (int argc, char *argv[])
{
NodeContainer routers;
routers.Create (2); // this is a container for my two routers
NodeContainer pc;
pc.Create (3); // this is a container for my three pc
NodeContainer servers;
pc.Add (routers.Get (0)); //connect the two node containers
servers.Create (2); // this is a container for my two servers
PointToPointHelper routerconnection; // router connection serial cable
CsmaHelper manyports; // the switch for the servers
CsmaHelper manyport; // the switch for the pcs
NetDeviceContainer routerinterface; // the container routerinterface
NetDeviceContainer serverinterface; // the container serverinterface
NetDeviceContainer pcinterface; // the container pcrinterface
routerinterface = routerconnection.Install (routers); // install interface on the nodes
serverinterface = manyports.Install (pc); // install interface on the nodes
pcinterface = manyport.Install (servers); // install interface on the nodes
InternetStackHelper mystack; //create internet stack TCP
mystack.Install (routers.Get(1));
mystack.Install (servers);
mystack.Install (pc);
Ipv4AddressHelper wanadresses;
wanadresses.SetBase ("192.170.10.0" , "255.255.255.0"); // assign ip adresses
Ipv4AddressHelper lanadresses;
lanadresses.SetBase ("10.170.0.0" , "255.255.255.0");
Ipv4AddressHelper maxpc;
maxpc.SetBase ("11.170.0.0" , "255.255.255.0");
Ipv4InterfaceContainer mywan = wanadresses.Assign (routerinterface); //puting ip address to the interfaces
Ipv4InterfaceContainer mylan = lanadresses.Assign (pcinterface);
Ipv4InterfaceContainer mypc = maxpc.Assign (serverinterface);
Ipv4GlobalRoutingHelper :: PopulateRoutingTables(); // enble routing protocol
UdpEchoServerHelper echoServer (170); // applicatio server
ApplicationContainer serverApps = echoServer.Install (routers.Get(0));
serverApps = echoServer.Install (routers.Get(1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (mywan.GetAddress (1), 170);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (pc.Get(0)); // pc client
clientApps = echoClient.Install (pc.Get(1));
clientApps = echoClient.Install (pc.Get(2));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
ApplicationContainer clientApp = echoClient.Install (servers.Get (0)); //servers client
clientApp = echoClient.Install (servers.Get (1));
clientApp.Start (Seconds (2.0));
clientApp.Stop (Seconds (10.0));
MobilityHelper isak; // the mobility
isak.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (5), "MinY", DoubleValue (10),
"DeltaX", DoubleValue (1), "DeltaY", DoubleValue (1));
isak.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
isak.Install (routers);
isak.Install (pc);
isak.Install(servers);
AnimationInterface anim("shisak.xml"); // output
anim.SetConstantPosition(routers.Get(0), 1.0, 2.0); // coordinates of two routers
anim.SetConstantPosition(routers.Get(1), 3.0, 4.0);
anim.SetConstantPosition(pc.Get(0), 5.0, 6.0);// coordinates of three devices
anim.SetConstantPosition(pc.Get(1), 7.0, 8.0);
anim.SetConstantPosition(pc.Get(2), 9.0, 10.0);
anim.SetConstantPosition(servers.Get(0), 11.0, 12.0); // coordinates of two servers
anim.SetConstantPosition(servers.Get(1), 13.0, 14.0);
if (tracing == true) {
AsciiTraceHelper ascii;
isak.EnableAsciiAll(ascii.CreateFileStream("
isak4.tr"));
isak.EnablePcapAll("isak2");
}
//AsciiTraceHelper ascii;
//isak.EnableAsciiAll(ascii.CreateFileStream("
isak.tr"));
//isak.EnablePcapAll("isaks");
Simulator::Run ();
Simulator::Destroy ();
return 0;
}