示例#1
0
        public void Run()
        {
            HashSet<Node> network = NetworkGraph.GetNetworkGraph();
            int currentIteration = 0;

            table = new RoutingTable(this, network);

            while( true )
            {
                try
                {
                    if(IsOk())
                    {
                        table.PrintTable(currentIteration);
                        Broadcast(table);
                    }
                    else
                    {
                        Console.WriteLine(ipAddress + " has failed!");
                        break;
                    }

                    if( Program.enableNodeFailure )
                    {
                        RandomFail();
                    }

                    Thread.Sleep(1000);
                    currentIteration++;
                } catch ( NullReferenceException e) {}
            }
        }
示例#2
0
        private void Broadcast( RoutingTable t )
        {
            HashSet<Edge> edges = GetEdges();

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

                Node neighbor;

                if (x.GetAddress().Equals(ipAddress))
                    neighbor = y;
                else
                    neighbor = x;

                neighbor.Receive(this, t);

                t.IncrementTimer(neighbor.GetAddress());
            }
        }
示例#3
0
        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) { }
        }