AODV example added. Use ./waf --run aodv

This commit is contained in:
Pavel Boyko
2009-07-09 14:44:08 +04:00
parent 9c53293f9e
commit f18d57cae6
4 changed files with 216 additions and 4 deletions

210
examples/aodv.cc Normal file
View File

@@ -0,0 +1,210 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 IITP RAS
*
* 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
*
* This is an example script for AODV manet routing protocol.
*
* Authors: Pavel Boyko <boyko@iitp.ru>
*/
#include "ns3/aodv-module.h"
#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 "ns3/wifi-module.h"
#include <iostream>
#include <cmath>
using namespace ns3;
/**
* \brief Test script.
*
* This script creates 1-dimensional grid topology and runs UDP echo from one end to the other one.
*/
class AodvExample
{
public:
AodvExample ();
/// Configure script parameters, \return true on successful configuration
bool Configure (int argc, char **argv);
/// Run simulation
void Run ();
/// Report results
void Report (std::ostream & os);
private:
///\name parameters
//\{
/// Number of nodes
uint8_t size;
/// Distance between nodes, meters
double step;
/// Simulation time, seconds
double totalTime;
/// Write per-device PCAP traces if true
bool pcap;
//\}
///\name network
//\{
NodeContainer nodes;
NetDeviceContainer devices;
Ipv4InterfaceContainer interfaces;
//\}
private:
void CreateNodes ();
void CreateDevices ();
void InstallInternetStack ();
void InstallApplications ();
};
int main (int argc, char **argv)
{
AodvExample test;
if (! test.Configure(argc, argv))
NS_FATAL_ERROR ("Configuration failed. Aborted.");
test.Run ();
test.Report (std::cout);
return 0;
}
//-----------------------------------------------------------------------------
AodvExample::AodvExample () :
size (2),
step (150),
totalTime (10),
pcap (true)
{
}
bool
AodvExample::Configure (int argc, char **argv)
{
SeedManager::SetSeed(12345);
CommandLine cmd;
cmd.AddValue ("pcap", "Write PCAP traces.", pcap);
cmd.AddValue ("size", "Number of nodes.", size);
cmd.AddValue ("time", "Simulation time, s.", totalTime);
cmd.AddValue ("step", "Grid step, m", step);
cmd.Parse (argc, argv);
return true;
}
void
AodvExample::Run ()
{
CreateNodes ();
CreateDevices ();
InstallInternetStack ();
InstallApplications ();
std::cout << "Starting simulation for " << totalTime << " s ...\n";
Simulator::Stop (Seconds (totalTime));
Simulator::Run ();
Simulator::Destroy ();
}
void
AodvExample::Report (std::ostream &)
{
std::cout << "Done.\n";
}
void
AodvExample::CreateNodes ()
{
nodes.Create (size);
// Name nodes
for (uint32_t i = 0; i < size; ++i)
{
std::ostringstream os;
os << "node-" << i;
Names::Add (os.str (), nodes.Get (i));
}
// Create static grid
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (step),
"DeltaY", DoubleValue (0),
"GridWidth", UintegerValue (size),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (nodes);
}
void
AodvExample::CreateDevices ()
{
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifiMac.SetType ("ns3::AdhocWifiMac");
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("wifia-6mbs"));
devices = wifi.Install (wifiPhy, wifiMac, nodes);
if (pcap)
{
wifiPhy.EnablePcapAll (std::string ("aodv-"));
}
}
void
AodvExample::InstallInternetStack ()
{
AodvHelper aodv;
// you can configure AODV attributes here using aodv.Set(name, value)
InternetStackHelper stack;
stack.SetRoutingHelper (aodv);
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.0.0.0", "255.0.0.0");
interfaces = address.Assign (devices);
}
void
AodvExample::InstallApplications ()
{
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
serverApps.Start (Seconds (0));
serverApps.Stop (Seconds (totalTime));
UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9);
Time packetInterval (Seconds (0.1));
uint32_t packetSize (1024);
echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)std::floor(totalTime / packetInterval.GetSeconds())));
echoClient.SetAttribute ("Interval", TimeValue (packetInterval));
echoClient.SetAttribute ("PacketSize", UintegerValue (packetSize));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (size - 1));
clientApps.Start (Seconds (0));
clientApps.Stop (Seconds (totalTime));
}

View File

@@ -1,7 +1,9 @@
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
def build(bld):
print "Don't want to build examples"
obj = bld.create_ns3_program('aodv')
obj.source = 'aodv.cc'
# obj = bld.create_ns3_program('hello-simulator')
# obj.source = 'hello-simulator.cc'
#

View File

@@ -26,7 +26,7 @@
namespace ns3
{
AodvHelper::AodvHelper()
AodvHelper::AodvHelper() : Ipv4RoutingHelper ()
{
m_agentFactory.SetTypeId ("ns3::aodv::RoutingProtocol");
}

View File

@@ -31,7 +31,7 @@ namespace ns3
* \ingroup aodv
* \brief Helper class that adds AODV routing to nodes.
*/
class AodvHelper
class AodvHelper : public Ipv4RoutingHelper
{
public:
AodvHelper();
@@ -50,7 +50,7 @@ public:
* \param name the name of the attribute to set
* \param value the value of the attribute to set.
*
* This method controls the attributes of ns3::olsr::RoutingProtocol
* This method controls the attributes of ns3::aodv::RoutingProtocol
*/
void Set (std::string name, const AttributeValue &value);