b’Routers_template_2020_Go.1 (6).tar.gz’
package main
import (
“flag”
“fmt”
“log”
“math/big”
“os”
“time”
“routers”
)
var (
topology = flag.String(“t”, “Mesh”, “`topology` (by size: Line, Ring, Star, Fully_Connected; “+
“by dimension and size: Mesh, Torus; by dimension: Hypercube, Cube_Connected_Cycles, Butterfly, Wrap_Around_Butterfly)”)
size = flag.Uint(“s”, 20, “size”)
dimension = flag.Uint(“d”, 3, “dimension”)
//printConnections = flag.Bool(“c”, true, “print connections”)
//printDistances = flag.Bool(“i”, true, “print distances”)
settleTime = flag.Duration(“w”, time.Second/10, “routers settle time”)
//timeout = flag.Duration(“o”, time.Second/10, “comms timeout”)
mode = flag.String(“m”, “One_To_All”, “`mode` (One_To_All, All_To_One)”)
dropouts = flag.Uint(“x”, 0, “dropouts”)
repeats = flag.Uint(“r”, 10, “repeats”)
force = flag.Bool(“f”, false, “force the creation of a large number of routers”)
)
func main() {
flag.Parse()
if *size == 0 && (*topology == “Line” || *topology == “Ring” || *topology == “Star” || *topology == “Fully_Connected” ||
*topology == “Mesh” || *topology == “Torus”) {
fmt.Fprintln(os.Stderr, “You have requested a topology with zero routers. Try increasing size (-s).”)
os.Exit(1)
}
var template routers.Template
switch *topology {
case “Line”, “Ring”:
template = make(routers.Template, *size)
for i := routers.RouterId(0); uint(i) < *size; i++ {
template[i] = []routers.RouterId{i - 1, i + 1}
}
if *topology == "Line" {
template[0] = template[0][1:]
template[*size-1] = template[*size-1][:len(template[*size-1])-1]
} else {
template[0][0] = routers.RouterId(*size - 1)
template[*size-1][1] = 0
}
case "Star":
template = make(routers.Template, *size)
if *size > 0 {
template[0] = make([]routers.RouterId, *size-1)
for i := routers.RouterId(1); uint(i) < *size; i++ {
template[0][i-1] = i
}
for i := uint(1); i < *size; i++ {
template[i] = []routers.RouterId{0}
}
}
case "Fully_Connected":
template = make(routers.Template, *size)
for i := routers.RouterId(0); uint(i) < *size; i++ {
template[i] = make([]routers.RouterId, *size-1)
for j := routers.RouterId(0); uint(j) < *size-1; j++ {
if j < i {
template[i][j] = j
} else {
template[i][j] = j + 1
}
}
}
case "Mesh":
template = make(routers.Template, exp(*size, *dimension))
for i := routers.RouterId(0); int(i) < len(template); i++ {
temp := make(map[routers.RouterId]struct{})
for d := uint(0); d < *dimension; d++ {
if int(i)-(1<
temp[i-(1<
fmt.Fprintf(os.Stderr, “Your chosen configuration would generate a very large number of routers.\n”+
“Try setting dimension (-d) smaller. (Would generate %v routers.)\n”+
“If you’re really sure, you can use -f to proceed anyway.\n”, z)
os.Exit(1)
}
if !z.IsUint64() {
fmt.Fprintln(os.Stderr, “OK, but seriously though, this would generate more than 2^64 routers. Aborting.”)
os.Exit(1)
}
return uint(z.Uint64())
}
package routers
import “log”
func Router(self RouterId, incoming <-chan interface{}, neighbours []chan<- interface{}, framework chan<- Envelope) { for { select { case raw := <-incoming: switch msg := raw.(type) { case Envelope: if msg.Dest == self { framework <- msg } else { // Handle forwarding on a message here msg.Hops += 1 //neighbours[???] <- msg } // Add more cases to handle any other message types you create here default: log.Printf("[%v] received unexpected message %g\n", self, msg) } } } } # Default ignored files /shelf/ /workspace.xml # Datasource local storage ignored files /dataSources/ /dataSources.local.xml # Editor-based HTTP Client requests /httpRequests/ true package routers type RouterId uint type Template [][]RouterId type Envelope struct { Dest RouterId Hops uint Message interface{} } type TestMessage int func MakeRouters(t Template) (in []chan<- interface{}, out <-chan Envelope) { channels := make([]chan interface{}, len(t)) framework := make(chan Envelope) in = make([]chan<- interface{}, len(t)) for i := range channels { channels[i] = make(chan interface{}) in[i] = channels[i] } out = framework for routerId, neighbourIds := range t { neighbours := make([]chan<- interface{}, len(neighbourIds)) for i, id := range neighbourIds { neighbours[i] = channels[id] } go Router(RouterId(routerId), channels[routerId], neighbours, framework) } return } module routers go 1.14 routers/cmd/test_routers/main.go routers/router.go routers/.idea/routers-go.iml routers/.idea/modules.xml routers/.idea/.gitignore routers/.idea/workspace.xml routers/.idea/misc.xml routers/routers.go routers/go.mod