diff options
author | David Doan <daviddoan@Davids-MacBook-Pro-70.local> | 2023-10-06 19:33:48 -0400 |
---|---|---|
committer | David Doan <daviddoan@Davids-MacBook-Pro-70.local> | 2023-10-06 19:33:48 -0400 |
commit | ded5a362b43715497a6f887354dd1a20bc9a621b (patch) | |
tree | e3bbb29c28bd5545d5897124d64f982ee07eb358 | |
parent | 5a5dec572c01a7d306c3bdd3fd0ad8cec63c6049 (diff) |
small updates
-rw-r--r-- | pkg/protocol.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/pkg/protocol.go b/pkg/protocol.go index 9358099..63951d6 100644 --- a/pkg/protocol.go +++ b/pkg/protocol.go @@ -58,10 +58,19 @@ type RIPEntry struct { mask netip.Prefix; } +type RoutingTable interface { + Initialize(config IpConfig) (error) + AddRoute(dest Address, cost uint16_t, mask netip.Prefix) (error) + RemoveRoute(dest Address) (error) + GetRoute(dest Address) (Routing, error) +} + + myInterfaces := make([]Interface); myNeighbors := make(map[string]Neighbor) myRIPNeighbors := make(map[string]Neighbor) protocolHandlers := make(map[uint16]HandlerFunc) +routingTable := RoutingTable{} // routingTable := make(map[Address]Routing) func Initialize(config IpConfig) (error) { @@ -90,6 +99,10 @@ func Initialize(config IpConfig) (error) { for _, neighbor := range lnxConfig.RipNeighbors { myRIPNeighbors[neighbor.DestAddr.String()] = Neighbor{neighbor.DestAddr, neighbor.UDPAddr, neighbor.InterfaceName} } + // call routingTable.Initialize(config) + // create new routing table + routingTable.Initialize(config) + } func ListerToInterfaces() { @@ -197,7 +210,6 @@ func SendIp(dst netip.Addr, port uint16, protocolNum uint16, data []byte, iface log.Panicln("Dial: ", err) } - // Start filling in the header message := data[20:] hdr := ipv4header.IPv4Header{ Version: data[0] >> 4, @@ -215,14 +227,11 @@ func SendIp(dst netip.Addr, port uint16, protocolNum uint16, data []byte, iface Options: []byte{}, } - // Assemble the header into a byte array headerBytes, err := hdr.Marshal() if err != nil { log.Fatalln("Error marshalling header: ", err) } - // Compute the checksum (see below) - // Cast back to an int, which is what the Header structure expects hdr.Checksum = int(ComputeChecksum(headerBytes)) headerBytes, err = hdr.Marshal() @@ -274,14 +283,6 @@ func RemoveRecvHandler(protocolNum uint8) (error) { return nil } -// func routeRip(data []byte) (error) { -// // deconstruct packet -// newRIPMessage := RIPMessage{} -// newRIPMessage.command = data[0] -// newRIPMessage.numEntries = data[1] -// newRIPMessage.entries = make([]RIPEntry, newRIPMessage.numEntries) -// } - func PrintNeighbors() { for _, iface := range myNeighbors { fmt.Printf("%s\n", iface.addr.String()) |