diff options
author | David Doan <daviddoan@Davids-MacBook-Pro-70.local> | 2023-10-23 15:26:45 -0400 |
---|---|---|
committer | David Doan <daviddoan@Davids-MacBook-Pro-70.local> | 2023-10-23 15:26:45 -0400 |
commit | aaa3e0e5279c534bb07856bbce867e4cde2ed255 (patch) | |
tree | 44cfe6a0d344a07e2c94d2e69726b2130de7eebb | |
parent | 766ee3654c3ccca3b9a80d26736bfcbb9e37d708 (diff) | |
parent | 4dff16be71e58c8669ddfdcd5bcee90061b2cf51 (diff) |
comments and refactoring
-rw-r--r-- | pkg/ipstack/ipstack.go | 24 | ||||
-rwxr-xr-x | vhost | bin | 3110259 -> 0 bytes | |||
-rwxr-xr-x | vrouter | bin | 3110267 -> 0 bytes |
3 files changed, 19 insertions, 5 deletions
diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go index 038a2d4..e3d9ca2 100644 --- a/pkg/ipstack/ipstack.go +++ b/pkg/ipstack/ipstack.go @@ -192,8 +192,11 @@ func InterfaceListenerRoutine(i *Interface) { if closed { // stop this go routine if channel is closed return } - - time.Sleep(1 * time.Millisecond) + //if !isUp { // don't call the listeners if interface is down + // continue + //} + // TODO: remove these "training wheels" + // time.Sleep(1 * time.Millisecond) err := RecvIP(i, &isUp) if err != nil { continue @@ -232,7 +235,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) { @@ -375,7 +389,7 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de // check if the interface is up 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 the header is nil, create a new one if hdr == nil { @@ -462,7 +476,7 @@ func RecvIP(iface *Interface, isOpen *bool) error { // check if the interface is up 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 @@ -886,7 +900,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() Binary files differdiff --git a/vrouter b/vrouter Binary files differdeleted file mode 100755 index 230afe9..0000000 --- a/vrouter +++ /dev/null |