From 6fe8b91fb91882f456ebba16ee9a27f804c24e26 Mon Sep 17 00:00:00 2001 From: sotech117 Date: Mon, 23 Oct 2023 14:57:34 -0400 Subject: small refactoring --- pkg/ipstack/ipstack.go | 2 +- vhost | Bin 3105176 -> 3095650 bytes vrouter | Bin 3105176 -> 3095650 bytes 3 files changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go index 61b33b0..2ab2a5f 100644 --- a/pkg/ipstack/ipstack.go +++ b/pkg/ipstack/ipstack.go @@ -887,7 +887,7 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I if entry.cost == INFINITY { // remove after GC time if the COST is still INFINITY go func() { - time.Sleep(12 * time.Second) + time.Sleep(time.Second * time.Duration(MAX_TIMEOUT)) if routingTable[destination].Cost == INFINITY { delete(routingTable, destination) mu.Lock() diff --git a/vhost b/vhost index f9b9407..7ca732c 100755 Binary files a/vhost and b/vhost differ diff --git a/vrouter b/vrouter index b5f089b..7b61c7e 100755 Binary files a/vrouter and b/vrouter differ -- cgit v1.2.3-70-g09d2 From fbda20200bd0f54cda6c0b09bfbe6f991ee77d9f Mon Sep 17 00:00:00 2001 From: sotech117 Date: Mon, 23 Oct 2023 15:08:11 -0400 Subject: add RIP request on interface UP along with better error messages for interfaces being down & up --- pkg/ipstack/ipstack.go | 15 +++++++++++++-- vhost | Bin 3095650 -> 3105680 bytes vrouter | Bin 3095650 -> 3105648 bytes 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go index 2ab2a5f..f6c86a8 100644 --- a/pkg/ipstack/ipstack.go +++ b/pkg/ipstack/ipstack.go @@ -226,7 +226,18 @@ func InterfaceUp(iface *Interface) { ripEntries := make([]RIPEntry, 0) ripEntries = append(ripEntries, RIPEntry{iface.IpPrefix.Masked(), LOCAL_COST}) sendTriggeredUpdates(ripEntries) + + // send a request to all neighbors of this iface to get info ASAP + for _, neighbor := range myNeighbors[iface.Name] { + message := makeRipMessage(1, nil) + addr := iface.IpPrefix.Addr() + _, err := SendIP(&addr, neighbor, RIP_PROTOCOL, message, neighbor.VipAddr.String(), nil) + if err != nil { + fmt.Println("Error sending RIP request to neighbor on interfaceup", err) + } + } } + } func InterfaceUpREPL(ifaceName string) { @@ -379,7 +390,7 @@ func CleanUp() { func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, destIP string, hdr *ipv4header.IPv4Header) (int, error) { iface, err := GetInterfaceByName(dest.Name) if !iface.State { - return -1, errors.New("error: interface is down") + return -1, errors.Errorf("error SEND: %s is down", iface.Name) } if hdr == nil { @@ -466,7 +477,7 @@ func RecvIP(iface *Interface, isOpen *bool) error { } if !*isOpen { - return errors.New("interface is down") + return errors.Errorf("error RECV: %s is down", iface.Name) } // Marshal the received byte array into a UDP header diff --git a/vhost b/vhost index 7ca732c..82e8ed0 100755 Binary files a/vhost and b/vhost differ diff --git a/vrouter b/vrouter index 7b61c7e..6a34548 100755 Binary files a/vrouter and b/vrouter differ -- cgit v1.2.3-70-g09d2 From 4dff16be71e58c8669ddfdcd5bcee90061b2cf51 Mon Sep 17 00:00:00 2001 From: sotech117 Date: Mon, 23 Oct 2023 15:14:04 -0400 Subject: remove training wheels used for testing --- pkg/ipstack/ipstack.go | 2 +- vhost | Bin 3105680 -> 3095650 bytes vrouter | Bin 3105648 -> 3095650 bytes 3 files changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go index f6c86a8..030b9c7 100644 --- a/pkg/ipstack/ipstack.go +++ b/pkg/ipstack/ipstack.go @@ -190,7 +190,7 @@ func InterfaceListenerRoutine(i *Interface) { // continue //} // TODO: remove these "training wheels" - time.Sleep(1 * time.Millisecond) + // time.Sleep(1 * time.Millisecond) err := RecvIP(i, &isUp) if err != nil { // fmt.Println("Error receiving IP packet", err) diff --git a/vhost b/vhost index 82e8ed0..1d2d12f 100755 Binary files a/vhost and b/vhost differ diff --git a/vrouter b/vrouter index 6a34548..1329ee6 100755 Binary files a/vrouter and b/vrouter differ -- cgit v1.2.3-70-g09d2