aboutsummaryrefslogtreecommitdiff
path: root/pkg/ipstack
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-10-22 09:58:24 -0400
committersotech117 <michael_foiani@brown.edu>2023-10-22 09:58:24 -0400
commitd7c20268db996cd4a6599d85d0219a525dd43e6e (patch)
treeeca7a03955aab9f70372d99b1965527a7c1e1650 /pkg/ipstack
parente333100499904a35126dd70eea58802ed9761435 (diff)
implement delete from table based on timeout
Diffstat (limited to 'pkg/ipstack')
-rw-r--r--pkg/ipstack/ipstack.go46
1 files changed, 41 insertions, 5 deletions
diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go
index 4a552cf..5160ab2 100644
--- a/pkg/ipstack/ipstack.go
+++ b/pkg/ipstack/ipstack.go
@@ -10,6 +10,7 @@ import (
"log"
"net"
"net/netip"
+ "sync"
"time"
// "bytes"
// "unicode"
@@ -616,16 +617,44 @@ func periodicUpdateRoutine() {
}
}
-//timeoutTable := make(map[netip.Addr]time.Time)
-//func manageTimeoutsRoutine() {
-// for
-//}
+var mu sync.Mutex
+var timeoutTable = make(map[netip.Prefix]int)
+var MAX_TIMEOUT = 12
+
+func manageTimeoutsRoutine() {
+ for {
+ time.Sleep(time.Second)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(len(timeoutTable))
+ mu.Lock()
+ for prefix, _ := range timeoutTable {
+ go func(p netip.Prefix) {
+ timeoutTable[p]++
+ if timeoutTable[p] == MAX_TIMEOUT {
+ delete(routingTable, p)
+ delete(timeoutTable, p)
+ }
+
+ wg.Done()
+ }(prefix)
+ }
+ wg.Wait()
+ mu.Unlock()
+
+ // fmt.Println("Timeout table: ", timeoutTable)
+ }
+}
func startRipRoutines() {
// send a request to every neighbor
go func() {
for _, iface := range myInterfaces {
for _, neighbor := range myNeighbors[iface.Name] {
+ _, in := myRIPNeighbors[neighbor.VipAddr.String()]
+ if !in {
+ continue
+ }
// send a request
message := NewRIPMessage(1, nil)
err := SendRIPMessage(*iface, neighbor, message)
@@ -639,7 +668,7 @@ func startRipRoutines() {
go periodicUpdateRoutine()
// make a "timeout" table, for each response we add to the table via rip
- // go manageTimeoutsRoutine()
+ go manageTimeoutsRoutine()
// start a routine that sends updates every 10 seconds
}
@@ -692,6 +721,8 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I
continue
}
+ fmt.Println(address)
+
prefix := netip.PrefixFrom(netip.MustParseAddr(address), int(entry.mask))
// fmt.Println(prefix.String())
@@ -700,6 +731,11 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I
if entry.cost < node.Cost {
routingTable[prefix.Masked()] = Hop{entry.cost + 1, "R", src, hdr.Src}
}
+ if node.Type == "R" {
+ mu.Lock()
+ timeoutTable[prefix.Masked()] = 0
+ mu.Unlock()
+ }
continue
}