Make examples runable as tests

This commit is contained in:
Tim Schubert 2020-08-29 21:11:55 +02:00
parent fccc05f6c2
commit 3f4ba0a8c1
5 changed files with 107 additions and 26 deletions

View file

@ -22,7 +22,7 @@ int main(int argc, char *argv[])
CommandLine cmd; CommandLine cmd;
std::string orbitFile; std::string orbitFile;
std::string traceFile; std::string traceFile;
double duration; double duration = 60;
cmd.AddValue("orbitFile", "CSV file with orbit parameters", orbitFile); cmd.AddValue("orbitFile", "CSV file with orbit parameters", orbitFile);
cmd.AddValue("traceFile", "CSV file to store mobility trace in", traceFile); cmd.AddValue("traceFile", "CSV file to store mobility trace in", traceFile);
cmd.AddValue("precision", "ns3::LeoCircularOrbitMobilityModel::Precision"); cmd.AddValue("precision", "ns3::LeoCircularOrbitMobilityModel::Precision");
@ -30,7 +30,16 @@ int main(int argc, char *argv[])
cmd.Parse (argc, argv); cmd.Parse (argc, argv);
LeoOrbitNodeHelper orbit; LeoOrbitNodeHelper orbit;
NodeContainer satellites = orbit.Install (orbitFile); NodeContainer satellites;
if (orbitFile.empty())
{
satellites = orbit.Install (orbitFile);
}
else
{
satellites = orbit.Install ({ LeoOrbit (1200, 20, 32, 16),
LeoOrbit (1180, 30, 12, 10) });
}
Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
MakeCallback (&CourseChange)); MakeCallback (&CourseChange));

View file

@ -74,18 +74,18 @@ int main (int argc, char *argv[])
CommandLine cmd; CommandLine cmd;
std::string orbitFile; std::string orbitFile;
std::string traceFile; std::string traceFile;
LeoLatLong source; LeoLatLong source (51.84, 10.28);
LeoLatLong destination; LeoLatLong destination (40.76, -73.96);
std::string islRate; std::string islRate = "2Gbps";
std::string constellation; std::string constellation = "TelesatGateway";
uint32_t latGws = 20; uint32_t latGws = 20;
uint32_t lonGws = 20; uint32_t lonGws = 20;
double interval; double interval = 1;
double duration; double duration = 100;
bool islEnabled = false; bool islEnabled = true;
bool traceDrops = false; bool traceDrops = true;
bool traceTxRx = false; bool traceTxRx = true;
bool traceFwd = false; bool traceFwd = true;
std::string routingProto = "aodv"; std::string routingProto = "aodv";
cmd.AddValue("orbitFile", "CSV file with orbit parameters", orbitFile); cmd.AddValue("orbitFile", "CSV file with orbit parameters", orbitFile);
cmd.AddValue("traceFile", "CSV file to store mobility trace in", traceFile); cmd.AddValue("traceFile", "CSV file to store mobility trace in", traceFile);
@ -117,7 +117,16 @@ int main (int argc, char *argv[])
} }
LeoOrbitNodeHelper orbit; LeoOrbitNodeHelper orbit;
NodeContainer satellites = orbit.Install (orbitFile); NodeContainer satellites;
if (orbitFile.empty())
{
satellites = orbit.Install (orbitFile);
}
else
{
satellites = orbit.Install ({ LeoOrbit (1200, 20, 32, 16),
LeoOrbit (1180, 30, 12, 10) });
}
LeoGndNodeHelper ground; LeoGndNodeHelper ground;
NodeContainer stations = ground.Install (latGws, lonGws); NodeContainer stations = ground.Install (latGws, lonGws);

View file

