예제 #1
0
        public RoutingTable( Node n, HashSet<Node> netGraph )
        {
            this.currentNode = n;

            HashSet<Edge> neighborsEdges = n.GetEdges();

            foreach( Edge e in neighborsEdges )
            {
                Node x = e.GetX();
                Node y = e.GetY();

                Node neighbor;

                if (currentNode.Equals(x))
                    neighbor = y;
                else
                    neighbor = x;

                neighborNodes.Add(neighbor);
            }

            foreach( Node r in netGraph )
            {
                String curIP = r.GetAddress();

                if( !curIP.Equals( currentNode.GetAddress()) && !neighborNodes.Contains( r ) )
                {
                    destinationIP.Add(curIP);
                    subnetMask.Add(n.GetMask());
                    distanceMetric.Add(infinity);
                    nextHopIP.Add("0.0.0.0");
                }
                else if ( neighborNodes.Contains(r) )
                {
                    int weight = 0;

                    foreach( Edge e in neighborsEdges )
                    {
                        Node x = e.GetX();
                        Node y = e.GetY();

                        if( x.Equals(r) || y.Equals(r) )
                        {
                            weight = e.GetWeight();
                        }
                    }

                    destinationIP.Add(curIP);
                    subnetMask.Add(n.GetMask());
                    distanceMetric.Add(weight);
                    nextHopIP.Add(n.GetAddress());
                    destinationTimes.Add(0);
                }
            }
        }
예제 #2
0
파일: Node.cs 프로젝트: umbarger/RouterRIP
        private void Receive( Node neighbor, RoutingTable neighborTable )
        {
            try
            {
                String neighborAddress = neighbor.GetAddress();

                List<String> neighborDestinations = neighborTable.GetDestinations();
                List<String> myDestinations = table.GetDestinations();

                // Compare the neighbor's routing table with your own... Update better routes
                foreach (String nDest in neighborDestinations)
                {
                    foreach (String myDest in myDestinations)
                    {
                        if (myDest.Equals(nDest))
                        {
                            int myMetric = table.GetDistanceMetric(myDest);
                            int nMetric = neighborTable.GetDistanceMetric(nDest);

                            if (nMetric < myMetric)
                            {
                                int newMetric;
                                int curNodeToNeighborDistance = table.GetDistanceMetric(nDest);

                                if (curNodeToNeighborDistance == (int)Int32.MaxValue)
                                    newMetric = nMetric;
                                else
                                    newMetric = nMetric + curNodeToNeighborDistance;

                                table.UpdateMetric(myDest, newMetric);
                                table.UpdateNextHop(myDest, table.GetDestination(neighborAddress));

                                table.ResetTimer(myDest);
                                table.ResetTimer(nDest);
                            }
                        }
                    }
                }

                table.ResetTimer(neighborAddress);
            }
            catch (NullReferenceException e) { }
        }