diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-10-23 10:43:49 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-10-23 10:43:49 -0400 |
commit | 097e6330ec777698cbaf87e008df9295e9978782 (patch) | |
tree | cb2e77a33362f3d7bf7770b32a1a3f5bec691e6b | |
parent | c0bb904306866d31d0a2644c2b74989fa3c43261 (diff) |
fixed split horizon algorithm. also, small bug fixes with RIP request and response.
-rw-r--r-- | pkg/ipstack/ipstack.go | 35 | ||||
-rwxr-xr-x | vhost | bin | 3095810 -> 3104664 bytes | |||
-rwxr-xr-x | vrouter | bin | 3095810 -> 3104672 bytes |
3 files changed, 21 insertions, 14 deletions
diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go index 019d97b..c8a4fe8 100644 --- a/pkg/ipstack/ipstack.go +++ b/pkg/ipstack/ipstack.go @@ -652,7 +652,7 @@ func periodicUpdateRoutine() { } var mu sync.Mutex -var timeoutTable = make(map[netip.Prefix]int) +var timeoutTable = make(map[netip.Addr]int) var MAX_TIMEOUT = 12 func sendTriggeredUpdates(newEntries []RIPEntry) { @@ -698,23 +698,28 @@ func manageTimeoutsRoutine() { //mu.Unlock() mu.Lock() - for prefix, _ := range timeoutTable { - timeoutTable[prefix]++ - if timeoutTable[prefix] == MAX_TIMEOUT { - delete(routingTable, prefix) - delete(timeoutTable, prefix) + for addr, _ := range timeoutTable { + timeoutTable[addr]++ + if timeoutTable[addr] == MAX_TIMEOUT { + delete(timeoutTable, addr) + + newEntries := make([]RIPEntry, 0) + for p, hop := range routingTable { + if hop.VIP == addr { + delete(routingTable, p) + newEntries = append(newEntries, RIPEntry{p, INFINITY}) + } + } // send triggered update on timeout - go func(p netip.Prefix) { - newEntries := make([]RIPEntry, 0) - newEntries = append(newEntries, RIPEntry{p, INFINITY}) + if len(newEntries) > 0 { sendTriggeredUpdates(newEntries) - }(prefix) + } } } // fmt.Println("timeout table: ", timeoutTable) mu.Unlock() - // fmt.Println("Timeout table: ", timeoutTable) + //fmt.Println("Timeout table: ", timeoutTable) } } @@ -793,7 +798,7 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I cost: cost, }) } - res := makeRipMessage(2, nil) + res := makeRipMessage(2, entries) _, err := SendIP(&hdr.Dst, neighbor, RIP_PROTOCOL, res, hdr.Src.String(), nil) if err != nil { return err @@ -844,8 +849,10 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I // then we can increase the cost by that new value if hop.VIP == hdr.Src && entry.cost > hop.Cost { + // fmt.Println("Updating route to ", destination.String(), "with cost", entry.cost) if entry.cost == INFINITY { - routingTable[destination] = Hop{entry.cost, "R", src, hdr.Src} + // if we receive infinity from the same neighbor, then delete the route + delete(routingTable, destination) } else { routingTable[destination] = Hop{entry.cost + 1, "R", src, hdr.Src} } @@ -864,7 +871,7 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I // upon an update from this prefix, reset its timeout if hop.Type == "R" { mu.Lock() - timeoutTable[destination] = 0 + timeoutTable[hdr.Src] = 0 mu.Unlock() } continue Binary files differBinary files differ |