Supports IPv6 address for scp and rsync

ONOS-7680

Change-Id: Ica7466715c64765310bfc7bf34126ed02d1818b7
diff --git a/tools/build/build-offline-karaf b/tools/build/build-offline-karaf
index 76b0fd1..f7f4a63 100755
--- a/tools/build/build-offline-karaf
+++ b/tools/build/build-offline-karaf
@@ -11,7 +11,7 @@
 # get a small cell
 source ${ONOS_ROOT}/tools/dev/bash_profile
 cell borrow 60 1+0
-scp /tmp/${KARAF_TARFILE_NAME}.gz sdn@${OC1}:/tmp/${KARAF_TARFILE_NAME}.gz
+scp /tmp/${KARAF_TARFILE_NAME}.gz sdn@[${OC1}]:/tmp/${KARAF_TARFILE_NAME}.gz
 
 ssh sdn@${OC1} "
 
@@ -52,7 +52,7 @@
 
 # fetch the new offline karaf tar ball
 BUILD_NUMBER="apache-karaf-${KARAF_VERSION}-offline-$(date +'%Y%m%d')"
-scp sdn@${OC1}:karaf-offline.tar.gz /tmp/${BUILD_NUMBER}.tar.gz
+scp sdn@[${OC1}]:karaf-offline.tar.gz /tmp/${BUILD_NUMBER}.tar.gz
 
 cell return
 
diff --git a/tools/test/bin/onos-config b/tools/test/bin/onos-config
index 84b9764..97519b8 100755
--- a/tools/test/bin/onos-config
+++ b/tools/test/bin/onos-config
@@ -30,6 +30,7 @@
 
 node=${1:-$OCI}
 remote=$ONOS_USER@$node
+remote_scp=$ONOS_USER@[$node]
 
 # ONOS boot features
 export ONOS_BOOT_FEATURES="${ONOS_BOOT_FEATURES:-webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui}"
@@ -64,11 +65,11 @@
 # Generate a default cluster.json from the ON* environment variables
 CDEF_FILE=/tmp/${remote}.cluster.json
 onos-gen-partitions $CDEF_FILE
-scp -q $CDEF_FILE $remote:$ONOS_INSTALL_DIR/config/cluster.json
+scp -q $CDEF_FILE $remote_scp:$ONOS_INSTALL_DIR/config/cluster.json
 
 # Copy tools/package/config/ to remote
-scp -qr ${ONOS_ROOT}/tools/package/config/ $remote:$ONOS_INSTALL_DIR/
+scp -qr ${ONOS_ROOT}/tools/package/config/ $remote_scp:$ONOS_INSTALL_DIR/
 
 # Copy the desired initial network configuration to remote if needed
 [ -n "$ONOS_CFG" -a -f "$ONOS_CFG" -a "${1:-$OCI}" = "$OC1" ] && \
-    scp $ONOS_CFG $remote:$ONOS_INSTALL_DIR/config/network-cfg.json || true
+    scp $ONOS_CFG $remote_scp:$ONOS_INSTALL_DIR/config/network-cfg.json || true
diff --git a/tools/test/bin/onos-fetch-db b/tools/test/bin/onos-fetch-db
index b25adbf..6bf0ad5 100755
--- a/tools/test/bin/onos-fetch-db
+++ b/tools/test/bin/onos-fetch-db
@@ -39,6 +39,6 @@
 for node in $nodes; do
     echo "fetching from ${node}..."
     mkdir -p ${node}
