Professional Documents
Culture Documents
In AODV, networks are silent until connections are established. Network nodes that need
connections broadcast a request for connection. The remaining AODV nodes forward the message
and record the node that requested a connection. Thus, they create a series of temporary routes
back to the requesting node.
A node that receives such messages and holds a route to a desired node sends a backward
message through temporary routes to the requesting node. The node that initiated the request
uses the route containing the least number of hops through other nodes. The entries that are not
used in routing tables are recycled after some time. If a link fails, the routing error is passed back
to the transmitting node and the process is repeated.
using namespace
ns3; class
AodvExample {
public:
AodvExample ();
private:
// network
/// nodes used in the example
NodeContainer nodes;
/// devices used in the example
NetDeviceContainer devices;
/// interfaces used in the example
Ipv4InterfaceContainer interfaces; private:
/// Create the nodes void
CreateNodes (); /// Create
the devices void
CreateDevices (); ///
Create the network void
InstallInternetStack ();
/// Create the simulation applications
void InstallApplications ();
};
test.Run ();
test.Report (std::cout);
return 0;
}
//-----------------------------------------------------------------------------
AodvExample::AodvExample () :
size (10), step
(50), totalTime
(100), pcap
(true),
printRoutes (true)
{}
bool
AodvExample::Configure (int argc, char **argv)
{
// Enable AODV logs by default. Comment this if too noisy
// LogComponentEnable("AodvRoutingProtocol", LOG_LEVEL_ALL);
SeedManager::SetSeed (12345);
CommandLine cmd;
void
AodvExample::Run () {
// Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", UintegerValue (1)); // enable
rts cts all the time. CreateNodes ();
CreateDevices ();
InstallInternetStack ();
InstallApplications ();
AnimationInterface anim("119CS0171_LAB_7.xml"); std::cout
<< "Starting simulation for " << totalTime << " s ...\n";
void
AodvExample::CreateDevices ()
{
WifiMacHelper wifiMac;
wifiMac.SetType ("ns3::AdhocWifiMac");
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ()); WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue
("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0));
devices = wifi.Install (wifiPhy, wifiMac, nodes);
if (pcap)
{
wifiPhy.EnablePcapAll (std::string ("aodv"));
}
}
void
AodvExample::InstallInternetStack ()
{
AodvHelper aodv;
if (printRoutes)
{
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("aodv.routes",
std::ios::out);
aodv.PrintRoutingTableAllAt (Seconds (8), routingStream);
}
}
void
AodvExample::InstallApplications ()
{
V4PingHelper ping (interfaces.GetAddress (size - 1));
ping.SetAttribute ("Verbose", BooleanValue (true));
Wireshark
NetAnim
Question 2
CODE
#include "ns3/aodv-module.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
#include "ns3/v4ping-helper.h"
#include "ns3/position-allocator.h"
#include "ns3/propagation-loss-model.h"
#include "ns3/applications-module.h"
#include "ns3/v4ping.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/udp-client-server-helper.h"
#include "ns3/udp-server.h"
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
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);
YansWifiPhyHelper wifiPhy;
private: // parameters ///
Number of nodes uint32_t
size;
/// Distance between nodes, meters
double step;
/// Simulation time, seconds
double simTime;
/// Write per-device PCAP traces if true
bool pcap;
/// Print routes if true bool
private: void
CreateNodes(); void
CreateDevices(); void
InstallInternetStack(); void
InstallApplications(); };
NS_LOG_COMPONENT_DEFINE("ManetTest");
if (!test.Configure(argc, argv))
NS_FATAL_ERROR("Configuration failed. Aborted.");
test.Run();
test.Report(std::cout);
return 0;
}
//-----------------------------------------------------------------------------
AodvExample::AodvExample() : size(10),
step(5),
simTime(50),
pcap(true),
printRoutes(false)
{}
if (verbose)
{
LogComponentEnable("UdpSocket", LOG_LEVEL_INFO);
LogComponentEnable("UdpServer", LOG_LEVEL_INFO);
}
return true;
}
void AodvExample::Run() {
// Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", UintegerValue (1)); //
enable rts cts all the time. CreateNodes();
CreateDevices();
InstallInternetStack();
InstallApplications();
// std::cout << "Starting simulation for " << simTime << " s ...\n";
Simulator::Stop(Seconds(simTime));
Simulator::Run();
Simulator::Destroy();
}
void AodvExample::CreateNodes()
{
std::cout << "Creating " << (unsigned)size << " nodes with transmission range " << txrange << "m.\n";
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));
}
uint16_t i = 0;
;
double vec[3];
if (file.is_open())
{
while (getline(file, line))
{
// std::cout<<line<< '\n';
char seps[] = ","; char *token;
token = strtok(&line[0], seps);
// std::cout << token << "\n";
void AodvExample::CreateDevices()
{
wifiMac.SetType("ns3::AdhocWifiMac");
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
wifiChannel.AddPropagationLoss("ns3::RangePropagationLossModel",
"MaxRange", DoubleValue(txrange));
wifiPhy.SetChannel(wifiChannel.Create());
WifiHelper wifi;
wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
"DataMode", StringValue("OfdmRate6Mbps"), "RtsCtsThreshold",
UintegerValue(0)); 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); // has effect on the next Install
() stack.Install(nodes); Ipv4AddressHelper address;
address.SetBase("10.0.0.0", "255.0.0.0"); interfaces =
address.Assign(devices); for (uint32_t i = 0; i < (size / 2); i++)
{
serverAddress[i] = Address(interfaces.GetAddress(i));
}
if (printRoutes)
{
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("aodv.routes",
std::ios::out);
aodv.PrintRoutingTableAllAt (Seconds (8), routingStream);
}
}
apps.Start(Seconds(interval_start));
apps.Stop(Seconds(interval_end));
interval_start = interval_end + 1.0;
interval_end = interval_start + interval;
}
Simulator::Run();
k = 0;
monitor->CheckForLostPackets();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
// std::cout << "Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";
// std::cout << " Tx Bytes: " << i->second.txBytes << "\n";
// std::cout << " Rx Bytes: " << i->second.rxBytes << "\n";
// std::cout << " Throughput: " << i->second.rxBytes * 8.0 / (i->second.timeLastRxPacket.GetSeconds()
- i->second.timeFirstTxPacket.GetSeconds())/1024/1024 << " Mbps\n";
}
}
OUTPUT