Professional Documents
Culture Documents
Test 5
Test 5
/*
* 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/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/internet-module.h"
#include "ns3/object.h"
#include "ns3/uinteger.h"
#include "ns3/traced-value.h"
#include "ns3/trace-source-accessor.h"
#include "ns3/type-id.h"
#include "ns3/object-base.h"
#include "ns3/scheduler.h"
#include "ns3/calendar-scheduler.h"
#include "ns3/callback.h"
#include <iostream>
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
void
CourseChange (std::string context, Ptr<const MobilityModel> model)
{
Vector position = model->GetPosition ();
NS_LOG_UNCOND (context <<
" x = " <<
position.x <<
", y = " <<
position.y);
}
/*
//Set position of the WifiApNodes
//===========================
static void
SetPosition (Ptr<Node> node, Vector position)
{
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
mobility->SetPosition (position);
} */
int
main (int argc, char *argv[])
{
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
// LogComponentEnable ("Aarfcd", LOG_LEVEL_INFO);
// Create 11 nodes
NodeContainer wifiApNode; // create WiFi Ap nodes
wifiApNode.Create (nap);
NodeContainer wifiStaNodes; // create WiFi station nodes
wifiStaNodes.Create (nsta);
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (true));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);
/*Config::Set("/$ns3::NodeListPriv/NodeList/0/$ns3::Node/DeviceList/
0/$ns3::WifiNetDevice/Mac/$ns3::AdhocWifiMac/DcaTxop/$ns3::DcaTxop/
Queue/$ns3::WifiMacQueue/MaxDelay", TimeValue(Seconds(...))); */
//Config::Set("/NodeList/y/DeviceList/y/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMa
c/VO_EdcaTxopN/Queue/$ns3::WifiMacQueue/MaxPacketNumber", UintegerValue(5));
//Config::Set("/NodeList/y/DeviceList/y/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMa
c/VO_EdcaTxopN/Queue/$ns3::WifiMacQueue/MaxDelay", TimeValue(Seconds(0.01)));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiStaNodes);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
//SetPosition (wifiApNode , Vector (0.0,0.0,0.0));
//SetPosition (wifiApNode.Get(0), Vector (0.0,0.0,0.0));
mobility.Install (wifiApNode);
InternetStackHelper stack;
stack.Install (wifiApNode);
stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
NS_LOG_INFO ("Assign IP Addresses.");
address.SetBase ("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer wifiApInterfaces;
wifiApInterfaces = address.Assign (apDevices);
Ipv4InterfaceContainer wifiInterfaces;
wifiInterfaces = address.Assign (staDevices);
//Set application = data transfer ==============================
// UDP receiver ----(ABID FOLLOWING NO. 1 SHOWS 1,2 ABID)
Address remoteAddress1 = InetSocketAddress(wifiInterfaces.GetAddress (1),1000);
PacketSinkHelper receiver1 ("ns3::UdpSocketFactory", remoteAddress1);
ApplicationContainer receiverapp1 =receiver1.Install(wifiStaNodes.Get (1));
receiverapp1.Start (Seconds (2.0));
receiverapp1.Stop (Seconds (10.0));
Config::ConnectWithoutContext("/NodeList/1/ApplicationList/0/$ns3::OnOffApplication
/Rx", MakeCallback (&SetTagTid));
Ptr<OnOffApplication> onoffappBE;
onoffappBE = DynamicCast<OnOffApplication>(senderapps1.Get(0));
onoffappBE->TraceConnectWithoutContext("Tx", MakeBoundCallback
(&SetTagTid, AC_BE));
senderapps1.Start(Seconds(2.0))
;
senderapps1.Stop(Seconds(10.0));
Config::ConnectWithoutContext("/NodeList/3/ApplicationList/1/$ns3::OnOffApplication
/Rx", MakeCallback (&SetTagTid));
Ptr<OnOffApplication> onoffappBK;
onoffappBK = DynamicCast<OnOffApplication>(senderpps2.Get(0));
onoffappBK->TraceConnectWithoutContext("Tx", MakeBoundCallback
(&SetTagTid, AC_BE));
senderpps2.Start (Seconds (1.0));
senderpps2.Stop (Seconds (4.0));
//second TCP traffic
//TCP receiver---
Address remoteAddress3 = InetSocketAddress (wifiInterfaces.GetAddress (4), 3000);
PacketSinkHelper receiver3 ("ns3::TcpSocketFactory", remoteAddress3);
ApplicationContainer receiverapp3 = receiver3.Install (wifiStaNodes.Get (4));
receiverapp3.Start (Seconds (5.0));
receiverapp3.Stop (Seconds (10.0));
Config::ConnectWithoutContext("/NodeList/3/ApplicationList/2/$ns3::OnOffApplication
/Rx", MakeCallback (&SetTagTid));
Ptr<OnOffApplication> onoffappBK2;
onoffappBK2 = DynamicCast<OnOffApplication>(senderapp3.Get(0));
onoffappBK2->TraceConnectWithoutContext("Tx", MakeBoundCallback
(&SetTagTid, AC_BE));
senderapp3.Start (Seconds (5.0));
senderapp3.Stop (Seconds (10.0));
senderapps4 = sender4.Install(wifiStaNodes.Get(5));
Config::ConnectWithoutContext("/NodeList/6/ApplicationList/3/$ns3::OnOffApplication
/Rx", MakeCallback (&SetTagTid));
Ptr<OnOffApplication> onoffappVO;
onoffappVO = DynamicCast<OnOffApplication>(senderapps4.Get(0));
onoffappVO->TraceConnectWithoutContext("Tx", MakeBoundCallback
(&SetTagTid, AC_VO));
senderapps4.Start(Seconds(5.0));
senderapps4.Stop(Seconds(8.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
//output================
Simulator::Run ();
Simulator::Destroy ();
return 0;
}