From 6d03d77e2110c880c63c8716385d2b936ccc4b78 Mon Sep 17 00:00:00 2001 From: Alex Stancu Date: Mon, 10 May 2021 19:35:52 +0300 Subject: [PATCH] Add blank type of NTS. Add a type of simulated NF which is blank and waiting for YANG models to be uploaded and installed at runtime. Issue-ID: SIM-68 Change-Id: I2f9b234222563e27afadbb6bf6032288786bfdb7 Signed-off-by: Alex Stancu --- ntsimulator/.env | 10 +- ntsimulator/deploy/base/build_ntsim-ng.sh | 1 + ntsimulator/deploy/base/ubuntu.Dockerfile | 12 +- ntsimulator/deploy/blank/Dockerfile | 42 ++++++ ntsimulator/deploy/blank/config.json | 9 ++ ntsimulator/deploy/blank/container-tag.yaml | 2 + ntsimulator/deploy/blank/local.Dockerfile | 42 ++++++ ntsimulator/deploy/nts-manager/Dockerfile | 4 + ntsimulator/deploy/nts-manager/config.json | 8 -- ntsimulator/deploy/nts-manager/container-tag.yaml | 2 +- ntsimulator/deploy/o-ran-du/container-tag.yaml | 2 +- ntsimulator/deploy/o-ran-ru-fh/config.json | 80 ++++------- ntsimulator/deploy/o-ran-ru-fh/container-tag.yaml | 2 +- .../data/ietf-interfaces-operational.xml | 151 +++++++++++++++++++++ .../o-ran-ru-fh/data/ietf-interfaces-running.xml | 111 +++++++++++++++ ntsimulator/deploy/o-ran/container-tag.yaml | 2 +- ntsimulator/deploy/x-ran/config.json | 8 -- ntsimulator/deploy/x-ran/container-tag.yaml | 2 +- ntsimulator/docker-compose.yaml | 35 ++--- ntsimulator/nts-ng-docker-image-build-ubuntu.yaml | 11 ++ ntsimulator/ntsim-ng/core/app/blank.c | 149 ++++++++++++++++++++ ntsimulator/ntsim-ng/core/app/blank.h | 20 +++ ntsimulator/ntsim-ng/core/app/network_function.c | 1 - ntsimulator/ntsim-ng/core/app/supervisor.c | 50 ++++++- ntsimulator/ntsim-ng/core/app/supervisor.h | 2 +- ntsimulator/ntsim-ng/core/framework.c | 122 +++++++++++++++-- ntsimulator/ntsim-ng/core/framework.h | 1 + .../features/ves_file_ready/ves_file_ready.c | 16 +-- ntsimulator/ntsim-ng/main.c | 14 +- ntsimulator/ntsim-ng/utils/rand_utils.c | 6 +- ntsimulator/ntsim-ng/utils/sys_utils.c | 16 +++ ntsimulator/ntsim-ng/utils/sys_utils.h | 5 + 32 files changed, 812 insertions(+), 126 deletions(-) create mode 100644 ntsimulator/deploy/blank/Dockerfile create mode 100644 ntsimulator/deploy/blank/config.json create mode 100644 ntsimulator/deploy/blank/container-tag.yaml create mode 100644 ntsimulator/deploy/blank/local.Dockerfile create mode 100644 ntsimulator/deploy/o-ran-ru-fh/data/ietf-interfaces-operational.xml create mode 100644 ntsimulator/deploy/o-ran-ru-fh/data/ietf-interfaces-running.xml create mode 100644 ntsimulator/ntsim-ng/core/app/blank.c create mode 100644 ntsimulator/ntsim-ng/core/app/blank.h diff --git a/ntsimulator/.env b/ntsimulator/.env index d06eb28..40a1525 100644 --- a/ntsimulator/.env +++ b/ntsimulator/.env @@ -1,11 +1,11 @@ -DOCKER_REPO=nexus3.o-ran-sc.org:10004/o-ran-sc/ +DOCKER_REPO=o-ran-sc/ NTS_MANAGER_PORT=8300 -NTS_BUILD_VERSION=1.2.3 +NTS_BUILD_VERSION=1.3.0 IPv6_ENABLED=false SSH_CONNECTIONS=1 TLS_CONNECTIONS=0 -NTS_HOST_IP=10.20.11.136 +NTS_HOST_IP=10.20.11.121 NTS_HOST_BASE_PORT=50000 NTS_HOST_NETCONF_SSH_BASE_PORT=0 NTS_HOST_NETCONF_TLS_BASE_PORT=1000 @@ -13,7 +13,7 @@ NTS_HOST_TRANSFER_FTP_BASE_PORT=2000 NTS_HOST_TRANSFER_SFTP_BASE_PORT=2000 NTS_NF_MOUNT_POINT_ADDRESSING_METHOD=host-mapping -NTS_NF_STANDALONE_START_FEATURES="datastore-populate ves-heartbeat ves-file-ready ves-pnf-registration netconf-call-home web-cut-through" +NTS_NF_STANDALONE_START_FEATURES="datastore-populate ves-heartbeat ves-file-ready ves-pnf-registration web-cut-through" SDN_CONTROLLER_PROTOCOL=http SDN_CONTROLLER_IP=172.40.0.21 @@ -22,7 +22,7 @@ SDN_CONTROLLER_CALLHOME_PORT=6666 SDN_CONTROLLER_USERNAME=admin SDN_CONTROLLER_PASSWORD=admin -VES_COMMON_HEADER_VERSION=7.1 +VES_COMMON_HEADER_VERSION=7.2.1 VES_ENDPOINT_PROTOCOL=https VES_ENDPOINT_IP=172.40.0.90 VES_ENDPOINT_PORT=8443 diff --git a/ntsimulator/deploy/base/build_ntsim-ng.sh b/ntsimulator/deploy/base/build_ntsim-ng.sh index b64f071..fe7a367 100755 --- a/ntsimulator/deploy/base/build_ntsim-ng.sh +++ b/ntsimulator/deploy/base/build_ntsim-ng.sh @@ -33,6 +33,7 @@ files=( "core/app/manager_actions.c" "core/app/manager_sysrepo.c" "core/app/network_function.c" + "core/app/blank.c" "core/datastore/schema.c" "core/datastore/generate.c" "core/datastore/populate.c" diff --git a/ntsimulator/deploy/base/ubuntu.Dockerfile b/ntsimulator/deploy/base/ubuntu.Dockerfile index 69d69ce..be86b97 100644 --- a/ntsimulator/deploy/base/ubuntu.Dockerfile +++ b/ntsimulator/deploy/base/ubuntu.Dockerfile @@ -137,7 +137,9 @@ COPY ./deploy/base/build_ntsim-ng.sh /opt/dev/ntsim-ng/build_ntsim-ng.sh RUN \ cd /opt/dev/ntsim-ng && \ sed -i '/argp/d' build_ntsim-ng.sh && \ - ./build_ntsim-ng.sh + ./build_ntsim-ng.sh && \ + rm -rf source && \ + rm -f build_ntsim-ng.sh # copy SSH related scripts and keys COPY ./deploy/base/ca.key /home/netconf/.ssh/ca.key @@ -158,10 +160,11 @@ RUN apt-get update ARG BUILD_WITH_DEBUG ENV BUILD_WITH_DEBUG=${BUILD_WITH_DEBUG} -RUN if [ -n "${BUILD_WITH_DEBUG}" ]; then DEBIAN_FRONTEND="noninteractive" apt-get install -y gdb valgrind ; fi +RUN if [ -n "${BUILD_WITH_DEBUG}" ]; then DEBIAN_FRONTEND="noninteractive" apt-get install -y gdb valgrind nano mc ; fi RUN apt-get install -y --no-install-recommends \ psmisc \ + unzip \ openssl \ openssh-client \ vsftpd \ @@ -197,13 +200,14 @@ COPY --from=builder /opt/dev/ntsim-ng /opt/dev/ntsim-ng # copy SSH related scripts and keys COPY --from=builder /home/netconf/.ssh /home/netconf/.ssh -### FTP configuration +### FTP and SFTP configuration RUN \ mkdir /ftp && \ + chown -R netconf:netconf /ftp && \ mkdir /var/run/vsftpd && \ mkdir /var/run/vsftpd/empty && \ mkdir /run/sshd && \ - echo "Match User netconf\n ChrootDirectory /ftp\n X11Forwarding no\n AllowTcpForwarding no\n ForceCommand internal-sftp" >> /etc/ssh/sshd_config + echo "Match User netconf\n ChrootDirectory /\n X11Forwarding no\n AllowTcpForwarding no\n ForceCommand internal-sftp -d /ftp" >> /etc/ssh/sshd_config COPY ./deploy/base/vsftpd.conf /etc/vsftpd.conf COPY ./deploy/base/vsftpd.userlist /etc/vsftpd.userlist diff --git a/ntsimulator/deploy/blank/Dockerfile b/ntsimulator/deploy/blank/Dockerfile new file mode 100644 index 0000000..cb748c3 --- /dev/null +++ b/ntsimulator/deploy/blank/Dockerfile @@ -0,0 +1,42 @@ +# +# Copyright 2020 highstreet technologies GmbH and others +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +################ +#### DEVICE #### +################ + +FROM nexus3.o-ran-sc.org:10004/o-ran-sc/nts-ng-base:latest +LABEL maintainer="alexandru.stancu@highstreet-technologies.com / adrian.lita@highstreet-technologies.com" + +# ntsim-ng configuration and deployment +COPY ./config.json /opt/dev/ntsim-ng/config/config.json + +# init with bare data for network-function to work (blank image will wait for new YANG models to be installed) +RUN /opt/dev/ntsim-ng/ntsim-ng --container-init -w /opt/dev/ntsim-ng +RUN rm -rf /opt/dev/deploy + +# finishing container build +ARG BUILD_DATE +LABEL build-date=$BUILD_DATE + +# add exposed ports +EXPOSE 830-929 +EXPOSE 21-22 + +ENV NTS_FUNCTION_TYPE=NTS_FUNCTION_TYPE_BLANK + +# run +WORKDIR /opt/dev/workspace +CMD ["/opt/dev/ntsim-ng/ntsim-ng", "-w/opt/dev/ntsim-ng", "--supervisor"] diff --git a/ntsimulator/deploy/blank/config.json b/ntsimulator/deploy/blank/config.json new file mode 100644 index 0000000..305114b --- /dev/null +++ b/ntsimulator/deploy/blank/config.json @@ -0,0 +1,9 @@ +{ + "supervisor-rules": { + "ntsim-blank-network-function": { + "path": "/opt/dev/ntsim-ng/ntsim-ng", + "args": ["-w/opt/dev/ntsim-ng", "-b"], + "nomanual": true + } + } +} \ No newline at end of file diff --git a/ntsimulator/deploy/blank/container-tag.yaml b/ntsimulator/deploy/blank/container-tag.yaml new file mode 100644 index 0000000..0cd0ef4 --- /dev/null +++ b/ntsimulator/deploy/blank/container-tag.yaml @@ -0,0 +1,2 @@ +--- +tag: 1.3.0 \ No newline at end of file diff --git a/ntsimulator/deploy/blank/local.Dockerfile b/ntsimulator/deploy/blank/local.Dockerfile new file mode 100644 index 0000000..10837f4 --- /dev/null +++ b/ntsimulator/deploy/blank/local.Dockerfile @@ -0,0 +1,42 @@ +# +# Copyright 2020 highstreet technologies GmbH and others +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +################ +#### DEVICE #### +################ + +FROM o-ran-sc/nts-ng-base:latest +LABEL maintainer="alexandru.stancu@highstreet-technologies.com / adrian.lita@highstreet-technologies.com" + +# ntsim-ng configuration and deployment +COPY ./config.json /opt/dev/ntsim-ng/config/config.json + +# init with bare data for network-function to work (blank image will wait for new YANG models to be installed) +RUN /opt/dev/ntsim-ng/ntsim-ng --container-init -w /opt/dev/ntsim-ng +RUN rm -rf /opt/dev/deploy + +# finishing container build +ARG BUILD_DATE +LABEL build-date=$BUILD_DATE + +# add exposed ports +EXPOSE 830-929 +EXPOSE 21-22 + +ENV NTS_FUNCTION_TYPE=NTS_FUNCTION_TYPE_BLANK + +# run +WORKDIR /opt/dev/workspace +CMD ["/opt/dev/ntsim-ng/ntsim-ng", "-w/opt/dev/ntsim-ng", "--supervisor"] diff --git a/ntsimulator/deploy/nts-manager/Dockerfile b/ntsimulator/deploy/nts-manager/Dockerfile index 11790fb..ee0e0f1 100644 --- a/ntsimulator/deploy/nts-manager/Dockerfile +++ b/ntsimulator/deploy/nts-manager/Dockerfile @@ -27,6 +27,10 @@ COPY ./config.json /opt/dev/ntsim-ng/config/config.json # ntsim-ng init docker RUN /opt/dev/ntsim-ng/ntsim-ng --container-init -w /opt/dev/ntsim-ng +# finishing container build +ARG BUILD_DATE +LABEL build-date=$BUILD_DATE + # add exposed ports EXPOSE 830-929 EXPOSE 21-22 diff --git a/ntsimulator/deploy/nts-manager/config.json b/ntsimulator/deploy/nts-manager/config.json index f71c4f9..0c5c1e9 100644 --- a/ntsimulator/deploy/nts-manager/config.json +++ b/ntsimulator/deploy/nts-manager/config.json @@ -13,14 +13,6 @@ "stderr": "log/netopeer-stderr.log" }, - "sshd": { - "path": "/usr/sbin/sshd", - "args": ["-D"], - "autorestart": true, - "stdout": "log/sshd-stdout.log", - "stderr": "log/sshd-stderr.log" - }, - "ntsim-manager": { "path": "/opt/dev/ntsim-ng/ntsim-ng", "args": ["-w/opt/dev/ntsim-ng", "-m"], diff --git a/ntsimulator/deploy/nts-manager/container-tag.yaml b/ntsimulator/deploy/nts-manager/container-tag.yaml index ec29baf..0cd0ef4 100644 --- a/ntsimulator/deploy/nts-manager/container-tag.yaml +++ b/ntsimulator/deploy/nts-manager/container-tag.yaml @@ -1,2 +1,2 @@ --- -tag: 1.2.3 \ No newline at end of file +tag: 1.3.0 \ No newline at end of file diff --git a/ntsimulator/deploy/o-ran-du/container-tag.yaml b/ntsimulator/deploy/o-ran-du/container-tag.yaml index ec29baf..0cd0ef4 100644 --- a/ntsimulator/deploy/o-ran-du/container-tag.yaml +++ b/ntsimulator/deploy/o-ran-du/container-tag.yaml @@ -1,2 +1,2 @@ --- -tag: 1.2.3 \ No newline at end of file +tag: 1.3.0 \ No newline at end of file diff --git a/ntsimulator/deploy/o-ran-ru-fh/config.json b/ntsimulator/deploy/o-ran-ru-fh/config.json index 818320d..1934a03 100644 --- a/ntsimulator/deploy/o-ran-ru-fh/config.json +++ b/ntsimulator/deploy/o-ran-ru-fh/config.json @@ -70,93 +70,73 @@ "random-generation-enabled": true, "pre-generated-operational-data": [ - "../deploy/data/ietf-hardware-operational.json" + "../deploy/data/ietf-hardware-operational.json", + "../deploy/data/ietf-interfaces-operational.xml" ], "pre-generated-running-data": [ - "../deploy/data/ietf-hardware-running.json" + "../deploy/data/ietf-hardware-running.json", + "../deploy/data/ietf-interfaces-running.xml" ] }, "fault-rules" : { - "yang-notif-template" : "$$uint16_counter$$%%object%%%%affected-object%%%%fault-severity%%%%cleared%%%%text%%%%date-time%%", + "yang-notif-template" : "%%fault-id%%%%object%%%%affected-object%%%%fault-severity%%%%cleared%%%%text%%%%date-time%%", "choosing-method" : "linear", "faults" : [ { - "condition" : "CPRI Port Down", - "object" : "Slot-0-Port-A", + "condition" : "Interface Fault", + "object" : "interface-1", "severity" : "MAJOR", "date-time" : "$$time$$", - "specific-problem" : "CPRI Port Down", - - "fault-severity" : "MAJOR", - "affected-object" : "%%object%%", - "cleared" : "false", - "text" : "CPRI Port Down" - }, - - { - "condition" : "CPRI Port Down", - "object" : "Slot-0-Port-A", - "severity" : "NORMAL", - "date-time" : "$$time$$", - "specific-problem" : "CPRI Port Down", - - "fault-severity" : "MAJOR", - "affected-object" : "%%object%%", - "cleared" : "true", - "text" : "CPRI Port Down" - }, - - { - "condition" : "CPRI Port Down", - "object" : "Slot-0-Port-C", - "severity" : "MAJOR", - "date-time" : "$$time$$", - "specific-problem" : "CPRI Port Down", - + "specific-problem" : "Interface Fault", + + "fault-id": "30", "fault-severity" : "MAJOR", - "affected-object" : "%%object%%", + "affected-object" : "$$hostname$$", "cleared" : "false", - "text" : "CPRI Port Down" + "text" : "Interface Fault" }, { - "condition" : "CPRI Port Down", - "object" : "Slot-0-Port-C", + "condition" : "Interface Fault", + "object" : "interface-1", "severity" : "NORMAL", "date-time" : "$$time$$", - "specific-problem" : "CPRI Port Down", + "specific-problem" : "Interface Fault", + "fault-id": "30", "fault-severity" : "MAJOR", - "affected-object" : "%%object%%", + "affected-object" : "$$hostname$$", "cleared" : "true", - "text" : "CPRI Port Down" + "text" : "Interface Fault" }, { - "condition" : "CPRI Port Down", - "object" : "Slot-2-Port-B", + "condition" : "C/U-plane logical Connection faulty", + "object" : "interface-1", "severity" : "MAJOR", "date-time" : "$$time$$", - "specific-problem" : "CPRI Port Down", + "specific-problem" : "C/U-plane logical Connection faulty", + "fault-id": "28", "fault-severity" : "MAJOR", - "affected-object" : "%%object%%", + "affected-object" : "$$hostname$$", "cleared" : "false", - "text" : "CPRI Port Down" + "text" : "C/U-plane logical Connection faulty" }, { - "condition" : "CPRI Port Down", - "object" : "Slot-2-Port-B", + "condition" : "C/U-plane logical Connection faulty", + "object" : "interface-1", "severity" : "NORMAL", "date-time" : "$$time$$", - "specific-problem" : "CPRI Port Down", + "specific-problem" : "C/U-plane logical Connection faulty", + "fault-id": "28", "fault-severity" : "MAJOR", - "affected-object" : "%%object%%", + "affected-object" : "$$hostname$$", "cleared" : "true", - "text" : "CPRI Port Down" + "text" : "C/U-plane logical Connection faulty" } ] } diff --git a/ntsimulator/deploy/o-ran-ru-fh/container-tag.yaml b/ntsimulator/deploy/o-ran-ru-fh/container-tag.yaml index ec29baf..0cd0ef4 100644 --- a/ntsimulator/deploy/o-ran-ru-fh/container-tag.yaml +++ b/ntsimulator/deploy/o-ran-ru-fh/container-tag.yaml @@ -1,2 +1,2 @@ --- -tag: 1.2.3 \ No newline at end of file +tag: 1.3.0 \ No newline at end of file diff --git a/ntsimulator/deploy/o-ran-ru-fh/data/ietf-interfaces-operational.xml b/ntsimulator/deploy/o-ran-ru-fh/data/ietf-interfaces-operational.xml new file mode 100644 index 0000000..4e474d3 --- /dev/null +++ b/ntsimulator/deploy/o-ran-ru-fh/data/ietf-interfaces-operational.xml @@ -0,0 +1,151 @@ + + + interface-1 + Simulated interface for O-RU + ianaift:ethernetCsmacd + true + disabled + + false + false + 42783 +
+ 6.122.172.49 + 14 + static +
+
+ 206.35.59.57 + 199.41.255.188 + random +
+ + 48.159.72.129 + 42:8f:12:23:03:d3 + other + + + 187.230.45.63 + 77:b5:38:45:08:be + dynamic + + 13 + + 38 + 16 + 62 + 27 + + X5f0ExbIx4jg5fpd9c0wiOEJbCXzpYxe3M7AkiaRnlZsAgxCsx0LlFmwhk6yavM5iTFu4Idr3cTwtj0NQ0ycFVAO7ymh41meM2IQCNhFZ33km30c4ygJlRqshMJlFYrsS1iuOs1Gv5SJ8SNcr4WENm740IiyGJ0qLaUrCW7Z10A9SombsaQ7oPboptWYdOoQRjhl7hl8hV91bv5vxNCVuOcTh0RmP84Grm1qD + 21 + + + 2zF55KBup + 5 + + +
+ + true + true + 1163652863 +
+ ea87:d264:da5e:5b19:4713:7266:f91e:14f7 + 124 + other + tentative +
+
+ 2853:6b9:c531:f3c1:6875:f55:17ea:157b + 65 + link-layer + preferred +
+ + e6ae:4eeb:25c8:4ce6:9a7:5c2c:4293:f42e + 65:58:a4:47:f1:91 + other + + probe + + + f88d:e8e9:8f68:ff46:ae1a:8329:67bc:bd6f + 32:d7:a9:c1:37:14 + other + incomplete + + 1225514618 + + true + true + 2335597472 + 922813230 + + 33 + + 29 + 50 + 14 + 61 + + 8iROcw05EJqk0qe08RerP + 18 + + + M14steKtoB9s09xEKPYLf4LfWZHDetPSuUkP05bgykIym746WUR3ZCjVuSqIlgAI2Nx2KIiaV0Bh7xnVs7YjB965TwF7E8PGVeAxPSHKKaTJI8w2fnlRwjWqPuxmCe2xsDWhnvT0GMBoV8i2vDTTOIbvcAROOUd9p9qMEcEcYgsLgKODfzw3hAzlaq9Zce8BfqgUCUYt2r6abMNrmcuDMVZWm0Nq7N2m6a8IW73Zy21BOP2aTpGxkxlyp9ZwO + 29 + + +
+ b2:24:6a:90:68:bb + ba:33:50:5b:58:f7 + 2c:2b:1f:8c:3f:a2 + + 113 + + 60489 + true + + 3 + 0 + 1 + 6 + 4 + + dtSbiQU8fgixwU6tOQNLIc1PPuz2LFeQ862rPWr44JtAvzVbi + 5 + + + MQHBk8vYNCGOII7pwymAaP2xhPJrxxjcn1NA9bqPN6D + 2 + + + up + unknown + 2018-12-04T01:22:44Z + 1399123220 + fc:07:1e:ec:24:a3 + 80kcD05DwnN81FHWZgSwQXgpN7kjx4KF44JzXOcl3St5p21gjLM9A2yg1LzyPk + 80kcD05DwnN81FHWZgSwQXgpN7kjx4KF44JzXOcl3St5p21gjLM9A2yg1LzyPk + 2897952377425309696 + + 2037-04-15T16:07:29Z + 2571268368646403584 + 6267618126971935744 + 1109994561130658944 + 3315305959068576256 + 1267048002 + 2454029092 + 603209482 + 1059514199864528128 + 6657904184753078272 + 5105130509884859392 + 2014558074734005248 + 2053161590 + 1475901304 + + 1976-10-15T10:34:12Z + 56 + 143 +
+
diff --git a/ntsimulator/deploy/o-ran-ru-fh/data/ietf-interfaces-running.xml b/ntsimulator/deploy/o-ran-ru-fh/data/ietf-interfaces-running.xml new file mode 100644 index 0000000..580fe3f --- /dev/null +++ b/ntsimulator/deploy/o-ran-ru-fh/data/ietf-interfaces-running.xml @@ -0,0 +1,111 @@ + + + interface-1 + Simulated interface for O-RU + ianaift:ethernetCsmacd + true + disabled + + false + false + 42783 +
+ 6.122.172.49 + 14 +
+
+ 206.35.59.57 + 199.41.255.188 +
+ + 48.159.72.129 + 42:8f:12:23:03:d3 + + + 187.230.45.63 + 77:b5:38:45:08:be + + 13 + + 38 + 16 + 62 + 27 + + X5f0ExbIx4jg5fpd9c0wiOEJbCXzpYxe3M7AkiaRnlZsAgxCsx0LlFmwhk6yavM5iTFu4Idr3cTwtj0NQ0ycFVAO7ymh41meM2IQCNhFZ33km30c4ygJlRqshMJlFYrsS1iuOs1Gv5SJ8SNcr4WENm740IiyGJ0qLaUrCW7Z10A9SombsaQ7oPboptWYdOoQRjhl7hl8hV91bv5vxNCVuOcTh0RmP84Grm1qD + 21 + + + 2zF55KBup + 5 + + +
+ + true + true + 1163652863 +
+ ea87:d264:da5e:5b19:4713:7266:f91e:14f7 + 124 +
+
+ 2853:6b9:c531:f3c1:6875:f55:17ea:157b + 65 +
+ + e6ae:4eeb:25c8:4ce6:9a7:5c2c:4293:f42e + 65:58:a4:47:f1:91 + + + f88d:e8e9:8f68:ff46:ae1a:8329:67bc:bd6f + 32:d7:a9:c1:37:14 + + 1225514618 + + true + true + 2335597472 + 922813230 + + 33 + + 29 + 50 + 14 + 61 + + 8iROcw05EJqk0qe08RerP + 18 + + + M14steKtoB9s09xEKPYLf4LfWZHDetPSuUkP05bgykIym746WUR3ZCjVuSqIlgAI2Nx2KIiaV0Bh7xnVs7YjB965TwF7E8PGVeAxPSHKKaTJI8w2fnlRwjWqPuxmCe2xsDWhnvT0GMBoV8i2vDTTOIbvcAROOUd9p9qMEcEcYgsLgKODfzw3hAzlaq9Zce8BfqgUCUYt2r6abMNrmcuDMVZWm0Nq7N2m6a8IW73Zy21BOP2aTpGxkxlyp9ZwO + 29 + + +
+ b2:24:6a:90:68:bb + ba:33:50:5b:58:f7 + 2c:2b:1f:8c:3f:a2 + + 113 + + 60489 + true + + 3 + 0 + 1 + 6 + 4 + + dtSbiQU8fgixwU6tOQNLIc1PPuz2LFeQ862rPWr44JtAvzVbi + 5 + + + MQHBk8vYNCGOII7pwymAaP2xhPJrxxjcn1NA9bqPN6D + 2 + + +
+
diff --git a/ntsimulator/deploy/o-ran/container-tag.yaml b/ntsimulator/deploy/o-ran/container-tag.yaml index ec29baf..0cd0ef4 100644 --- a/ntsimulator/deploy/o-ran/container-tag.yaml +++ b/ntsimulator/deploy/o-ran/container-tag.yaml @@ -1,2 +1,2 @@ --- -tag: 1.2.3 \ No newline at end of file +tag: 1.3.0 \ No newline at end of file diff --git a/ntsimulator/deploy/x-ran/config.json b/ntsimulator/deploy/x-ran/config.json index aec6853..b91496c 100644 --- a/ntsimulator/deploy/x-ran/config.json +++ b/ntsimulator/deploy/x-ran/config.json @@ -13,14 +13,6 @@ "stderr": "log/netopeer-stderr.log" }, - "sshd": { - "path": "/usr/sbin/sshd", - "args": ["-D"], - "autorestart": true, - "stdout": "log/sshd-stdout.log", - "stderr": "log/sshd-stderr.log" - }, - "ntsim-network-function": { "path": "/opt/dev/ntsim-ng/ntsim-ng", "args": ["-w/opt/dev/ntsim-ng", "-f"], diff --git a/ntsimulator/deploy/x-ran/container-tag.yaml b/ntsimulator/deploy/x-ran/container-tag.yaml index ec29baf..0cd0ef4 100644 --- a/ntsimulator/deploy/x-ran/container-tag.yaml +++ b/ntsimulator/deploy/x-ran/container-tag.yaml @@ -1,2 +1,2 @@ --- -tag: 1.2.3 \ No newline at end of file +tag: 1.3.0 \ No newline at end of file diff --git a/ntsimulator/docker-compose.yaml b/ntsimulator/docker-compose.yaml index 7de1e0b..f11f0eb 100644 --- a/ntsimulator/docker-compose.yaml +++ b/ntsimulator/docker-compose.yaml @@ -1,7 +1,7 @@ version: '3.7' services: ntsim-ng: - image: "${DOCKER_REPO}ntsim-ng-manager:${NTS_BUILD_VERSION}" + image: "${DOCKER_REPO}nts-ng-manager:${NTS_BUILD_VERSION}" container_name: nts-ng-manager stop_grace_period: 5m ports: @@ -43,10 +43,11 @@ services: image: "${DOCKER_REPO}nts-ng-o-ran-ru-fh:${NTS_BUILD_VERSION}" cap_add: - SYS_ADMIN + - NET_ADMIN stop_grace_period: 5m hostname: "O-RAN-O-RU-1" ports: - - "::18300:830" + - ":::18300:830" environment: IPv6_ENABLED: ${IPv6_ENABLED} SSH_CONNECTIONS: ${SSH_CONNECTIONS} @@ -76,17 +77,18 @@ services: VES_ENDPOINT_USERNAME: ${VES_ENDPOINT_USERNAME} VES_ENDPOINT_PASSWORD: ${VES_ENDPOINT_PASSWORD} - networks: - app_net: + # networks: + # app_net: ntsim-ng-o-du: image: "${DOCKER_REPO}nts-ng-o-ran-du:${NTS_BUILD_VERSION}" cap_add: - SYS_ADMIN + - NET_ADMIN stop_grace_period: 5m hostname: "O-RAN-O-DU-1" ports: - - "::18301:830" + - ":::18301:830" environment: IPv6_ENABLED: ${IPv6_ENABLED} SSH_CONNECTIONS: ${SSH_CONNECTIONS} @@ -100,7 +102,6 @@ services: NTS_HOST_NETCONF_TLS_BASE_PORT: ${NTS_HOST_NETCONF_TLS_BASE_PORT} NTS_HOST_TRANSFER_FTP_BASE_PORT: ${NTS_HOST_TRANSFER_FTP_BASE_PORT} NTS_HOST_TRANSFER_SFTP_BASE_PORT: ${NTS_HOST_TRANSFER_SFTP_BASE_PORT} - SDN_CONTROLLER_PROTOCOL: ${SDN_CONTROLLER_PROTOCOL} SDN_CONTROLLER_IP: ${SDN_CONTROLLER_IP} @@ -116,17 +117,17 @@ services: VES_ENDPOINT_AUTH_METHOD: ${VES_ENDPOINT_AUTH_METHOD} VES_ENDPOINT_USERNAME: ${VES_ENDPOINT_USERNAME} VES_ENDPOINT_PASSWORD: ${VES_ENDPOINT_PASSWORD} - networks: - app_net: + # networks: + # app_net: -networks: - app_net: - driver: bridge - ipam: - driver: default +# networks: +# app_net: +# driver: bridge +# ipam: +# driver: default # We can attach to any other docker network, like in the example below -# networks: -# default: -# external: -# name: smo_integration \ No newline at end of file +networks: + default: + external: + name: smo_integration \ No newline at end of file diff --git a/ntsimulator/nts-ng-docker-image-build-ubuntu.yaml b/ntsimulator/nts-ng-docker-image-build-ubuntu.yaml index 23ea07d..65e4973 100644 --- a/ntsimulator/nts-ng-docker-image-build-ubuntu.yaml +++ b/ntsimulator/nts-ng-docker-image-build-ubuntu.yaml @@ -78,3 +78,14 @@ services: labels: - "description=nts-ng" dockerfile: local.Dockerfile + + ################################################### + ####### Blank image + ################################################### + nts-ng-blank_version_tag: + image: ${DOCKER_REPO}nts-ng-blank:${NTS_BUILD_VERSION} + build: + context: ./deploy/blank + labels: + - "description=nts-ng" + dockerfile: local.Dockerfile diff --git a/ntsimulator/ntsim-ng/core/app/blank.c b/ntsimulator/ntsim-ng/core/app/blank.c new file mode 100644 index 0000000..baef1b6 --- /dev/null +++ b/ntsimulator/ntsim-ng/core/app/blank.c @@ -0,0 +1,149 @@ +/************************************************************************* +* +* Copyright 2021 highstreet technologies GmbH and others +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +***************************************************************************/ + +#define _GNU_SOURCE + +#include "blank.h" +#include "utils/log_utils.h" +#include "utils/sys_utils.h" +#include "utils/nts_utils.h" +#include +#include + +#include "core/framework.h" +#include "core/container.h" +#include "core/session.h" +#include "core/nc_config.h" + +#define DOCKER_DEPLOY_ZIP "/opt/dev/deploy.zip" +#define FTP_DEPLOY_ZIP "/ftp/deploy.zip" + +//checkAL: see all todos if doing also YANG-install through netopeer + +int blank_run(void) { + log_add_verbose(1, LOG_COLOR_BOLD_YELLOW"running as BLANK NTS daemon...\n"LOG_COLOR_RESET); + log_add_verbose(1, LOG_COLOR_BOLD_YELLOW"Docker IP:"LOG_COLOR_RESET" %s\n", framework_environment.settings.ip_v6_enabled ? framework_environment.settings.ip_v6 : framework_environment.settings.ip_v4); + + char shell_command[512]; + + if(session_init() != NTS_ERR_OK) { + log_error("session_init() failed\n"); + return NTS_ERR_FAILED; + } + + if(netconf_configure() != NTS_ERR_OK) { + log_error("netconf_configure() failed\n") + return NTS_ERR_FAILED; + } + + session_free(); + + vsftp_daemon_init(); + sftp_daemon_init(); + + //todo: run netopeer + + char *zipfile = DOCKER_DEPLOY_ZIP; + if(file_exists(zipfile)) { + goto blank_install_zip; + } + else { + log_add_verbose(2, "%s was not found, waiting for deploy.zip on other means...\n"); + } + +blank_run_wait_for_file: + while(!framework_sigint) { + zipfile = FTP_DEPLOY_ZIP; + if(file_exists(zipfile)) { + goto blank_install_zip; + } + + //todo: check netopeer for data + + sleep(1); + } + + vsftp_daemon_deinit(); + sftp_daemon_deinit(); + + log_error("blank image daemon was called to stop before installing anything\n"); + return NTS_ERR_FAILED; + + +blank_install_zip: { + log_add_verbose(1, "found deploy.zip in "LOG_COLOR_BOLD_BLUE"%s"LOG_COLOR_RESET"\n", zipfile); + log_add_verbose(1, "starting install...\n"); + + //check if zip is ok + sprintf(shell_command, "unzip -qq -t %s", zipfile); + if(system(shell_command) != 0) { + log_error("%s invalid ZIP file\n", zipfile); + goto blank_install_failed; + } + + //unzip to /opt/dev/deploy + sprintf(shell_command, "unzip -qq %s -d /opt/dev/deploy", zipfile); + if(system(shell_command) != 0) { + log_error("unzip filed for unknown reason\n", zipfile); + goto blank_install_failed; + } + + if(strcmp(zipfile, FTP_DEPLOY_ZIP) == 0) { + sprintf(shell_command, "rm -f %s", zipfile); + if(system(shell_command) != 0) { + log_error("failed to remove %s\n", zipfile); + } + } + + if(!file_exists("/opt/dev/deploy/config.json")) { + log_error("/opt/dev/deploy/config.json not found!\n"); + goto blank_install_failed; + } + + //move /opt/dev/deploy/config.json to /opt/dev/ntsim-ng/config/config.json + system("mv /opt/dev/deploy/config.json /opt/dev/ntsim-ng/config/config.json"); + + //todo: kill netopeer + + //run container_self_init() + if(!container_self_init()) { + log_error("container_self_init() error\n"); + goto blank_install_failed; + } + + //send SIGUSR1 to supervisor to reload everything and start fresh + kill(1, SIGUSR1); + + log_add_verbose(1, LOG_COLOR_BOLD_GREEN"blank image successfully replaced!"LOG_COLOR_RESET"\n"); + vsftp_daemon_deinit(); + sftp_daemon_deinit(); + + return NTS_ERR_OK; + } + +blank_install_failed: { + //remove zipfile + sprintf(shell_command, "rm -rf %s", zipfile); + system(shell_command); + + system("rm -rf /opt/dev/deploy"); + + log_error("%s failed to install...\n", zipfile); + log_error("try again with new file...\n"); + goto blank_run_wait_for_file; + } +} diff --git a/ntsimulator/ntsim-ng/core/app/blank.h b/ntsimulator/ntsim-ng/core/app/blank.h new file mode 100644 index 0000000..8bea0ad --- /dev/null +++ b/ntsimulator/ntsim-ng/core/app/blank.h @@ -0,0 +1,20 @@ +/************************************************************************* +* +* Copyright 2020 highstreet technologies GmbH and others +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +***************************************************************************/ + +#pragma once + +int blank_run(void); diff --git a/ntsimulator/ntsim-ng/core/app/network_function.c b/ntsimulator/ntsim-ng/core/app/network_function.c index 1d2147a..af80c94 100644 --- a/ntsimulator/ntsim-ng/core/app/network_function.c +++ b/ntsimulator/ntsim-ng/core/app/network_function.c @@ -692,7 +692,6 @@ static int faults_update_config(sr_session_ctx_t *session) { } faults_fault_list_clear(); - faults_counters_clear(); if(data == 0) { return NTS_ERR_OK; } diff --git a/ntsimulator/ntsim-ng/core/app/supervisor.c b/ntsimulator/ntsim-ng/core/app/supervisor.c index 8612a08..44a2ee8 100644 --- a/ntsimulator/ntsim-ng/core/app/supervisor.c +++ b/ntsimulator/ntsim-ng/core/app/supervisor.c @@ -47,11 +47,41 @@ typedef struct { static void supervisor_spawn(supervisor_control_block_t *scb); static void supervisor_free_scb(int count, supervisor_control_block_t *scb); static void supervisor_on_signal(int signo); +static void supervisor_on_sigusr(int signo); static volatile sig_atomic_t supervisor_got_signal_stop = 0; +static volatile sig_atomic_t supervisor_got_signal_reload = 0; static bool nts_manual; -int supervisor_run(void) { +int supervisor_run(int argc, char **argv) { +supervisor_start: + if(file_exists("/opt/dev/deploy/.env")) { + FILE * fp; + char * line = 0; + size_t len = 0; + ssize_t read; + + fp = fopen("/opt/dev/deploy/.env", "r"); + if(fp) { + log_add_verbose(1, "[supervisor] found /opt/dev/deploy/.env\n"); + + while ((read = getline(&line, &len, fp)) != -1) { + if(line[strlen(line) - 1] == '\n') { + line[strlen(line) - 1] = 0; + } + + log_add_verbose(1, "[supervisor] adding .env var: %s\n", line); + putenv(strdup(line)); + } + + fclose(fp); + free(line); + } + } + + supervisor_got_signal_reload = 0; + supervisor_got_signal_stop = 0; + int scb_count = framework_config.supervisor.rules_count; supervisor_control_block_t *scb = (supervisor_control_block_t*)malloc(sizeof(supervisor_control_block_t) * framework_config.supervisor.rules_count); if(scb == 0) { @@ -81,6 +111,7 @@ int supervisor_run(void) { signal(SIGINT, supervisor_on_signal); signal(SIGTERM, supervisor_on_signal); signal(SIGQUIT, supervisor_on_signal); + signal(SIGUSR1, supervisor_on_sigusr); for(int i = 0; i < scb_count; i++) { supervisor_spawn(&scb[i]); @@ -145,6 +176,18 @@ int supervisor_run(void) { supervisor_free_scb(scb_count, scb); framework_free(); + if(supervisor_got_signal_reload) { + if(framework_init(argc, argv) != NTS_ERR_OK) { + log_error(LOG_COLOR_BOLD_RED"framework_init() error\n"); + framework_free(); + return EXIT_FAILURE; + } + + log_add_verbose(1, "[supervisor] SIGUSR1 received, restarting everything... (this is a *new* logfile)\n"); + + goto supervisor_start; + } + return NTS_ERR_OK; } @@ -214,3 +257,8 @@ static void supervisor_free_scb(int count, supervisor_control_block_t *scb) { static void supervisor_on_signal(int signo) { supervisor_got_signal_stop = signo; } + +static void supervisor_on_sigusr(int signo) { + supervisor_got_signal_stop = SIGTERM; + supervisor_got_signal_reload = 1; +} diff --git a/ntsimulator/ntsim-ng/core/app/supervisor.h b/ntsimulator/ntsim-ng/core/app/supervisor.h index a714dee..1e7119f 100644 --- a/ntsimulator/ntsim-ng/core/app/supervisor.h +++ b/ntsimulator/ntsim-ng/core/app/supervisor.h @@ -17,4 +17,4 @@ #pragma once -int supervisor_run(void); +int supervisor_run(int argc, char **argv); diff --git a/ntsimulator/ntsim-ng/core/framework.c b/ntsimulator/ntsim-ng/core/framework.c index 39f152f..6d9ab48 100644 --- a/ntsimulator/ntsim-ng/core/framework.c +++ b/ntsimulator/ntsim-ng/core/framework.c @@ -45,6 +45,7 @@ static struct argp_option options[] = { { "supervisor", 's', 0, 0, "Run as supervisor; manager/network-function is chosen via config.json"}, { "manager", 'm', 0, 0, "Run the daemon as manager." }, { "network-function", 'f', 0, 0, "Run the daemon as network function." }, + { "blank", 'b', 0, 0, "Run the deamon as a blank network function." }, { "generate", 'g', 0, 0, "Generate population data without commiting." }, { "test-mode", 't', 0, 0, "Test mode." }, @@ -69,7 +70,92 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state); int framework_init(int argc, char **argv) { //environment vars framework_environment.nts.version = (getenv(ENV_VAR_NTS_BUILD_VERSION) && strlen(getenv(ENV_VAR_NTS_BUILD_VERSION))) ? strdup(getenv(ENV_VAR_NTS_BUILD_VERSION)) : strdup(NTS_VERSION_FALLBACK"!"); - framework_environment.nts.build_time = (getenv(ENV_VAR_NTS_BUILD_TIME) && strlen(getenv(ENV_VAR_NTS_BUILD_TIME))) ? strdup(getenv(ENV_VAR_NTS_BUILD_TIME)) : strdup("N/A"); + if(getenv(ENV_VAR_NTS_BUILD_TIME) && strlen(getenv(ENV_VAR_NTS_BUILD_TIME))) { + framework_environment.nts.build_time = strdup(getenv(ENV_VAR_NTS_BUILD_TIME)); + } + else { + if(__DATE__[0] == '?') { + framework_environment.nts.build_time = strdup("1970-01-01T00:00:00Z"); + } + else { + //01234567890 + //May 4 2021 + int year = 0; + int month = 1; + int day = 0; + + year = (__DATE__[10] - '0') + (__DATE__[9] - '0')*10 + (__DATE__[8] - '0')*100 + (__DATE__[7] - '0')*1000; + day = (__DATE__[5] - '0'); + if(__DATE__[4] != ' ') { + day += (__DATE__[4] - '0')*10; + } + + switch(__DATE__[0]) { + case 'J': + switch(__DATE__[1]) { + case 'a': + month = 1; + break; + + case 'u': + if(__DATE__[2] == 'n') { + month = 6; + } + else { + month = 7; + } + break; + } + break; + + case 'F': + month = 2; + break; + + case 'M': + switch(__DATE__[2]) { + case 'r': + month = 3; + break; + + case 'y': + month = 5; + break; + } + break; + + case 'A': + switch(__DATE__[1]) { + case 'p': + month = 4; + break; + + case 'u': + month = 8; + break; + } + break; + + case 'S': + month = 9; + break; + + case 'O': + month = 10; + break; + + case 'N': + month = 11; + break; + + case 'D': + month = 12; + break; + } + + asprintf(&framework_environment.nts.build_time, "%04d-%02d-%02dT%sZ", year, month, day, __TIME__); + } + } //set argp_version char *version = 0; @@ -116,6 +202,11 @@ int framework_init(int argc, char **argv) { stderr_file = "log/stderr-install.txt"; break; + case NTS_MODE_BLANK: + log_file = "log/log-blank.txt"; + stderr_file = "log/stderr-blank.txt"; + break; + case NTS_MODE_SUPERVISOR: log_file = "log/log-supervisor.txt"; stderr_file = "log/stderr-supervisor.txt"; @@ -363,18 +454,25 @@ static int framework_config_init(void) { framework_config.datastore_populate.preg_running = 0; //config init - if(!dir_exists("config")) { - log_add_verbose(2, "[framework-config] config/ folder wasn't found; created.\n"); - mkdir("config", 0777); + char *config_file = "config/config.json"; + if(file_exists("/opt/dev/config/config.json")) { + config_file = "/opt/dev/config/config.json"; + log_add_verbose(1, LOG_COLOR_BOLD_MAGENTA"config.json is loaded from external volume!\n"LOG_COLOR_RESET); } + else { + if(!dir_exists("config")) { + log_add_verbose(2, "[framework-config] config/ folder wasn't found; created.\n"); + mkdir("config", 0777); + } - if(!file_exists("config/config.json")) { - log_add_verbose(2, "[framework-config] config.json file missing; created.\n"); - file_touch("config/config.json", "{}"); - } + if(!file_exists("config/config.json")) { + log_add_verbose(2, "[framework-config] config.json file missing; created.\n"); + file_touch("config/config.json", "{}"); + } + } - log_add_verbose(2, "[framework-config] parsing config.json\n"); - char *config_contents = file_read_content("config/config.json"); + log_add_verbose(2, "[framework-config] parsing config.json from %s\n", config_file); + char *config_contents = file_read_content(config_file); cJSON *json = cJSON_Parse(config_contents); free(config_contents); if(!json) { @@ -808,6 +906,10 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { iter_arguments->nts_mode = NTS_MODE_NETWORK_FUNCTION; break; + case 'b': + iter_arguments->nts_mode = NTS_MODE_BLANK; + break; + case 'g': iter_arguments->nts_mode = NTS_MODE_GENERATE_DATA; break; diff --git a/ntsimulator/ntsim-ng/core/framework.h b/ntsimulator/ntsim-ng/core/framework.h index 1c8a266..fa791b8 100644 --- a/ntsimulator/ntsim-ng/core/framework.h +++ b/ntsimulator/ntsim-ng/core/framework.h @@ -68,6 +68,7 @@ typedef enum { NTS_MODE_SUPERVISOR, NTS_MODE_MANAGER, NTS_MODE_NETWORK_FUNCTION, + NTS_MODE_BLANK, NTS_MODE_GENERATE_DATA, NTS_MODE_TEST, } nts_mode_t; diff --git a/ntsimulator/ntsim-ng/features/ves_file_ready/ves_file_ready.c b/ntsimulator/ntsim-ng/features/ves_file_ready/ves_file_ready.c index 1531126..d7f340e 100644 --- a/ntsimulator/ntsim-ng/features/ves_file_ready/ves_file_ready.c +++ b/ntsimulator/ntsim-ng/features/ves_file_ready/ves_file_ready.c @@ -35,8 +35,6 @@ static int ves_file_ready_invoke_pm_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data); static int ves_file_ready_send_message(sr_session_ctx_t *session, const char *file_location, int port); static cJSON* ves_create_file_ready_fields(const char* file_location); -static void ves_file_ready_vsftp_daemon_init(void); -static void ves_file_ready_vsftp_daemon_deinit(void); static sr_subscription_ctx_t *ves_file_ready_subscription = 0; @@ -55,7 +53,8 @@ int ves_file_ready_feature_start(sr_session_ctx_t *current_session) { return NTS_ERR_FAILED; } - ves_file_ready_vsftp_daemon_init(); + sftp_daemon_init(); + vsftp_daemon_init(); } return NTS_ERR_OK; @@ -71,21 +70,14 @@ int ves_file_ready_feature_stop(void) { return NTS_ERR_FAILED; } - ves_file_ready_vsftp_daemon_deinit(); + vsftp_daemon_deinit(); + sftp_daemon_deinit(); ves_file_ready_subscription = 0; } return NTS_ERR_OK; } -static void ves_file_ready_vsftp_daemon_init(void) { - system("/usr/sbin/vsftpd &"); -} - -static void ves_file_ready_vsftp_daemon_deinit(void) { - system("killall -9 vsftpd"); -} - static int ves_file_ready_invoke_pm_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { int ssh_base_port = 0; int tls_base_port = 0; diff --git a/ntsimulator/ntsim-ng/main.c b/ntsimulator/ntsim-ng/main.c index 316fe0a..76abef6 100644 --- a/ntsimulator/ntsim-ng/main.c +++ b/ntsimulator/ntsim-ng/main.c @@ -35,6 +35,7 @@ #include "core/app/supervisor.h" #include "core/app/manager.h" #include "core/app/network_function.h" +#include "core/app/blank.h" #include "core/datastore/schema.h" #include "core/datastore/generate.h" #include "core/datastore/populate.h" @@ -104,7 +105,7 @@ int main(int argc, char **argv) { case NTS_MODE_SUPERVISOR: //run in supervisor mode - if(supervisor_run() != NTS_ERR_OK) { + if(supervisor_run(argc, argv) != NTS_ERR_OK) { log_error("supervisor_run() failed\n"); return_code = EXIT_FAILURE; } @@ -130,6 +131,15 @@ int main(int argc, char **argv) { goto main_clean; break; + case NTS_MODE_BLANK: + if(blank_run() != NTS_ERR_OK) { + log_error("blank_run() failed\n"); + return_code = EXIT_FAILURE; + } + + goto main_clean_framework; + break; + case NTS_MODE_GENERATE_DATA: if(datastore_generate_data(DATASTORE_RUNNING_PATH, DATASTORE_OPERATIONAL_PATH) != NTS_ERR_OK) { log_error("datastore_generate_data() failed\n"); @@ -175,7 +185,7 @@ int main(int argc, char **argv) { } main_clean: - log_add_verbose(1, LOG_COLOR_BOLD_RED"\nstopping now...\n"LOG_COLOR_RESET); + log_add_verbose(1, LOG_COLOR_BOLD_RED"stopping now...\n"LOG_COLOR_RESET); nc_client_destroy(); main_clean_context: context_free(); diff --git a/ntsimulator/ntsim-ng/utils/rand_utils.c b/ntsimulator/ntsim-ng/utils/rand_utils.c index 06d746c..296daa8 100644 --- a/ntsimulator/ntsim-ng/utils/rand_utils.c +++ b/ntsimulator/ntsim-ng/utils/rand_utils.c @@ -880,13 +880,15 @@ static rand_range_t rand_range(const char *range, const LY_DATA_TYPE type) { } static char *rand_date_and_time(void) { - time_t t = rand_uint32() / 2; + time_t now = time(0); + time_t start_date = 1577836800; //2020-01-01T00:00:00Z + + time_t t = start_date + rand_uint32() % (now - start_date); struct tm lt; (void)localtime_r(&t, <); char *ret = (char *)malloc(21); if(!ret) { - log_error("bad malloc\n"); return 0; } strftime(ret, 21, "%Y-%m-%dT%H:%M:%SZ", <); diff --git a/ntsimulator/ntsim-ng/utils/sys_utils.c b/ntsimulator/ntsim-ng/utils/sys_utils.c index 3449d63..d6def2e 100644 --- a/ntsimulator/ntsim-ng/utils/sys_utils.c +++ b/ntsimulator/ntsim-ng/utils/sys_utils.c @@ -468,3 +468,19 @@ char *read_key(const char *filename) { return key_string; } + +void vsftp_daemon_init(void) { + system("/usr/sbin/vsftpd &"); +} + +void vsftp_daemon_deinit(void) { + system("killall -9 vsftpd"); +} + +void sftp_daemon_init(void) { + system("/usr/sbin/sshd -D &"); +} + +void sftp_daemon_deinit(void) { + system("killall -9 sshd"); +} diff --git a/ntsimulator/ntsim-ng/utils/sys_utils.h b/ntsimulator/ntsim-ng/utils/sys_utils.h index 2794ac5..f5c2cf2 100644 --- a/ntsimulator/ntsim-ng/utils/sys_utils.h +++ b/ntsimulator/ntsim-ng/utils/sys_utils.h @@ -47,3 +47,8 @@ uint8_t *b64_decode(const char *data, size_t input_length, size_t *output_length char *str_replace(const char *orig, const char *rep, const char *with); char *read_key(const char *filename); + +void vsftp_daemon_init(void); +void vsftp_daemon_deinit(void); +void sftp_daemon_init(void); +void sftp_daemon_deinit(void); -- 2.16.6