Added RAMCloud replication parameter to cluster script.
Modified onos.sh so that RAMCloud host parameter falls back to hostname.
Added usage for "deldb" option to onos.sh.
Added interactive confirmation of deldb to onos.sh.

Change-Id: Icf7022574758bc544d1e2f85abc0f83a7e8e48d8
diff --git a/cluster-mgmt/conf/onos-cluster.conf b/cluster-mgmt/conf/onos-cluster.conf
index d36dd35..ddf99b2 100644
--- a/cluster-mgmt/conf/onos-cluster.conf
+++ b/cluster-mgmt/conf/onos-cluster.conf
@@ -10,6 +10,10 @@
 # Protocol used by RAMCloud cluster (fast+udp by default)
 #cluster.hosts.ramcloud.protocol = fast+udp
 
+# Number of RAMCloud replicas (0 by default)
+# On N node cluster, maximum value will be N-1 replicas
+#cluster.hosts.ramcloud.server.replicas = 0
+
 # Communication method used for Hazelcast communication
 #cluster.hosts.hazelcast.network = multicast
 cluster.hosts.hazelcast.network = tcp-ip
diff --git a/cluster-mgmt/conf/template/onos_node.conf.template b/cluster-mgmt/conf/template/onos_node.conf.template
index b6e069d..0dadf66 100644
--- a/cluster-mgmt/conf/template/onos_node.conf.template
+++ b/cluster-mgmt/conf/template/onos_node.conf.template
@@ -32,6 +32,11 @@
 # Port number of RAMCloud server (12242 by default)
 ramcloud.server.port = __RAMCLOUD_SERVER_PORT__
 
+# RAMCloud server option replicas (0 by default)
+# This value must be the same cluster wide.
+# On N node cluster, maximum value will be N-1 replicas
+ramcloud.server.replicas = __RAMCLOUD_SERVER_REPLICAS__
+
 # List of hostname/ip[:port] which forms Hazelcast datagrid
 # If this value is empty, Hazelcast will be set to multicast mode.
 # Inversely, if this value is set, multicast settings will be ignored.
diff --git a/cluster-mgmt/onos-cluster.sh b/cluster-mgmt/onos-cluster.sh
index 0e03c29..fac7110 100755
--- a/cluster-mgmt/onos-cluster.sh
+++ b/cluster-mgmt/onos-cluster.sh
@@ -31,12 +31,13 @@
   echo "${CLUSTER_CONF} not found."
   exit 1
 fi
-CLUSTER_HOSTS=$(read-conf ${CLUSTER_CONF}       cluster.hosts.names             `hostname` | tr ',' ' ')
-CLUSTER_BACKEND=$(read-conf ${CLUSTER_CONF}     cluster.hosts.backend)
-CLUSTER_RC_PROTOCOL=$(read-conf ${CLUSTER_CONF} cluster.hosts.ramcloud.protocol "fast+udp")
-CLUSTER_HC_NETWORK=$(read-conf ${CLUSTER_CONF}  cluster.hosts.hazelcast.network)
-CLUSTER_HC_ADDR=$(read-conf ${CLUSTER_CONF}     cluster.hosts.hazelcast.multicast.address "224.2.2.3")
-CLUSTER_HC_PORT=$(read-conf ${CLUSTER_CONF}     cluster.hosts.hazelcast.multicast.port    "54327")
+CLUSTER_HOSTS=$(read-conf ${CLUSTER_CONF}              cluster.hosts.names                       `hostname` | tr ',' ' ')
+CLUSTER_BACKEND=$(read-conf ${CLUSTER_CONF}            cluster.hosts.backend)
+CLUSTER_RC_PROTOCOL=$(read-conf ${CLUSTER_CONF}        cluster.hosts.ramcloud.protocol           "fast+udp")
+CLUSTER_RC_SERVER_REPLICAS=$(read-conf ${CLUSTER_CONF} cluster.hosts.ramcloud.server.replicas    "0")
+CLUSTER_HC_NETWORK=$(read-conf ${CLUSTER_CONF}         cluster.hosts.hazelcast.network)
+CLUSTER_HC_ADDR=$(read-conf ${CLUSTER_CONF}            cluster.hosts.hazelcast.multicast.address "224.2.2.3")
+CLUSTER_HC_PORT=$(read-conf ${CLUSTER_CONF}            cluster.hosts.hazelcast.multicast.port    "54327")
 ############################################
 
 