-    scp -p -r $ONOS_USER@${node}:$ONOS_INSTALL_DIR/karaf/data/partitions/* ./${node}/
+    scp -p -r $ONOS_USER@[${node}]:$ONOS_INSTALL_DIR/karaf/data/partitions/* ./${node}/
 done
 
diff --git a/tools/test/bin/onos-fetch-logs b/tools/test/bin/onos-fetch-logs
index 4a866d6..bfcbd5a 100755
--- a/tools/test/bin/onos-fetch-logs
+++ b/tools/test/bin/onos-fetch-logs
@@ -39,5 +39,5 @@
 for node in $nodes; do
     echo "fetching from ${node}..."
     mkdir -p ${node}
-    scp -p $ONOS_USER@${node}:$ONOS_INSTALL_DIR/log/karaf.log* ./${node}/
+    scp -p $ONOS_USER@[${node}]:$ONOS_INSTALL_DIR/log/karaf.log* ./${node}/
 done
diff --git a/tools/test/bin/onos-install b/tools/test/bin/onos-install
index 7eb881a..391640c 100755
--- a/tools/test/bin/onos-install
+++ b/tools/test/bin/onos-install
@@ -55,10 +55,11 @@
 
 node=${1:-$OCI}
 remote=$ONOS_USER@$node
+remote_scp=$ONOS_USER@[$node]
 
 $(dirname $0)/onos-push-bits $node
 
-[ ! -z "$mvn_settings" ] && scp -q $mvn_settings $remote:/tmp/settings.xml
+[ ! -z "$mvn_settings" ] && scp -q $mvn_settings $remote_scp:/tmp/settings.xml
 
 ssh -tt $remote "
     [ -z "$upgrade" ] && [ -d $ONOS_INSTALL_DIR/bin ] && echo \"ONOS is already installed\" && exit 1
@@ -124,4 +125,4 @@
 [ -f "$ONOS_CLUSTER_KEY_FILE" ] && onos-push-cluster-key $1
 
 # Unless -n option was given, attempt to ignite the ONOS service.
-[ -z "$nostart" ] && onos-service $node start || true
\ No newline at end of file
+[ -z "$nostart" ] && onos-service $node start || true
diff --git a/tools/test/bin/onos-log-write b/tools/test/bin/onos-log-write
index 840c43f..2897270 100755
--- a/tools/test/bin/onos-log-write
+++ b/tools/test/bin/onos-log-write
@@ -9,6 +9,7 @@
 
 remote=$(find_node $1)
 remote=$ONOS_USER@${remote:-$OCI}
+remote_scp=$ONOS_USER@[${remote:-$OCI}]
 message=$2
 
 if [ -z "$message" ]; then
@@ -33,5 +34,5 @@
 #ssh -t $remote "sudo mkdir -p $(dirname $LOG) && echo $text | sudo tee -a $LOG"
 
 figlet $message > /tmp/message.txt
-scp /tmp/message.txt $remote:/tmp
+scp /tmp/message.txt $remote_scp:/tmp
 ssh -t $remote "sudo mkdir -p $(dirname $LOG) && cat /tmp/message.txt | sudo tee -a $LOG; rm /tmp/message.txt"
diff --git a/tools/test/bin/onos-mininet b/tools/test/bin/onos-mininet
index 0af3860..e5898d2 100755
--- a/tools/test/bin/onos-mininet
+++ b/tools/test/bin/onos-mininet
@@ -11,6 +11,7 @@
 cmd="$1" && shift
 log="screenlog.0"
 remote="$ONOS_USER@$OCN"
+remote_scp="$ONOS_USER@[$OCN]"
 screenversion=$(ssh $remote screen -v | sed -n -e 's/^Screen version \([0-9]*\.[0-9]*\).*$/\1/p')
 # note: Screen version check for >4.04 may be inaccurate - The only sure thing is that v4.01
 #       requires logname to NOT be given while in v4.05 it is optional (as long as -L is the
@@ -62,7 +63,7 @@
     ssh $remote "rm -f $log; echo logfile flush 1 > ~/.screenrc"
     (
     $mininet "$@"
-    scp $remote:$log /tmp/mininet.log
+    scp $remote_scp:$log /tmp/mininet.log
     ssh $remote rm -f $log
     ) &
     ;;
diff --git a/tools/test/bin/onos-push-bits b/tools/test/bin/onos-push-bits
index b65c438..9b2bac2 100755
--- a/tools/test/bin/onos-push-bits
+++ b/tools/test/bin/onos-push-bits
@@ -28,6 +28,7 @@
 
 node=${1:-$OCI}
 remote=$ONOS_USER@$node
+remote_with_bracket=$ONOS_USER@[$node]
 SSH_OPTIONS=" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
  -o ControlMaster=auto -o ControlPath=~/.ssh/mux-%r@%h:%p \
  -o ControlPersist=300 "
@@ -69,7 +70,7 @@
   rsync -az --delete --checksum --omit-dir-times --progress \
         -e "ssh $SSH_OPTIONS" \
         --rsync-path="mkdir -p /tmp/$ONOS_BITS/ && rsync" \
-        $RSYNC_STAGE/ $remote:/tmp/$ONOS_BITS
+        $RSYNC_STAGE/ $remote_with_bracket:/tmp/$ONOS_BITS
 
   # create $ONOS_TAR equivalent tar ball remotely
   # TODO hash will not be the same as local one, probably due to different uid, etc.
@@ -84,6 +85,6 @@
   if [ -n "$locHash" ] && [ "$locHash" = "$remHash" ]; then
       echo "ONOS bits $ONOS_TAR already up-to-date on $node..."
   else
-      scp -q $ONOS_TAR $remote:/tmp
+      scp -q $ONOS_TAR $remote_with_bracket:/tmp
   fi
 fi
diff --git a/tools/test/bin/onos-push-bits-through-proxy b/tools/test/bin/onos-push-bits-through-proxy
index 5ba72b7..b983af2 100755
--- a/tools/test/bin/onos-push-bits-through-proxy
+++ b/tools/test/bin/onos-push-bits-through-proxy
@@ -21,6 +21,6 @@
     echo \"Pushing to \$other ...\";
     scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
         /tmp/\$(basename $ONOS_TAR) \
-        $ONOS_USER@\$other:/tmp/\$(basename $ONOS_TAR)
+        $ONOS_USER@[\$other]:/tmp/\$(basename $ONOS_TAR)
   done
 "
diff --git a/tools/test/bin/onos-push-cluster-key b/tools/test/bin/onos-push-cluster-key
index c2a77f6..d5cd5fe 100755
--- a/tools/test/bin/onos-push-cluster-key
+++ b/tools/test/bin/onos-push-cluster-key
@@ -6,6 +6,6 @@
 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
 . $ONOS_ROOT/tools/build/envDefaults
 
-remote=$ONOS_USER@${1:-$OCI}
+remote=$ONOS_USER@[${1:-$OCI}]
 
-scp -q $ONOS_CLUSTER_KEY_FILE $remote:$ONOS_INSTALL_DIR/config/onos.jks
\ No newline at end of file
+scp -q $ONOS_CLUSTER_KEY_FILE $remote:$ONOS_INSTALL_DIR/config/onos.jks
diff --git a/tools/test/bin/onos-push-routing b/tools/test/bin/onos-push-routing
index 0926772..f2eecee 100755
--- a/tools/test/bin/onos-push-routing
+++ b/tools/test/bin/onos-push-routing
@@ -20,7 +20,7 @@
 node=${1:-$OCN}
 
 ssh $ONOS_USER@$node sudo rm -rf routing
-scp -qr $routing $ONOS_USER@$node:
+scp -qr $routing $ONOS_USER@[$node]:
 
 echo "@stc routing_root=$routing_root"
 echo "@stc routing=$routing"
diff --git a/tools/test/bin/onos-push-test-bits b/tools/test/bin/onos-push-test-bits
index 4f6ba57..60c8590 100755
--- a/tools/test/bin/onos-push-test-bits
+++ b/tools/test/bin/onos-push-test-bits
@@ -8,8 +8,9 @@
 
 node=${1:-$OCN}
 remote=$ONOS_USER@$node
+remote_scp=$ONOS_USER@[$node]
 
-scp -q $ONOS_TEST_TAR $remote:/tmp
+scp -q $ONOS_TEST_TAR $remote_scp:/tmp
 ssh $remote "
     rm -f /tmp/onos $ONOS_TEST_BITS
     cd /tmp && tar zxf $ONOS_TEST_BITS.tar.gz && ln -s onos-test-$ONOS_POM_VERSION onos
diff --git a/tools/test/bin/onos-push-topos b/tools/test/bin/onos-push-topos
index ba96e50..0200c6f 100755
--- a/tools/test/bin/onos-push-topos
+++ b/tools/test/bin/onos-push-topos
@@ -9,4 +9,4 @@
 node=${1:-$OCN}
 
 ssh $ONOS_USER@$node sudo rm -f topos/*.pyc
-scp -qr $ONOS_ROOT/tools/test/topos $ONOS_USER@$node:
+scp -qr $ONOS_ROOT/tools/test/topos $ONOS_USER@[$node]:
diff --git a/tools/test/bin/onos-start-network b/tools/test/bin/onos-start-network
index 083262d..e668b8d 100755
--- a/tools/test/bin/onos-start-network
+++ b/tools/test/bin/onos-start-network
@@ -33,7 +33,7 @@
 
 echo "Copying topology files to mininet vm."
 $SSHCMD -n $ONOS_USER@$OCN mkdir -p topos
-$SCPCMD $ONOS_ROOT/tools/test/topos/* $ONOS_USER@$OCN:topos/
+$SCPCMD $ONOS_ROOT/tools/test/topos/* $ONOS_USER@[$OCN]:topos/
 
 echo "Starting Network."
 $SSHCMD -t $ONOS_USER@$OCN sudo python $topo $(env | sort | egrep "^OC[0-9]+" | cut -d= -f2)
diff --git a/tools/test/bin/proxy-stc b/tools/test/bin/proxy-stc
index b63c48b..bf31bc3 100755
--- a/tools/test/bin/proxy-stc
+++ b/tools/test/bin/proxy-stc
@@ -39,6 +39,6 @@
 status=$?
 
 mkdir -p /tmp/stc
-scp -r ${ONOS_USER}@${OCN}:/tmp/stc/* /tmp/stc/
+scp -r ${ONOS_USER}@[${OCN}]:/tmp/stc/* /tmp/stc/
 
-exit $status
\ No newline at end of file
+exit $status
diff --git a/tools/test/scenarios/bin/mininet-trellis b/tools/test/scenarios/bin/mininet-trellis
index 8be1922..4ec52d6 100755
--- a/tools/test/scenarios/bin/mininet-trellis
+++ b/tools/test/scenarios/bin/mininet-trellis
@@ -1,6 +1,7 @@
 #!/bin/bash
 
 remote=$ONOS_USER@$OCN
+remote_scp=$ONOS_USER@[$OCN]
 mininet="ssh -t -t $remote screen -L -S mininet"
 
 CONTROLLERS="$OC1"
@@ -13,12 +14,12 @@
 
 echo >/tmp/invoke_trellis_hag "cd routing/trellis && sudo ./trellis_hag.py -c '$CONTROLLERS'"
 chmod +x /tmp/invoke_trellis_hag
-scp /tmp/invoke_trellis_hag $remote:
+scp /tmp/invoke_trellis_hag $remote_scp:
 
 ssh $remote "rm -f $log; echo logfile flush 1 > ~/.screenrc"
     (
     $mininet ./invoke_trellis_hag
-    scp $remote:$log /tmp/mininet.log
+    scp $remote_scp:$log /tmp/mininet.log
     ssh $remote rm -f $log
     ) &