예제 #1
0
func main() {
	var g *graph.DefaultGraph
	g, _ = utils.ReadFileToGraph("topology.txt")
	g = utils.ReadFile("topology.txt")
	fmt.Print(g.String())

	labels := utils.GetLabelList(g)
	fmt.Println(labels)

	neighbors, _ := utils.GetNeighborMap(g)
	fmt.Println(neighbors)
}
예제 #2
0
파일: client.go 프로젝트: Grissess/sdnd16
func main() {

	var ipAddress, recordName, filename, input string
	var db database.RoutingDatabase
	var DBerr error

	color.Set(color.FgHiGreen, color.Bold, color.BlinkSlow)
	fmt.Println("\nWelcome to the NRA System, written in golang\n")
	color.Unset()

	fmt.Println("Enter IP address and port of the database server you'd like to use")
	fmt.Println("If none is entered, the default server will be used (testing only)\n")
	color.Unset()

	color.Set(color.FgWhite)
	fmt.Print("IP address and port >> ")
	color.Unset()

	fmt.Scanln(&ipAddress)

	if ipAddress == "" {
		color.Set(color.FgHiBlue)
		fmt.Println("No ip address selected, using default database")
		color.Unset()
		ipAddress = "128.153.144.171:6379"
	}

	color.Set(color.FgWhite)
	fmt.Print("Enter the name of the database record you wish to use >> ")
	color.Unset()
	fmt.Scanln(&recordName)

	exists, DBerr := database.TopologyExists(recordName, "tcp", ipAddress)

	if DBerr != nil {
		panic(DBerr)
	}

	if exists {
		color.Set(color.FgHiBlue)
		fmt.Println("This record exists!\n")
		color.Unset()

		db, DBerr = database.ConnectToDatabase(recordName, "tcp", ipAddress)

		topo, TPerr := db.GetTopology()

		//fmt.Printf("CLI: gb.GetTopo[%v]: %v\n", TPerr, topo)

		if DBerr != nil {
			panic(DBerr)
		}
		queryPaths(db)

	} else {
		color.Set(color.FgHiBlue)
		fmt.Println("This record does not exist.  Please check your spelling")
		color.Set(color.FgWhite)
		fmt.Print("Would you like to create a record by this name? [Y/N] >> ")
		color.Unset()
		fmt.Scanln(&input)

		if input == "Y" || input == "y" {
			color.Set(color.FgWhite)
			fmt.Print("Give me the name of a topology file >> ")
			color.Unset()

			fmt.Scanln(&filename)
			g, labels, Uerror := utils.ReadFileToGraph(filename)

			if Uerror != nil {
				panic(Uerror)
			}

			revLabels := utils.GetRevLabels(labels)
			paths := path.DijkstraAllPaths(g)
			pathMap := algorithms.ConvertAllPaths(g, paths)

			realPathMap := make(map[int]map[int]string)

			for k := range pathMap {
				smallMap := pathMap[k]
				newMap := make(map[int]string)
				for k2 := range smallMap {
					stringForPath := smallMap[k2].PathString(labels)
					newMap[k2] = stringForPath
				}
				realPathMap[k] = newMap
			}

			//fmt.Printf("CLI: pathMap: %v\n", pathMap)
			//fmt.Printf("CLI: realPathMap: %v\n", realPathMap)

			db, DBerr = database.NewRoutingDatabase(recordName, "tcp", ipAddress, revLabels, realPathMap, utils.GetNeighborMap(g))

			topo, TPerr := db.GetTopology()

			//fmt.Printf("CLI: db.GetTopo[%v]: %v\n", TPerr, topo)

			if DBerr != nil {
				panic(DBerr)
			}

			color.Set(color.FgHiGreen, color.Bold)
			fmt.Println("Database created correctly!")
			color.Unset()

			queryPaths(db)

		} else {
			color.Set(color.FgHiGreen, color.Bold)
			fmt.Println("Thank you for using golang NRA!")
			color.Unset()
		}
	}
}