Skip to content

Commit

Permalink
Modificacion Multicast en varias subredes
Browse files Browse the repository at this point in the history
Modificación que permite hacer uso la restauración Multicast en un escenario en el que el servidor donde se aloja el servidor de opengnsys es la puerta de acceso a los clientes de Opengnsys y se posee varias subredes. Esto es necesario a que udp-sender se asocia directamente a la interfaz con la que se inicia la comunicación no permitiendo usar tablas de enrutamiento o método similares para reenviar el tráfico por una interfaz concreta.
Esta modificación no es válida en el caso en que el servidor de Opengnsys no sea la puerta de enlace debido a este comando que es usado para determinar la dirección IP que se usara para establecer la comunicación entre cliente y servidor
           ip route show 0.0.0.0/0 | cut -d\  -f3
Sería necesario encontrar una alternativa donde en la que tanto el cliente como el servidor puede determinar la dirección IP de la interfaz del servidor con la cual se comunica ambos.
  • Loading branch information
danmasber committed Nov 30, 2020
1 parent 2f9f649 commit 1384b09
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 52 deletions.
5 changes: 3 additions & 2 deletions admin/Sources/Services/ogAdmRepoAux
Expand Up @@ -78,8 +78,9 @@ case "$PARM1" in
#3 opciones de multicast
FILE="$PARM2"
MCASTOPT="$PARM3"
echolog "Ejecutar $(which sendFileMcast) $FILE $MCASTOPT"
sendFileMcast $FILE $MCASTOPT &>> $MCASTLOG
IPINTEFAZ="$PARM4"
echolog "Ejecutar $(which sendFileMcast) $FILE $MCASTOPT $IPINTEFAZ"
sendFileMcast $FILE $MCASTOPT $IPINTEFAZ &>> $MCASTLOG
case $? in
1) echolog "Parametros insuficientes"
exit 1 ;;
Expand Down
47 changes: 5 additions & 42 deletions client/engine/Protocol.lib
Expand Up @@ -451,46 +451,8 @@ then
SERVERADDRESS=" --mcast-rdv-address ${SESSION[1]}"
else
# Deteccion automatica de la subred del cliente para anadir la IP del repositorio a la orden udp-receiver en el caso de encontrarse en distinta subred del repo
REPOIP="$(ogGetRepoIp)"
CLIENTIP=$(ip -o address show up | awk '$2!~/lo/ {if ($3~/inet$/) {printf ("%s ", $4)}}')
MASCARA=`echo $CLIENTIP | cut -f2 -d/`
CLIENTIP=`echo $CLIENTIP | cut -f1 -d/`
RIPBT=""
IPBT=""
for (( i = 1 ; i < 5 ; i++ ))
do
RIP=`echo $REPOIP | cut -f$i -d.`
RIP=`echo "$[$RIP + 256]"`
RIPB=""
while [ $RIP -gt 0 ]
do
let COCIENTE=$RIP/2
let RESTO=$RIP%2
RIPB=$RESTO$RIPB
RIP=$COCIENTE
done
RIPB=`echo "$RIPB" | cut -c2-`
RIPBT=$RIPBT$RIPB
IP=`echo $CLIENTIP | cut -f$i -d.`
IP=`echo "$[$IP + 256]"`
IPB=""
while [ $IP -gt 0 ]
do
let COCIENTE=$IP/2
let RESTO=$IP%2
IPB=$RESTO$IPB
IP=$COCIENTE
done
IPB=`echo "$IPB" | cut -c2-`
IPBT=$IPBT$IPB
done
REPOSUBRED=`echo $RIPBT | cut -c1-$MASCARA`
CLIENTSUBRED=`echo $IPBT | cut -c1-$MASCARA`
if [ $REPOSUBRED == $CLIENTSUBRED ]; then
SERVERADDRESS=" "
else
SERVERADDRESS=" --mcast-rdv-address $REPOIP"
fi
REPOIP="$(ip route show 0.0.0.0/0 | cut -d\ -f3)"
SERVERADDRESS=" --mcast-rdv-address $REPOIP"
fi
#La tercera opcion de la sesion para el cliente: ${SESSION[2]} ERRORSESSION - TIMEOUT ERROR IF NO FOUNT SESSEION MULTICAST
if ogCheckStringInReg ${SESSION[2]} "^[0-9]{1,10}$" &>/dev/null
Expand Down Expand Up @@ -855,15 +817,16 @@ PROTOOPT="$2"
PORT=$(echo $2 | cut -f1 -d":")
let PORTAUX=$PORT+1
REPOIP=$(ogGetRepoIp)
REPOIPAUX=$(ip route show 0.0.0.0/0 | cut -d\ -f3)
REPOPORTAUX=2009
REPEAT=0
until nmap -n -sU -p $PORTAUX $REPOIP | grep open
until nmap -n -sU -p $PORTAUX $REPOIPAUX | grep open
do
let REPEAT=$REPEAT+1
[ "$REPEAT" -lt 6 ] || ogRaiseError session log $OG_ERR_PROTOCOLJOINMASTER "MULTICAST \"$FILE\" \"$PROTOOPT\" $FILELIST" || return $?
echo "$MSG_SCRIPTS_TASK_START : hose $REPOIP $REPOPORTAUX --out sh -c "echo -ne START_MULTICAST $FILE $2""
#update-cache:
hose $REPOIP $REPOPORTAUX --out sh -c "echo -ne START_MULTICAST "$FILE" "$PROTOOPT""
hose $REPOIP $REPOPORTAUX --out sh -c "echo -ne START_MULTICAST "$FILE" "$PROTOOPT" "$REPOIPAUX""
#multicas-direct: hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST /$IMAGE.img $OPTPROTOCOLO"
sleep 10
done
Expand Down
5 changes: 4 additions & 1 deletion client/shared/scripts/restoreImage
Expand Up @@ -90,7 +90,10 @@ case "$PROTO" in
#TODO comprobar parametros anteriores
ogEcho log session "[40] ogMcastReceiverPartition $DISK $PART $PORT $TOOL $COMPRESS"
ogMcastRequest "$IMGNAME.img" "$PROTOOPT" || exit $?
ogExecAndLog command ogMcastReceiverPartition "$DISK" "$PART" "$PORT" "$TOOL" "$COMPRESS"
NUMBER=$[ ( $RANDOM % 30 ) + 10 ]
ogEcho log session "[40] Esperando $NUMBER segundos para iniciar la conexion multicast"
sleep $NUMBER
ogExecAndLog command ogMcastReceiverPartition "$DISK" "$PART" "$PORT" "$TOOL" "$COMPRESS"
RETVAL=$?
;;
*) # Protocolo desconocido.
Expand Down
6 changes: 6 additions & 0 deletions repoman/bin/getRepoIface
Expand Up @@ -6,4 +6,10 @@

