Fixing the access network null simulation and adjusting layout.

Change-Id: Ib6f0c100789b1f802269018d36aed8d06ce4e5d4
diff --git a/tools/test/topos/access-gw.json b/tools/test/topos/access-gw.json
deleted file mode 100644
index 7268110..0000000
--- a/tools/test/topos/access-gw.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
-  "hosts" : {
-    "00:00:00:00:00:01/None" : {
-      "basic" : {
-        "name" : "GW-A1",
-        "roles" : [ "gateway" ], "gridX" : 0.0, "gridY" : 0.0, "locType" : "grid", "uiType" : "router"
-      }
-    },
-    "00:00:00:00:00:02/None" : {
-      "basic" : {
-        "name" : "GW-A2",
-        "roles" : [ "gateway" ], "gridX" : 0.0, "gridY" : 0.0, "locType" : "grid", "uiType" : "router"
-      }
-    },
-    "00:00:00:00:00:0D/None" : {
-      "basic" : {
-        "name" : "GW-B1",
-        "roles" : [ "gateway" ], "gridX" : 0.0, "gridY" : 0.0, "locType" : "grid", "uiType" : "router"
-      }
-    },
-    "00:00:00:00:00:0E/None" : {
-      "basic" : {
-        "name" : "GW-B2",
-        "roles" : [ "gateway" ], "gridX" : 0.0, "gridY" : 0.0, "locType" : "grid", "uiType" : "router"
-      }
-    }
-  }
-}
\ No newline at end of file
diff --git a/tools/test/topos/access-null b/tools/test/topos/access-null
index 460fb6b..20f1452 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,29 +57,26 @@
 
 
 # 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 {
     echo "$@" >> $CMDS
 }
 
-function y {
-    let p="${3:-400} * ($1 - 1) - (${3:-400} * ($2 - 1)) / 2 + ${4:-0}"
-    echo $p
-}
-
 # Create spines
 for spine in $(seq 1 $spines); do
-    sim "null-create-device switch Spine-${spine} ${spinePorts} 0 $(y $spine $spines) grid"
+    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} -200 $(y $l1 4) grid"
-    sim "null-create-device switch Leaf-${pair}2 ${leafPorts} -200 $(y $l2 4) grid"
+    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"
 
     for spine in $(seq 1 $spines); do
@@ -86,17 +86,23 @@
         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} -400 $(y $host $serviceHosts 60 $offset) grid"
+        sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.1.${host}"
     done
 done
 
 # Create single access leafs with dual links to the spines
 for access in $(seq $accessLeaves); do
-    sim "null-create-device switch Access-${access} ${accessPorts} 200 $(y $access $accessLeaves) grid"
+    sim "null-create-device switch Access-${access} ${accessPorts}"
 
     for spine in $(seq 1 $spines); do
         for link in $(seq 1 $spineLinks); do
@@ -105,7 +111,7 @@
     done
 
     # Create hosts for each access single leaf
-    sim "null-create-hosts Access-${access} 10.1${access}.1.*" $accessHosts 500 $(y $access $accessLeaves) 6
+    sim "null-create-hosts Access-${access} 10.1${access}.1.*" $accessHosts
     # sim "null-create-hosts Access-${access} 10.1${access}.2.*" $accessHosts
 done
 
@@ -129,3 +135,11 @@
 # Add devices, links, and hosts
 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
\ No newline at end of file
diff --git a/tools/test/topos/co-fo-access-null b/tools/test/topos/co-fo-access-null
index 0fff17b..ea657a8 100755
--- a/tools/test/topos/co-fo-access-null
+++ b/tools/test/topos/co-fo-access-null
@@ -74,6 +74,8 @@
     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
@@ -93,6 +95,7 @@
     [ $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
@@ -140,3 +143,12 @@
 # Add devices, links, and hosts
 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
+