@ -1,6 +1,7 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include <fstream> #include <fstream>
#include <vector>
#include "ns3/log.h" #include "ns3/log.h"
#include "ns3/config.h" #include "ns3/config.h"
@ -10,7 +11,6 @@
#include "ns3/integer.h" #include "ns3/integer.h"
#include "leo-orbit-node-helper.h" #include "leo-orbit-node-helper.h"
#include "../model/leo-orbit.h"
using namespace std; using namespace std;
@ -34,16 +34,10 @@ LeoOrbitNodeHelper::SetAttribute (string name, const AttributeValue &value)
} }
NodeContainer NodeContainer
LeoOrbitNodeHelper::Install (const std::string &orbitFile) LeoOrbitNodeHelper::Install (const LeoOrbit &orbit)
{ {
NS_LOG_FUNCTION (this << orbitFile); NS_LOG_FUNCTION (this << orbit);
NodeContainer nodes;
ifstream orbits;
orbits.open (orbitFile, ifstream::in);
LeoOrbit orbit;
while ((orbits >> orbit))
{
MobilityHelper mobility; MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::LeoCircularOrbitPostionAllocator", mobility.SetPositionAllocator ("ns3::LeoCircularOrbitPostionAllocator",
"NumOrbits", IntegerValue (orbit.planes), "NumOrbits", IntegerValue (orbit.planes),
@ -55,7 +49,22 @@ LeoOrbitNodeHelper::Install (const std::string &orbitFile)
NodeContainer c; NodeContainer c;
c.Create (orbit.sats*orbit.planes); c.Create (orbit.sats*orbit.planes);
mobility.Install (c); mobility.Install (c);
nodes.Add (c);
return c;
}
NodeContainer
LeoOrbitNodeHelper::Install (const std::string &orbitFile)
{
NS_LOG_FUNCTION (this << orbitFile);
NodeContainer nodes;
ifstream orbits;
orbits.open (orbitFile, ifstream::in);
LeoOrbit orbit;
while ((orbits >> orbit))
{
nodes.Add (Install (orbit));
NS_LOG_DEBUG ("Added orbit plane"); NS_LOG_DEBUG ("Added orbit plane");
} }
orbits.close (); orbits.close ();
@ -65,4 +74,21 @@ LeoOrbitNodeHelper::Install (const std::string &orbitFile)
return nodes; return nodes;
} }
NodeContainer
LeoOrbitNodeHelper::Install (const vector<LeoOrbit> &orbits)
{
NS_LOG_FUNCTION (this << orbits);
NodeContainer nodes;
for (uint64_t i = 0; i < orbits.size(); i++)
{
nodes.Add (Install (orbits[i]));
NS_LOG_DEBUG ("Added orbit plane");
}
NS_LOG_DEBUG ("Added " << nodes.GetN () << " nodes");
return nodes;
}
}; // namespace ns3 }; // namespace ns3

View file

@ -9,6 +9,7 @@
#include "ns3/node-container.h" #include "ns3/node-container.h"
#include "ns3/leo-circular-orbit-mobility-model.h" #include "ns3/leo-circular-orbit-mobility-model.h"
#include "ns3/leo-circular-orbit-position-allocator.h" #include "ns3/leo-circular-orbit-position-allocator.h"
#include "ns3/leo-orbit.h"
/** /**
* \brief Builds a node container of nodes with LEO positions using a list of * \brief Builds a node container of nodes with LEO positions using a list of
@ -33,6 +34,20 @@ public:
*/ */
NodeContainer Install (const std::string &orbitFile); NodeContainer Install (const std::string &orbitFile);
/**
*
* \param orbits orbit definitions
* \returns a node container containing nodes using the specified attributes
*/
NodeContainer Install (const std::vector<LeoOrbit> &orbits);
/**
*
* \param orbit orbit definition
* \returns a node container containing nodes using the specified attributes
*/
NodeContainer Install (const LeoOrbit &orbit);
/** /**
* Set an attribute for each node * Set an attribute for each node
* *

22
test/examples-to-run.py Normal file
View file

@ -0,0 +1,22 @@
#! /usr/bin/env python3
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# A list of C++ examples to run in order to ensure that they remain
# buildable and runnable over time. Each tuple in the list contains
#
# (example_name, do_run, do_valgrind_run).
#
# See test.py for more information.
cpp_examples = [
("leo-orbit", "True", "True"),
("leo-delay", "True", "True"),
("leo-bulk-send", "True", "True"),
]
# A list of Python examples to run in order to ensure that they remain
# runnable over time. Each tuple in the list contains
#
# (example_name, do_run).
#
# See test.py for more information.
python_examples = []