Skip to content

Commit

Permalink
Renamed tests and changed cached parameters from references to pointe…
Browse files Browse the repository at this point in the history
…rs to facilitate testing.
  • Loading branch information
Paolo Fittipaldi committed Jun 19, 2024
1 parent 054ddcd commit cca8f1c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
8 changes: 5 additions & 3 deletions quisp/channels/FreeSpaceChannel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
using namespace omnetpp;
namespace channels {

FreeSpaceChannel::FreeSpaceChannel() : parameter_distance(par("distance")), parameter_delay(par("delay")){};
FreeSpaceChannel::FreeSpaceChannel(){};

void FreeSpaceChannel::initialize() {
cDatarateChannel::initialize();
parameter_distance = &par("distance");
parameter_delay = &par("delay");
speed_of_light_in_freespace = par("speed_of_light_in_freespace").doubleValue();
const char *filename = par("distance_csv").stringValue();
csv_varies_delay = par("csv_varies_delay").boolValue();
Expand Down Expand Up @@ -60,7 +62,7 @@ SimTime FreeSpaceChannel::getNextCheckTime() {
}

void FreeSpaceChannel::recalculateChannelParameters() {
parameter_distance.setDoubleValue(dist_parser->getPropertyAtTime(simTime().dbl()));
if (csv_varies_delay) parameter_delay.setDoubleValue(parameter_distance.doubleValue() / speed_of_light_in_freespace);
parameter_distance->setDoubleValue(dist_parser->getPropertyAtTime(simTime().dbl()));
if (csv_varies_delay) parameter_delay->setDoubleValue(parameter_distance->doubleValue() / speed_of_light_in_freespace);
}
} // namespace channels
4 changes: 2 additions & 2 deletions quisp/channels/FreeSpaceChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class FreeSpaceChannel : public cDatarateChannel {
private:
OrbitalParameters op;
OrbitalDataParser *dist_parser;
cPar &parameter_distance;
cPar &parameter_delay;
cPar *parameter_distance;
cPar *parameter_delay;
bool csv_varies_delay = true;
double speed_of_light_in_freespace = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <test_utils/ChannelType.h>
#include <test_utils/TestUtils.h>

#include "FSChannel.h"
#include "FreeSpaceChannel.h"

#include <fstream>

Expand All @@ -15,7 +15,7 @@ using namespace quisp::messages;
using namespace quisp::modules::SharedResource;
using namespace omnetpp;
using namespace quisp_test::utils;
using OriginalFSChannel = channels::FSChannel;
using OriginalFreeSpaceChannel = channels::FreeSpaceChannel;
using quisp_test::channel_type::TestChannelType;

namespace {
Expand All @@ -27,18 +27,18 @@ class MockNode : public quisp_test::TestQNode {
bool is_qnode;
};

class FSChannel : public OriginalFSChannel {
class FreeSpaceChannel : public OriginalFreeSpaceChannel {
public:
FSChannel() : OriginalFSChannel::FSChannel() {
FreeSpaceChannel() : OriginalFreeSpaceChannel::FreeSpaceChannel() {
setParDouble(this, "distance", 0);
setParDouble(this, "delay", 0);
setParDouble(this, "datarate", 0);
setParDouble(this, "ber", 0);
setParDouble(this, "per", 0);
setParDouble(this, "orbital_period", 86400);
setParDouble(this, "speed_of_light_in_FS", 299792458);
setParDouble(this, "speed_of_light_in_freespace", 299792458);
setParBool(this, "disabled", false);
setParBool(this, "CSV_varies_delay", true);
setParBool(this, "csv_varies_delay", true);

setComponentType(new TestChannelType("test channel"));
}
Expand Down Expand Up @@ -80,7 +80,7 @@ class TestSimpleModule : public cSimpleModule {
}
};

class FSChannelTest : public ::testing::Test {
class FreeSpaceChannelTest : public ::testing::Test {
protected:
void SetUp() {
generateTestCSV("channels/test_dist_csv.csv");
Expand All @@ -95,11 +95,11 @@ class FSChannelTest : public ::testing::Test {
sat_gate = sat_node->addGate("sat_gate", cGate::INOUT);
ground_gate = ground_node->addGate("ground_gate", cGate::INOUT);

downlink_chl = new FSChannel();
downlink_chl = new FreeSpaceChannel();

sim->registerComponent(downlink_chl);

utils::setParStr(downlink_chl, "distance_CSV", "channels/test_dist_csv.csv");
utils::setParStr(downlink_chl, "distance_csv", "channels/test_dist_csv.csv");

sat_node->gate("sat_gate$o")->connectTo(ground_node->gate("ground_gate$i"), downlink_chl, true);

Expand Down Expand Up @@ -130,31 +130,31 @@ class FSChannelTest : public ::testing::Test {
TestSimpleModule* sat_simplemodule;
MockNode* sat_node;
MockNode* ground_node;
FSChannel* downlink_chl;
FreeSpaceChannel* downlink_chl;
cGate* sat_gate;
cGate* ground_gate;
};

TEST_F(FSChannelTest, messageWhenNonVisible) {
TEST_F(FreeSpaceChannelTest, messageWhenNonVisible) {
cMessage* msg = new cMessage();
cChannel::Result res = downlink_chl->public_processMessage(msg);
sim->run();
ASSERT_EQ(res.discard, true);
}

TEST_F(FSChannelTest, messageWhenVisible) {
TEST_F(FreeSpaceChannelTest, messageWhenVisible) {
auto timeout = new cMessage;
sat_simplemodule->scheduleAfter(200, timeout);
sim->executeNextEvent();
auto msg = new cMessage;
cChannel::Result res = downlink_chl->public_processMessage(msg);
sim->run();
ASSERT_EQ(res.discard, false);
simtime_t delay = downlink_chl->par("distance").doubleValue() / downlink_chl->par("speed_of_light_in_FS").doubleValue();
simtime_t delay = downlink_chl->par("distance").doubleValue() / downlink_chl->par("speed_of_light_in_freespace").doubleValue();
ASSERT_EQ(res.delay.raw(), delay.raw());
}

TEST_F(FSChannelTest, messageAfterVisible) {
TEST_F(FreeSpaceChannelTest, messageAfterVisible) {
auto timeout = new cMessage;
sat_simplemodule->scheduleAfter(600, timeout);
sim->executeNextEvent();
Expand All @@ -164,18 +164,18 @@ TEST_F(FSChannelTest, messageAfterVisible) {
ASSERT_EQ(res.discard, true);
}

TEST_F(FSChannelTest, messageFollowingDayVisible) {
TEST_F(FreeSpaceChannelTest, messageFollowingDayVisible) {
auto timeout = new cMessage;
sat_simplemodule->scheduleAfter(86700, timeout);
sim->executeNextEvent();
auto msg = new cMessage;
cChannel::Result res = downlink_chl->public_processMessage(msg);
sim->run();
ASSERT_EQ(res.discard, false);
simtime_t delay = downlink_chl->par("distance").doubleValue() / downlink_chl->par("speed_of_light_in_FS").doubleValue();
simtime_t delay = downlink_chl->par("distance").doubleValue() / downlink_chl->par("speed_of_light_in_freespace").doubleValue();
ASSERT_EQ(res.delay.raw(), delay.raw()); // Comparing the raw int64_t values doesn't lose precision, unlike .dbl().
}
TEST_F(FSChannelTest, messageFollowingDayNonVisible) {
TEST_F(FreeSpaceChannelTest, messageFollowingDayNonVisible) {
auto timeout = new cMessage;
sat_simplemodule->scheduleAfter(86801, timeout);
sim->executeNextEvent();
Expand Down

0 comments on commit cca8f1c

Please sign in to comment.