CS计算机代考程序代写 package main

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<= 0 {
temp[i-(1< 0 && !*force {
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())
}