Skip to content

Commit

Permalink
Merge pull request #1669 from FIWARE/dds/ddsModule
Browse files Browse the repository at this point in the history
Remake for new ddsModule (dds enabler)
  • Loading branch information
kzangeli authored Sep 16, 2024
2 parents 944395b + e03fe94 commit 9b86833
Show file tree
Hide file tree
Showing 53 changed files with 603 additions and 85 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ add_definitions(-DLM_ON)
add_definitions(-DORIONLD)

add_definitions(-fPIC)
add_definitions(-std=c++11)
add_definitions(-std=c++17)
add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)

# Baseline compiler flags, any change here will affect all build types
Expand Down Expand Up @@ -273,9 +273,10 @@ SET (COMMON_STATIC_LIBS
)

SET (DYNAMIC_LIBS
fastrtps
fastdds
fastcdr
foonathan_memory-0.7.3
ddsenabler
tinyxml2
prom
promhttp
Expand Down Expand Up @@ -409,7 +410,7 @@ if (error EQUAL 0)
ADD_SUBDIRECTORY(src/lib/metricsMgr)
ADD_SUBDIRECTORY(src/lib/logSummary)
ADD_SUBDIRECTORY(src/app/orionld)
ADD_SUBDIRECTORY(test/functionalTest/ftClient)
# ADD_SUBDIRECTORY(test/functionalTest/ftClient)
else ()
MESSAGE("cmake: NOT OK")
endif (error EQUAL 0)
29 changes: 28 additions & 1 deletion docker/build-ubi/04.install-fastdds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ dnf config-manager --set-enabled powertools
yum -y install tinyxml2-devel boost-devel yaml-cpp yaml-cpp-devel
yum -y --nogpgcheck install https://dl.fedoraproject.org/pub/fedora/linux/releases/39/Everything/x86_64/os/Packages/a/asio-devel-1.28.1-2.fc39.x86_64.rpm


# Fast-DDS
mkdir /opt/Fast-DDS

Expand Down Expand Up @@ -122,3 +121,31 @@ mkdir build
cd build
cmake ..
cmake --build . --target install


#
# DDS Enabler
#
cd /opt/Fast-DDS
git clone https://github.com/eProsima/FIWARE-DDS-Enabler.git
cd FIWARE-DDS-Enabler

yum -y install lz4-devel libzstd-devel

mkdir -p build/ddsenabler_participants
cd build/ddsenabler_participants
cmake ../../ddsenabler_participants
cmake --build . --target install
cd ../..

mkdir -p build/ddsenabler_yaml
cd build/ddsenabler_yaml
cmake ../../ddsenabler_yaml
cmake --build . --target install
cd ../..

mkdir -p build/ddsenabler
cd build/ddsenabler
cmake ../../ddsenabler
cmake --build . --target install
cd ../..
8 changes: 5 additions & 3 deletions src/app/orionld/orionld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ bool ddsSupport = false;
char ddsSubsTopics[512];
char ddsTopicType[512];
char ddsConfigFile[512];
char ddsEnablerConfigFile[512];



Expand Down Expand Up @@ -351,6 +352,7 @@ char ddsConfigFile[512];
#define DDS_SUBS_TOPICS_DESC "topics to subscribe to on DDS"
#define DDS_TOPIC_TYPE_DESC "DDS topic type"
#define DDS_CONFIG_FILE_DESC "DDS configuration file"
#define DDS_ENABLER_CONFIG_FILE_DESC "DDS Enabler configuration file"



Expand All @@ -362,7 +364,6 @@ char ddsConfigFile[512];



#define DDS_CONF_FILE "src/app/orionld/.ddsConfig"
/* ****************************************************************************
*
* paArgs - option vector for the Parse CLI arguments library
Expand Down Expand Up @@ -460,7 +461,8 @@ PaArgument paArgs[] =
{ "-dds", &ddsSupport, "DDS", PaBool, PaOpt, false, false, true, USE_DDS_DESC },
{ "-ddsSubsTopics", ddsSubsTopics, "DDS_SUBS_TOPICS", PaString, PaOpt, _i "", PaNL, PaNL, DDS_SUBS_TOPICS_DESC },
{ "-ddsTopicType", ddsTopicType, "DDS_TOPIC_TYPE", PaString, PaOpt, _i "NGSI-LD", PaNL, PaNL, DDS_TOPIC_TYPE_DESC },
{ "-ddsConfigFile", ddsConfigFile, "DDS_CONFIG_FILE", PaString, PaOpt, _i DDS_CONF_FILE, PaNL, PaNL, DDS_CONFIG_FILE_DESC },
{ "-ddsConfigFile", ddsConfigFile, "DDS_CONFIG_FILE", PaString, PaOpt, _i "", PaNL, PaNL, DDS_CONFIG_FILE_DESC },
{ "-ddsEnablerConfigFile", ddsEnablerConfigFile, "DDS_CONFIG_FILE_PATH", PaString, PaOpt, _i "", PaNL, PaNL, DDS_ENABLER_CONFIG_FILE_DESC },

PA_END_OF_ARGS
};
Expand Down Expand Up @@ -1428,7 +1430,7 @@ int main(int argC, char* argV[])
pernotLoopStart();

if (ddsSupport == true)
ddsInit(kjsonP, ddsConfigFile, ddsTopicType, ddsSubsTopics, DDSOpModeDefault);
ddsInit(kjsonP, DDSOpModeDefault);

if (socketService == true)
{
Expand Down
14 changes: 11 additions & 3 deletions src/lib/orionld/common/orionldState.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,23 @@ extern EntityMap* entityMaps; // Used by GET /entities in t
extern bool entityMapsEnabled; // Enable Entity Maps
extern bool distSubsEnabled; // Enable distributed subscriptions
extern bool noArrayReduction; // Used by arrayReduce in pCheckAttribute.cpp
extern bool ddsSupport; // Publish/Subscriba via DDS
extern char ddsTopicType[512];

extern char localIpAndPort[135]; // Local address for X-Forwarded-For (from orionld.cpp)
extern unsigned long long inReqPayloadMaxSize;
extern unsigned long long outReqMsgMaxSize;



// -----------------------------------------------------------------------------
//
// CLI params for DDS
//
extern bool ddsSupport; // Publish/Subscriba via DDS
extern char ddsTopicType[512];
extern char ddsConfigFile[512];
extern char ddsEnablerConfigFile[512];



// -----------------------------------------------------------------------------
//
// Global variables for Prometheus
Expand Down
14 changes: 1 addition & 13 deletions src/lib/orionld/dds/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,9 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

SET (SOURCES
NgsildEntity.cxx
NgsildEntityPubSubTypes.cxx
NgsildPublisher.cpp
NgsildSubscriber.cpp
DdsNotificationReceiver.cpp
DdsNotificationSender.cpp
ddsSubscribe.cpp
ddsPublish.cpp
ddsNotification.cpp
ddsInit.cpp
kjTreeLog.cpp
ddsConfigTopicToAttribute.cpp
ddsConfigLoad.cpp
ddsEntityCreateFromAttribute.cpp
ddsAttributeCreate.cpp
kjTreeLog.cpp
)

# Include directories
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
129 changes: 129 additions & 0 deletions src/lib/orionld/dds/archived/ddsInit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
*
* Copyright 2024 FIWARE Foundation e.V.
*
* This file is part of Orion-LD Context Broker.
*
* Orion-LD Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion-LD Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* orionld at fiware dot org
*
* Author: Ken Zangelin
*/
#include <unistd.h> // access

extern "C"
{
#include "ktrace/kTrace.h" // trace messages - ktrace library
#include "kbase/kStringSplit.h" // kStringSplit
#include "kjson/kjson.h" // Kjson
#include "kjson/KjNode.h" // KjNode
}

#include "orionld/common/traceLevels.h" // kjTreeLog2
#include "orionld/kjTree/kjNavigate.h" // kjNavigate
#include "orionld/dds/ddsSubscribe.h" // ddsSubscribe
#include "orionld/dds/ddsNotification.h" // ddsNotification
#include "orionld/dds/ddsConfigLoad.h" // ddsConfigLoad
#include "orionld/dds/ddsConfigTopicToAttribute.h" // ddsConfigTopicToAttribute - TMP: debugging
#include "orionld/dds/kjTreeLog.h" // kjTreeLog2
#include "orionld/dds/ddsInit.h" // Own interface



// -----------------------------------------------------------------------------
//
// ddsOpMode -
//
DdsOperationMode ddsOpMode;



// -----------------------------------------------------------------------------
//
// ddsInit - initialization function for DDS
//
// PARAMETERS
// * ddsTopicType
// * ddsSubsTopics
// * mode - the DDS mode the broker is working in
//
int ddsInit(Kjson* kjP, const char* ddsConfigFile, const char* ddsTopicType, char* ddsSubsTopics, DdsOperationMode _ddsOpMode)
{
ddsOpMode = _ddsOpMode; // Not yet in use ... invent usage or remove !

//
// DDS Configuration File
//
errno = 0;
if (access(ddsConfigFile, R_OK) == 0)
{
if (ddsConfigLoad(kjP, ddsConfigFile) != 0)
KT_X(1, "Error reading/parsing the DDS config file '%s'", ddsConfigFile);

#ifdef DEBUG
extern KjNode* ddsConfigTree;
kjTreeLog2(ddsConfigTree, "DDS Config", StDdsConfig);
KT_T(StDdsConfig, "Topics:");
const char* path[3] = { "dds", "topics", NULL };
KjNode* topics = kjNavigate(ddsConfigTree, path , NULL, NULL);

if (topics != NULL)
{
for (KjNode* topicP = topics->value.firstChildP; topicP != NULL; topicP = topicP->next)
{
char* entityId = (char*) "N/A";
char* entityType = (char*) "N/A";
char* attribute = ddsConfigTopicToAttribute(topicP->name, &entityId, &entityType);

KT_T(StDdsConfig, "Topic: '%s':", topicP->name);
KT_T(StDdsConfig, " Attribute: '%s'", attribute);
KT_T(StDdsConfig, " Entity ID: '%s'", entityId);
KT_T(StDdsConfig, " Entity Type: '%s'", entityType);
}
}
#endif
}
// else
// KT_X(1, ("Unable to read the DDS config file '%s' (%s)", ddsConfigFile, strerror(errno));


//
// DDS Subscriptions
//
// For now, the topics to subscribe to is input to the broker, as a CLI parameter with
// the topics as a comma-separated list.
// This is temporary, just to be able to test things.
//
// I imagine in the end, all DDS topics will be found via dicovery and the broker will
// subscribe to all of them. Or, perhaps some filter. We'll see.
// For now, just a CSV.
//
if (ddsSubsTopics[0] == 0)
return 0;

KT_V("topics: %s", ddsSubsTopics);
char* topicV[100];
int topics = kStringSplit(ddsSubsTopics, ',', topicV, 3);

KT_V("no of topics: %d", topics);
for (int ix = 0; ix < topics; ix++)
{
KT_V("Subscribing to DDS topic %s::%s", ddsTopicType, topicV[ix]);
ddsSubscribe(ddsTopicType, topicV[ix], ddsNotification);
}

return 0;
}
51 changes: 51 additions & 0 deletions src/lib/orionld/dds/archived/ddsInit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef SRC_LIB_ORIONLD_DDS_DDSINIT_H_
#define SRC_LIB_ORIONLD_DDS_DDSINIT_H_

/*
*
* Copyright 2024 FIWARE Foundation e.V.
*
* This file is part of Orion-LD Context Broker.
*
* Orion-LD Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion-LD Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* orionld at fiware dot org
*
* Author: Ken Zangelin
*/
extern "C"
{
#include "kjson/kjson.h" // Kjson
}



// -----------------------------------------------------------------------------
//
// DdsOperationMode -
//
typedef enum DdsOperationMode
{
DDSOpModeDefault
} DdsOperationMode;


// -----------------------------------------------------------------------------
//
// ddsInit -
//
extern int ddsInit(Kjson* kjP, const char* ddsConfigFile, const char* ddsTopicType, char* ddsSubsTopics, DdsOperationMode ddsOpMode);

#endif // SRC_LIB_ORIONLD_DDS_DDSINIT_H_
Loading

0 comments on commit 9b86833

Please sign in to comment.