diff options
Diffstat (limited to 'cmd/vrouter')
-rw-r--r-- | cmd/vrouter/main.go | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/cmd/vrouter/main.go b/cmd/vrouter/main.go index abd0fc0..89f6e5d 100644 --- a/cmd/vrouter/main.go +++ b/cmd/vrouter/main.go @@ -10,25 +10,25 @@ import ( ) -func SendUpdates() { - myInterfaces := ipstack.GetInterfaces() - myNeighbors := ipstack.GetNeighbors() - for _, iface := range myInterfaces { - // send RIP updates to all neighbors - for _, _ = range myNeighbors { - // iface.udp.Write(neighbor, data) - // iface.RecvSocket.Write(neighbor, data) - // wait for response for 12 seconds - response := make([]byte, 512) - iface.RecvSocket.Read(response) - time.Sleep(12 * time.Second) - if len(response) == 0 { - // ipstack.RemoveNeighbor(neighbor) - } - } - } - time.Sleep(5 * time.Second) -} +// func SendUpdates() { +// myInterfaces := ipstack.GetInterfaces() +// myNeighbors := ipstack.GetNeighbors() +// for _, iface := range myInterfaces { +// // send RIP updates to all neighbors +// for _, _ = range myNeighbors { +// // iface.udp.Write(neighbor, data) +// // iface.RecvSocket.Write(neighbor, data) +// // wait for response for 12 seconds +// response := make([]byte, 512) +// iface.RecvSocket.Read(response) +// time.Sleep(12 * time.Second) +// if len(response) == 0 { +// // ipstack.RemoveNeighbor(neighbor) +// } +// } +// } +// time.Sleep(5 * time.Second) +// } func main() { if len(os.Args) != 2 { @@ -44,8 +44,14 @@ func main() { // myNeighbors := ipstack.GetNeighbors() // myRoutes := ipstack.GetRoutes() - go SendUpdates() + go func() { + for { + ipstack.SendUpdates() + time.Sleep(5 * time.Second) + } + }() + go ipstack.CheckAndUpdateRoutingTable() scanner := bufio.NewScanner(os.Stdin) @@ -90,9 +96,18 @@ func main() { fmt.Println(err) continue } - ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) + err = ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) + if err != nil { + fmt.Println(err) + continue + } + continue + } + err = ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) + if err != nil { + fmt.Println(err) + continue } - ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) } } if len(line) > 2 { |