examples, internet, prop, spect, uan: Cache math functions and frequently used variables

This commit is contained in:
Eduardo Almeida
2023-09-13 18:53:39 +01:00
parent d3ea4d2da0
commit a4b43cb532
12 changed files with 226 additions and 240 deletions

View File

@@ -35,7 +35,7 @@ using namespace ns3;
int
main(int argc, char* argv[])
{
uint32_t FrameSize = 1500; // bytes
uint32_t frameSizeBytes = 1500;
std::ofstream file("frame-success-rate-dsss.plt");
const std::vector<std::string> modes{
@@ -46,7 +46,7 @@ main(int argc, char* argv[])
};
CommandLine cmd(__FILE__);
cmd.AddValue("FrameSize", "The frame size in bytes", FrameSize);
cmd.AddValue("FrameSize", "The frame size in bytes", frameSizeBytes);
cmd.Parse(argc, argv);
Gnuplot plot = Gnuplot("frame-success-rate-dsss.eps");
@@ -56,27 +56,27 @@ main(int argc, char* argv[])
Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
WifiTxVector txVector;
for (uint32_t i = 0; i < modes.size(); i++)
{
std::cout << modes[i] << std::endl;
Gnuplot2dDataset dataset(modes[i]);
txVector.SetMode(modes[i]);
uint32_t frameSizeBits = frameSizeBytes * 8;
for (double snr = -10.0; snr <= 20.0; snr += 0.1)
for (const auto& mode : modes)
{
std::cout << mode << std::endl;
Gnuplot2dDataset dataset(mode);
txVector.SetMode(mode);
WifiMode wifiMode(mode);
for (double snrDb = -10.0; snrDb <= 20.0; snrDb += 0.1)
{
double psYans = yans->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
double snr = std::pow(10.0, snrDb / 10.0);
double psYans = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (psYans < 0.0 || psYans > 1.0)
{
// error
exit(1);
}
double psNist = nist->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
double psNist = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (psNist < 0.0 || psNist > 1.0)
{
std::cout << psNist << std::endl;
@@ -87,10 +87,7 @@ main(int argc, char* argv[])
{
exit(1);
}
double psTable = table->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
double psTable = table->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (psTable < 0.0 || psTable > 1.0)
{
std::cout << psTable << std::endl;
@@ -101,7 +98,7 @@ main(int argc, char* argv[])
{
exit(1);
}
dataset.Add(snr, psYans);
dataset.Add(snrDb, psYans);
}
plot.AddDataset(dataset);

View File

@@ -86,66 +86,61 @@ main(int argc, char* argv[])
mode << format << "Mcs" << +endMcs;
modes.push_back(mode.str());
for (uint32_t i = 0; i < modes.size(); i++)
for (const auto& mode : modes)
{
std::cout << modes[i] << std::endl;
Gnuplot2dDataset yansdataset(modes[i]);
Gnuplot2dDataset nistdataset(modes[i]);
Gnuplot2dDataset tabledataset(modes[i]);
txVector.SetMode(modes[i]);
std::cout << mode << std::endl;
Gnuplot2dDataset yansdataset(mode);
Gnuplot2dDataset nistdataset(mode);
Gnuplot2dDataset tabledataset(mode);
txVector.SetMode(mode);
for (double snr = -5.0; snr <= (endMcs * 5); snr += 0.1)
WifiMode wifiMode(mode);
for (double snrDb = -5.0; snrDb <= (endMcs * 5); snrDb += 0.1)
{
double ps = yans->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
size);
double snr = std::pow(10.0, snrDb / 10.0);
double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, size);
if (ps < 0 || ps > 1)
{
// error
exit(1);
}
yansdataset.Add(snr, 1 - ps);
ps = nist->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
size);
yansdataset.Add(snrDb, 1 - ps);
ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, size);
if (ps < 0 || ps > 1)
{
// error
exit(1);
}
nistdataset.Add(snr, 1 - ps);
ps = table->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
size);
nistdataset.Add(snrDb, 1 - ps);
ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, size);
if (ps < 0 || ps > 1)
{
// error
exit(1);
}
tabledataset.Add(snr, 1 - ps);
tabledataset.Add(snrDb, 1 - ps);
}
if (tableErrorModelEnabled)
{
std::stringstream ss;
ss << "Table-" << modes[i];
ss << "Table-" << mode;
tabledataset.SetTitle(ss.str());
plot.AddDataset(tabledataset);
}
if (yansErrorModelEnabled)
{
std::stringstream ss;
ss << "Yans-" << modes[i];
ss << "Yans-" << mode;
yansdataset.SetTitle(ss.str());
plot.AddDataset(yansdataset);
}
if (nistErrorModelEnabled)
{
std::stringstream ss;
ss << "Nist-" << modes[i];
ss << "Nist-" << mode;
nistdataset.SetTitle(ss.str());
plot.AddDataset(nistdataset);
}

