/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#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/ipv4-global-routing-helper.h"
#include "ns3/olsr-helper.h"
#include "ns3/aodv-helper.h"
#include "ns3/dsdv-helper.h"
#include "ns3/dsr-helper.h"
#include <fstream>
#include <string>
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
void CourseChange (std::string context, Ptr<const MobilityModel> model)
{
Vector position = model->GetPosition ();
NS_LOG_UNCOND (context <<
" x = " << position.x << ", y = " << position.y);
}
int
main (int argc, char *argv[])
{
bool verbose = true;
std::string animFile = "mymanet.xml";
CommandLine cmd;
cmd.AddValue ("verbose", "Jestli běží aplikace, tak povol logování.", verbose);
cmd.Parse (argc,argv);
if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
NodeContainer wifiStaNodes;
wifiStaNodes.Create (20);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
QosWifiMacHelper mac = QosWifiMacHelper::Default();
//NqosWifiMacHelper mac = NqosWifiMacHelper::Default();
mac.SetType("ns3::AdhocWifiMac");
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes); //zařízení je přiřazeno uzlu, s patřičnými phy a mac vlastnostmi.
OlsrHelper olsr;
//AodvHelper aodv;
//DsdvHelper dsdv;
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (10.0),
"MinY", DoubleValue (10.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (2.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
mobility.Install (wifiStaNodes);
InternetStackHelper stack;
stack.SetRoutingHelper(olsr);
//stack.SetRoutingHelper(aodv);
//stack.SetRoutingHelper(dsdv);
stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.3.0", "255.255.255.0");
address.Assign (staDevices);
Ipv4InterfaceContainer interface = address.Assign(staDevices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (wifiStaNodes.Get(0));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interface.GetAddress(0), 9);
//Můžu využít díky Ipv4InterfaceContainer.
echoClient.SetAttribute ("MaxPackets", UintegerValue (2));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); //Velikost paketu
ApplicationContainer clientApps = echoClient.Install (wifiStaNodes.Get (19));
clientApps.Start (Seconds (4.0));
clientApps.Stop (Seconds (10.0));
AnimationInterface::SetNodeDescription (wifiStaNodes, "STA");
AnimationInterface anim (animFile);
anim.EnablePacketMetadata (true); //Povolí popis zasílaných zpráv
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Stop (Seconds (10.0));
std::ostringstream oss;
oss << "/NodeList/" << wifiStaNodes.Get (1)->GetId () <<
"/$ns3::MobilityModel/CourseChange";
Config::Connect (oss.str (), MakeCallback (&CourseChange));
phy.EnablePcap("manet",staDevices.Get(19),true);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}