Skip to content

Commit

Permalink
handle changes of Identity properties
Browse files Browse the repository at this point in the history
Change-Id: I750bab99531289fcb9e8c194ef981adf3611654d
  • Loading branch information
riebl committed Jan 3, 2019
1 parent cea01b3 commit cff6d7c
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/artery/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_library(core SHARED
traci/VehicleType.cc
utility/AsioScheduler.cc
utility/AsioTask.cc
utility/Identity.cc
utility/IdentityRegistry.cc
utility/FilterRules.cc
utility/Geometry.cc
Expand Down
19 changes: 12 additions & 7 deletions src/artery/application/Middleware.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ void Middleware::initialize(int stage)
mRouter = inet::getModuleFromPar<Router>(par("routerModule"), findHost());
mUpdateInterval = par("updateInterval");
mUpdateMessage = new cMessage("middleware update");
mIdentity.host = findHost();
mIdentity.host->subscribe(Identity::changeSignal, this);
} else if (stage == InitStages::Self) {
mFacilities.register_const(&mTimer);
mFacilities.register_mutable(&mLocalDynamicMap);
mFacilities.register_const(&mIdentity);
mFacilities.register_const(&mStationType);

initializeIdentity(mIdentity);
initializeServices(InitStages::Self);

// start update cycle with random jitter to avoid unrealistic node synchronization
Expand All @@ -59,12 +60,6 @@ void Middleware::initialize(int stage)
}
}

void Middleware::initializeIdentity(Identity& id)
{
id.host = findHost();
id.geonet = notNullPtr(mRouter)->getAddress();
}

void Middleware::initializeServices(int stage)
{
cXMLElement* config = par("services").xmlValue();
Expand Down Expand Up @@ -128,6 +123,16 @@ void Middleware::handleMessage(cMessage *msg)
}
}

void Middleware::receiveSignal(omnetpp::cComponent*, omnetpp::simsignal_t signal, long changes, omnetpp::cObject* obj)
{
if (signal == Identity::changeSignal) {
auto identity = check_and_cast<Identity*>(obj);
if (mIdentity.update(*identity, changes)) {
emit(artery::IdentityRegistry::updateSignal, &mIdentity);
}
}
}