View File

@@ -37,7 +37,7 @@ using namespace ns3;
int
main(int argc, char* argv[])
{
uint32_t FrameSize = 1500; // bytes
uint32_t frameSizeBytes = 1500;
std::ofstream yansfile("yans-frame-success-rate-be.plt");
std::ofstream nistfile("nist-frame-success-rate-be.plt");
std::ofstream tablefile("table-frame-success-rate-be.plt");
@@ -60,7 +60,7 @@ main(int argc, char* argv[])
};
CommandLine cmd(__FILE__);
cmd.AddValue("FrameSize", "The frame size", FrameSize);
cmd.AddValue("FrameSize", "The frame size", frameSizeBytes);
cmd.Parse(argc, argv);
Gnuplot yansplot = Gnuplot("yans-frame-success-rate-be.eps");
@@ -72,48 +72,45 @@ main(int argc, char* argv[])
Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
WifiTxVector txVector;
for (uint32_t i = 0; i < modes.size(); i++)
uint32_t frameSizeBits = frameSizeBytes * 8;
for (const auto& mode : modes)
{
std::cout << modes[i] << std::endl;
Gnuplot2dDataset yansdataset(modes[i]);
Gnuplot2dDataset nistdataset(modes[i]);
Gnuplot2dDataset tabledataset(modes[i]);
txVector.SetMode(modes[i]);
std::cout << mode << std::endl;
Gnuplot2dDataset yansdataset(mode);
Gnuplot2dDataset nistdataset(mode);
Gnuplot2dDataset tabledataset(mode);
txVector.SetMode(mode);
for (double snr = -5.0; snr <= 55.0; snr += 0.1)
WifiMode wifiMode(mode);
for (double snrDb = -5.0; snrDb <= 55.0; snrDb += 0.1)
{
double ps = yans->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
yansdataset.Add(snr, ps);
double snr = std::pow(10.0, snrDb / 10.0);
ps = nist->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
nistdataset.Add(snr, ps);
yansdataset.Add(snrDb, ps);
ps = table->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
tabledataset.Add(snr, ps);
nistdataset.Add(snrDb, ps);
ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
tabledataset.Add(snrDb, ps);
}
yansplot.AddDataset(yansdataset);

View File

@@ -35,7 +35,7 @@ using namespace ns3;
int
main(int argc, char* argv[])
{
uint32_t FrameSize = 1500; // bytes
uint32_t frameSizeBytes = 1500;
std::ofstream yansfile("yans-frame-success-rate-ax.plt");
std::ofstream nistfile("nist-frame-success-rate-ax.plt");
std::ofstream tablefile("table-frame-success-rate-ax.plt");
@@ -56,7 +56,7 @@ main(int argc, char* argv[])
};
CommandLine cmd(__FILE__);
cmd.AddValue("FrameSize", "The frame size", FrameSize);
cmd.AddValue("FrameSize", "The frame size", frameSizeBytes);
cmd.Parse(argc, argv);
Gnuplot yansplot = Gnuplot("yans-frame-success-rate-ax.eps");
@@ -68,48 +68,45 @@ main(int argc, char* argv[])
Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
WifiTxVector txVector;
for (uint32_t i = 0; i < modes.size(); i++)
uint32_t frameSizeBits = frameSizeBytes * 8;
for (const auto& mode : modes)
{
std::cout << modes[i] << std::endl;
Gnuplot2dDataset yansdataset(modes[i]);
Gnuplot2dDataset nistdataset(modes[i]);
Gnuplot2dDataset tabledataset(modes[i]);
txVector.SetMode(modes[i]);
std::cout << mode << std::endl;
Gnuplot2dDataset yansdataset(mode);
Gnuplot2dDataset nistdataset(mode);
Gnuplot2dDataset tabledataset(mode);
txVector.SetMode(mode);
for (double snr = -5.0; snr <= 40.0; snr += 0.1)
WifiMode wifiMode(mode);
for (double snrDb = -5.0; snrDb <= 40.0; snrDb += 0.1)
{
double ps = yans->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
yansdataset.Add(snr, ps);
double snr = std::pow(10.0, snrDb / 10.0);
ps = nist->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
nistdataset.Add(snr, ps);
yansdataset.Add(snrDb, ps);
ps = table->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
tabledataset.Add(snr, ps);
nistdataset.Add(snrDb, ps);
ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
tabledataset.Add(snrDb, ps);
}
yansplot.AddDataset(yansdataset);

View File

@@ -35,7 +35,7 @@ using namespace ns3;
int
main(int argc, char* argv[])
{
uint32_t FrameSize = 1500; // bytes
uint32_t frameSizeBytes = 1500;
std::ofstream yansfile("yans-frame-success-rate-n.plt");
std::ofstream nistfile("nist-frame-success-rate-n.plt");
std::ofstream tablefile("table-frame-success-rate-n.plt");
@@ -52,7 +52,7 @@ main(int argc, char* argv[])
};
CommandLine cmd(__FILE__);
cmd.AddValue("FrameSize", "The frame size in bytes", FrameSize);
cmd.AddValue("FrameSize", "The frame size in bytes", frameSizeBytes);
cmd.Parse(argc, argv);
Gnuplot yansplot = Gnuplot("yans-frame-success-rate-n.eps");
@@ -64,48 +64,45 @@ main(int argc, char* argv[])
Ptr<NistErrorRateModel> nist = CreateObject<NistErrorRateModel>();
Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
for (uint32_t i = 0; i < modes.size(); i++)
uint32_t frameSizeBits = frameSizeBytes * 8;
for (const auto& mode : modes)
{
std::cout << modes[i] << std::endl;
Gnuplot2dDataset yansdataset(modes[i]);
Gnuplot2dDataset nistdataset(modes[i]);
Gnuplot2dDataset tabledataset(modes[i]);
txVector.SetMode(modes[i]);
std::cout << mode << std::endl;
Gnuplot2dDataset yansdataset(mode);
Gnuplot2dDataset nistdataset(mode);
Gnuplot2dDataset tabledataset(mode);
txVector.SetMode(mode);
for (double snr = -5.0; snr <= 30.0; snr += 0.1)
WifiMode wifiMode(mode);
for (double snrDb = -5.0; snrDb <= 30.0; snrDb += 0.1)
{
double ps = yans->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
yansdataset.Add(snr, ps);
double snr = std::pow(10.0, snrDb / 10.0);
ps = nist->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
nistdataset.Add(snr, ps);
yansdataset.Add(snrDb, ps);
ps = table->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
tabledataset.Add(snr, ps);
nistdataset.Add(snrDb, ps);
ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
tabledataset.Add(snrDb, ps);
}
yansplot.AddDataset(yansdataset);

View File

@@ -37,7 +37,7 @@ using namespace ns3;
int
main(int argc, char* argv[])
{
uint32_t FrameSize = 1500; // bytes
uint32_t frameSizeBytes = 1500;
std::ofstream yansfile("yans-frame-success-rate-ofdm.plt");
std::ofstream nistfile("nist-frame-success-rate-ofdm.plt");
std::ofstream tablefile("table-frame-success-rate-ofdm.plt");
@@ -54,7 +54,7 @@ main(int argc, char* argv[])
};
CommandLine cmd(__FILE__);
cmd.AddValue("FrameSize", "The frame size in bytes", FrameSize);
cmd.AddValue("FrameSize", "The frame size in bytes", frameSizeBytes);
cmd.Parse(argc, argv);
Gnuplot yansplot = Gnuplot("yans-frame-success-rate-ofdm.eps");
@@ -66,48 +66,45 @@ main(int argc, char* argv[])
Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
WifiTxVector txVector;
for (uint32_t i = 0; i < modes.size(); i++)
uint32_t frameSizeBits = frameSizeBytes * 8;
for (const auto& mode : modes)
{
std::cout << modes[i] << std::endl;
Gnuplot2dDataset yansdataset(modes[i]);
Gnuplot2dDataset nistdataset(modes[i]);
Gnuplot2dDataset tabledataset(modes[i]);
txVector.SetMode(modes[i]);
std::cout << mode << std::endl;
Gnuplot2dDataset yansdataset(mode);
Gnuplot2dDataset nistdataset(mode);
Gnuplot2dDataset tabledataset(mode);
txVector.SetMode(mode);
for (double snr = -5.0; snr <= 30.0; snr += 0.1)
WifiMode wifiMode(mode);
for (double snrDb = -5.0; snrDb <= 30.0; snrDb += 0.1)
{
double ps = yans->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
yansdataset.Add(snr, ps);
double snr = std::pow(10.0, snrDb / 10.0);
ps = nist->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
nistdataset.Add(snr, ps);
yansdataset.Add(snrDb, ps);
ps = table->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
tabledataset.Add(snr, ps);
nistdataset.Add(snrDb, ps);
ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
tabledataset.Add(snrDb, ps);
}
yansplot.AddDataset(yansdataset);

View File

@@ -36,7 +36,7 @@ using namespace ns3;
int
main(int argc, char* argv[])
{
uint32_t FrameSize = 1500; // bytes
uint32_t frameSizeBytes = 1500;
std::ofstream yansfile("yans-frame-success-rate-ac.plt");
std::ofstream nistfile("nist-frame-success-rate-ac.plt");
std::ofstream tablefile("table-frame-success-rate-ac.plt");
@@ -54,7 +54,7 @@ main(int argc, char* argv[])
};
CommandLine cmd(__FILE__);
cmd.AddValue("FrameSize", "The frame size in bytes", FrameSize);
cmd.AddValue("FrameSize", "The frame size in bytes", frameSizeBytes);
cmd.Parse(argc, argv);
Gnuplot yansplot = Gnuplot("yans-frame-success-rate-ac.eps");
@@ -66,48 +66,45 @@ main(int argc, char* argv[])
Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
WifiTxVector txVector;
for (uint32_t i = 0; i < modes.size(); i++)
uint32_t frameSizeBits = frameSizeBytes * 8;
for (const auto& mode : modes)
{
std::cout << modes[i] << std::endl;
Gnuplot2dDataset yansdataset(modes[i]);
Gnuplot2dDataset nistdataset(modes[i]);
Gnuplot2dDataset tabledataset(modes[i]);
txVector.SetMode(modes[i]);
std::cout << mode << std::endl;
Gnuplot2dDataset yansdataset(mode);
Gnuplot2dDataset nistdataset(mode);
Gnuplot2dDataset tabledataset(mode);
txVector.SetMode(mode);
for (double snr = -5.0; snr <= 30.0; snr += 0.1)
WifiMode wifiMode(mode);
for (double snrDb = -5.0; snrDb <= 30.0; snrDb += 0.1)
{
double ps = yans->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
yansdataset.Add(snr, ps);
double snr = std::pow(10.0, snrDb / 10.0);
ps = nist->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
nistdataset.Add(snr, ps);
yansdataset.Add(snrDb, ps);
ps = table->GetChunkSuccessRate(WifiMode(modes[i]),
txVector,
std::pow(10.0, snr / 10.0),
FrameSize * 8);
ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
tabledataset.Add(snr, ps);
nistdataset.Add(snrDb, ps);
ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
if (ps < 0.0 || ps > 1.0)
{
// error
exit(1);
}
tabledataset.Add(snrDb, ps);
}
yansplot.AddDataset(yansdataset);

View File

@@ -404,11 +404,13 @@ Ipv4L3ProtocolRxTxSink(Ptr<const Packet> p, Ptr<Ipv4> ipv4, uint32_t interface)
bool
InternetStackHelper::PcapHooked(Ptr<Ipv4> ipv4)
{
auto id = ipv4->GetObject<Node>()->GetId();
for (InterfaceFileMapIpv4::const_iterator i = g_interfaceFileMapIpv4.begin();
i != g_interfaceFileMapIpv4.end();
++i)
{
if ((*i).first.first == ipv4->GetObject<Node>()->GetId())
if ((*i).first.first == id)
{
return true;
}
@@ -510,11 +512,13 @@ Ipv6L3ProtocolRxTxSink(Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface)
bool
InternetStackHelper::PcapHooked(Ptr<Ipv6> ipv6)
{
auto id = ipv6->GetObject<Node>()->GetId();
for (InterfaceFileMapIpv6::const_iterator i = g_interfaceFileMapIpv6.begin();
i != g_interfaceFileMapIpv6.end();
++i)
{
if ((*i).first.first == ipv6->GetObject<Node>()->GetId())
if ((*i).first.first == id)
{
return true;
}
@@ -774,11 +778,13 @@ Ipv4L3ProtocolRxSinkWithContext(Ptr<OutputStreamWrapper> stream,
bool
InternetStackHelper::AsciiHooked(Ptr<Ipv4> ipv4)
{
auto id = ipv4->GetObject<Node>()->GetId();
for (InterfaceStreamMapIpv4::const_iterator i = g_interfaceStreamMapIpv4.begin();
i != g_interfaceStreamMapIpv4.end();
++i)
{
if ((*i).first.first == ipv4->GetObject<Node>()->GetId())
if ((*i).first.first == id)
{
return true;
}
@@ -1118,11 +1124,13 @@ Ipv6L3ProtocolRxSinkWithContext(Ptr<OutputStreamWrapper> stream,
bool
InternetStackHelper::AsciiHooked(Ptr<Ipv6> ipv6)
{
auto id = ipv6->GetObject<Node>()->GetId();
for (InterfaceStreamMapIpv6::const_iterator i = g_interfaceStreamMapIpv6.begin();
i != g_interfaceStreamMapIpv6.end();
++i)
{
if ((*i).first.first == ipv6->GetObject<Node>()->GetId())
if ((*i).first.first == id)
{
return true;
}

View File

@@ -155,20 +155,19 @@ Cost231PropagationLossModel::GetLoss(Ptr<MobilityModel> a, Ptr<MobilityModel> b)
return 0.0;
}
double frequency_MHz = m_frequency * 1e-6;
double logFrequencyMhz = std::log10(m_frequency * 1e-6);
double logDistanceKm = std::log10(distance * 1e-3);
double logBSAntennaHeight = std::log10(m_BSAntennaHeight);
double distance_km = distance * 1e-3;
double C_H = 0.8 + ((1.11 * std::log10(frequency_MHz)) - 0.7) * m_SSAntennaHeight -
(1.56 * std::log10(frequency_MHz));
double C_H =
0.8 + ((1.11 * logFrequencyMhz) - 0.7) * m_SSAntennaHeight - (1.56 * logFrequencyMhz);
// from the COST231 wiki entry
// See also http://www.lx.it.pt/cost231/final_report.htm
// Ch. 4, eq. 4.4.3, pg. 135
double loss_in_db =
46.3 + (33.9 * std::log10(frequency_MHz)) - (13.82 * std::log10(m_BSAntennaHeight)) - C_H +
((44.9 - 6.55 * std::log10(m_BSAntennaHeight)) * std::log10(distance_km)) + m_shadowing;
double loss_in_db = 46.3 + (33.9 * logFrequencyMhz) - (13.82 * logBSAntennaHeight) - C_H +
((44.9 - 6.55 * logBSAntennaHeight) * logDistanceKm) + m_shadowing;
NS_LOG_DEBUG("dist =" << distance << ", Path Loss = " << loss_in_db);

View File

@@ -25,6 +25,7 @@
#include "ns3/log.h"
#include "ns3/mobility-model.h"
#include <algorithm>
#include <cmath>
namespace ns3
@@ -80,19 +81,26 @@ OkumuraHataPropagationLossModel::GetLoss(Ptr<MobilityModel> a, Ptr<MobilityModel
{
double loss = 0.0;
double fmhz = m_frequency / 1e6;
double dist = a->GetDistanceFrom(b) / 1000.0;
double log_fMhz = std::log10(fmhz);
double dist = a->GetDistanceFrom(b);
Vector aPosition = a->GetPosition();
Vector bPosition = b->GetPosition();
double hb = std::max(aPosition.z, bPosition.z);
double hm = std::min(aPosition.z, bPosition.z);
NS_ASSERT_MSG(hb > 0 && hm > 0, "nodes' height must be greater then 0");
double log_hb = std::log10(hb);
double log_aHeight = 13.82 * log_hb;
double log_bHeight = 0.0;
if (m_frequency <= 1.500e9)
{
// standard Okumura Hata
// see eq. (4.4.1) in the COST 231 final report
double log_f = std::log10(fmhz);
double hb =
(a->GetPosition().z > b->GetPosition().z ? a->GetPosition().z : b->GetPosition().z);
double hm =
(a->GetPosition().z < b->GetPosition().z ? a->GetPosition().z : b->GetPosition().z);
NS_ASSERT_MSG(hb > 0 && hm > 0, "nodes' height must be greater then 0");
double log_aHeight = 13.82 * std::log10(hb);
double log_bHeight = 0.0;
if (m_citySize == LargeCity)
{
if (fmhz < 200)
@@ -106,21 +114,21 @@ OkumuraHataPropagationLossModel::GetLoss(Ptr<MobilityModel> a, Ptr<MobilityModel
}
else
{
log_bHeight = 0.8 + (1.1 * log_f - 0.7) * hm - 1.56 * log_f;
log_bHeight = 0.8 + (1.1 * log_fMhz - 0.7) * hm - 1.56 * log_fMhz;
}
NS_LOG_INFO(this << " logf " << 26.16 * log_f << " loga " << log_aHeight << " X "
<< (((44.9 - (6.55 * std::log10(hb)))) * std::log10(a->GetDistanceFrom(b)))
<< " logb " << log_bHeight);
loss = 69.55 + (26.16 * log_f) - log_aHeight +
(((44.9 - (6.55 * std::log10(hb)))) * std::log10(dist)) - log_bHeight;
NS_LOG_INFO(this << " logf " << 26.16 * log_fMhz << " loga " << log_aHeight << " X "
<< ((44.9 - (6.55 * log_hb)) * std::log10(dist)) << " logb "
<< log_bHeight);
loss = 69.55 + (26.16 * log_fMhz) - log_aHeight +
((44.9 - (6.55 * log_hb)) * std::log10(dist / 1e3)) - log_bHeight;
if (m_environment == SubUrbanEnvironment)
{
loss += -2 * (std::pow(std::log10(fmhz / 28), 2)) - 5.4;
}
else if (m_environment == OpenAreasEnvironment)
{
loss += -4.70 * std::pow(std::log10(fmhz), 2) + 18.33 * std::log10(fmhz) - 40.94;
loss += -4.70 * std::pow(log_fMhz, 2) + 18.33 * log_fMhz - 40.94;
}
}
else
@@ -128,28 +136,20 @@ OkumuraHataPropagationLossModel::GetLoss(Ptr<MobilityModel> a, Ptr<MobilityModel
// COST 231 Okumura model
// see eq. (4.4.3) in the COST 231 final report
double log_f = std::log10(fmhz);
double hb =
(a->GetPosition().z > b->GetPosition().z ? a->GetPosition().z : b->GetPosition().z);
double hm =
(a->GetPosition().z < b->GetPosition().z ? a->GetPosition().z : b->GetPosition().z);
NS_ASSERT_MSG(hb > 0 && hm > 0, "nodes' height must be greater then 0");
double log_aHeight = 13.82 * std::log10(hb);
double log_bHeight = 0.0;
double C = 0.0;
if (m_citySize == LargeCity)
{
log_bHeight = 3.2 * std::pow((std::log10(11.75 * hm)), 2);
log_bHeight = 3.2 * std::pow(std::log10(11.75 * hm), 2);
C = 3;
}
else
{
log_bHeight = (1.1 * log_f - 0.7) * hm - (1.56 * log_f - 0.8);
log_bHeight = (1.1 * log_fMhz - 0.7) * hm - (1.56 * log_fMhz - 0.8);
}
loss = 46.3 + (33.9 * log_f) - log_aHeight +
(((44.9 - (6.55 * std::log10(hb)))) * std::log10(dist)) - log_bHeight + C;
loss = 46.3 + (33.9 * log_fMhz) - log_aHeight +
((44.9 - (6.55 * log_hb)) * std::log10(dist / 1e3)) - log_bHeight + C;
}
return loss;
}

View File

@@ -153,8 +153,10 @@ FtrFadingModelAverageTest::DoRun()
// Generate a set of values for the FTR model parameters
for (uint8_t j = 0; j < NUM_VALUES; j++)
{
sigma[j] = std::pow(2, j);
k[j] = std::pow(2, j);
double power = std::pow(2, j);
sigma[j] = power;
k[j] = power;
delta[j] = double(j) / NUM_VALUES; // Delta must be in [0, 1]
}

View File

@@ -57,7 +57,7 @@ UanNoiseModelDefault::GetTypeId()
}
// Common acoustic noise formulas. These can be found
// in "Priniciples of Underwater Sound" by Robert J. Urick
// in "Principles of Underwater Sound" by Robert J. Urick
double
UanNoiseModelDefault::GetNoiseDbHz(double fKhz) const
{
@@ -71,18 +71,18 @@ UanNoiseModelDefault::GetNoiseDbHz(double fKhz) const
double thermalDb;
double noiseDb;
turbDb = 17.0 - 30.0 * std::log10(fKhz);
double log_fKhz = std::log10(fKhz);
turbDb = 17.0 - 30.0 * log_fKhz;
turb = std::pow(10.0, turbDb * 0.1);
shipDb =
40.0 + 20.0 * (m_shipping - 0.5) + 26.0 * std::log10(fKhz) - 60.0 * std::log10(fKhz + 0.03);
shipDb = 40.0 + 20.0 * (m_shipping - 0.5) + 26.0 * log_fKhz - 60.0 * std::log10(fKhz + 0.03);
ship = std::pow(10.0, (shipDb * 0.1));
windDb = 50.0 + 7.5 * std::pow(m_wind, 0.5) + 20.0 * std::log10(fKhz) -
40.0 * std::log10(fKhz + 0.4);
windDb = 50.0 + 7.5 * std::pow(m_wind, 0.5) + 20.0 * log_fKhz - 40.0 * std::log10(fKhz + 0.4);
wind = std::pow(10.0, windDb * 0.1);
thermalDb = -15 + 20 * std::log10(fKhz);
thermalDb = -15 + 20 * log_fKhz;
thermal = std::pow(10, thermalDb * 0.1);
noiseDb = 10 * std::log10(turb + ship + wind + thermal);