UnModbusRedirect

Setup:

The redirectModbus.sh script is distributed with this component, in the folder

data/unModbusRedirect

Itneeds to be set up for execution though sudo with /etc/sudoers entry such as

scada ALL = (root) NOPASSWD: /opt/scada/PVSS_projects/redirectModbus.sh



In CERN production systems the command is often installed as

/acc/sys/default/pvss/tools/RedirectModbus/redirectModbus.sh

and hence the /etc/sudoers entries may differ

Configuration:

The configuration file needs to be created, with tab-separated entries (one per line) in the following format

PLC_IP	PORT_NUMBER	<PROJECT_NAME>	<DRIVER_NUMBER> <# COMMMENT>



The PLC_IP and PORT_NUMBER are mandatory; entries that start with the "#" character will be kept as comments; empty lines are skipped.

The recommended location for the configuration file is

/opt/unicryo/PVSS_projects/redirectModbus.cfg 

and it will be automatically recognized by the tool; otherwise it needs to be specified explicitly with the -cfg flag (See below)

Execution:

With proper configuration, the redirection could be executed with a command such as

sudo /acc/sys/default/pvss/tools/RedirectModbus/redirectModbus.sh -configure

Custom location for configuration file may be specified with the "-cfg <myconffile>" option.

For more options of calling the script please refer to the technical documentation chapter below



Technical Documentation:

Note that the same documenation may be found in the comment at the top of the redirectModbus.sh script.

# Usage:
# 1) [sudo] redirectModbus.sh -configure
# -> reads the configuration from the default file /opt/unicryo/PVSS_projects/redirectModbus.cfg
# keeping/modifying the current redirects based on the parameters from config file
# 2) [sudo] redirectModbus.sh -configure -cfg /opt/someuser/redirectModbus.cfg
# -> reads the configuration from the specific config file /opt/someuser/redirectModbus.cfg
# keeping/modifying the current redirects based on the parameters from config file
# 3) [sudo] redirectModbus.sh -configureClear
# -> reads the configuration from /opt/unicryo/PVSS_projects/redirectModbus.cfg
# clears all the current redirects and replaces with the ones from config file
# 4) [sudo] redirectModbus.sh -configureClear -cfg /opt/someuser/redirectModbus.cfg
# -> reads the configuration from specific config file /opt/someuser/redirectModbus.cfg
# clears all the current redirects and replaces with the ones from config file
# 5) [sudo] redirectModbus.sh -clear
# -> clears all the redirects
# 6) [sudo] redirectModubus.sh -status
# -> display the currently active redirection map
# 7) [sudo] redirectModubus.sh <PLC_IP> <WCCOAmod_port>
# -> applies a single redirection (see below)
#
# Description:
# ------------
# This script reconfigures the Linux IP stack (iptables) to reroute the
# packets for the PVSS MODBUS driver (port 502), so that many projects could run
# on the same machine.
#
# The scripts allow to configure the redirection of packets depending on the IP
# address they are coming from. The packets are redirected to the same machine,
# yet to a specified port.
#
# Such solution solves a problem of MODBUS in "push" mode, where the destination
# TCP/IP port needs to be equal to 502. If we want to run multiple PVSS projects
# in the same machine, we need more instances of the MODBUS driver running,
# and each of them needs to listen on a different TCP/IP port.
#
# The script needs to be executed by root or by a user with sudo rights
# (in the latter case, sudo may prompt for user's password).
#
# Note that the script is intelligent enough to see whether the redirection
# rule already exists for a specified PLC and
# adapts the settings appropriately
#
# Example:
# --------
# PLC1 (172.18.25.136) should be connected to WCCOAmod of Project1
# PLC2 (172.18.37.9) should be connected to WCCOAmod of Project2
#
# - configure WCCOAmod on Project1 to start with port number 8502
# and on Project2 with port number 9502. You do it in the config file, eg
# for Project1:
# [mod_2]
# tcpServerPort=8502
#
# - to activate the redirection, execute
# redirectModbus.sh 172.18.25.136 8502
# redirectModbus.sh 172.18.37.9 9502
#
# For more details about the origins, look, for instance, at:
# https://icecontrols.cern.ch/jira/browse/ENS-1922
# https://icecontrols.cern.ch/jira/browse/ENS-3875
# look also at https://icecontrols.cern.ch/jira/browse/SCD-37

Example of configuration file:



# Format: tab separated lines, one entry per redirection
# PLC_IP PORT_NUMBER <PROJECT_NAME> <DRIVER_NUMBER> <#COMMENT>
192.168.1.100 5120 Proj1 2
192.168.1.101 5121 Proj1 3 # This one for test
# The line below is the most minimalistic form
192.168.1.201 5201