vyshak srivatsa
unread,Jul 6, 2014, 11:58:48 PM7/6/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ns-3-...@googlegroups.com
Hello all,
I am trying to find the number of neighbouring nodes using aodv protocol for which i have used Ns3::aodv::neighbours:: m_nb and then m_nb.size() so that it returns the size of the vector m_nb which is nothing but the neighbour information . Is it rite ?? or is there any other logic to find the neighbours info ??
*(m_nb is private but still i made slight changes in module so that i can access it)
Assuming my logic is proper i have designed a simple scenario as below and tried to get the size of the vector m_nb but unfortunately i am getting it as 0 , please can anyone help me with this, where am i going wrong ??
#include "ns3/aodv-module.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/applications-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/flow-monitor-module.h"
#include "myapp.h"
#include <vector>
#include <iostream>
#include <cmath>
//Time u,o;
int pnum;
NS_LOG_COMPONENT_DEFINE ("Snmp");
using namespace ns3;
void
PrintPacket()
{
std::cout << Simulator::Now().GetSeconds() << "\t"<< pnum << "\n";
Simulator::Schedule(Seconds(5.0), &PrintPacket);
}
int main (int argc, char *argv[])
{
std::string phyMode ("DsssRate1Mbps");
double distance = 500; // m
uint32_t numNodes = 25; // by default, 5x5
// double interval = 0.001; // seconds
uint32_t packetSize = 600; // bytes
uint32_t numPackets = 10000000;
// int size = 25;
//int totalTime =50;
std::string rtslimit = "1500";
CommandLine cmd;
cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
cmd.AddValue ("distance", "distance (m)", distance);
cmd.AddValue ("packetSize", "distance (m)", packetSize);
cmd.AddValue ("rtslimit", "RTS/CTS Threshold (bytes)", rtslimit);
cmd.Parse (argc, argv);
// Convert to time object
//Time interPacketInterval = Seconds (interval);
// turn off RTS/CTS for frames below 2200 bytes
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue (rtslimit));
// Fix non-unicast data rate to be the same as that of unicast
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (phyMode));
NodeContainer c;
c.Create (numNodes);
/* 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 ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0));
NetDeviceContainer devices;
devices = wifi.Install (wifiPhy, wifiMac, c);
*/
// WifiHelper wifi;
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
// set it to zero; otherwise, gain will be added
wifiPhy.Set ("RxGain", DoubleValue (-10) );
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
wifiPhy.SetChannel (wifiChannel.Create ());
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0));
// Add a non-QoS upper mac, and disable rate control
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
// Set it to adhoc mode
wifiMac.SetType ("ns3::AdhocWifiMac");
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (distance),
"DeltaY", DoubleValue (distance),
"GridWidth", UintegerValue (5),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (c);
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 (c);
Ipv4AddressHelper address;
address.SetBase ("10.0.0.0", "255.0.0.0");
Ipv4InterfaceContainer ifcont = address.Assign (devices);
//uint32_t nNodes = c.GetN ();
Ptr<Node> node = c.Get(1) ;
/*for (uint32_t i = 1 ; i < nNodes; ++i)
{
node = c.Get (i);
//i->method (); // some Node method
}
*/
Ptr<Ipv4> v_ipv4 = node->GetObject<Ipv4> ();
//node->AggregateObject (v_ipv4);
NS_ASSERT_MSG (v_ipv4, "Ipv4 not installed on node");
Ptr<NetDevice> d= node->GetDevice(0);
//NS_ASSERT (d != NULL);
Ptr<Ipv4L3Protocol>l3=v_ipv4 -> GetObject<Ipv4L3Protocol>();
//Ptr<NetDevice>d=node->GetDevice(0);
NS_ASSERT (d != NULL);
Ptr<NetDevice>d2=l3 -> GetNetDevice (l3->GetInterfaceForDevice(d));
Ptr<WifiNetDevice> wd = DynamicCast<WifiNetDevice>(d2);
Ptr<WifiMac> wm=wd->GetMac();
Ptr<WifiPhy> wp=wd->GetPhy();
Ptr<RegularWifiMac> rw = DynamicCast<RegularWifiMac>(wm);
//Ptr<WifiMacHeader> wh = DynamicCast<WifiMacHeader>(wm);
std::cout<<"sifs "<<rw->GetSifs()<<std::endl;
Ptr<Ipv4RoutingProtocol> proto = v_ipv4->GetRoutingProtocol ();
NS_ASSERT_MSG (proto, "Ipv4 routing not installed on node");
Ptr<aodv::RoutingProtocol> aodvv = DynamicCast<aodv::RoutingProtocol> (proto);
pnum = aodvv->Size(); (i have created a function which returns the size of the m_nb)
// Create Apps
uint16_t sinkPort = 6; // use the same for all apps
// UDP connection from N0 to N24
Address sinkAddress1 (InetSocketAddress (ifcont.GetAddress (24), sinkPort)); // interface of n24
PacketSinkHelper packetSinkHelper1 ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
ApplicationContainer sinkApps1 = packetSinkHelper1.Install (c.Get (24)); //n2 as sink
sinkApps1.Start (Seconds (0.));
sinkApps1.Stop (Seconds (100.));
Ptr<Socket> ns3UdpSocket1 = Socket::CreateSocket (c.Get (0), UdpSocketFactory::GetTypeId ()); //source at n0
// Create UDP application at n0
Ptr<MyApp> app1 = CreateObject<MyApp> ();
app1->Setup (ns3UdpSocket1, sinkAddress1, packetSize, numPackets, DataRate ("1Mbps"));
c.Get (0)->AddApplication (app1);
app1->SetStartTime (Seconds (31.));
app1->SetStopTime (Seconds (100.));
// UDP connection from N10 to N14
Address sinkAddress2 (InetSocketAddress (ifcont.GetAddress (14), sinkPort)); // interface of n14
PacketSinkHelper packetSinkHelper2 ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
ApplicationContainer sinkApps2 = packetSinkHelper2.Install (c.Get (14)); //n14 as sink
sinkApps2.Start (Seconds (0.));
sinkApps2.Stop (Seconds (100.));
Ptr<Socket> ns3UdpSocket2 = Socket::CreateSocket (c.Get (10), UdpSocketFactory::GetTypeId ()); //source at n10
// Create UDP application at n10
Ptr<MyApp> app2 = CreateObject<MyApp> ();
app2->Setup (ns3UdpSocket2, sinkAddress2, packetSize, numPackets, DataRate ("1Mbps"));
c.Get (10)->AddApplication (app2);
app2->SetStartTime (Seconds (31.5));
app2->SetStopTime (Seconds (100.));
// UDP connection from N20 to N4
Address sinkAddress3 (InetSocketAddress (ifcont.GetAddress (4), sinkPort)); // interface of n4
PacketSinkHelper packetSinkHelper3 ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
ApplicationContainer sinkApps3 = packetSinkHelper3.Install (c.Get (4)); //n2 as sink
sinkApps3.Start (Seconds (0.));
sinkApps3.Stop (Seconds (100.));
Ptr<Socket> ns3UdpSocket3 = Socket::CreateSocket (c.Get (20), UdpSocketFactory::GetTypeId ()); //source at n20
// Create UDP application at n20
Ptr<MyApp> app3 = CreateObject<MyApp> ();
app3->Setup (ns3UdpSocket3, sinkAddress3, packetSize, numPackets, DataRate ("1Mbps"));
c.Get (20)->AddApplication (app3);
app3->SetStartTime (Seconds (32.));
app3->SetStopTime (Seconds (100.));
// Install FlowMonitor on all nodes
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
NS_LOG_INFO ("Run Simulation.");
Simulator::Schedule(Seconds(5.0), &PrintPacket);
Simulator::Stop (Seconds(50.0));
Simulator::Run ();
}