cModule* Middleware::findHost()
{
return inet::getContainingNode(this);
Expand Down
6 changes: 4 additions & 2 deletions src/artery/application/Middleware.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "artery/application/StationType.h"
#include "artery/application/Timer.h"
#include "artery/utility/Identity.h"
#include <omnetpp/clistener.h>
#include <omnetpp/csimplemodule.h>
#include <omnetpp/simtime.h>
#include <vanetza/btp/data_request.hpp>
Expand All @@ -29,7 +30,7 @@ class Router;
/**
* Middleware providing a runtime context for services.
*/
class Middleware : public omnetpp::cSimpleModule
class Middleware : public omnetpp::cSimpleModule, public omnetpp::cListener
{
public:
typedef uint16_t port_type;
Expand All @@ -53,7 +54,8 @@ class Middleware : public omnetpp::cSimpleModule
void finish() override;
void handleMessage(omnetpp::cMessage* msg) override;

virtual void initializeIdentity(Identity&);
// cListener
void receiveSignal(omnetpp::cComponent*, omnetpp::simsignal_t, long, omnetpp::cObject*) override;

omnetpp::cModule* findHost();
void setStationType(const StationType&);
Expand Down
4 changes: 2 additions & 2 deletions src/artery/application/Middleware.ned
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ simple Middleware like IMiddleware
{
parameters:
@class(Middleware);
@signal[Identity.update](type=artery::Identity);
@signal[Identity.remove](type=artery::Identity);
@signal[IdentityUpdated](type=artery::Identity);
@signal[IdentityRemoved](type=artery::Identity);
@signal[StoryboardSignal](type=StoryboardSignal);

string routerModule;
Expand Down
12 changes: 5 additions & 7 deletions src/artery/application/VehicleMiddleware.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ void VehicleMiddleware::initialize(int stage)
initializeStationType(mVehicleController->getVehicleClass());
getFacilities().register_const(&mVehicleDataProvider);
mVehicleDataProvider.update(mVehicleController);

Identity identity;
identity.traci = mVehicleController->getVehicleId();
identity.application = mVehicleDataProvider.station_id();
emit(Identity::changeSignal, Identity::ChangeTraCI | Identity::ChangeStationId, &identity);
}

Middleware::initialize(stage);
Expand All @@ -36,13 +41,6 @@ void VehicleMiddleware::finish()
findHost()->unsubscribe(MobilityBase::stateChangedSignal, this);
}

void VehicleMiddleware::initializeIdentity(Identity& id)
{
Middleware::initializeIdentity(id);
id.traci = mVehicleController->getVehicleId();
id.application = mVehicleDataProvider.station_id();
}

void VehicleMiddleware::initializeStationType(const std::string& vclass)
{
using vanetza::geonet::StationType;
Expand Down
4 changes: 1 addition & 3 deletions src/artery/application/VehicleMiddleware.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@

#include "artery/application/Middleware.h"
#include "artery/application/VehicleDataProvider.h"
#include <omnetpp/clistener.h>

namespace artery
{

class VehicleMiddleware : public Middleware, public omnetpp::cListener
class VehicleMiddleware : public Middleware
{
public:
void initialize(int stage) override;
void finish() override;

protected:
void initializeIdentity(Identity&) override;
void initializeStationType(const std::string&);
void initializeVehicleController(omnetpp::cPar&);
void receiveSignal(omnetpp::cComponent*, omnetpp::simsignal_t, omnetpp::cObject*, omnetpp::cObject*) override;
Expand Down
1 change: 1 addition & 0 deletions src/artery/application/VehicleMiddleware.ned
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ simple VehicleMiddleware extends Middleware
{
parameters:
@class(VehicleMiddleware);
@signal[IdentityChanged](type=long);

string localEnvironmentModule = default("");
string globalEnvironmentModule = default("");
Expand Down
11 changes: 8 additions & 3 deletions src/artery/networking/Router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void Router::initialize(int stage)
// basic router setup
auto runtime = inet::getModuleFromPar<Runtime>(par("runtimeModule"), this);
mRouter.reset(new vanetza::geonet::Router(*runtime, mMIB));
mRouter->set_address(generateAddress()); // VehicleMiddleware determines station type at first stage
vanetza::MacAddress init_mac = vanetza::create_mac_address(getId());
mRouter->set_address(generateAddress(init_mac));

// register security entity if available
if (mSecurityEntity) {
Expand Down Expand Up @@ -89,6 +90,9 @@ void Router::handleMessage(omnetpp::cMessage* msg)
auto* properties = omnetpp::check_and_cast<RadioDriverProperties*>(msg);
auto addr = generateAddress(properties->LinkLayerAddress);
mRouter->set_address(addr);
Identity identity;
identity.geonet = addr;
emit(Identity::changeSignal, Identity::ChangeGeoNetAddress, &identity);
} else {
error("Do not know how to handle received message");
}
Expand Down Expand Up @@ -149,13 +153,14 @@ vanetza::geonet::Address Router::getAddress() const
return mRouter->get_local_position_vector().gn_addr;
}

vanetza::geonet::Address Router::generateAddress()
vanetza::geonet::Address Router::generateAddress(const vanetza::MacAddress& mac)
{
vanetza::geonet::Address gnAddr;
gnAddr.is_manually_configured(true);
// VehicleMiddleware determines station type during initialisation
gnAddr.station_type(mMiddleware->getStationType());
gnAddr.country_code(0);
gnAddr.mid(mRadioDriver->getMacAddress());
gnAddr.mid(mac);
return gnAddr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/artery/networking/Router.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Router : public omnetpp::cSimpleModule, public omnetpp::cListener

protected:
virtual void initializeManagementInformationBase(vanetza::geonet::ManagementInformationBase&);
vanetza::geonet::Address generateAddress();
vanetza::geonet::Address generateAddress(const vanetza::MacAddress&);

private:
vanetza::geonet::ManagementInformationBase mMIB;
Expand Down
2 changes: 2 additions & 0 deletions src/artery/networking/Router.ned
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ simple Router
{
parameters:
@class(Router);
@signal[IdentityChanged](type=long);

string dccModule;
string middlewareModule;
string radioDriverModule;
Expand Down
42 changes: 42 additions & 0 deletions src/artery/utility/Identity.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Artery V2X Simulation Framework
* Copyright 2019 Raphael Riebl
* Licensed under GPLv2, see COPYING file for detailed license and warranty terms.
*/

#include "artery/utility/Identity.h"
#include <omnetpp/regmacros.h>

namespace artery
{

// Identity has no source file yet
Register_Class(Identity)

using namespace omnetpp;

const simsignal_t Identity::changeSignal = cComponent::registerSignal("IdentityChanged");

bool Identity::update(const Identity& update, long changes)
{
bool changed = false;

if (changes & ChangeTraCI) {
traci = update.traci;
changed = true;
}

if (changes & ChangeStationId) {
application = update.application;
changed = true;
}

if (changes & ChangeGeoNetAddress) {
geonet = update.geonet;
changed = true;
}

return changed;
}

} // namespace artery
12 changes: 11 additions & 1 deletion src/artery/utility/Identity.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ namespace artery
class Identity : public omnetpp::cObject
{
public:
omnetpp::cModule* host = nullptr; /*< host module, e.g. Car node */
static const omnetpp::simsignal_t changeSignal;
enum Changes {
ChangeNone = 0,
ChangeTraCI = 1,
ChangeStationId = 2,
ChangeGeoNetAddress = 4
};

bool update(const Identity&, long changes);

omnetpp::cModule* host = nullptr; /*< host module, e.g. vehicle node */
std::string traci; /*< Vehicle ID used by TraCI protocol */
uint32_t application = 0; /*< ETSI station ID */
vanetza::geonet::Address geonet; /*< GeoNetworking layer */
Expand Down
7 changes: 2 additions & 5 deletions src/artery/utility/IdentityRegistry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
namespace artery
{

// Identity has no source file yet
Register_Class(Identity)

Define_Module(IdentityRegistry)

using namespace omnetpp;

const simsignal_t IdentityRegistry::updateSignal = cComponent::registerSignal("Identity.update");
const simsignal_t IdentityRegistry::removeSignal = cComponent::registerSignal("Identity.remove");
const simsignal_t IdentityRegistry::updateSignal = cComponent::registerSignal("IdentityUpdated");
const simsignal_t IdentityRegistry::removeSignal = cComponent::registerSignal("IdentityRemoved");

void IdentityRegistry::initialize()
{
Expand Down

0 comments on commit cff6d7c

Please sign in to comment.