remove makefile extra tab

Change-Id: I20564e801d307935b9669db81665cc0ed130e698
Signed-off-by: gunjan5 <gupatel@ciena.com>
diff --git a/config-generator/Dockerfile b/config-generator/Dockerfile
new file mode 100644
index 0000000..9cdb0a6
--- /dev/null
+++ b/config-generator/Dockerfile
@@ -0,0 +1,26 @@
+FROM ubuntu:14.04
+
+RUN apt-get update && apt-get install --no-install-recommends -y \
+    ca-certificates \
+    curl \
+    mercurial \
+    git-core
+RUN curl -s https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz | tar -v -C /usr/local -xz
+
+ENV GOPATH /go
+ENV GOROOT /usr/local/go
+ENV PATH /usr/local/go/bin:/go/bin:/usr/local/bin:$PATH
+
+WORKDIR /app
+
+# copy binary into image
+COPY app /app/
+COPY hosts.tpl /app/
+COPY links.tpl /app/
+COPY ports.tpl /app/
+COPY devices.tpl /app/
+
+VOLUME /app
+
+
+# ENTRYPOINT ["./app"]
\ No newline at end of file
diff --git a/config-generator/Godeps/Godeps.json b/config-generator/Godeps/Godeps.json
new file mode 100644
index 0000000..1b908bc
--- /dev/null
+++ b/config-generator/Godeps/Godeps.json
@@ -0,0 +1,6 @@
+{
+	"ImportPath": ".",
+	"GoVersion": "go1.6",
+	"GodepVersion": "v69",
+	"Deps": []
+}
diff --git a/config-generator/Godeps/Readme b/config-generator/Godeps/Readme
new file mode 100644
index 0000000..4cdaa53
--- /dev/null
+++ b/config-generator/Godeps/Readme
@@ -0,0 +1,5 @@
+This directory tree is generated automatically by godep.
+
+Please do not edit.
+
+See https://github.com/tools/godep for more information.
diff --git a/config-generator/Makefile b/config-generator/Makefile
new file mode 100644
index 0000000..ea30963
--- /dev/null
+++ b/config-generator/Makefile
@@ -0,0 +1,35 @@
+
+default: image
+
+ansible:
+	ansible-playbook ./setup.yml -v -vvvv -u gunjan -i ./host.yml --ask-pass
+
+get:
+	goimports -w .
+	go get -t -d -v ./...
+
+src:
+	docker run --rm -it -v "$GOPATH":/gopath -v "$(pwd)":/app -e "GOPATH=/gopath" -w /app golang:1.6.1 sh -c 'CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o app'
+
+fmt:
+	gofmt -w .
+	#TODO: go lint, go vet
+test:
+	go test -v -race ./...
+	go test -cover -v ./...
+
+image:
+	docker build -t gunjan5/configGen .
+
+run:
+	docker run --rm -it gunjan5/configGen
+
+build:
+	GOOS=linux GOARCH=amd64 go build -o app
+
+depsave:
+	godep save
+
+depupdate:
+	go get -t -v ./...
+	godep update
diff --git a/config-generator/README.md b/config-generator/README.md
new file mode 100644
index 0000000..d694e71
--- /dev/null
+++ b/config-generator/README.md
@@ -0,0 +1,7 @@
+# config Gen
+
+- install Go
+- Make sure ONOS is reachable on localhost or modify the IP in the configGen.go
+- Make sure devices, hosts are connected and showing up in ONOS
+- Run by `go run congifGen.go`
+- You should see `network-cfg.json` file in your current directory
diff --git a/config-generator/configGen.go b/config-generator/configGen.go
new file mode 100644
index 0000000..c57b145
--- /dev/null
+++ b/config-generator/configGen.go
@@ -0,0 +1,175 @@
+package main
+
+import (
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"os"
+	"strings"
+	"text/template"
+)
+
+type hosts struct {
+	Host []struct {
+		Mac         string   `json:"mac"`
+		IpAddresses []string `json:"ipAddresses"`
+		Location    struct {
+			ElementID string `json:"elementId`
+			Port      string `json:"port"`
+		} `json:"location"`
+		Comma   string
+		Gateway string
+	} `json:"hosts"`
+}
+
+type devices struct {
+	Device []struct {
+		Id          string `json:"id"`
+		ChassisId   string `json:"chassisId"`
+		Annotations struct {
+			ManagementAddress string `json:"managementAddress"`
+		} `json:"annotations"`
+		Comma string `default:","`
+	} `json:"devices"`
+}
+
+type onosLinks struct {
+	Links []link `json:"links"`
+}
+
+type link struct {
+	Src devicePort `json:"src"`
+	Dst devicePort `json:"dst"`
+}
+
+type devicePort struct {
+	Port   string `json:"port"`
+	Device string `json:"device"`
+}
+
+type linkStructJSON struct {
+	Val   string
+	Comma string
+}
+
+func main() {
+	onos := "http://karaf:karaf@127.0.0.1:8181"
+
+	err := os.Remove("network-cfg.json")
+	if err != nil {
+		fmt.Println("Warning: no file called network-cfg.json (ignore if this is the first run)")
+	}
+	generateDevicesJSON(onos)
+	generateLinkJSON(onos)
+	generateHostJSON(onos)
+
+	fmt.Println("Config file generated: network-cfg.json")
+
+}
+
+func writeToFile(object interface{}, t string) {
+	f, err := os.OpenFile("network-cfg.json", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
+	if err != nil {
+		panic(err)
+	}
+
+	defer f.Close()
+
+	tpl, err := template.ParseFiles(t)
+	check(err)
+	err = tpl.Execute(f, object)
+	check(err)
+}
+
+func generateDevicesJSON(onos string) {
+	ds := getData(onos + "/onos/v1/devices")
+
+	var d devices
+	err := json.Unmarshal(ds, &d)
+	check(err)
+
+	for k, _ := range d.Device {
+		d.Device[k].Comma = ","
+		if k >= len(d.Device)-1 {
+			d.Device[k].Comma = ""
+		}
+	}
+
+	writeToFile(d.Device, "devices.tpl")
+
+}
+
+func generateHostJSON(onos string) {
+	hs := getData(onos + "/onos/v1/hosts")
+	var h hosts
+	err := json.Unmarshal(hs, &h)
+	check(err)
+
+	for k, _ := range h.Host {
+
+		h.Host[k].Comma = ","
+		if k >= len(h.Host)-1 {
+			h.Host[k].Comma = ""
+		}
+
+		parts := strings.Split(h.Host[k].IpAddresses[0], ".")
+		ip := ""
+		for _, v := range parts[:len(parts)-1] {
+			ip = ip + v + "."
+		}
+		h.Host[k].Gateway = ip
+	}
+
+	writeToFile(h.Host, "ports.tpl")
+
+	writeToFile(h.Host, "hosts.tpl")
+
+}
+
+func generateLinkJSON(onos string) {
+
+	links := getData(onos + "/onos/v1/links")
+
+	var l onosLinks
+	err := json.Unmarshal(links, &l)
+	check(err)
+
+	var in []linkStructJSON
+
+	for k, v := range l.Links {
+
+		comma := ","
+		val := fmt.Sprint(v.Src.Device + "/" + v.Src.Port + "-" + v.Dst.Device + "/" + v.Dst.Port)
+		if k >= len(l.Links)-1 {
+			comma = ""
+		}
+
+		tmp := linkStructJSON{val, comma}
+		in = append(in, tmp)
+
+	}
+
+	writeToFile(in, "links.tpl")
+
+}
+
+func getData(url string) []byte {
+
+	resp, err := http.Get(url)
+	check(err)
+
+	defer resp.Body.Close()
+
+	body, err := ioutil.ReadAll(resp.Body)
+	check(err)
+
+	return body
+
+}
+
+func check(e error) {
+	if e != nil {
+		panic(e)
+	}
+}
diff --git a/config-generator/devices.tpl b/config-generator/devices.tpl
new file mode 100644
index 0000000..2bb0e27
--- /dev/null
+++ b/config-generator/devices.tpl
@@ -0,0 +1,15 @@
+{
+ "devices" : {
+{{ range . }}
+    "{{ .Id}}" : {
+            "segmentrouting" : {
+                "name" : "device-{{ .ChassisId }}",
+                "nodeSid" : 1{{ .ChassisId }},
+                "routerIp" : "{{ .Annotations.ManagementAddress }}",
+                "routerMac" : "cc:37:ab:cc:ef:{{ .ChassisId }}",
+                "isEdgeRouter" : true,
+                "adjacencySids" : []
+            }
+    }{{ .Comma }}{{ end }}
+ },
+
diff --git a/config-generator/hosts.tpl b/config-generator/hosts.tpl
new file mode 100644
index 0000000..3fb102c
--- /dev/null
+++ b/config-generator/hosts.tpl
@@ -0,0 +1,17 @@
+ "hosts" : {
+{{ range . }}
+	"{{ .Mac }}/-1" : {
+		"basic" : {
+			"ips" : ["{{ range $element := .IpAddresses }}{{ $element }}{{ end}}"],
+			"location" : "{{ .Location.ElementID }}/{{ .Location.Port }}"
+		}
+	}{{ .Comma }}{{ end }}
+ },
+ "apps" : {
+        "org.onosproject.core" : {
+            "core" : {
+                "linkDiscoveryMode" : "STRICT"
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/config-generator/links.tpl b/config-generator/links.tpl
new file mode 100644
index 0000000..4f39412
--- /dev/null
+++ b/config-generator/links.tpl
@@ -0,0 +1,7 @@
+ "links": {
+{{ range . }}
+    "{{ .Val }}": {
+         "basic": {}
+     }{{ .Comma }}{{ end }}
+ },
+
diff --git a/config-generator/network-cfg.json b/config-generator/network-cfg.json
new file mode 100644
index 0000000..c074e37
--- /dev/null
+++ b/config-generator/network-cfg.json
@@ -0,0 +1,140 @@
+{
+ "devices" : {
+
+    "of:0000000000000021" : {
+            "segmentrouting" : {
+                "name" : "device-21",
+                "nodeSid" : 121,
+                "routerIp" : "10.6.0.7",
+                "routerMac" : "cc:37:ab:cc:ef:21",
+                "isEdgeRouter" : true,
+                "adjacencySids" : []
+            }
+    },
+    "of:0000000000000011" : {
+            "segmentrouting" : {
+                "name" : "device-11",
+                "nodeSid" : 111,
+                "routerIp" : "10.6.0.6",
+                "routerMac" : "cc:37:ab:cc:ef:11",
+                "isEdgeRouter" : true,
+                "adjacencySids" : []
+            }
+    },
+    "of:0000000000000022" : {
+            "segmentrouting" : {
+                "name" : "device-22",
+                "nodeSid" : 122,
+                "routerIp" : "10.6.0.10",
+                "routerMac" : "cc:37:ab:cc:ef:22",
+                "isEdgeRouter" : true,
+                "adjacencySids" : []
+            }
+    },
+    "of:0000000000000012" : {
+            "segmentrouting" : {
+                "name" : "device-12",
+                "nodeSid" : 112,
+                "routerIp" : "10.6.0.8",
+                "routerMac" : "cc:37:ab:cc:ef:12",
+                "isEdgeRouter" : true,
+                "adjacencySids" : []
+            }
+    }
+ },
+
+ "links": {
+
+    "of:0000000000000011/2-of:0000000000000022/31": {
+         "basic": {}
+     },
+    "of:0000000000000022/31-of:0000000000000011/2": {
+         "basic": {}
+     },
+    "of:0000000000000022/32-of:0000000000000012/2": {
+         "basic": {}
+     },
+    "of:0000000000000021/31-of:0000000000000011/1": {
+         "basic": {}
+     },
+    "of:0000000000000012/1-of:0000000000000021/32": {
+         "basic": {}
+     },
+    "of:0000000000000012/2-of:0000000000000022/32": {
+         "basic": {}
+     },
+    "of:0000000000000021/32-of:0000000000000012/1": {
+         "basic": {}
+     },
+    "of:0000000000000011/1-of:0000000000000021/31": {
+         "basic": {}
+     }
+ },
+
+"ports": {
+
+  "of:0000000000000022/3" : {
+    	"interfaces": [
+    		{
+        		"ips" : [ "10.6.2.254/24" ]
+    		}
+    	]
+	},
+  "of:0000000000000022/4" : {
+    	"interfaces": [
+    		{
+        		"ips" : [ "10.6.2.254/24" ]
+    		}
+    	]
+	},
+  "of:0000000000000021/2" : {
+    	"interfaces": [
+    		{
+        		"ips" : [ "10.6.1.254/24" ]
+    		}
+    	]
+	},
+  "of:0000000000000021/1" : {
+    	"interfaces": [
+    		{
+        		"ips" : [ "10.6.1.254/24" ]
+    		}
+    	]
+	}
+ },
+
+ "hosts" : {
+
+	"3C:FD:FE:9E:95:99/-1" : {
+		"basic" : {
+			"ips" : ["10.6.2.3"],
+			"location" : "of:0000000000000022/3"
+		}
+	},
+	"3C:FD:FE:9E:94:29/-1" : {
+		"basic" : {
+			"ips" : ["10.6.2.4"],
+			"location" : "of:0000000000000022/4"
+		}
+	},
+	"3C:FD:FE:9E:98:68/-1" : {
+		"basic" : {
+			"ips" : ["10.6.1.2"],
+			"location" : "of:0000000000000021/2"
+		}
+	},
+	"3C:FD:FE:9E:94:30/-1" : {
+		"basic" : {
+			"ips" : ["10.6.1.1"],
+			"location" : "of:0000000000000021/1"
+		}
+	}
+ },
+ "apps" : {
+        "org.onosproject.core" : {
+            "core" : {
+                "linkDiscoveryMode" : "STRICT"
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/config-generator/ports.tpl b/config-generator/ports.tpl
new file mode 100644
index 0000000..1252024
--- /dev/null
+++ b/config-generator/ports.tpl
@@ -0,0 +1,11 @@
+"ports": {
+{{ range . }}
+  "{{ .Location.ElementID }}/{{ .Location.Port }}" : {
+    	"interfaces": [
+    		{
+        		"ips" : [ "{{ .Gateway }}254/24" ]
+    		}
+    	]
+	}{{ .Comma }}{{ end }}
+ },
+