Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dds/config file #1693

Merged
merged 7 commits into from
Oct 14, 2024
Merged
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
1 change: 0 additions & 1 deletion docker/build-ubi/04.install-fastdds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ yum -y --nogpgcheck install https://dl.fedoraproject.org/pub/fedora/linux/releas
# Fast-DDS
mkdir /opt/Fast-DDS


#
# foonathan_memory_vendor
#
Expand Down
86 changes: 86 additions & 0 deletions scripts/configFile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

# Copyright 2021 Telefonica Investigacion y Desarrollo, S.A.U
#
# This file is part of Orion Context Broker.
#
# Orion 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 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 Context Broker. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# iot_support at tid dot es

echo '{'
echo ' "dds": {'
echo ' "ddsmodule": {'
echo ' "dds": {'
echo ' "domain": 0,'
echo ' "allowlist": ['
echo ' {'
echo ' "name": "*"'
echo ' }'
echo ' ],'
echo ' "blocklist": ['
echo ' {'
echo ' "name": "add_blocked_topics_list_here"'
echo ' }'
echo ' ]'
echo ' },'
echo ' "topics": {'
echo ' "name": "*",'
echo ' "qos": {'
echo ' "durability": "TRANSIENT_LOCAL",'
echo ' "history-depth": 10'
echo ' }'
echo ' },'
echo ' "ddsenabler": null,'
echo ' "specs": {'
echo ' "threads": 12,'
echo ' "logging": {'
echo ' "stdout": false,'
echo ' "verbosity": "info"'
echo ' }'
echo ' }'
echo ' },'
echo ' "ngsild": {'
echo ' "topics": {'

