merge
This commit is contained in:
@@ -105,7 +105,7 @@ main (int argc, char *argv[])
|
||||
// 2) Set up a default multicast route on the sender n0
|
||||
// 3) Have node n4 join the multicast group
|
||||
// We have a helper that can help us with static multicast
|
||||
StaticMulticastRouteHelper multicast;
|
||||
Ipv4StaticRoutingHelper multicast;
|
||||
|
||||
// 1) Configure a (static) multicast route on node n2 (multicastRouter)
|
||||
Ptr<Node> multicastRouter = c.Get (2); // The node in question
|
||||
@@ -121,10 +121,6 @@ main (int argc, char *argv[])
|
||||
Ptr<NetDevice> senderIf = nd0.Get(0);
|
||||
multicast.SetDefaultMulticastRoute (sender, senderIf);
|
||||
|
||||
// 3) Have node n4 join the multicast group
|
||||
Ptr<Node> receiver = c.Get (4);
|
||||
multicast.JoinMulticastGroup (receiver, multicastSource, multicastGroup);
|
||||
|
||||
//
|
||||
// Create an OnOff application to send UDP datagrams from node zero to the
|
||||
// multicast group (node four will be listening).
|
||||
|
||||
@@ -55,7 +55,6 @@
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/internet-stack-module.h"
|
||||
#include "ns3/emu-module.h"
|
||||
#include "ns3/v4ping-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
@@ -149,7 +148,8 @@ main (int argc, char *argv[])
|
||||
// of ARP, IPv4, ICMP, UDP and TCP.
|
||||
//
|
||||
NS_LOG_INFO ("Add Internet Stack");
|
||||
AddInternetStack (node);
|
||||
InternetStackHelper internetStackHelper;
|
||||
internetStackHelper.Install (node);
|
||||
|
||||
NS_LOG_INFO ("Create IPv4 Interface");
|
||||
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
|
||||
@@ -175,7 +175,9 @@ main (int argc, char *argv[])
|
||||
Ipv4Address gateway ("1.2.3.4");
|
||||
NS_ABORT_MSG_IF (gateway == "1.2.3.4", "You must change the gateway IP address before running this example");
|
||||
|
||||
ipv4->SetDefaultRoute (gateway, interface);
|
||||
Ipv4StaticRoutingHelper ipv4RoutingHelper;
|
||||
Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4);
|
||||
staticRouting->SetDefaultRoute (gateway, interface);
|
||||
|
||||
//
|
||||
// Create the ping application. This application knows how to send
|
||||
|
||||
@@ -97,12 +97,14 @@ main (int argc, char *argv[])
|
||||
ipv4C->SetMetric (ifIndexC, 1);
|
||||
ipv4C->SetUp (ifIndexC);
|
||||
|
||||
Ipv4StaticRoutingHelper ipv4RoutingHelper;
|
||||
// Create static routes from A to C
|
||||
Ptr<Ipv4StaticRouting> staticRoutingA = ipv4RoutingHelper.GetStaticRouting (ipv4A);
|
||||
// The ifIndex for this outbound route is 1; the first p2p link added
|
||||
ipv4A->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.2"), 1);
|
||||
staticRoutingA->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.2"), 1);
|
||||
Ptr<Ipv4StaticRouting> staticRoutingB = ipv4RoutingHelper.GetStaticRouting (ipv4B);
|
||||
// The ifIndex we want on node B is 2; 0 corresponds to loopback, and 1 to the first point to point link
|
||||
ipv4B->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"), 2);
|
||||
|
||||
staticRoutingB->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"), 2);
|
||||
// Create the OnOff application to send UDP datagrams of size
|
||||
// 210 bytes at a rate of 448 Kb/s
|
||||
uint16_t port = 9; // Discard port (RFC 863)
|
||||
|
||||
@@ -91,7 +91,7 @@ int main (int argc, char *argv[])
|
||||
InternetStackHelper internet;
|
||||
// The next statement switches the nodes to 'NSC'-Mode.
|
||||
// It disables the native ns-3 TCP model and loads the NSC library.
|
||||
internet.SetNscStack (nscStack);
|
||||
internet.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue(nscStack));
|
||||
internet.Install (n);
|
||||
|
||||
if (tcpCong != "cubic") // make sure we only fail if both --nscstack and --TCP_CONGESTION are used
|
||||
|
||||
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
InternetStackHelper internetStack;
|
||||
|
||||
internetStack.SetNscStack ("liblinux2.6.26.so");
|
||||
internetStack.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue("liblinux2.6.26.so"));
|
||||
// this switches nodes 0 and 1 to NSCs Linux 2.6.26 stack.
|
||||
internetStack.Install (n.Get(0));
|
||||
internetStack.Install (n.Get(1));
|
||||
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
// the next statement doesn't change anything for the nodes 0, 1, and 2; since they
|
||||
// already have a stack assigned.
|
||||
internetStack.SetNscStack ("liblinux2.6.18.so");
|
||||
internetStack.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue("liblinux2.6.18.so"));
|
||||
// this switches node 3 to NSCs Linux 2.6.18 stack.
|
||||
internetStack.Install (n.Get(3));
|
||||
// and then agains disables sack/timestamps/wscale on node 3.
|
||||
|
||||
229
examples/wifi-clear-channel-cmu.cc
Normal file
229
examples/wifi-clear-channel-cmu.cc
Normal file
@@ -0,0 +1,229 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 The Boeing Company
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Author: Guangyu Pei <guangyu.pei@boeing.com>
|
||||
*/
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/common-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
#include "ns3/mobility-module.h"
|
||||
#include "ns3/contrib-module.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("Main");
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
class Experiment
|
||||
{
|
||||
public:
|
||||
Experiment ();
|
||||
Experiment (std::string name);
|
||||
uint32_t Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
|
||||
const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel);
|
||||
private:
|
||||
void ReceivePacket (Ptr<Socket> socket);
|
||||
void SetPosition (Ptr<Node> node, Vector position);
|
||||
Vector GetPosition (Ptr<Node> node);
|
||||
Ptr<Socket> SetupPacketReceive (Ptr<Node> node);
|
||||
void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
|
||||
uint32_t pktCount, Time pktInterval );
|
||||
|
||||
uint32_t m_pktsTotal;
|
||||
Gnuplot2dDataset m_output;
|
||||
};
|
||||
|
||||
Experiment::Experiment ()
|
||||
{}
|
||||
|
||||
Experiment::Experiment (std::string name)
|
||||
: m_output (name)
|
||||
{
|
||||
m_output.SetStyle (Gnuplot2dDataset::LINES);
|
||||
}
|
||||
|
||||
void
|
||||
Experiment::SetPosition (Ptr<Node> node, Vector position)
|
||||
{
|
||||
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
|
||||
mobility->SetPosition (position);
|
||||
}
|
||||
|
||||
Vector
|
||||
Experiment::GetPosition (Ptr<Node> node)
|
||||
{
|
||||
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
|
||||
return mobility->GetPosition ();
|
||||
}
|
||||
|
||||
void
|
||||
Experiment::ReceivePacket (Ptr<Socket> socket)
|
||||
{
|
||||
Ptr<Packet> packet;
|
||||
while (packet = socket->Recv ())
|
||||
{
|
||||
m_pktsTotal ++;
|
||||
}
|
||||
}
|
||||
|
||||
Ptr<Socket>
|
||||
Experiment::SetupPacketReceive (Ptr<Node> node)
|
||||
{
|
||||
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
|
||||
Ptr<Socket> sink = Socket::CreateSocket (node, tid);
|
||||
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
|
||||
sink->Bind (local);
|
||||
sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
|
||||
return sink;
|
||||
}
|
||||
|
||||
void
|
||||
Experiment::GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
|
||||
uint32_t pktCount, Time pktInterval )
|
||||
{
|
||||
if (pktCount > 0)
|
||||
{
|
||||
socket->Send (Create<Packet> (pktSize));
|
||||
Simulator::Schedule (pktInterval, &Experiment::GenerateTraffic, this,
|
||||
socket, pktSize,pktCount-1, pktInterval);
|
||||
}
|
||||
else
|
||||
{
|
||||
socket->Close ();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
|
||||
const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel)
|
||||
{
|
||||
m_pktsTotal = 0;
|
||||
|
||||
NodeContainer c;
|
||||
c.Create (2);
|
||||
|
||||
InternetStackHelper internet;
|
||||
internet.Install (c);
|
||||
|
||||
YansWifiPhyHelper phy = wifiPhy;
|
||||
phy.SetChannel (wifiChannel.Create ());
|
||||
|
||||
NqosWifiMacHelper mac = wifiMac;
|
||||
NetDeviceContainer devices = wifi.Install (phy, mac, c);
|
||||
|
||||
MobilityHelper mobility;
|
||||
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
|
||||
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
|
||||
positionAlloc->Add (Vector (5.0, 0.0, 0.0));
|
||||
mobility.SetPositionAllocator (positionAlloc);
|
||||
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
|
||||
mobility.Install (c);
|
||||
|
||||
Ipv4AddressHelper ipv4;
|
||||
NS_LOG_INFO ("Assign IP Addresses.");
|
||||
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i = ipv4.Assign (devices);
|
||||
|
||||
Ptr<Socket> recvSink = SetupPacketReceive (c.Get (0));
|
||||
|
||||
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
|
||||
Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
|
||||
InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
|
||||
source->Connect (remote);
|
||||
uint32_t packetSize = 1014;
|
||||
uint32_t maxPacketCount = 200;
|
||||
Time interPacketInterval = Seconds (1.);
|
||||
Simulator::Schedule (Seconds (1.0), &Experiment::GenerateTraffic,
|
||||
this, source, packetSize, maxPacketCount,interPacketInterval);
|
||||
Simulator::Run ();
|
||||
|
||||
Simulator::Destroy ();
|
||||
|
||||
return m_pktsTotal;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
std::ofstream outfile ("clear-channel.plt");
|
||||
std::vector <std::string> modes;
|
||||
|
||||
modes.push_back ("wifib-1mbs");
|
||||
modes.push_back ("wifib-2mbs");
|
||||
modes.push_back ("wifib-5.5mbs");
|
||||
modes.push_back ("wifib-11mbs");
|
||||
// disable fragmentation
|
||||
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
|
||||
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
|
||||
|
||||
CommandLine cmd;
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
Gnuplot gnuplot = Gnuplot ("clear-channel.eps");
|
||||
|
||||
for (uint32_t i = 0; i < modes.size(); i++)
|
||||
{
|
||||
std::cout << modes[i] << std::endl;
|
||||
Gnuplot2dDataset dataset (modes[i]);
|
||||
|
||||
for (double rss = -102.0; rss <= -80.0; rss += 0.5)
|
||||
{
|
||||
Experiment experiment;
|
||||
dataset.SetStyle (Gnuplot2dDataset::LINES);
|
||||
|
||||
WifiHelper wifi;
|
||||
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
|
||||
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
|
||||
StringValue (modes[i]));
|
||||
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
|
||||
"DataMode",StringValue(modes[i]),
|
||||
"ControlMode",StringValue(modes[i]));
|
||||
wifiMac.SetType ("ns3::AdhocWifiMac");
|
||||
|
||||
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
|
||||
YansWifiChannelHelper wifiChannel ;
|
||||
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
|
||||
wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue(rss));
|
||||
|
||||
|
||||
NS_LOG_DEBUG (modes[i]);
|
||||
experiment = Experiment (modes[i]);
|
||||
wifiPhy.Set ("Standard", StringValue ("802.11b") );
|
||||
wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (-110.0) );
|
||||
wifiPhy.Set ("CcaMode1Threshold", DoubleValue (-110.0) );
|
||||
wifiPhy.Set ("TxPowerStart", DoubleValue (15.0) );
|
||||
wifiPhy.Set ("RxGain", DoubleValue (0) );
|
||||
wifiPhy.Set ("RxNoiseFigure", DoubleValue (7) );
|
||||
uint32_t pktsRecvd = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
|
||||
dataset.Add (rss, pktsRecvd);
|
||||
}
|
||||
|
||||
gnuplot.AddDataset (dataset);
|
||||
}
|
||||
gnuplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
|
||||
gnuplot.SetLegend ("RSS(dBm)", "Number of packets received");
|
||||
gnuplot.SetExtra ("set xrange [-102:-83]");
|
||||
gnuplot.GenerateOutput (outfile);
|
||||
outfile.close ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -120,6 +120,10 @@ def build(bld):
|
||||
['core', 'simulator', 'mobility', 'wifi'])
|
||||
obj.source = 'wifi-adhoc.cc'
|
||||
|
||||
obj = bld.create_ns3_program('wifi-clear-channel-cmu',
|
||||
['core', 'simulator', 'mobility', 'wifi'])
|
||||
obj.source = 'wifi-clear-channel-cmu.cc'
|
||||
|
||||
obj = bld.create_ns3_program('wifi-ap',
|
||||
['core', 'simulator', 'mobility', 'wifi'])
|
||||
obj.source = 'wifi-ap.cc'
|
||||
|
||||
Reference in New Issue
Block a user