From 41a675f0f260b7436713a63f6cf2f1db7f8d827f Mon Sep 17 00:00:00 2001 From: sotech117 Date: Mon, 9 Oct 2023 10:00:06 -0400 Subject: fix the bugs with filling data structures --- pkg/ipstack/ipstack.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'pkg/ipstack/ipstack.go') diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go index abaa09f..e4d1651 100644 --- a/pkg/ipstack/ipstack.go +++ b/pkg/ipstack/ipstack.go @@ -10,15 +10,14 @@ import ( const ( MAX_IP_PACKET_SIZE = 1400 - LOCAL_COST uint32 = 4294967295 // 2^32 - 1 - STATIC_COST uint32 = 1 + LOCAL_COST uint32 = 0 + STATIC_COST uint32 = 4294967295 // 2^32 - 1 ) // STRUCTS --------------------------------------------------------------------- type Interface struct { - Name string - IpAddress netip.Addr - IpPrefix netip.Prefix + Name string + IpPrefix netip.Prefix RecvSocket net.Conn SocketChannel chan<- bool @@ -52,7 +51,7 @@ type Hop struct { // GLOBAL VARIABLES (data structures) ------------------------------------------ var myInterfaces []Interface -var myNeighbors = make(map[string]Neighbor) +var myNeighbors = make(map[string][]Neighbor) // var myRIPNeighbors = make(map[string]Neighbor) type HandlerFunc func(int, string, *[]byte) error @@ -93,10 +92,10 @@ func Initialize(lnxFilePath string) error { // 1) initialize the interfaces on this node here and into the routing table for _, iface := range lnxConfig.Interfaces { + prefix := netip.PrefixFrom(iface.AssignedIP, iface.AssignedPrefix.Bits()) i := &Interface{ Name: iface.Name, - IpAddress: iface.AssignedIP, - IpPrefix: iface.AssignedPrefix, + IpPrefix: prefix, RecvSocket: nil, SocketChannel: nil, State: false, @@ -108,8 +107,8 @@ func Initialize(lnxFilePath string) error { myInterfaces = append(myInterfaces, *i) // add to routing table - ifacePrefix := netip.PrefixFrom(iface.AssignedIP, iface.AssignedPrefix.Bits()) - routingTable[ifacePrefix] = Hop{STATIC_COST, iface.Name} + //ifacePrefix := netip.PrefixFrom(iface.AssignedIP, iface.AssignedPrefix.Bits()) + //routingTable[ifacePrefix] = Hop{STATIC_COST, iface.Name} } // 2) initialize the neighbors connected to the node @@ -123,8 +122,7 @@ func Initialize(lnxFilePath string) error { if err != nil { return errors.WithMessage(err, "Error creating UDP socket for neighbor->\t"+neighbor.DestAddr.String()) } - // TODO: make a hash map - myNeighbors[neighbor.InterfaceName] = *n + myNeighbors[neighbor.InterfaceName] = append(myNeighbors[neighbor.InterfaceName], *n) // add to routing table neighborPrefix := netip.PrefixFrom(neighbor.DestAddr, 24) @@ -333,7 +331,9 @@ func PrintInterfaces() { func PrintNeighbors() { for ifaceName, neighbor := range myNeighbors { - fmt.Printf("%s\t%s\t%s\n", ifaceName, neighbor.IpAddress.String(), neighbor.UdpAddr.String()) + for _, n := range neighbor { + fmt.Printf("%s\t%s\t%s\n", ifaceName, n.UdpAddr.String(), n.VipAddr.String()) + } } } -- cgit v1.2.3-70-g09d2