Added README to cluster management tools.

Change-Id: Iddbf15b5ca9925b230c97e9a0a6d34c54ec6a97e

Fixed a bug onos-cluster.sh doesn't set RAMCloud coordinator address correctly.
Segregated onos-cluster.sh output directory from cluster-mgmt/conf/.

Change-Id: Icf108a445133a145f565b0e72a4c819d42f6df47
diff --git a/cluster-mgmt/README b/cluster-mgmt/README
new file mode 100644
index 0000000..1eb766f
--- /dev/null
+++ b/cluster-mgmt/README
@@ -0,0 +1,61 @@
+ONOS cluster management tools
+=============================
+
+This directory contains tools related to configuration and management of
+ONOS cluster. This file explains role of each script and composition of
+configuration files.
+
+
+Cluster management overview
+===========================
+
+ONOS cluster needs lots of configuration files and that makes it hard to keep
+consistency of configuration among ONOS nodes. Also, starting up and shutting
+down ONOS nodes needs CLI execution on each nodes. Cluster management tools
+are designed to kill those painful steps by centralizing interface into one
+host.
+
+Cluster management tools can create configuration files for each node and
+apply them. Cluster management tools can also start up and shut down all ONOS
+nodes simultaneously. If you want to see status of ONOS cluster, those tools
+can show status of all nodes at once.
+
+Cluster management tools also contain Mininet deployment tool. This tool can
+create Mininet network with arbitrary topology and with arbitrary controller
+assignment. If you want to run ONOS on virtual network, this tool can help.
+
+
+Composition of files
+====================
+
+Cluster management tools consist of some script files and configuration files.
+
+Description of files
+--------------------
+- onos-cluster.sh
+    Main script to manage ONOS cluster. This script can create and deploy
+    configuration files for each hosts, and can start/stop ONOS cluster.
+    This script can also show status of ONOS cluster nodes.
+    Try "onos-cluster.sh" to see detailed usage.
+    
+- conf/onos-cluster.conf
+    Configuration file of ONOS cluster. This is the only file you need to
+    modify. See into the file for parameter detail.
+
+- conf/generated/*
+    Configuration files generated by onos-cluster.sh. 
+
+- conf/logs
+    Console logs of each nodes generated during deployment of configuration.
+
+- conf/template/*
+    Templates of configuration files referred during generation of file.
+    DO NOT change or delete these files.
+
+- mininet/start_topo.py
+    Script to start Mininet. This script read topology file and create
+    topology as described. This script also connect virtual switches to ONOS
+    cluster nodes according to topology file.
+    
+- mininet/topo.py
+    Topology file used by start_topo.py.
diff --git a/cluster-mgmt/conf/onos-cluster.conf b/cluster-mgmt/conf/onos-cluster.conf
index ddf99b2..cf2cab1 100644
--- a/cluster-mgmt/conf/onos-cluster.conf
+++ b/cluster-mgmt/conf/onos-cluster.conf
@@ -4,8 +4,8 @@
 cluster.hosts.names = onosdev1, onosdev2, onosdev3, onosdev4
 
 # Back-end module to store topology/flows
-cluster.hosts.backend = hazelcast
-#cluster.hosts.backend = ramcloud
+#cluster.hosts.backend = hazelcast
+cluster.hosts.backend = ramcloud
 
 # Protocol used by RAMCloud cluster (fast+udp by default)
 #cluster.hosts.ramcloud.protocol = fast+udp
@@ -57,8 +57,8 @@
 
 ### SSH settings used for delivering config files ###
 # Common username used to login host (current user by default)
-#remote.common.ssh.user = mininet
+#remote.common.ssh.user = onos
 
 # Host-specific username settings
-#remote.onosdev1.ssh.user = mininet
-#remote.onosdev2.ssh.user = mininet
+#remote.onosdev1.ssh.user = onos
+#remote.onosdev2.ssh.user = onos
diff --git a/cluster-mgmt/conf/template/onos_node.conf.template b/cluster-mgmt/conf/template/onos_node.conf.template
index 0dadf66..a97a36a 100644
--- a/cluster-mgmt/conf/template/onos_node.conf.template
+++ b/cluster-mgmt/conf/template/onos_node.conf.template
@@ -18,7 +18,7 @@
 ramcloud.coordinator.protocol = __RAMCLOUD_PROTOCOL__
 
 # IP address of RAMCloud coordinator (host.ip by default)
-ramcloud.coordinator.ip = __RAMCLOUD_IP__
+ramcloud.coordinator.ip = __RAMCLOUD_COORD_IP__
 
 # Port number of RAMCloud coordinator (12246 by default)
 ramcloud.coordinator.port = __RAMCLOUD_COORD_PORT__
@@ -27,7 +27,7 @@
 ramcloud.server.protocol = __RAMCLOUD_PROTOCOL__
 
 # IP address of RAMCloud server (host.ip by default)
-ramcloud.server.ip = __RAMCLOUD_IP__
+ramcloud.server.ip = __RAMCLOUD_SERVER_IP__
 
 # Port number of RAMCloud server (12242 by default)
 ramcloud.server.port = __RAMCLOUD_SERVER_PORT__
diff --git a/cluster-mgmt/onos-cluster.sh b/cluster-mgmt/onos-cluster.sh
index fac7110..6c23cdc 100755
--- a/cluster-mgmt/onos-cluster.sh
+++ b/cluster-mgmt/onos-cluster.sh
@@ -21,6 +21,7 @@
 CLUSTER_HOME=${ONOS_CLUSTER_HOME:-$(cd `dirname $0`; pwd)}
 CLUSTER_CONF_DIR=${CLUSTER_HOME}/conf
 CLUSTER_CONF=${ONOS_CLUSTER_CONF:-${CLUSTER_CONF_DIR}/onos-cluster.conf}
+CLUSTER_CONF_OUTPUT_DIR=${CLUSTER_CONF_DIR}/generated
 CLUSTER_TEMPLATE_DIR=${CLUSTER_CONF_DIR}/template
 CLUSTER_LOGDIR=${ONOS_CLUSTER_LOGDIR:-${CLUSTER_HOME}/logs}
 
@@ -47,7 +48,7 @@
 ### Parallel SSH settings ###
 SSH=${SSH:-ssh}
 PSSH=${PSSH:-parallel-ssh}
-PSSH_CONF=${CLUSTER_CONF_DIR}/pssh.hosts
+PSSH_CONF=${CLUSTER_CONF_OUTPUT_DIR}/pssh.hosts
 SCP=${SCP:-scp}
 #############################
 
@@ -157,14 +158,14 @@
     exit 1
   fi
   
-  local onos_conf="${CLUSTER_CONF_DIR}/onos_node.${host_name}.conf"
+  local onos_conf="${CLUSTER_CONF_OUTPUT_DIR}/onos_node.${host_name}.conf"
   local tempfile=`begin-conf-creation ${onos_conf}`
   local filename=`basename ${onos_conf}`
   echo -n "Creating ${filename} ... "
 
   cp ${ONOS_CONF_TEMPLATE} ${tempfile}
   
-  local prefix="cluster.${host}"
+  local prefix="cluster.${host_name}"
   
   local host_ip=$(read-conf ${CLUSTER_CONF} "${prefix}.ip")
   local host_string=${host_ip}
@@ -190,11 +191,28 @@
   sed -i -e "s|__BACKEND__|${CLUSTER_BACKEND}|" ${tempfile}
   sed -i -e "s|__ZK_HOSTS__|${zk_hosts}|" ${tempfile}
   sed -i -e "s|__RAMCLOUD_PROTOCOL__|${CLUSTER_RC_PROTOCOL}|" ${tempfile}
-  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}
   
+  # Filling RAMCloud parameters
+  local host_role=$(read-conf ${CLUSTER_CONF} "cluster.${host}.role")
+  if [ "${host_role}" = "coord-node" -o "${host_role}" = "coord-and-server-node" ]; then
+    sed -i -e "s|__RAMCLOUD_COORD_IP__|${rc_ip}|" ${tempfile}
+    sed -i -e "s|__RAMCLOUD_COORD_PORT__|${rc_coord_port}|" ${tempfile}
+  else
+    # comment out
+    sed -i -e "s|^\(.*__RAMCLOUD_COORD_IP__.*\)$|#\1|" ${tempfile}
+    sed -i -e "s|^\(.*__RAMCLOUD_COORD_PORT__.*\)$|#\1|" ${tempfile}
+  fi
+  if [ "${host_role}" = "server-node" -o "${host_role}" = "coord-and-server-node" ]; then
+    sed -i -e "s|__RAMCLOUD_SERVER_IP__|${rc_ip}|" ${tempfile}
+    sed -i -e "s|__RAMCLOUD_SERVER_PORT__|${rc_server_port}|" ${tempfile}
+  else
+    # comment out
+    sed -i -e "s|^\(.*__RAMCLOUD_SERVER_IP__.*\)$|#\1|" ${tempfile}
+    sed -i -e "s|^\(.*__RAMCLOUD_SERVER_PORT__.*\)$|#\1|" ${tempfile}
+  fi
+  sed -i -e "s|__RAMCLOUD_SERVER_REPLICAS__|${CLUSTER_RC_SERVER_REPLICAS}|" ${tempfile}
+  
+  # Filling Hazelcast parameters
   if [ ${CLUSTER_HC_NETWORK} = "tcp-ip" ]; then
     sed -i -e "s|__HAZELCAST_MEMBERS__|${hc_hosts}|" ${tempfile}
     
@@ -215,6 +233,8 @@
 
 # setup -f : force overwrite existing files
 function setup {
+  mkdir -p ${CLUSTER_CONF_OUTPUT_DIR}
+  
   if [ "${1}" = "-f" ]; then
     create-pssh-conf
     
@@ -225,7 +245,7 @@
     create-conf-interactive ${PSSH_CONF} create-pssh-conf
     
     for host in ${CLUSTER_HOSTS}; do 
-      local filename="${CLUSTER_CONF_DIR}/onos_node.${host}.conf"
+      local filename="${CLUSTER_CONF_OUTPUT_DIR}/onos_node.${host}.conf"
       create-conf-interactive ${filename} create-onos-conf ${host}
     done
   fi
@@ -247,7 +267,7 @@
   mkdir -p ${CLUSTER_LOGDIR}
   
   for host in ${CLUSTER_HOSTS}; do
-    local conf=${CLUSTER_CONF_DIR}/onos_node.${host}.conf
+    local conf=${CLUSTER_CONF_OUTPUT_DIR}/onos_node.${host}.conf
     if [ ! -f ${conf} ]; then
       echo "[ERROR] ${conf} not found"
       local command=`basename ${0}`