From 392f3f25ea9c08b473128f8d5960404aee033244 Mon Sep 17 00:00:00 2001 From: Marija Stevic Date: Thu, 24 Sep 2015 19:14:51 +0200 Subject: [PATCH 01/10] fixed the error in opal client src code --- clients/opal/udp/models/send_receive/src/s2ss.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/opal/udp/models/send_receive/src/s2ss.c b/clients/opal/udp/models/send_receive/src/s2ss.c index 5ea9a0cc1..97f825d60 100644 --- a/clients/opal/udp/models/send_receive/src/s2ss.c +++ b/clients/opal/udp/models/send_receive/src/s2ss.c @@ -132,7 +132,7 @@ static void *SendToIPPort(void *arg) for (i = 0; i < msg.length; i++) msg.data[i].f = (float) mdldata[i]; - msg_size = MSG_LEN(msg.length); + msg_size = MSG_LEN(&msg); /**********************************************************************/ /* Perform the actual write to the ip port */ @@ -205,7 +205,7 @@ static void *RecvFromIPPort(void *arg) if (msg.endian != MSG_ENDIAN_HOST) msg_swap(&msg); - msg_size = MSG_LEN(msg.length); + msg_size = MSG_LEN(&msg); /***********************************************************************/ if (n < 1) { From 4d64550df64ba87bf65dae25b0b4b21c63189dc3 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 25 Sep 2015 14:46:53 +0200 Subject: [PATCH 02/10] added README for LiveUSB --- contrib/liveusb/README.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 contrib/liveusb/README.txt diff --git a/contrib/liveusb/README.txt b/contrib/liveusb/README.txt new file mode 100644 index 000000000..05f6d6e24 --- /dev/null +++ b/contrib/liveusb/README.txt @@ -0,0 +1,24 @@ +S2SS LiveUSB Image +=================================================================== + +This archive contains an image of Fedora installation +which has been tuned for low latency and overall performance. +It facilitates the setup of a S2SS instance and is designed to be used +by partners of the Institute for Automation of Complex Power Systems (ACS). + +This image will automatically request an IP address via DHCP +and create a SSH tunnel to the central orchestration server. +This allows further configuration and control. + +The default credentials are: + + User: root + Password: s2ss-admin + +Copy image with bundled tool [1] to a USB stick or a harddisk. +The image is about 2GB in size. +IMPORTANT: All contents of the stick will be wiped! Make backups! + +[1] http://www.alexpage.de/usb-image-tool/ + +Contact: Steffen Vogel \ No newline at end of file From 51f9a855c625a6dd2c3f7874616d9381c33a15dd Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 25 Sep 2015 15:07:03 +0200 Subject: [PATCH 03/10] fixed network byte order for sequence number and message length restructured code --- .../opal/udp/models/send_receive/src/s2ss.c | 258 +++++++++--------- 1 file changed, 122 insertions(+), 136 deletions(-) diff --git a/clients/opal/udp/models/send_receive/src/s2ss.c b/clients/opal/udp/models/send_receive/src/s2ss.c index 97f825d60..9beef8095 100644 --- a/clients/opal/udp/models/send_receive/src/s2ss.c +++ b/clients/opal/udp/models/send_receive/src/s2ss.c @@ -87,7 +87,6 @@ static void *SendToIPPort(void *arg) /* Data from the S2SS server */ struct msg msg = MSG_INIT(0); - int msg_size; #ifdef _DEBUG // TODO: workaround msg_send = &msg; @@ -96,69 +95,65 @@ static void *SendToIPPort(void *arg) OpalPrint("%s: SendToIPPort thread started\n", PROGNAME); OpalGetNbAsyncSendIcon(&nbSend); - if (nbSend >= 1) { - do { - /* This call unblocks when the 'Data Ready' line of a send icon is asserted. */ - if ((n = OpalWaitForAsyncSendRequest(&SendID)) != EOK) { - ModelState = OpalGetAsyncModelState(); - if ((ModelState != STATE_RESET) && (ModelState != STATE_STOP)) { - OpalSetAsyncSendIconError(n, SendID); - OpalPrint("%s: OpalWaitForAsyncSendRequest(), errno %d\n", PROGNAME, n); - } - - continue; + if (nbSend < 1) { + OpalPrint("%s: SendToIPPort: No transimission block for this controller. Stopping thread.\n", PROGNAME); + return NULL; + } + + do { + /* This call unblocks when the 'Data Ready' line of a send icon is asserted. */ + if ((n = OpalWaitForAsyncSendRequest(&SendID)) != EOK) { + ModelState = OpalGetAsyncModelState(); + if ((ModelState != STATE_RESET) && (ModelState != STATE_STOP)) { + OpalSetAsyncSendIconError(n, SendID); + OpalPrint("%s: OpalWaitForAsyncSendRequest(), errno %d\n", PROGNAME, n); } - /* No errors encountered yet */ + continue; + } + + /* No errors encountered yet */ + OpalSetAsyncSendIconError(0, SendID); + + /* Get the size of the data being sent by the unblocking SendID */ + OpalGetAsyncSendIconDataLength(&mdldata_size, SendID); + if (mdldata_size / sizeof(double) > MSG_VALUES) { + OpalPrint("%s: Number of signals for SendID=%d exceeds allowed maximum (%d)\n", + PROGNAME, SendID, MSG_VALUES); + return NULL; + } + + /* Read data from the model */ + OpalGetAsyncSendIconData(mdldata, mdldata_size, SendID); + + msg.length = mdldata_size / sizeof(double); + for (i = 0; i < msg.length; i++) + msg.data[i].f = (float) mdldata[i]; + + /* Convert to network byte order */ + msg.sequence = htonl(seq++); + msg.length = htons(msg.length); + + /* Perform the actual write to the ip port */ + if (SendPacket((char *) &msg, MSG_LEN(&msg)) < 0) + OpalSetAsyncSendIconError(errno, SendID); + else OpalSetAsyncSendIconError(0, SendID); - /* Get the size of the data being sent by the unblocking SendID */ - OpalGetAsyncSendIconDataLength(&mdldata_size, SendID); - if (mdldata_size / sizeof(double) > MSG_VALUES) { - OpalPrint("%s: Number of signals for SendID=%d exceeds allowed maximum (%d)\n", - PROGNAME, SendID, MSG_VALUES); + /* This next call allows the execution of the "asynchronous" process + * to actually be synchronous with the model. To achieve this, you + * should set the "Sending Mode" in the Async_Send block to + * NEED_REPLY_BEFORE_NEXT_SEND or NEED_REPLY_NOW. This will force + * the model to wait for this process to call this + * OpalAsyncSendRequestDone function before continuing. */ + OpalAsyncSendRequestDone(SendID); - return NULL; - } + /* Before continuing, we make sure that the real-time model + * has not been stopped. If it has, we quit. */ + ModelState = OpalGetAsyncModelState(); + } while ((ModelState != STATE_RESET) && (ModelState != STATE_STOP)); - /* Read data from the model */ - OpalGetAsyncSendIconData(mdldata, mdldata_size, SendID); - -/******* FORMAT TO SPECIFIC PROTOCOL HERE *****************************/ - // msg.dev_id = SendID; /* Use the SendID as a device ID here */ - msg.sequence = htons(seq++); - msg.length = mdldata_size / sizeof(double); - - for (i = 0; i < msg.length; i++) - msg.data[i].f = (float) mdldata[i]; - - msg_size = MSG_LEN(&msg); -/**********************************************************************/ - - /* Perform the actual write to the ip port */ - if (SendPacket((char *) &msg, msg_size) < 0) - OpalSetAsyncSendIconError(errno, SendID); - else - OpalSetAsyncSendIconError(0, SendID); - - /* This next call allows the execution of the "asynchronous" process - * to actually be synchronous with the model. To achieve this, you - * should set the "Sending Mode" in the Async_Send block to - * NEED_REPLY_BEFORE_NEXT_SEND or NEED_REPLY_NOW. This will force - * the model to wait for this process to call this - * OpalAsyncSendRequestDone function before continuing. */ - OpalAsyncSendRequestDone(SendID); - - /* Before continuing, we make sure that the real-time model - * has not been stopped. If it has, we quit. */ - ModelState = OpalGetAsyncModelState(); - } while ((ModelState != STATE_RESET) && (ModelState != STATE_STOP)); - - OpalPrint("%s: SendToIPPort: Finished\n", PROGNAME); - } - else { - OpalPrint("%s: SendToIPPort: No transimission block for this controller. Stopping thread.\n", PROGNAME); - } + OpalPrint("%s: SendToIPPort: Finished\n", PROGNAME); return NULL; } @@ -176,91 +171,82 @@ static void *RecvFromIPPort(void *arg) /* Data from the S2SS server */ struct msg msg = MSG_INIT(0); - unsigned msg_size; OpalPrint("%s: RecvFromIPPort thread started\n", PROGNAME); OpalGetNbAsyncRecvIcon(&nbRecv); - if (nbRecv >= 1) { - do { - -/******* FORMAT TO SPECIFIC PROTOCOL HERE ******************************/ - n = RecvPacket((char *) &msg, sizeof(msg), 1.0); - - /** @todo: Check and ntohs() sequence number! */ - - if (msg.version != MSG_VERSION) { - OpalPrint("%s: Received message with unknown version. Skipping..\n", PROGNAME); - continue; - } - else if (msg.type != MSG_TYPE_DATA) { - OpalPrint("%s: Received no data. Skipping..\n", PROGNAME); - continue; - } - - /** @todo: We may check the sequence number here. */ - - msg.sequence = ntohs(msg.sequence); - - if (msg.endian != MSG_ENDIAN_HOST) - msg_swap(&msg); - - msg_size = MSG_LEN(&msg); -/***********************************************************************/ - - if (n < 1) { - ModelState = OpalGetAsyncModelState(); - if ((ModelState != STATE_RESET) && (ModelState != STATE_STOP)) { - // n == 0 means timeout, so we continue silently - //if (n == 0) - // OpalPrint("%s: Timeout while waiting for data\n", PROGNAME, errno); - // n == -1 means a more serious error, so we print it - if (n == -1) - OpalPrint("%s: Error %d while waiting for data\n", PROGNAME, errno); - continue; - } - break; - } - else if (n != msg_size) { - OpalPrint("%s: Received incoherent packet (size: %d, complete: %d)\n", PROGNAME, n, msg_size); - continue; - } - -/******* FORMAT TO SPECIFIC PROTOCOL HERE *******************************/ - OpalSetAsyncRecvIconStatus(msg.sequence, RecvID); /* Set the Status to the message ID */ - OpalSetAsyncRecvIconError(0, RecvID); /* Set the Error to 0 */ - - /* Get the number of signals to send back to the model */ - OpalGetAsyncRecvIconDataLength(&mdldata_size, RecvID); - - if (mdldata_size / sizeof(double) > MSG_VALUES) { - OpalPrint("%s: Number of signals for RecvID=%d (%d) exceeds allowed maximum (%d)\n", - PROGNAME, RecvID, mdldata_size / sizeof(double), MSG_VALUES); - return NULL; - } - - if (mdldata_size / sizeof(double) > msg.length) { - OpalPrint("%s: Number of signals for RecvID=%d (%d) exceeds what was received (%d)\n", - PROGNAME, RecvID, mdldata_size / sizeof(double), msg.length); - } - - for (i = 0; i < msg.length; i++) - mdldata[i] = (double) msg.data[i].f; -/************************************************************************/ - - OpalSetAsyncRecvIconData(mdldata, mdldata_size, RecvID); - - /* Before continuing, we make sure that the real-time model - * has not been stopped. If it has, we quit. */ - ModelState = OpalGetAsyncModelState(); - } while ((ModelState != STATE_RESET) && (ModelState != STATE_STOP)); - - OpalPrint("%s: RecvFromIPPort: Finished\n", PROGNAME); - } - else { + if (nbRecv < 1) { OpalPrint("%s: RecvFromIPPort: No reception block for this controller. Stopping thread.\n", PROGNAME); + return NULL; } + do { + /* Receive message */ + n = RecvPacket((char *) &msg, sizeof(msg), 1.0); + if (n < 1) { + ModelState = OpalGetAsyncModelState(); + if ((ModelState != STATE_RESET) && (ModelState != STATE_STOP)) { + if (n == 0) /* timeout, so we continue silently */ + OpalPrint("%s: Timeout while waiting for data\n", PROGNAME, errno); + if (n == -1) /* a more serious error, so we print it */ + OpalPrint("%s: Error %d while waiting for data\n", PROGNAME, errno); + + continue; + } + break; + } + + /* Check message contents */ + if (msg.version != MSG_VERSION) { + OpalPrint("%s: Received message with unknown version. Skipping..\n", PROGNAME); + continue; + } + + if (msg.type != MSG_TYPE_DATA) { + OpalPrint("%s: Received no data. Skipping..\n", PROGNAME); + continue; + } + + /* Convert to host byte order */ + msg.sequence = ntohl(msg.sequence); + msg.length = ntohs(msg.length); + + if (n != MSG_LEN(&msg)) { + OpalPrint("%s: Received incoherent packet (size: %d, complete: %d)\n", PROGNAME, n, MSG_LEN(&msg)); + continue; + } + + if (msg.endian != MSG_ENDIAN_HOST) + msg_swap(&msg); + + /* Update OPAL model */ + OpalSetAsyncRecvIconStatus(msg.sequence, RecvID); /* Set the Status to the message ID */ + OpalSetAsyncRecvIconError(0, RecvID); /* Set the Error to 0 */ + + /* Get the number of signals to send back to the model */ + OpalGetAsyncRecvIconDataLength(&mdldata_size, RecvID); + if (mdldata_size / sizeof(double) > MSG_VALUES) { + OpalPrint("%s: Number of signals for RecvID=%d (%d) exceeds allowed maximum (%d)\n", + PROGNAME, RecvID, mdldata_size / sizeof(double), MSG_VALUES); + return NULL; + } + + if (mdldata_size / sizeof(double) > msg.length) + OpalPrint("%s: Number of signals for RecvID=%d (%d) exceeds what was received (%d)\n", + PROGNAME, RecvID, mdldata_size / sizeof(double), msg.length); + + for (i = 0; i < msg.length; i++) + mdldata[i] = (double) msg.data[i].f; + + OpalSetAsyncRecvIconData(mdldata, mdldata_size, RecvID); + + /* Before continuing, we make sure that the real-time model + * has not been stopped. If it has, we quit. */ + ModelState = OpalGetAsyncModelState(); + } while ((ModelState != STATE_RESET) && (ModelState != STATE_STOP)); + + OpalPrint("%s: RecvFromIPPort: Finished\n", PROGNAME); + return NULL; } From ec2595e70392c49ab799eb05b43f2a2ecdd4563f Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 27 Sep 2015 14:47:17 +0200 Subject: [PATCH 04/10] renamed README --- clients/{README.txt => README.md} | 2 ++ 1 file changed, 2 insertions(+) rename clients/{README.txt => README.md} (92%) diff --git a/clients/README.txt b/clients/README.md similarity index 92% rename from clients/README.txt rename to clients/README.md index 3ce8ce243..85ccf0f48 100644 --- a/clients/README.txt +++ b/clients/README.md @@ -1,3 +1,5 @@ +# S2SS clients + This directory contains code and projects to connect various simulators and tools to the S2SS server. From c75e03db7752a872f327ab9de2558abb02a50b3f Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 27 Sep 2015 16:04:15 +0200 Subject: [PATCH 05/10] moved some stuff to InetDistSim repository because it does not belong to S2SS --- contrib/liveusb/README.txt | 24 -------- contrib/liveusb/chroot.sh | 10 ---- contrib/liveusb/etc/default/grub | 7 --- contrib/liveusb/etc/hostname | 1 - contrib/liveusb/etc/hosts | 10 ---- contrib/liveusb/etc/image-release | 1 - contrib/liveusb/etc/image/setup.sh | 1 - contrib/liveusb/etc/modprobe.d/blacklist.conf | 3 - contrib/liveusb/etc/modprobe.d/e1000e.conf | 3 - contrib/liveusb/etc/sysconfig/ip6tables | 31 ---------- contrib/liveusb/etc/sysconfig/iptables | 34 ----------- contrib/liveusb/etc/sysconfig/network | 1 - .../etc/systemd/system/dhclient.service | 15 ----- .../etc/systemd/system/mongoose.service | 15 ----- .../liveusb/etc/systemd/system/setup.service | 16 ------ contrib/liveusb/etc/tuned/active_profile | 1 - contrib/liveusb/prepare.sh | 9 --- contrib/liveusb/setup.sh | 56 ------------------- contrib/liveusb/update_boot.sh | 24 -------- contrib/liveusb/yum-packages.txt | 56 ------------------- contrib/tinc.sh | 45 --------------- 21 files changed, 363 deletions(-) delete mode 100644 contrib/liveusb/README.txt delete mode 100755 contrib/liveusb/chroot.sh delete mode 100644 contrib/liveusb/etc/default/grub delete mode 100644 contrib/liveusb/etc/hostname delete mode 100644 contrib/liveusb/etc/hosts delete mode 100644 contrib/liveusb/etc/image-release delete mode 120000 contrib/liveusb/etc/image/setup.sh delete mode 100644 contrib/liveusb/etc/modprobe.d/blacklist.conf delete mode 100644 contrib/liveusb/etc/modprobe.d/e1000e.conf delete mode 100644 contrib/liveusb/etc/sysconfig/ip6tables delete mode 100644 contrib/liveusb/etc/sysconfig/iptables delete mode 100644 contrib/liveusb/etc/sysconfig/network delete mode 100644 contrib/liveusb/etc/systemd/system/dhclient.service delete mode 100644 contrib/liveusb/etc/systemd/system/mongoose.service delete mode 100644 contrib/liveusb/etc/systemd/system/setup.service delete mode 100644 contrib/liveusb/etc/tuned/active_profile delete mode 100644 contrib/liveusb/prepare.sh delete mode 100755 contrib/liveusb/setup.sh delete mode 100755 contrib/liveusb/update_boot.sh delete mode 100644 contrib/liveusb/yum-packages.txt delete mode 100755 contrib/tinc.sh diff --git a/contrib/liveusb/README.txt b/contrib/liveusb/README.txt deleted file mode 100644 index 05f6d6e24..000000000 --- a/contrib/liveusb/README.txt +++ /dev/null @@ -1,24 +0,0 @@ -S2SS LiveUSB Image -=================================================================== - -This archive contains an image of Fedora installation -which has been tuned for low latency and overall performance. -It facilitates the setup of a S2SS instance and is designed to be used -by partners of the Institute for Automation of Complex Power Systems (ACS). - -This image will automatically request an IP address via DHCP -and create a SSH tunnel to the central orchestration server. -This allows further configuration and control. - -The default credentials are: - - User: root - Password: s2ss-admin - -Copy image with bundled tool [1] to a USB stick or a harddisk. -The image is about 2GB in size. -IMPORTANT: All contents of the stick will be wiped! Make backups! - -[1] http://www.alexpage.de/usb-image-tool/ - -Contact: Steffen Vogel \ No newline at end of file diff --git a/contrib/liveusb/chroot.sh b/contrib/liveusb/chroot.sh deleted file mode 100755 index 6e02c1bed..000000000 --- a/contrib/liveusb/chroot.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -mount /dev/sdb1 /media/usb - -for part in dev sys proc; do - umount /media/usb/$part - mount -o bind /$part /media/usb/$part -done - -chroot /media/usb diff --git a/contrib/liveusb/etc/default/grub b/contrib/liveusb/etc/default/grub deleted file mode 100644 index d3bd7ac6b..000000000 --- a/contrib/liveusb/etc/default/grub +++ /dev/null @@ -1,7 +0,0 @@ -GRUB_TIMEOUT=5 -GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" -GRUB_DEFAULT=1 -GRUB_DISABLE_SUBMENU=false -GRUB_TERMINAL_OUTPUT="console" -GRUB_CMDLINE_LINUX="isolcpus=6,7 selinux=0 audit=0" -GRUB_DISABLE_RECOVERY=true diff --git a/contrib/liveusb/etc/hostname b/contrib/liveusb/etc/hostname deleted file mode 100644 index da598be9b..000000000 --- a/contrib/liveusb/etc/hostname +++ /dev/null @@ -1 +0,0 @@ -unknown-s2ss diff --git a/contrib/liveusb/etc/hosts b/contrib/liveusb/etc/hosts deleted file mode 100644 index 05fc89de2..000000000 --- a/contrib/liveusb/etc/hosts +++ /dev/null @@ -1,10 +0,0 @@ -127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 -::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - -# Orchestrator - -# ACS hosts -134.130.169.31 acs-s2ss -134.130.169.32 acs-gtfpga -137.226.160.69 acs-opal -137.226.160.115 acs-workstation diff --git a/contrib/liveusb/etc/image-release b/contrib/liveusb/etc/image-release deleted file mode 100644 index bd8b58947..000000000 --- a/contrib/liveusb/etc/image-release +++ /dev/null @@ -1 +0,0 @@ -0.5-turin diff --git a/contrib/liveusb/etc/image/setup.sh b/contrib/liveusb/etc/image/setup.sh deleted file mode 120000 index a645eb309..000000000 --- a/contrib/liveusb/etc/image/setup.sh +++ /dev/null @@ -1 +0,0 @@ -setup.sh \ No newline at end of file diff --git a/contrib/liveusb/etc/modprobe.d/blacklist.conf b/contrib/liveusb/etc/modprobe.d/blacklist.conf deleted file mode 100644 index 6874104fc..000000000 --- a/contrib/liveusb/etc/modprobe.d/blacklist.conf +++ /dev/null @@ -1,3 +0,0 @@ -blacklist snd_hda_intel -blacklist nouveau -blacklist mei_me diff --git a/contrib/liveusb/etc/modprobe.d/e1000e.conf b/contrib/liveusb/etc/modprobe.d/e1000e.conf deleted file mode 100644 index 74dea577d..000000000 --- a/contrib/liveusb/etc/modprobe.d/e1000e.conf +++ /dev/null @@ -1,3 +0,0 @@ -# More conservative interrupt throttling for better latency -# https://www.kernel.org/doc/Documentation/networking/e1000e.txt -option e1000e InterruptThrottleRate=1 diff --git a/contrib/liveusb/etc/sysconfig/ip6tables b/contrib/liveusb/etc/sysconfig/ip6tables deleted file mode 100644 index 13f6e5ed7..000000000 --- a/contrib/liveusb/etc/sysconfig/ip6tables +++ /dev/null @@ -1,31 +0,0 @@ -*filter -:INPUT ACCEPT -:FORWARD ACCEPT -:OUTPUT ACCEPT - -# Allow loopback traffic --A INPUT -i lo -j ACCEPT - -# Allow established connections, and those not coming from the outside --A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - -# Allow HTTP --A INPUT -p tcp --dport http -m conntrack --ctstate NEW -j ACCEPT - -# Allow SSH --A INPUT -p tcp --dport ssh -m conntrack --ctstate NEW -j ACCEPT - -# Allow Tinc --A INPUT -p udp --dport tinc -j ACCEPT --A INPUT -p tcp --dport tinc -j ACCEPT - -# Accept Pings --A INPUT -p icmpv6 -j ACCEPT - -# Reject everything else --A INPUT -j REJECT - -# We wont act as a router --A FORWARD -j REJECT - -COMMIT diff --git a/contrib/liveusb/etc/sysconfig/iptables b/contrib/liveusb/etc/sysconfig/iptables deleted file mode 100644 index cfdd9d2f3..000000000 --- a/contrib/liveusb/etc/sysconfig/iptables +++ /dev/null @@ -1,34 +0,0 @@ -*filter -:INPUT ACCEPT -:FORWARD ACCEPT -:OUTPUT ACCEPT - -# Allow loopback traffic --A INPUT -i lo -j ACCEPT - -# Allow established connections, and those not coming from the outside --A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - -# Allow HTTP --A INPUT -p tcp --dport http -m conntrack --ctstate NEW -j ACCEPT - -# Allow VPN --A INPUT -s 10.0.0.0/8 -j ACCEPT - -# Allow SSH --A INPUT -p tcp --dport ssh -m conntrack --ctstate NEW -j ACCEPT - -# Allow Tinc --A INPUT -p udp --dport tinc -j ACCEPT --A INPUT -p tcp --dport tinc -j ACCEPT - -# Accept Pings --A INPUT -p icmp -j ACCEPT - -# Reject everything else --A INPUT -j REJECT - -# We wont act as a router --A FORWARD -j REJECT - -COMMIT diff --git a/contrib/liveusb/etc/sysconfig/network b/contrib/liveusb/etc/sysconfig/network deleted file mode 100644 index 61c4a5ad8..000000000 --- a/contrib/liveusb/etc/sysconfig/network +++ /dev/null @@ -1 +0,0 @@ -NETWORKING=yes diff --git a/contrib/liveusb/etc/systemd/system/dhclient.service b/contrib/liveusb/etc/systemd/system/dhclient.service deleted file mode 100644 index 71f78f25f..000000000 --- a/contrib/liveusb/etc/systemd/system/dhclient.service +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=dhclient on all interfaces -Wants=network.target - -[Service] -Type=forking -ExecStart=/sbin/dhclient -4 -w - -Restart=on-failure -RestartSec=10 - -TimeoutSec=60 - -[Install] -WantedBy=network.target diff --git a/contrib/liveusb/etc/systemd/system/mongoose.service b/contrib/liveusb/etc/systemd/system/mongoose.service deleted file mode 100644 index 2ff7070d7..000000000 --- a/contrib/liveusb/etc/systemd/system/mongoose.service +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=The mongoose Web server -After=network.target - -[Service] -Type=simple -User=nobody -Group=nobody -Restart=always -ExecStart=/usr/bin/mongoose -p 80 -r /var/www/ -StandardOutput=syslog -SyslogIdentifier=mongoose - -[Install] -WantedBy=multi-user.target diff --git a/contrib/liveusb/etc/systemd/system/setup.service b/contrib/liveusb/etc/systemd/system/setup.service deleted file mode 100644 index b5ea9a011..000000000 --- a/contrib/liveusb/etc/systemd/system/setup.service +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=S2SS LiveUSB Image setup -Requires=network-online.target - -[Service] -Type=simple -ExecStart=/etc/image/setup.sh -RemainAfterExit=yes - -Restart=on-failure -RestartSec=10 - -TimeoutSec=60 - -[Install] -WantedBy=multi-user.target diff --git a/contrib/liveusb/etc/tuned/active_profile b/contrib/liveusb/etc/tuned/active_profile deleted file mode 100644 index 239b12e08..000000000 --- a/contrib/liveusb/etc/tuned/active_profile +++ /dev/null @@ -1 +0,0 @@ -latency-performance diff --git a/contrib/liveusb/prepare.sh b/contrib/liveusb/prepare.sh deleted file mode 100644 index eb7a9a755..000000000 --- a/contrib/liveusb/prepare.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -rpm -Uvh http://ccrma.stanford.edu/planetccrma/mirror/fedora/linux/planetccrma/20/i386/planetccrma-repo-1.1-3.fc20.ccrma.noarch.rpm - -yum update - -yum install planetccrma-core - -source update_boot.sh diff --git a/contrib/liveusb/setup.sh b/contrib/liveusb/setup.sh deleted file mode 100755 index e2918ff18..000000000 --- a/contrib/liveusb/setup.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -set -e - -RECIPIENTS="stvogel@eonerc.rwth-aachen.de,mstevic@eonerc.rwth-aachen.de" - -SERVER=s2ss.0l.de -USER=acs - -PORT=$(shuf -i 60000-65535 -n 1) - -# wait for working network connection -while ! curl http://canihazip.com/s &> /dev/null; do - sleep 1 -done - -IP=$(curl -s http://canihazip.com/s) -HOSTNAME=$(dig +short -x $IP) -if [ -z "$HOSTNAME" ]; then - HOSTNAME=$(hostname) -fi - -# check if system has net connectivity. otherwise die... -ssh -q -o ConnectTimeout=2 $USER@$SERVER - -# setup SSH tunnel for mail notification -ssh -f -N -L 25:localhost:25 $USER@$SERVER -# setup SSH reverse tunnel for remote administration -ssh -f -N -R $PORT:localhost:22 $USER@$SERVER - -# send mail with notification about new node -sendmail "$RECIPIENTS" < -To: $RECIPIENTS - -There's a new host with the S2SS LiveUSB Image running: - -Version: $(cat /etc/image-release) -Reverse SSH tunnel port: $PORT -Internet IP: $IP -Hostname: $HOSTNAME - -Latency: -$(ping -qc 5 $SERVER) - -Traceroute: -$(traceroute $SERVER) - -Interfaces: -$(ip addr) - -Hardware: -$(lshw) - -EOF diff --git a/contrib/liveusb/update_boot.sh b/contrib/liveusb/update_boot.sh deleted file mode 100755 index f0c87ca0e..000000000 --- a/contrib/liveusb/update_boot.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -# author: Christian Berendt - -set -x - -for kernel in $(find /boot/vmlinuz*); do - version=$(basename $kernel) - version=${version#*-} - if [ ! -e /boot/initramfs-$version.img ]; then - sudo /usr/bin/dracut /boot/initramfs-$version.img $version - fi -done - -for image in $(find /boot/initramfs*); do - version=${image%.img} - version=${version#*initramfs-} - if [ ! -e /boot/vmlinuz-$version ]; then - sudo rm $image - fi -done - -/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg - diff --git a/contrib/liveusb/yum-packages.txt b/contrib/liveusb/yum-packages.txt deleted file mode 100644 index 0a5117f19..000000000 --- a/contrib/liveusb/yum-packages.txt +++ /dev/null @@ -1,56 +0,0 @@ -authconfig-6.2.6-4.fc20.x86_64 -automake-1.13.4-6.fc20.noarch -bash-completion-2.1-3.fc20.noarch -bind-utils-9.9.4-18.P2.fc20.x86_64 -biosdevname-0.5.0-2.fc20.x86_64 -bzip2-1.0.6-9.fc20.x86_64 -dhclient-4.2.7-2.fc20.x86_64 -dosfstools-3.0.27-1.fc20.x86_64 -dracut-config-rescue-037-11.git20140402.fc20.x86_64 -e2fsprogs-1.42.12-3.fc20.x86_64 -efibootmgr-0.11.0-1.fc20.x86_64 -ftp-0.17-65.fc20.x86_64 -gcc-4.8.3-7.fc20.x86_64 -gdb-7.7.1-21.fc20.x86_64 -gdisk-0.8.10-2.fc20.x86_64 -git-svn-1.9.3-2.fc20.x86_64 -grub2-2.00-27.fc20.x86_64 -htop-1.0.3-3.fc20.x86_64 -iptables-services-1.4.19.1-1.fc20.x86_64 -kbd-1.15.5-12.fc20.x86_64 -kernel-modules-extra-3.18.9-100.fc20.x86_64 -kernel-rt-modules-extra-3.14.29-200.rt26.1.fc20.ccrma.x86_64 -libconfig-1.4.9-5.fc20.x86_64 -lshw-B.02.17-2.fc20.x86_64 -lzo-devel-2.08-1.fc20.x86_64 -mailx-12.5-11.fc20.x86_64 -man-db-2.6.5-6.fc20.x86_64 -minicom-2.6.2-4.fc20.x86_64 -nano-2.3.2-5.fc20.x86_64 -nmap-6.45-1.fc20.x86_64 -ntp-4.2.6p5-20.fc20.x86_64 -numactl-2.0.9-2.fc20.x86_64 -openssh-server-6.4p1-8.fc20.x86_64 -openssl-devel-1.0.1e-41.fc20.x86_64 -parted-3.1-13.fc20.x86_64 -passwd-0.79-2.fc20.x86_64 -patch-2.7.1-7.fc20.x86_64 -pciutils-devel-3.3.0-1.fc20.x86_64 -planetccrma-repo-1.1-3.fc20.ccrma.noarch -policycoreutils-2.2.5-4.fc20.x86_64 -psmisc-22.20-3.fc20.x86_64 -readline-devel-6.2-10.fc20.x86_64 -rootfiles-8.1-16.fc20.noarch -schedtool-1.3.0-9.fc20.x86_64 -screen-4.1.0-0.19.20120314git3c2946.fc20.x86_64 -setserial-2.17-34.fc20.x86_64 -socat-1.7.2.4-1.fc20.x86_64 -ssmtp-2.64-14.fc20.x86_64 -sudo-1.8.12-1.fc20.x86_64 -tar-1.26-31.fc20.x86_64 -tcpdump-4.5.1-3.fc20.x86_64 -texinfo-5.1-4.fc20.x86_64 -traceroute-2.0.20-1.fc20.x86_64 -tuned-2.4.1-3.fc20.noarch -wget-1.16.1-2.fc20.x86_64 -yum-utils-1.1.31-27.fc20.noarch diff --git a/contrib/tinc.sh b/contrib/tinc.sh deleted file mode 100755 index a93de032d..000000000 --- a/contrib/tinc.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh - -# die on error -set -e - -if [ "$(hostname)" != "acs-s2ss" ]; then - echo "This script has to be run only acs-s2ss!" 1>&2 - exit 1 -fi - -if [ "$(id -u)" != "0" ]; then - echo -e "This script must be run as root" 1>&2 - exit 1 -fi - -IP=78.91.103.24 -PORT=12010 -IPT=iptables -RULE1="-p udp --dport $PORT -s $IP -j REJECT" -RULE2="-p tcp --dport $PORT -s $IP -j REJECT" - -case $1 in - block) - $IPT -I INPUT 1 $RULE1 - $IPT -I INPUT 1 $RULE2 - service tincd restart - ;; - - unblock) - $IPT -D INPUT $RULE1 - $IPT -D INPUT $RULE2 - service tincd restart - ;; - - status) - $IPT -C INPUT $RULE1 && echo "Tinc UDP is blocked" - $IPT -C INPUT $RULE2 && echo "Tinc TCP is blocked" - - echo -n "Sintef " - tinc -n s2ss info sintef | grep "Reachability" - - echo -n "Frankfurt " - tinc -n s2ss info fra | grep "Reachability" - ;; -esac From 2c669866dd5fbca8dd769e2a6731e2e87022ebec Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 27 Sep 2015 17:53:39 +0200 Subject: [PATCH 06/10] fixed typo in Makefile --- server/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Makefile b/server/Makefile index a0d010e39..88b65f1d0 100644 --- a/server/Makefile +++ b/server/Makefile @@ -31,7 +31,7 @@ endif # Enable file node type support ifndef DISABLE_FILE override CFLAGS += -DENABLE_FILE - OBJS += ngsi.o + OBJS += file.o endif # Enable Socket node type when libnl3 is available From cf152ad4e06abbdfaba490b7f68e34ad3a9f5b9a Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 27 Sep 2015 18:03:41 +0200 Subject: [PATCH 07/10] updated build dependencies in documentation --- documentation/Install.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/Install.md b/documentation/Install.md index d70aaf05e..a509fef1e 100644 --- a/documentation/Install.md +++ b/documentation/Install.md @@ -12,11 +12,11 @@ Install libraries including developement headers for: Use the following command to install the dependencies under Debian-based distributions: - $ sudo apt-get install libconfig-dev libnl-3-dev libnl-route-3-dev + $ sudo apt-get install build-essential pkg-config libconfig-dev libnl-3-dev libnl-route-3-dev libpci-deb libjansson-dev libcurl4-openssl-dev uuid-dev or the following line for Fedora / CentOS / Redhat systems: - $ sudo yum install iproute2 libconfig-devel libnl3-devel + $ sudo yum install pkgconfig gcc make libconfig-devel libnl3-devel pciutils-devel libcurl-devel jansson-devel libuuid-devel **Important:** Please note that the server requires the [iproute2](http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2) From eee4d6151382a3c6ef709d385bf59b571f5cc74a Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 27 Sep 2015 18:05:35 +0200 Subject: [PATCH 08/10] fixed another unimportant typo --- server/src/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/server.c b/server/src/server.c index 0ef40890d..589a8582f 100644 --- a/server/src/server.c +++ b/server/src/server.c @@ -111,7 +111,7 @@ static void usage(const char *name) #ifdef ENABLE_SOCKET printf(" - socket: Network socket (libnl3)\n"); #endif -#ifdef ENABLE_PCI +#ifdef ENABLE_GTFPGA printf(" - gtfpga: GTFPGA PCIe card (libpci)\n"); #endif #ifdef ENABLE_OPAL_ASYNC From 74d163db555e3df70820c68c4558e4132f5c287a Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 27 Sep 2015 20:27:47 +0200 Subject: [PATCH 09/10] fixed reference counting for jansson objects --- server/src/ngsi.c | 66 ++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/server/src/ngsi.c b/server/src/ngsi.c index 06eb187c1..161e3a5eb 100644 --- a/server/src/ngsi.c +++ b/server/src/ngsi.c @@ -113,6 +113,8 @@ static int ngsi_request(CURL *handle, json_t *content, json_t **response) if (response) *response = resp; + else + json_decref(resp); free(post); free(chunk.data); @@ -124,27 +126,27 @@ void ngsi_prepare_context(struct node *n, config_setting_t *mapping) { struct ngsi *i = n->ngsi; - i->context = json_object(); - json_t *elements = json_array(); - - json_object_set(i->context, "contextElements", elements); - + i->context = json_object(); i->context_len = config_setting_length(mapping); i->context_map = alloc(i->context_len * sizeof(json_t *)); + + json_t *elements = json_array(); for (int j = 0; j < i->context_len; j++) { + /* Get token */ config_setting_t *ctoken = config_setting_get_elem(mapping, j); - const char *stoken = config_setting_get_string(ctoken); if (!stoken) cerror(mapping, "Invalid token"); + /* Parse token */ char eid[64], etype[64], aname[64], atype[64]; if (sscanf(stoken, "%63[^().](%63[^().]).%63[^().](%63[^().])", eid, etype, aname, atype) != 4) cerror(ctoken, "Invalid token: '%s'", stoken); /* Create entity */ - json_t *attributes; + json_t *attributes; /* borrowed reference */ + json_t *entity = json_lookup(elements, "id", eid); if (!entity) { entity = json_pack("{ s: s, s: s, s: b }", @@ -152,10 +154,10 @@ void ngsi_prepare_context(struct node *n, config_setting_t *mapping) "type", etype, "isPattern", 0 ); + json_array_append_new(elements, entity); attributes = json_array(); - json_object_set(entity, "attributes", attributes); - json_array_append(elements, entity); + json_object_set_new(entity, "attributes", attributes); } else { if (i->structure == NGSI_CHILDREN) @@ -164,55 +166,55 @@ void ngsi_prepare_context(struct node *n, config_setting_t *mapping) attributes = json_object_get(entity, "attributes"); } - /* Create attribute */ + /* Create attribute for entity */ if (json_lookup(attributes, "name", aname)) cerror(ctoken, "Duplicated attribute '%s' in NGSI mapping of node '%s'", aname, n->name); - json_t *metadatas; - json_t *attribute = json_pack("{ s: s, s: s, s: s }", - "name", aname, - "type", atype, - "value", "0" - ); + /* Create Metadata for attribute */ + json_t *metadatas = json_array(); - metadatas = json_array(); - json_object_set(attribute, "metadatas", metadatas); - - /* Metadata */ - json_array_append(metadatas, json_pack("{ s: s, s: s, s: s }", + json_array_append_new(metadatas, json_pack("{ s: s, s: s, s: s }", "name", "source", "type", "string", "value", "s2ss" )); - json_array_append(metadatas, json_pack("{ s: s, s: s, s: i }", + json_array_append_new(metadatas, json_pack("{ s: s, s: s, s: i }", "name", "index", "type", "integer", "value", j )); if (i->structure == NGSI_CHILDREN) { - json_array_append(attributes, json_pack("{ s: s, s: s, s: s }", + json_array_append_new(attributes, json_pack("{ s: s, s: s, s: s }", "name", "parentId", "type", "uuid", "value", eid )); - json_array_append(attributes, json_pack("{ s: s, s: s, s: s }", + json_array_append_new(attributes, json_pack("{ s: s, s: s, s: s }", "name", "source", "type", "string", "value", "measurement" )); - json_array_append(attributes, json_pack("{ s: s, s: s, s: o }", + json_array_append_new(attributes, json_pack("{ s: s, s: s, s: o }", "name", "timestamp", "type", "date", "value", json_date(NULL) )); } - json_array_append(attributes, attribute); - i->context_map[j] = attribute; + json_t *attribute = i->context_map[j] = json_pack("{ s: s, s: s, s: s }", + "name", aname, + "type", atype, + "value", "0" + ); + + json_object_set_new(attribute, "metadatas", metadatas); + json_array_append_new(attributes, attribute); } + + json_object_set_new(i->context, "contextElements", elements); } int ngsi_init(int argc, char *argv[], struct settings *set) @@ -300,7 +302,7 @@ int ngsi_open(struct node *n) curl_easy_setopt(i->curl, CURLOPT_HTTPHEADER, i->headers); /* Create entity and atributes */ - json_object_set(i->context, "updateAction", json_string("APPEND")); + json_object_set_new(i->context, "updateAction", json_string("APPEND")); return ngsi_request(i->curl, i->context, NULL) == 200 ? 0 : -1; } @@ -309,7 +311,7 @@ int ngsi_close(struct node *n) struct ngsi *i = n->ngsi; /* Delete attributes */ - json_object_set(i->context, "updateAction", json_string("DELETE")); + json_object_set_new(i->context, "updateAction", json_string("DELETE")); int code = ngsi_request(i->curl, i->context, NULL) == 200 ? 0 : -1; curl_easy_cleanup(i->curl); @@ -351,12 +353,12 @@ int ngsi_write(struct node *n, struct msg *pool, int poolsize, int first, int cn json_t *entity, *elements = json_object_get(i->context, "contextElements"); size_t ind; json_array_foreach(elements, ind, entity) - json_object_set(entity, "id", json_uuid()); + json_object_set_new(entity, "id", json_uuid()); - json_object_set(i->context, "updateAction", json_string("APPEND")); + json_object_set_new(i->context, "updateAction", json_string("APPEND")); } else - json_object_set(i->context, "updateAction", json_string("UPDATE")); + json_object_set_new(i->context, "updateAction", json_string("UPDATE")); json_t *response; int code = ngsi_request(i->curl, i->context, &response); From 46bd8a011efda40dafb8efac436cf3ce17e92bb5 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 28 Sep 2015 19:16:02 +0200 Subject: [PATCH 10/10] added "deduplication" hook: do not send messages which are too similar to their precursors --- server/include/config.h | 8 +++++--- server/include/hooks.h | 3 +++ server/src/hooks.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/server/include/config.h b/server/include/config.h index 5dec0bcd8..bbd2094f5 100644 --- a/server/include/config.h +++ b/server/include/config.h @@ -53,10 +53,12 @@ { "/dev/sda2", "\x53\xf6\xb5\xeb\x8b\x16\x46\xdc\x8d\x8f\x5b\x70\xb8\xc9\x1a\x2a", 0x468 } } /* Hook function configuration */ -#define HOOK_FIR_INDEX 1 /**< The first value of message should be filtered. */ -#define HOOK_TS_INDEX -1 /**< The last value of message should be overwritten by a timestamp. */ -#define HOOK_DECIMATE_RATIO 30 /**< Only forward every 30th message to the destination nodes. */ +#define HOOK_FIR_INDEX 1 /**< The first value of message should be filtered. */ +#define HOOK_TS_INDEX -1 /**< The last value of message should be overwritten by a timestamp. */ +#define HOOK_DECIMATE_RATIO 30 /**< Only forward every 30th message to the destination nodes. */ +#define HOOK_DEDUP_TYPE HOOK_ASYNC +#define HOOK_DEDUP_TRESH 1e-3 /**< Do not send messages when difference of values to last message is smaller than this threshold */ /** Global configuration */ struct settings { /** Process priority (lower is better) */ diff --git a/server/include/hooks.h b/server/include/hooks.h index 8cc8094ae..b54e11f82 100644 --- a/server/include/hooks.h +++ b/server/include/hooks.h @@ -76,6 +76,9 @@ struct hook { * @{ */ +/** Example hook: Drop messages whose values are similiar to the previous ones */ +int hook_deduplicate(struct path *); + /** Example hook: Print the message. */ int hook_print(struct path *p); diff --git a/server/src/hooks.c b/server/src/hooks.c index 733d2ba9b..8647c48c7 100644 --- a/server/src/hooks.c +++ b/server/src/hooks.c @@ -13,6 +13,7 @@ *********************************************************************************/ #include +#include #include "timing.h" #include "config.h" @@ -25,6 +26,33 @@ struct list hooks; +REGISTER_HOOK("deduplicate", 99, hook_deduplicate, HOOK_DEDUP_TYPE) +int hook_deduplicate(struct path *p) +{ + int ret = 0; +#if HOOK_DEDUP_TYPE == HOOK_ASYNC + /** Thread local storage (TLS) is used to maintain a copy of the last run of the hook */ + static __thread struct msg previous = MSG_INIT(0); + struct msg *prev = &previous; +#else + struct msg *prev = p->previous; +#endif + struct msg *cur = p->current; + + for (int i = 0; i < MIN(cur->length, prev->length); i++) { + if (fabs(cur->data[i].f - prev->data[i].f) > HOOK_DEDUP_TRESH) + goto out; + } + + ret = -1; /* no appreciable change in values, we will drop the packet */ + +out: +#if HOOK_DEDUP_TYPE == HOOK_ASYNC + memcpy(prev, cur, sizeof(struct msg)); /* save current message for next run */ +#endif + return ret; +} + REGISTER_HOOK("print", 99, hook_print, HOOK_MSG) int hook_print(struct path *p) {