Ejemplo n.º 1
0
        //run dijkstra to populate routing table
        public void ComputeShortestPaths()
        {
            List <string> _lstDestinations = new List <string>();

            foreach (Edge _edge in _hsEdges)
            {                           //create edge from link info
                _lstDestinations.Add(_edge.Source);
                _lstDestinations.Add(_edge.Destination);
            }

            Dijkstra dijkstra = new Dijkstra(_strId, _hsEdges); //pass start node and graph

            dijkstra.CalculatePath();                           //run algo to compute shortest path
            InitRoutingTable();                                 //reinitialize routing table
            foreach (string _strDestination in _lstDestinations)
            {
                string _strRoute = dijkstra.GetCostAndRoute(_strDestination); //in format: cost;p1,p2,p3....
                if (!string.IsNullOrEmpty(_strRoute))
                {
                    string   cost = _strRoute.Split(';')[0];                                  //element before ;
                    string[] path = (_strRoute.Split(';')[1]).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    Router   _destinationRouter = Program._dicRouters[path[path.Length - 1]]; //dest router is last on the array

                    RoutingRow _routingRow = new RoutingRow();
                    _routingRow.NetworkName = _destinationRouter._strNetworkName;
                    _routingRow.Cost        = int.Parse(cost) + _destinationRouter._nCostToNetwork; //router to router + network cost
                    _routingRow.Link        = path[1];                                              //second hop on path is the outgoing link
                    _hsRoutingTable.Add(_routingRow);
                }
            }
        }
Ejemplo n.º 2
0
        private void InitRoutingTable()
        {   //only add own network to routing table to start with
            _hsRoutingTable = new HashSet <RoutingRow>();
            RoutingRow _routingRow = new RoutingRow();

            _routingRow.NetworkName = _strNetworkName;
            _routingRow.Cost        = _nCostToNetwork;
            _routingRow.Link        = _strId;
            _hsRoutingTable.Add(_routingRow);
        }
Ejemplo n.º 3
0
        //network name is unique and PK, hence use only this for hashcode and equals
        public override bool Equals(object o)
        {
            if (o == null || GetType() != o.GetType())
            {
                return(false);
            }

            RoutingRow _another = (RoutingRow)o;

            return(_strNetworkName.Equals(_another._strNetworkName));
        }