Fixing the access network null simulation and adjusting layout.

Change-Id: Ib6f0c100789b1f802269018d36aed8d06ce4e5d4
diff --git a/tools/test/topos/access-null b/tools/test/topos/access-null
index 123f794..534df57 100755
--- a/tools/test/topos/access-null
+++ b/tools/test/topos/access-null
@@ -18,6 +18,7 @@
     echo "  -s spines"
     echo "  -l spineLinks"
     echo "  -S serviceHosts"
+    echo "  -G gateways"
     echo "  -a accessLeaves"
     echo "  -A accessHosts"
     exit 1
@@ -29,15 +30,17 @@
 serviceHosts=10
 accessLeaves=8
 accessHosts=100
+gateways=2
 
 # Scan arguments for user/password or other options...
-while getopts s:l:a:A:S:?h o; do
+while getopts s:l:a:A:S:G:?h o; do
     case "$o" in
         s) spines=$OPTARG;;
         l) spineLinks=$OPTARG;;
         a) accessLeaves=$OPTARG;;
         A) accessHosts=$OPTARG;;
         S) serviceHosts=$OPTARG;;
+        G) gateways=$OPTARG;;
         *) usage $0;;
     esac
 done
@@ -54,7 +57,7 @@
 
 
 # Create the script of ONOS commands first and then execute it all at once.
-export CMDS="/tmp/fab-onos.cmds"
+export CMDS="/tmp/access-onos.cmds"
 rm $CMDS
 
 function sim {
@@ -66,8 +69,12 @@
     sim "null-create-device switch Spine-${spine} ${spinePorts}"
 done
 
+gwIps=""
+
 # Create 2 leaf pairs with dual links to the spines and a link between the pair
 for pair in $serviceLeafGroups; do
+    [ $pair = A ] && l1=1 || l1=3
+    [ $pair = A ] && l2=2 || l2=4
     sim "null-create-device switch Leaf-${pair}1 ${leafPorts}"
     sim "null-create-device switch Leaf-${pair}2 ${leafPorts}"
     sim "null-create-link direct Leaf-${pair}1 Leaf-${pair}2"
@@ -79,8 +86,15 @@
         done
     done
 
-    # Create hosts for each leaf group; multi-homed to each leaf in the pair
+    # Create gateways attached to each leaf group; multi-homed to each leaf in the pair
     [ $pair = A ] && pn=1 || pn=2
+    for gw in $(seq 1 $gateways); do
+        sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.0.${gw}"
+        gwIps="${gwIps}|10.${pn}.0.${gw}"
+    done
+
+    # Create hosts for each leaf group; multi-homed to each leaf in the pair
+    [ $pair = A ] && offset=-400 || offset=400
     for host in $(seq 1 $serviceHosts); do
         sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.1.${host}"
     done
@@ -119,4 +133,13 @@
 sleep 2
 
 # Add devices, links, and hosts
-cat $CMDS | onos ${node}
\ No newline at end of file
+cat $CMDS | onos ${node}
+
+# After the network is created, add network config to assign roles to gateway IPs.
+cfg=""
+for gw in $(onos ${node} hosts | egrep "${gwIps/|/}" | cut -d, -f1 | cut -d= -f2); do
+    cfg="${cfg}, \"$gw\": { \"basic\": { \"uiType\" : \"router\", \"roles\": [ \"gateway\" ]}}"
+done
+echo "{ \"hosts\": { ${cfg/,/} }}" > $CMDS
+
+onos-netcfg ${node} $CMDS