I'm creating a AANET(Aircraft Ad-Hoc Networks) scenario in ns-3 simulator and I having some errors messages at simulation. I'm using the version ns-3.34 in Linux Mint Cinnamon. Here's the error in terminal:
Error message: assert failed. cond="m_wifiPhy->m_currentEvent == 0", +61.890322004s 15 file=../src/wifi/model/phy-entity.cc, line=467 terminate called without an active exception.
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2021 UFRN/UNIPAMPA
*
* 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
*
* Authors: Maiara (UNIPAMPA), Prof. Gerson (UNIPAMPA), Tarciana Guerra (UFRN), Vicente Sousa (UFRN)
*
*/
/* to run:
* NS_GLOBAL_VALUE="RngRun=1627332758828894" ./waf --run 'fanet-routing-compare --iNWifis=3000 --protocol=1 --iTransportMode=0 --simTime=10 --stOutputDir='/home/vicente/2021_1/UFRNUNIPAMPA/ns-allinone-3.34/ns-3.34/results_Campaign1_iNWifis''
*/
#include <sys/socket.h>
#include <errno.h>
#include <fstream>
#include <string>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <ctime>
#include <time.h>
#include <math.h>
#include <fstream>
#include <math.h>
#include <stack>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/aodv-helper.h"
#include "ns3/olsr-module.h"
#include "ns3/dsdv-module.h"
#include "ns3/dsr-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/mobility-module.h"
#include "ns3/wifi-module.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/fd-net-device-module.h"
#include "ns3/netanim-module.h"
#include "ns3/flow-monitor.h"
#include "ns3/flow-probe.h"
#include "ns3/ipv4-flow-classifier.h"
#include "ns3/ipv4-l3-protocol.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/energy-module.h"
#include "ns3/basic-energy-source.h"
#include <ns3/config-store-module.h>
#include "ns3/random-variable-stream.h"
#include "ns3/propagation-module.h"
#include "ns3/phy-entity.h"
#include "ns3/assert.h"
#include "ns3/minstrel-wifi-manager.h"
#include "ns3/minstrel-ht-wifi-manager.h"
using namespace ns3;
// Test if the file is empty
bool is_empty(std::ifstream& pFile)
{
return pFile.peek() == std::ifstream::traits_type::eof();
}
// To be used in tic toc time counter
clock_t startTimer;
time_t beginTimer;
//
// Implementation of tic, i.e., start time counter
void
tic()
{
beginTimer = time(&beginTimer);
struct tm * timeinfo;
timeinfo = localtime(&beginTimer);
std::cout << "simulation start at: " << asctime(timeinfo) << std::endl;
}
// implementation of toc, i.e., stop time counter
double
toc()
{
time_t finishTimer = time(&finishTimer);
double simTime = difftime(finishTimer, beginTimer) / 60.0;
struct tm * timeinfo;
timeinfo = localtime(&finishTimer);
std::cout << "simulation finished at: " << asctime(timeinfo) << std::endl;
//
std::cout << "Time elapsed: " << simTime << " minutes" << std::endl;
//
return simTime;
}
int main (int argc, char *argv[])
{
tic();
int iSeed = 1;
uint32_t iRunSeed = 1;
int iNWifis = 50;
double dTxp = 7.5;
double velMin = 200.0;
double velMax = 250.0;
std::string stPhyMode ("DsssRate1Mbps");
std::string rateManager = "ns3::MinstrelWifiManager";
std::string stRate ("2048bps");
std::string stPacketSize ("1024");
double dSimTime = 200.0;
double dTime2StartStatistics = 1.0; // Define the warmup time to collect statistics (must be lower than dSimTime)
uint32_t iProtocol = 2;
std::string stProtocolName = "protocol";
int iTransportMode = 0;
std::string stTransportModeName = "UDP";
std::string stOutputDir = "./";
int iJobID = 0;
CommandLine cmd;
cmd.AddValue ("iNWifis", "Number of end devices to include in the simulation", iNWifis);
cmd.AddValue ("iJobID", "JobID", iJobID);
cmd.AddValue ("velMin", "Minimum mobility speed", velMin);
cmd.AddValue ("velMax", "Maximum mobility speed", velMax);
cmd.AddValue ("dTxp", "Transmission Power", dTxp);
cmd.AddValue ("iProtocol", "1=OLSR;2=AODV;3=DSDV;4=DSR", iProtocol);
cmd.AddValue ("iTransportMode", "1:true, 0:false, default mode UDP",iTransportMode);
cmd.AddValue ("stOutputDir", "Output directory", stOutputDir);
cmd.AddValue ("dSimTime", "The time for which to simulate", dSimTime);
cmd.Parse (argc, argv);
// Setting default values
Config::SetDefault ("ns3::OnOffApplication::PacketSize",StringValue (stPacketSize));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue (stRate));
Config::SetDefault ("ns3::JakesProcess::DopplerFrequencyHz", DoubleValue (4000));
Config::SetDefault ("ns3::JakesProcess::NumberOfOscillators", UintegerValue (4));
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",StringValue (stPhyMode));
ConfigStore inputConfig;
inputConfig.ConfigureDefaults ();
// ############################################
// Scenario setup
// ############################################
NodeContainer adhocNodes;
adhocNodes.Create (iNWifis);
// ############################################
// Mobility Model
// ############################################
int64_t streamIndex = 0; // used to get consistent mobility across scenarios
MobilityHelper mobility;
ObjectFactory pos;
pos.SetTypeId ("ns3::RandomBoxPositionAllocator");
pos.Set ("X", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=391971]"));
pos.Set ("Y", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=48733]"));
pos.Set ("Z", StringValue ("ns3::UniformRandomVariable[Min=6000|Max=8434]"));
Ptr<PositionAllocator> taPositionAlloc = pos.Create ()->GetObject<PositionAllocator> ();
streamIndex += taPositionAlloc->AssignStreams (streamIndex);
mobility.SetMobilityModel ("ns3::GaussMarkovMobilityModel",
"Bounds", BoxValue (Box (0, 391971, 0, 48733, 6000, 8434)),
"TimeStep", TimeValue (Seconds (1)),
"Alpha", DoubleValue (0.85),
"MeanVelocity", StringValue ("ns3::UniformRandomVariable[Min=200|Max=250]"),
"MeanDirection", StringValue ("ns3::UniformRandomVariable[Min=0|Max=6.283185307]"),
"MeanPitch", StringValue ("ns3::UniformRandomVariable[Min=0.05|Max=0.05]"),
"NormalVelocity", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.0|Bound=0.0]"),
"NormalDirection", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.2|Bound=0.4]"),
"NormalPitch", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.02|Bound=0.04]"));
//mobility.SetPositionAllocator ("ns3::RandomBoxPositionAllocator",
// "X", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"),
// "Y", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"),
// "Z", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"));
mobility.SetPositionAllocator (taPositionAlloc);
mobility.Install (adhocNodes);
streamIndex += mobility.AssignStreams (adhocNodes, streamIndex);
NS_UNUSED (streamIndex); // From this point, streamIndex is unused
// ############################################
// PHY Layer setup
// ############################################
// Set Non-unicastMode rate to Unicast mode
// Setting up Wi-Fi phy and channel using helpers
// TODO: colocar isso como parâmetro
WifiHelper wifi;
wifi.SetStandard (WIFI_STANDARD_80211b);
// Channel Setup
YansWifiPhyHelper wifiPhy;
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss("ns3::JakesPropagationLossModel");
wifiChannel.AddPropagationLoss("ns3::FriisPropagationLossModel");
//wifiChannel.AddPropagationLoss("ns3::JakesProcess","DopplerFrequencyHz", DoubleValue(4000), "NumberOfOscillators", UintegerValue(5));
wifiPhy.SetChannel (wifiChannel.Create ());
// ############################################
// MAC Layer setup
// ############################################
WifiMacHelper wifiMac;
// Disable rate control (habilitar depois)
wifi.SetRemoteStationManager (rateManager);
//wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
// "DataMode",StringValue (stPhyMode),
// "ControlMode",StringValue (stPhyMode));
// Set Transmission power
// TODO: verificar se é em dBm ou em Watts
wifiPhy.Set ("TxPowerStart",DoubleValue (dTxp));
wifiPhy.Set ("TxPowerEnd", DoubleValue (dTxp));
// Set ad-hoc mode
wifiMac.SetType ("ns3::AdhocWifiMac");
NetDeviceContainer adhocDevices = wifi.Install (wifiPhy, wifiMac, adhocNodes);
// ############################################
// Internet Protocol stack setup
// ############################################
AodvHelper aodv;
OlsrHelper olsr;
DsdvHelper dsdv;
DsrHelper dsr;
DsrMainHelper dsrMain;
Ipv4ListRoutingHelper list;
InternetStackHelper internet;
switch (iProtocol)
{
case 1:
list.Add (olsr, 100);
stProtocolName = "OLSR";
break;
case 2:
list.Add (aodv, 100);
stProtocolName = "AODV";
break;
case 3:
list.Add (dsdv, 100);
stProtocolName = "DSDV";
break;
case 4:
stProtocolName = "DSR";
break;
default:
NS_FATAL_ERROR ("No such protocol:" << iProtocol);
}
if (iProtocol < 4)
{
internet.SetRoutingHelper (list);
internet.Install (adhocNodes);
}
else if (iProtocol == 4)
{
internet.Install (adhocNodes);
dsrMain.Install (dsr, adhocNodes);
}
// IP Assignment
Ipv4AddressHelper addressAdhoc;
addressAdhoc.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer adhocInterfaces;
adhocInterfaces = addressAdhoc.Assign (adhocDevices);
// ############################################
// Traffic Model and internet Protocol stack setup (based on
https://www.nsnam.org/doxygen/fd2fd-onoff_8cc_source.html)
// ############################################
std::string factory;
if ( iTransportMode == 1 )
{
factory = "ns3::TcpSocketFactory";
stTransportModeName = "TCP";
}
else
{
factory = "ns3::UdpSocketFactory";
stTransportModeName = "UDP";
}
uint16_t sinkPort = 8000;
// Create a traffic sink for each node
for (int i = 0; i < iNWifis; i++)
{
Address sinkLocalAddress (InetSocketAddress (adhocInterfaces.GetAddress (i), sinkPort));
PacketSinkHelper sinkHelper (factory, sinkLocalAddress);
Ptr<Node> sinkNode = adhocNodes.Get(i);
ApplicationContainer sinkApp = sinkHelper.Install ( sinkNode );
sinkApp.Start (Seconds (0.0));
sinkApp.Stop (Seconds (dSimTime));
}
// Create a traffic source for each node
// Create a traffic source for each node
for (int i = 0; i < iNWifis; i++){
for (int j = 0; j < iNWifis; j++){
if (i != j){
AddressValue serverAddress (InetSocketAddress (adhocInterfaces.GetAddress (i), sinkPort));
OnOffHelper onoff (factory, Address ());
onoff.SetAttribute ("Remote", serverAddress);
//TODO: verificar se as linhas comentadas abaixo são realmente necessárias
//onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
//onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
Ptr<Node> clientNode = adhocNodes.Get(j);
ApplicationContainer clientApps = onoff.Install (clientNode);
Ptr<UniformRandomVariable> var = CreateObject<UniformRandomVariable> ();
clientApps.Start (Seconds (var->GetValue (0.05,0.5)));
clientApps.Stop (Seconds (dSimTime));
}
}
}
// ############################################
// Energy Model according to examples/energy/energy-model-example.cc
// ############################################
/**** automatic installation via Helpers */
// for parameters see:
http://www.ee.washington.edu/research/nsl/papers/SIMUTools-11.pdf // energy source
BasicEnergySourceHelper basicSourceHelper;
// Configure energy source (default values in basic-energy-source.cc). Set a higher value to guarantee STA long lifetime
basicSourceHelper.Set("BasicEnergySourceInitialEnergyJ", DoubleValue( 100 * dSimTime ) );
// install source
EnergySourceContainer sources = basicSourceHelper.Install(adhocNodes);
// Device energy model
// According to "ns3/wifi-radio-energy-model.h", default values for power consumption are based on CC2420 radio chip, with
// supply voltage as 2.5V and currents as 17.4 mA (TX), 18.8 mA (RX), 20 uA
// (sleep) and 426 uA (idle).
WifiRadioEnergyModelHelper radioEnergyHelper;
// install device model
DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install(adhocDevices, sources);
// ############################################
// Output Setup
// ############################################
// Simulation Output file: t-put evaluation according to wifi-hidden-terminal.cc
AsciiTraceHelper asciiTraceHelper;
// File to store performance results
std::string chFileResults = stOutputDir+"/"+"Results_"+std::to_string(iJobID)+".txt";
//Ptr<OutputStreamWrapper> fileResults = asciiTraceHelper.CreateFileStream( chFileResults );
std::ifstream file(chFileResults.c_str());
bool firstTime = is_empty(file);
file.close();
std::ofstream myfile;
myfile.open(chFileResults.c_str(), std::ofstream::app);
if ( firstTime )
{
// file is empty: write down the header
myfile << "Flow_ID, Lost_Packets, Tx_Packets, Tx_Bytes, TxOffered(Mbps), Rx_Packets, Rx_Bytes, T_put(Mbps), Mean_Delay_Rx_Packets, Mean_Jitter, Packet_Loss_Ratio, AvgPowerConsumption, iNWifis, dTxp, iProtocol" << std::endl;
}
// File to store energy consumption
// TODO: implement the average power concumption and store on result file
//std::string chFileEnergy = stOutputDir+"/"+"Energy_"+std::to_string(iJobID)+".txt";
//Ptr<OutputStreamWrapper> fileEnergy = asciiTraceHelper.CreateFileStream( chFileEnergy );
// File to store simulations main parameters and real simulation duration
//std::string chFileParam = stOutputDir+"/"+"Params_"+std::to_string(iJobID)+".txt";
//Ptr<OutputStreamWrapper> streamSimParam = asciiTraceHelper.CreateFileStream(chFileParam);
//Getting seed and runSeed for checking and displaying purposes
iSeed = RngSeedManager::GetSeed();
iRunSeed = RngSeedManager::GetRun();
// Display current simulation information
std::cout <<
"Running with iNWifis = " << iNWifis <<
", txp = " << dTxp << " dBm" <<
", velMin = " << velMin << " m/s" <<
", velMax = " << velMax << " m/s" <<
", simulation Time =" << dSimTime << " s" <<
", Routing Protocol = " << stProtocolName <<
", Traffic = " << stTransportModeName <<
", iSeed = " << iSeed <<
", run stream = " << iRunSeed <<
", outputDir = " << stOutputDir << std::endl;
// Network Animation using NetAnim.
AnimationInterface anim("Fanet3D"+std::to_string(iJobID)+".xml");
// Mobility trace
// AsciiTraceHelper ascii;
// MobilityHelper::EnableAsciiAll (ascii.CreateFileStream (tr_name + ".mob"));
//
// Flowmonitor conifguration
// Simulation Output: create a instance and install FlowMonitor
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
monitor->Start( Seconds(dTime2StartStatistics) );
// ############################################
// Run simulation
// ############################################
Simulator::Stop (Seconds (dSimTime));
Simulator::Run ();
// ############################################
// Simulation output processing
// ############################################
//
// Power Consumption processing
// Simulation output: collect and save energy consumption metrics. There is an important difference
// between final consumption values with "#include "ns3/simple-device-energy-model.h"" is included or not.
//std::cout << "saving Energy Consumption data..." << std::endl;
// Energy consumption metrics will be saved in a new file named EnergyConsumption_Results.txt
//*fileEnergy->GetStream() << "STA_ID, STARemainingEnergy, STAEnergyConsumption" << std::endl;
//
double avgPowerConsumption = 0;
for (uint32_t iEs = 0; iEs < adhocNodes.GetN(); iEs++)
{
// Energy source by sources (if automatic installation)
Ptr<BasicEnergySource> basicSourcePtr = DynamicCast<BasicEnergySource>(
sources.Get(iEs));
// Energy model (if automatic installation)
// device energy model
Ptr<DeviceEnergyModel> basicRadioModelPtr =
basicSourcePtr->FindDeviceEnergyModels("ns3::WifiRadioEnergyModel").Get(
0);
// NS_LOG_UNCOND("energyModel collected pointer: " << basicRadioModelPtr
// << "\n energySource collected pointer: " << basicSourcePtr);
NS_ASSERT(basicRadioModelPtr != NULL);
//
avgPowerConsumption += basicRadioModelPtr->GetTotalEnergyConsumption();
//*fileEnergy->GetStream() << iEs << ", "
// << basicSourcePtr->GetRemainingEnergy() << ", "
// << basicRadioModelPtr->GetTotalEnergyConsumption() << std::endl;
//
}
avgPowerConsumption = avgPowerConsumption/adhocNodes.GetN();
// T-put calculation according to
http://paginas.fe.up.pt/~mricardo/doc/conferences/nstools2009/flowmon-paper.pdf double statDurationTX = 0;
double statDurationRX = 0;
//
monitor->CheckForLostPackets();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(
flowmon.GetClassifier());
std::cout << "Saving output data..." << std::endl;
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator iter =
stats.begin(); iter != stats.end(); ++iter)
{
// some metrics calculation
statDurationRX = iter->second.timeLastRxPacket.GetSeconds()- iter->second.timeFirstTxPacket.GetSeconds();
statDurationTX = iter->second.timeLastTxPacket.GetSeconds()- iter->second.timeFirstTxPacket.GetSeconds();
double meanDelay, meanJitter, packetLossRatio, txTput, rxTput;
if (iter->second.rxPackets > 0)
{
meanDelay = (iter->second.delaySum.GetSeconds()
/ iter->second.rxPackets);
}
else // this value is set to zero because the STA is not receiving any packet
{
meanDelay = 0;
}
//
if (iter->second.rxPackets > 1)
{
meanJitter = (iter->second.jitterSum.GetSeconds()
/ (iter->second.rxPackets - 1));
}
else // this value is set to zero because the STA is not receiving any packet
{
meanJitter = 0;
}
//
if (statDurationTX > 0)
{
txTput = iter->second.txBytes * 8.0 / statDurationTX / 1000 / 1000;
}
else
{
txTput = 0;
}
//
if (statDurationRX > 0)
{
rxTput = iter->second.rxBytes * 8.0 / statDurationRX / 1000 / 1000;
}
else
{
rxTput = 0;
}
//
if ((iter->second.lostPackets > 0) & (iter->second.rxPackets > 0))
{
packetLossRatio = (double) (iter->second.lostPackets
/ (double) (iter->second.rxPackets + iter->second.lostPackets));
}
else
{
packetLossRatio = 0;
}
// To see all flows
//Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(iter->first);
//std::cout << "Some problem to save metrics" << std::endl;
//std::cout << "Flow ID: " << iter->first << ", Source Port: "
// << t.sourcePort << ", Destination Port: " << t.destinationPort
// << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")" << std::endl;
// Save metrics
if (myfile)
{
myfile << (iter->first ) << ", "
<< (iter->second.lostPackets) << ", "
//
<< (iter->second.txPackets) << ", "
//
<< (iter->second.txBytes) << ", "
//
<< txTput << ", "
//
<< (iter->second.rxPackets) << ", "
//
<< (iter->second.rxBytes) << ", "
//
<< rxTput << ", "
//
<< meanDelay << ", "
//
<< meanJitter << ", "
//
<< packetLossRatio << ", ";
}
//
//Store some input parameters into a file (only for numerical parameters)
myfile << avgPowerConsumption << ", "
<< iNWifis << ", "
<< dTxp << ", "
<< iProtocol << std::endl;
}
toc();
myfile.close ();
//
Simulator::Destroy ();
return 0;
}
I've changed the version ns-3, Linux system, mobility model (instead of 3D Gauss Markov to RandonWaypoint) e this error continues. I would appreciate if someone could help with this problem. Please, reply if there's a solution for that. Thanks!!