@@ -192,6 +193,7 @@
   sed -i -e "s|__RAMCLOUD_IP__|${rc_ip}|" ${tempfile}
   sed -i -e "s|__RAMCLOUD_COORD_PORT__|${rc_coord_port}|" ${tempfile}
   sed -i -e "s|__RAMCLOUD_SERVER_PORT__|${rc_server_port}|" ${tempfile}
+  sed -i -e "s|__RAMCLOUD_SERVER_REPLICAS__|${CLUSTER_RC_SV_REPLICAS}|" ${tempfile}
   
   if [ ${CLUSTER_HC_NETWORK} = "tcp-ip" ]; then
     sed -i -e "s|__HAZELCAST_MEMBERS__|${hc_hosts}|" ${tempfile}
diff --git a/conf/onos_node.conf b/conf/onos_node.conf
index 75f9aa0..8215ce4 100644
--- a/conf/onos_node.conf
+++ b/conf/onos_node.conf
@@ -25,7 +25,7 @@
 # Protocol used by RAMCloud coordinator (fast+udp by default)
 #ramcloud.coordinator.protocol = fast+udp
 
-# IP address of RAMCloud coordinator (host.ip by default)
+# Listening address of RAMCloud coordinator (host.ip or 0.0.0.0 by default)
 #ramcloud.coordinator.ip = 127.0.0.1
 
 # Port number of RAMCloud coordinator (12246 by default)
@@ -38,7 +38,7 @@
 # Protocol used by RAMCloud server (fast+udp by default)
 #ramcloud.server.protocol = fast+udp
 
-# IP address of RAMCloud server (host.ip by default)
+# Listening address of RAMCloud server (host.ip or 0.0.0.0 by default)
 #ramcloud.server.ip = 127.0.0.1
 
 # Port number of RAMCloud server (12242 by default)
diff --git a/onos.sh b/onos.sh
index 045289b..b155176 100755
--- a/onos.sh
+++ b/onos.sh
@@ -162,7 +162,9 @@
  \$ ${scriptname} status
     Show status of ONOS-related processes
  \$ ${scriptname} {zk|rc-coord|rc-server|core} {start|stop|restart|status}
-    Control specific ONOS-related process"
+    Control specific ONOS-related process
+ \$ ${scriptname} rc deldb
+    Delete data in RAMCloud"
   
   echo "${usage}"
 }
@@ -503,11 +505,21 @@
 
 ### Functions related to RAMCloud coordinator
 function rc-coord-addr {
-  echo "${RC_COORD_PROTOCOL}:host=${RC_COORD_IP},port=${RC_COORD_PORT}"
+  local host=${RC_COORD_IP}
+  if [ -z "${host}" ]; then
+    # falling back to 0.0.0.0
+    host="0.0.0.0"
+  fi
+  echo "${RC_COORD_PROTOCOL}:host=${host},port=${RC_COORD_PORT}"
 }
 
 function rc-server-addr {
-  echo "${RC_SERVER_PROTOCOL}:host=${RC_SERVER_IP},port=${RC_SERVER_PORT}"
+  local host=${RC_SERVER_IP}
+  if [ -z "${host}" ]; then
+    # falling back to 0.0.0.0
+    host="0.0.0.0"
+  fi
+  echo "${RC_SERVER_PROTOCOL}:host=${host},port=${RC_SERVER_PORT}"
 }
 
 function rc-coord {
@@ -708,7 +720,18 @@
 }
 
 function del-server-backup {
-  # TODO might want confirmation, since data can be lost
+  echo -n "Delete RAMCloud backup server data [y/N]? "
+  while [ 1 ]; do
+    read key
+    if [ "${key}" == "Y" -o "${key}" == "y" ]; then
+      break
+    elif [ -z "${key}" -o "${key}" == "N" -o "${key}" == "n" ]; then
+      echo "Cancelled."
+      return
+    fi
+    echo "[y/N]? "
+  done
+
   echo -n "Removing RAMCloud backup server data ... "
   local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log")
   rm -f ${rc_datafile}
@@ -935,6 +958,7 @@
     rc-server $2
     ;;
   rc)
+    # TODO make deldb command more organized (clarify when it can work)
     rc-coord $2
     rc-server $2
     ;;