Ejemplo n.º 1
0
 public bool ConnectivityChanged(LSP old)
 {
     if (old == null)
     {
         return(true);
     }
     foreach (var item in this.Links)
     {
         int  val;
         bool exists = old.Links.TryGetValue(item.Key, out val);
         if (!exists || val != item.Value)
         {
             return(false);
         }
     }
     foreach (var item in old.Links)
     {
         int  val;
         bool exists = this.Links.TryGetValue(item.Key, out val);
         if (!exists || val != item.Value)
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
        public void OriginatePackage()
        {
            if (!started)
            {
                return;
            }

            Console.WriteLine($"Router {routerId} has originated a package.");

            foreach (var item in Connections)
            {
                item.TickCount++;
                if (item.TickCount > 1)
                {
                    item.Maxed = true;
                }
            }

            Dictionary <int, int> links = new Dictionary <int, int>();

            foreach (var item in Connections)
            {
                links.Add(item.Router.routerId, item.Cost);
            }
            LSP lsp = new LSP(routerId, ++sequenceId, links);

            replaceLSDB(lsp);
            ConstructRoutingTable();
            foreach (var item in Connections)
            {
                item.Router.ReceivePackage(lsp);
            }
        }
Ejemplo n.º 3
0
        public void ReceivePackage(LSP newLSP)
        {
            if (!started)
            {
                return;
            }



            newLSP.TTL--;

            foreach (var item in Connections)
            {
                if (item.Router.routerId == newLSP.SourceId)
                {
                    item.TickCount = 0;
                    item.Maxed     = false;
                }
            }
            LSP oldLSP;

            LSDB.TryGetValue(newLSP.SourceId, out oldLSP);
            if (newLSP.TTL > 0 && newLSP.Newer(oldLSP))
            {
                replaceLSDB(newLSP);
                if (newLSP.ConnectivityChanged(oldLSP))
                {
                    ConstructRoutingTable();
                }
                foreach (var item in Connections)
                {
                    item.Router.ReceivePackage(newLSP);
                }
            }
        }
Ejemplo n.º 4
0
 public bool Newer(LSP old)
 {
     if (old == null || this.SequenceId > old.SequenceId)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 5
0
 private void replaceLSDB(LSP newLSP)
 {
     LSDB[newLSP.SourceId] = newLSP;
 }