Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions src/libemane/frameworkphy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#include "tworaypropagationmodelalgorithm.h"
#include "precomputedpropagationmodelalgorithm.h"

#include <dlfcn.h>
#include <iterator>

namespace
Expand Down Expand Up @@ -264,10 +265,11 @@ void EMANE::FrameworkPHY::initialize(Registrar & registrar)
EMANE::ConfigurationProperties::DEFAULT,
{"precomputed"},
"Defines the pathloss mode of operation:"
" precomputed, 2ray or freespace.",
" precomputed, 2ray or freespace are built-in."
" Any other value loads"
" libpropagationmodel<name>.so as a plugin.",
1,
1,
"^(precomputed|2ray|freespace)$");
1);

configRegistrar.registerNumeric<double>("systemnoisefigure",
EMANE::ConfigurationProperties::DEFAULT,
Expand Down Expand Up @@ -458,7 +460,6 @@ void EMANE::FrameworkPHY::configure(const ConfigurationUpdate & update)
{
std::string sPropagationModel{item.second[0].asString()};

// regex has already validated values
if(sPropagationModel == "precomputed")
{
pPropagationModelAlgorithm_.reset(new PrecomputedPropagationModelAlgorithm{id_});
Expand All @@ -467,10 +468,41 @@ void EMANE::FrameworkPHY::configure(const ConfigurationUpdate & update)
{
pPropagationModelAlgorithm_.reset(new TwoRayPropagationModelAlgorithm{id_});
}
else
else if(sPropagationModel == "freespace")
{
pPropagationModelAlgorithm_.reset(new FreeSpacePropagationModelAlgorithm{id_});
}
else
{
// load propagation model plugin: libpropagationmodel<name>.so
std::string sLibName{"libpropagationmodel" + sPropagationModel + ".so"};

void * pHandle = dlopen(sLibName.c_str(), RTLD_NOW);

if(!pHandle)
{
throw makeException<ConfigureException>(
"Failed to load propagation model plugin %s: %s",
sLibName.c_str(),
dlerror());
}

using CreateFunc =
PropagationModelAlgorithm * (*)(NEMId, const ConfigurationUpdate &);

auto createFunc =
reinterpret_cast<CreateFunc>(dlsym(pHandle, "createPropagationModel"));

if(!createFunc)
{
dlclose(pHandle);
throw makeException<ConfigureException>(
"Propagation model plugin %s missing createPropagationModel symbol",
sLibName.c_str());
}

pPropagationModelAlgorithm_.reset(createFunc(id_, update));
}

LOGGER_STANDARD_LOGGING(pPlatformService_->logService(),
INFO_LEVEL,
Expand Down
2 changes: 2 additions & 0 deletions src/libemane/propagationmodelalgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

namespace EMANE
{
class LocationInfo;

class PropagationModelAlgorithm
{
public:
Expand Down