source /opt/opengnsys/etc/ogAdmRepo.cfg

#Si recibe una ip devolvera la interfaz donde se encuantre es IP asignada
if [ $# -eq 1 ]; then
IPlocal="$1"
fi


ip addr show | grep $IPlocal | cut -f2 | awk '{ print $NF }'
30 changes: 23 additions & 7 deletions repoman/bin/sendFileMcast
@@ -1,3 +1,4 @@

#!/bin/bash
#@brief Envía un fichero por multicast ORIGEN(fichero) DESTINO(sessionmulticast)
#@param path_file Camino completo del fichero a enviar
Expand All @@ -13,17 +14,33 @@ REPO_IFACE="$(/opt/opengnsys/bin/getRepoIface)"

# Si se solicita, mostrar ayuda.
if [ "$*" == "help" ]; then
echo "Formato: $PROG fichero|nombreImagen datosMulticast"
echo "Formato: $PROG fichero|nombreImagen datosMulticast [IPaAsociar]"
echo "Ejemplo: $PROG /opt/opengnsys/images/imagen1.pgz 9000:full-duplex:239.194.17.2:70M:20:120"
echo "Ejemplo: $PROG imagen1 9000:full:239.194.17.2:70M:20:120"
echo "Ejemplo: $PROG /opt/opengnsys/images/imagen1.pgz 9000:full-duplex:239.194.17.2:70M:20:120 172.17.2.1"
echo "Ejemplo: $PROG imagen1 9000:full:239.194.17.2:70M:20:120 172.17.2.1"
exit 0
fi
# Error si no se reciben 2 parámetros.
if [ $# -ne 2 ]; then
echo "$PROG Error: Formato: $PROG fichero|nombreImagen datosMulticast"
if [ $# -le 2 ]; then
echo "$PROG Error: Formato: $PROG fichero|nombreImagen datosMulticast [IPaAsociar]"
exit 1
fi

# Si se introdujo como argumento una interfaz a asociar se calculara la interfaz asociada a esta,
# sino se asociara a la interfaz por defecto de Opengnsys
if [ $# -eq 3 ]; then
REPO_IFACE="$(/opt/opengnsys/bin/getRepoIface $3)"
# De no poder calcularse se asignara a la interfaz por defecto de Opengnsys
if [ "$REPO_IFACE" == "" ]; then
REPO_IFACE="$(/opt/opengnsys/bin/getRepoIface)"
fi
else
REPO_IFACE="$(/opt/opengnsys/bin/getRepoIface)"
fi



# Fichero a enviar (camino completo o relativo al directorio del repositorio).
FICH="$1"
if [ "${FICH:0:15}" != "$OPENGNSYS" ]; then
Expand Down Expand Up @@ -56,8 +73,7 @@ fi
# Valores estandar no configurables.
CERROR="8x8/128"

# Envío de fichero por Multicast.
# Se desabilita el uso de mbuffer: esta versión del upd-sender no la admite.
#which mbuffer &> /dev/null && MBUFFER="--pipe 'mbuffer -m 20M'"
$OGBIN/udp-sender "$MBUFFER" --nokbd --retries-until-drop 65 --portbase "$PORTBASE" "$METHOD" --interface "$REPO_IFACE" --mcast-data-address "$ADDRESS" --fec "$CERROR" --max-bitrate "$BITRATE" --ttl 16 --min-clients "$NCLIENTS" --max-wait "$MAXTIME" --file "$FICHIMG"
$OGBIN/udp-sender "$MBUFFER" --nokbd --retries-until-drop 65 --interface "$REPO_IFACE" --portbase "$PORTBASE" "$METHOD" --mcast-data-address "$ADDRESS" --fec "$CERROR" --max-bitrate "$BITRATE" --ttl 16 --min-clients "$NCLIENTS" --max-wait "$MAXTIME" --file "$FICHIMG"



0 comments on commit 1384b09

Please sign in to comment.