while [ $# != 0 ]
do
items=$1
shift

topic=$(echo $items | awk -F, '{ print $1 }')
eType=$(echo $items | awk -F, '{ print $2 }')
eId=$(echo $items | awk -F, '{ print $3 }')
attr=$(echo $items | awk -F, '{ print $4 }')

if [ $# != 0 ]
then
comma=','
else
comma=''
fi

echo ' "'$topic'": {'
echo ' "entityType": "'$eType'",'
echo ' "entityId": "'$eId'",'
echo ' "attribute": "'$attr'"'
echo ' }'$comma
done


echo ' }'
echo ' }'
echo ' }'
echo '}'
33 changes: 22 additions & 11 deletions src/app/orionld/orionld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* CLI option '--insecure'.
*/
#include <stdio.h>
#include <unistd.h> // getppid, fork, setuid, sleep, gethostname, etc.
#include <unistd.h> // getppid, fork, setuid, sleep, gethostname, access, etc.
#include <string.h> // strchr
#include <fcntl.h> // open
#include <sys/types.h>
Expand Down Expand Up @@ -254,11 +254,9 @@ char defaultUserContextUrl[256];
bool ddsSupport = false;
char ddsSubsTopics[512];
char ddsTopicType[512];
char ddsConfigFile[512];
char ddsEnablerConfigFile[512];
char configFile[512];


#define DDSE_CONF_FILE "/tmp/DDS_ENABLER_CONFIGURATION.yaml"

/* ****************************************************************************
*
Expand Down Expand Up @@ -354,8 +352,7 @@ char ddsEnablerConfigFile[512];
#define USE_DDS_DESC "turn on DDS support"
#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"
#define CONFIG_FILE_DESC "Path to configuration file"
#define SUBORDINATE_ENDPOINT_DESC "endpoint URL for reception of notificatiopns from subordinate subscriptions (distributed subscriptions)"
#define PAGE_SIZE_DESC "default page size (no of entities, subscriptions, registrations)"
#define DUC_URL_DESC "URL to default user context"
Expand Down Expand Up @@ -466,11 +463,10 @@ PaArgument paArgs[] =
{ "-subordinateEndpoint", &subordinateEndpoint, "SUBORDINATE_ENDPOINT", PaStr, PaOpt, _i "", PaNL, PaNL, SUBORDINATE_ENDPOINT_DESC },
{ "-pageSize", &pageSize, "PAGE_SIZE", PaInt, PaOpt, 20, 1, 1000, PAGE_SIZE_DESC },
{ "-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 "", PaNL, PaNL, DDS_CONFIG_FILE_DESC },
{ "-ddsEnablerConfigFile", ddsEnablerConfigFile, "DDS_CONFIG_FILE_PATH", PaString, PaOpt, _i DDSE_CONF_FILE, PaNL, PaNL, DDS_ENABLER_CONFIG_FILE_DESC },
{ "-duc", defaultUserContextUrl, "DUC_URL", PaString, PaOpt, _i "", PaNL, PaNL, DUC_URL_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 },
{ "-configFile", configFile, "CONFIG_FILE", PaString, PaOpt, _i "", PaNL, PaNL, CONFIG_FILE_DESC },
{ "-duc", defaultUserContextUrl, "DUC_URL", PaString, PaOpt, _i "", PaNL, PaNL, DUC_URL_DESC },

PA_END_OF_ARGS
};
Expand Down Expand Up @@ -1075,6 +1071,21 @@ int main(int argC, char* argV[])

paParse(paArgs, argC, (char**) argV, 1, false);

//
// Config file
//
configFileP = configFile;
if (configFile[0] == 0)
{
char* home = getenv("HOME");

if (home != NULL)
{
snprintf(configFile, sizeof(configFile) - 1, "%s/.orionld", home);
if (access(configFile, R_OK) != 0)
configFileP = NULL;
}
}

//
// Initializing the new logging library, kTrace
Expand Down
1 change: 1 addition & 0 deletions src/lib/orionld/common/orionldState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Kjson kjson;
Kjson* kjsonP;
uint16_t portNo = 0;
int dbNameLen;
char* configFileP = NULL;
char* coreContextUrl = (char*) ORIONLD_CORE_CONTEXT_URL_DEFAULT; // v1.6, see orionld/context/orionldCoreContext.h
char orionldHostName[128];
int orionldHostNameLen = -1;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/orionld/common/orionldState.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ extern __thread OrionldConnectionState orionldState;
//
// Global state
//
extern char configFile[512];
extern char* configFileP;
extern char* coreContextUrl;
extern const char* builtinCoreContext;
extern char orionldHostName[128];
Expand Down Expand Up @@ -638,8 +640,6 @@ extern unsigned long long outReqMsgMaxSize;
//
extern bool ddsSupport; // Publish/Subscriba via DDS
extern char ddsTopicType[512];
extern char ddsConfigFile[512];
extern char ddsEnablerConfigFile[512];



Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/dds/ddsConfigTopicToAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ char* ddsConfigTopicToAttribute(const char* topic, char** entityIdPP, char** ent
if (ddsConfigTree == NULL)
return NULL; // No error - it's OK to not have a DDS Config File

const char* path[3] = { "dds", "topics", NULL };
const char* path[4] = { "dds", "ngsild", "topics", NULL };
static KjNode* topicsP = kjNavigate(ddsConfigTree, path, NULL, NULL);
KjNode* topicP = kjLookup(topicsP, topic);

Expand Down
48 changes: 23 additions & 25 deletions src/lib/orionld/dds/ddsInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern "C"
}

#include "orionld/common/traceLevels.h" // kjTreeLog2
#include "orionld/common/orionldState.h" // ddsEnablerConfigFile, ddsConfigFile
#include "orionld/common/orionldState.h" // configFile
#include "orionld/kjTree/kjNavigate.h" // kjNavigate
#include "orionld/dds/ddsConfigTopicToAttribute.h" // ddsConfigTopicToAttribute - for debugging only
#include "orionld/dds/ddsCategoryToKlogSeverity.h" // ddsCategoryToKlogSeverity
Expand Down Expand Up @@ -97,37 +97,35 @@ int ddsInit(Kjson* kjP, DdsOperationMode _ddsOpMode)
// DDS Configuration File
//
errno = 0;
if ((ddsConfigFile[0] != 0) && (access(ddsConfigFile, R_OK) == 0))
{
if (ddsConfigLoad(kjP, ddsConfigFile) != 0)
KT_X(1, "Error reading/parsing the DDS config file '%s'", ddsConfigFile);
if (ddsConfigLoad(kjP, configFileP) != 0)
KT_X(1, "Error reading/parsing the DDS config file '%s'", configFile);

#if 0
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);
extern KjNode* ddsConfigTree;
kjTreeLog2(ddsConfigTree, "DDS Config", StDdsConfig);
KT_T(StDdsConfig, "Topics:");
const char* path[4] = { "dds", "ngsild", "topics", NULL };
KjNode* topics = kjNavigate(ddsConfigTree, path , NULL, NULL);

if (topics != NULL)
if (topics != NULL)
{
for (KjNode* topicP = topics->value.firstChildP; topicP != NULL; topicP = topicP->next)
{
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);
}
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
}
#endif

KT_T(StDds, "Calling init_dds_enabler('%s')", ddsEnablerConfigFile);
eprosima::ddsenabler::init_dds_enabler(ddsEnablerConfigFile, ddsNotification, ddsTypeNotification, ddsLog);
KT_T(StDds, "Calling init_dds_enabler('%s')", configFile);
if (eprosima::ddsenabler::init_dds_enabler(configFile, ddsNotification, ddsTypeNotification, ddsLog) != 0)
KT_X(1, "Unable to initialize the DDS Enabler");

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,12 @@ Usage: orionld [option '-U' (extended usage)]
[option '-cSubCounters' <number of subscription counter updates before flush from sub-cache to DB (0: never, 1: always)>]
[option '-distributed' (turn on distributed operation)]
[option '-brokerId' <identity of this broker instance for registrations - for the Via header>]
[option '-subordinateEndpoint' <endpoint URL for reception of notificatiopns from subordinate subscriptions (distributed subscriptions)>]
[option '-pageSize' <default page size (no of entities, subscriptions, registrations)>]
[option '-dds' (turn on DDS support)]
[option '-ddsSubsTopics' <topics to subscribe to on DDS>]
[option '-ddsTopicType' <DDS topic type>]
[option '-ddsConfigFile' <DDS configuration file>]
[option '-ddsEnablerConfigFile' <DDS Enabler configuration file>]
[option '-subordinateEndpoint' <endpoint URL for reception of notificatiopns from subordinate subscriptions (distributed subscriptions)>]
[option '-pageSize' <default page size (no of entities, subscriptions, registrations)>]
[option '-configFile' <Path to configuration file>]
[option '-duc' <URL to default user context>]

--TEARDOWN--
7 changes: 3 additions & 4 deletions test/functionalTest/cases/0000_cli/command_line_options.test
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ Usage: orionld [option '-U' (extended usage)]
[option '-cSubCounters' <number of subscription counter updates before flush from sub-cache to DB (0: never, 1: always)>]
[option '-distributed' (turn on distributed operation)]
[option '-brokerId' <identity of this broker instance for registrations - for the Via header>]
[option '-subordinateEndpoint' <endpoint URL for reception of notificatiopns from subordinate subscriptions (distributed subscriptions)>]
[option '-pageSize' <default page size (no of entities, subscriptions, registrations)>]
[option '-dds' (turn on DDS support)]
[option '-ddsSubsTopics' <topics to subscribe to on DDS>]
[option '-ddsTopicType' <DDS topic type>]
[option '-ddsConfigFile' <DDS configuration file>]
[option '-ddsEnablerConfigFile' <DDS Enabler configuration file>]
[option '-subordinateEndpoint' <endpoint URL for reception of notificatiopns from subordinate subscriptions (distributed subscriptions)>]
[option '-pageSize' <default page size (no of entities, subscriptions, registrations)>]
[option '-configFile' <Path to configuration file>]
[option '-duc' <URL to default user context>]

--TEARDOWN--
21 changes: 3 additions & 18 deletions test/functionalTest/cases/0000_dds/dds_notifications.test
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,10 @@
the test client publishes on DDS, the broker receives DDS notifications and creates/updates the corresponding NGSI-LD entities

--SHELL-INIT--
echo '{
"dds": {
"topics": {
"P1": {
"entityId": "urn:ngsi-ld:camera:cam1",
"entityType": "Camera",
"attribute": "shutterSpeed"
},
"P2": {
"entityId": "urn:ngsi-ld:arm:arm1",
"entityType": "Arm",
"attribute": "armReach"
}
}
}
}' > /tmp/ddsConfig

$REPO_HOME/scripts/configFile.sh "P1,Camera,urn:ngsi-ld:camera:cam1,shutterSpeed" "P2,Arm,urn:ngsi-ld:arm:arm1,armReach" > $HOME/.orionld
$REPO_HOME/scripts/configFile.sh "P1,Camera,urn:ngsi-ld:camera:cam1,shutterSpeed" "P2,Arm,urn:ngsi-ld:arm:arm1,armReach" > $HOME/.ftClient
dbInit CB
orionldStart CB -mongocOnly -dds -ddsConfigFile /tmp/ddsConfig
orionldStart CB -mongocOnly -dds
ftClientStart -t 0-5000

--SHELL--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Test of orionld version service, with branch name
--SHELL-INIT--
dbInit CB
orionldStart CB -mongocOnly
$REPO_HOME/scripts/configFile.sh > ~/.ftClient
chmod 777 ~/.ftClient

ftClientStart -v -t 200
mkdir -p /tmp/orion/logs/ftClient2
ftClientStart -v -t 200 --port $FT2_PORT --logDir $FT2_LOG_DIR
Expand Down
Loading
Loading