aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/vhost/main.go15
-rw-r--r--cmd/vrouter/main.go59
2 files changed, 49 insertions, 25 deletions
diff --git a/cmd/vhost/main.go b/cmd/vhost/main.go
index 27e073f..2ecbfa7 100644
--- a/cmd/vhost/main.go
+++ b/cmd/vhost/main.go
@@ -65,11 +65,20 @@ 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 {
if line[:2] == "up" {
// get interface name
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 {