From 93416359403895d1dd1584c316d9e3dbfcc7a673 Mon Sep 17 00:00:00 2001 From: sotech117 Date: Mon, 23 Oct 2023 18:15:27 -0400 Subject: update socket name in readme --- README.md | 3 ++- cmd/vhost/main.go | 3 +-- pkg/ipstack/ipstack.go | 41 ++++++++++++++++++++--------------------- vhost | Bin 3110277 -> 3105370 bytes vrouter | Bin 3110285 -> 3105378 bytes 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 1be94fa..e097c82 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ type Interface struct { Name string IpPrefix netip.Prefix UdpAddr netip.AddrPort - RecvSocket net.UDPConn + + Socket net.UDPConn SocketChannel chan bool State bool diff --git a/cmd/vhost/main.go b/cmd/vhost/main.go index 5a8324f..3c35792 100644 --- a/cmd/vhost/main.go +++ b/cmd/vhost/main.go @@ -59,7 +59,7 @@ func main() { // combine message into one string messageToSend := strings.Join(message, " ") messageToSendBytes := []byte(messageToSend) - + address, _ := netip.ParseAddr(ipAddr) hop, err := ipstack.LongestPrefix(address) if err != nil { @@ -68,7 +68,6 @@ func main() { } myAddr := hop.Interface.IpPrefix.Addr() for _, neighbor := range ipstack.GetNeighbors()[hop.Interface.Name] { - // TODO: fix multiple send bug here on static route if neighbor.VipAddr == address || neighbor.VipAddr == hop.VIP && hop.Type == "S" { bytesWritten, err := ipstack.SendIP(&myAddr, neighbor, ipstack.TEST_PROTOCOL, messageToSendBytes, ipAddr, nil) diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go index d8db8d2..6c2330d 100644 --- a/pkg/ipstack/ipstack.go +++ b/pkg/ipstack/ipstack.go @@ -15,16 +15,16 @@ import ( ) const ( - MAX_IP_PACKET_SIZE = 1400 - LOCAL_COST uint32 = 0 - STATIC_COST uint32 = 4294967295 // 2^32 - 1 - MaxEntries = 64 - INFINITY = 16 - SIZE_OF_RIP_ENTRY = 12 - RIP_PROTOCOL = 200 - TEST_PROTOCOL = 0 - SIZE_OF_RIP_HEADER = 4 - MAX_TIMEOUT = 12 + MAX_IP_PACKET_SIZE = 1400 + LOCAL_COST uint32 = 0 + STATIC_COST uint32 = 4294967295 // 2^32 - 1 + MaxEntries = 64 + INFINITY = 16 + SIZE_OF_RIP_ENTRY = 12 + RIP_PROTOCOL = 200 + TEST_PROTOCOL = 0 + SIZE_OF_RIP_HEADER = 4 + MAX_TIMEOUT = 12 ) // STRUCTS --------------------------------------------------------------------- @@ -33,7 +33,7 @@ type Interface struct { IpPrefix netip.Prefix UdpAddr netip.AddrPort - RecvSocket net.UDPConn + Socket net.UDPConn SocketChannel chan bool State bool } @@ -112,13 +112,13 @@ func Initialize(lnxFilePath string) error { Name: iface.Name, IpPrefix: prefix, UdpAddr: iface.UDPAddr, - RecvSocket: net.UDPConn{}, + Socket: net.UDPConn{}, SocketChannel: make(chan bool), State: true, } // create the UDP listener - err := createUDPListener(iface.UDPAddr, &i.RecvSocket) + err := createUDPListener(iface.UDPAddr, &i.Socket) if err != nil { return errors.WithMessage(err, "Error creating UDP socket for interface->\t"+iface.Name) } @@ -177,7 +177,7 @@ func Initialize(lnxFilePath string) error { // defines the go routine that listens on the UDP socket func InterfaceListenerRoutine(i *Interface) { // decompose the interface - socket := i.RecvSocket + socket := i.Socket signal := i.SocketChannel // booleans to control listening routine @@ -377,7 +377,7 @@ func CleanUp() { close(iface.SocketChannel) } // close the UDP FD - err := iface.RecvSocket.Close() + err := iface.Socket.Close() if err != nil { continue } @@ -463,7 +463,7 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de // TODO: make this faster by removing call // send the packet - bytesWritten, err := iface.RecvSocket.WriteToUDP(bytesToSend, sendAddr) + bytesWritten, err := iface.Socket.WriteToUDP(bytesToSend, sendAddr) if err != nil { fmt.Println("Error writing to UDP socket") return -1, errors.WithMessage(err, "Error writing to UDP socket") @@ -472,14 +472,13 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de return bytesWritten, nil } - // RecvIP receives an IP packet from a source func RecvIP(iface *Interface, isOpen *bool) error { buffer := make([]byte, MAX_IP_PACKET_SIZE) // TODO: fix wording // Read on the UDP port // fmt.Println("wating to read from UDP socket") - _, _, err := iface.RecvSocket.ReadFromUDP(buffer) + _, _, err := iface.Socket.ReadFromUDP(buffer) if err != nil { return err } @@ -598,13 +597,13 @@ func RecvIP(iface *Interface, isOpen *bool) error { // creates a byte array that represents a RIP message func makeRipMessage(command uint16, entries []RIPEntry) []byte { - if command == 1 { // request message + if command == 1 { // request message buf := make([]byte, SIZE_OF_RIP_HEADER) binary.BigEndian.PutUint16(buf[0:2], command) binary.BigEndian.PutUint16(buf[2:4], uint16(0)) return buf } - + // command == 2, response message // create the buffer @@ -951,4 +950,4 @@ func LongestPrefix(src netip.Addr) (Hop, error) { } } return Hop{}, errors.Errorf("No route to ip %s on table.", src) -} \ No newline at end of file +} diff --git a/vhost b/vhost index 727a450..5cbef76 100755 Binary files a/vhost and b/vhost differ diff --git a/vrouter b/vrouter index b193fa9..b7bf03d 100755 Binary files a/vrouter and b/vrouter differ -- cgit v1.2.3-70-g09d2