예제 #1
0
 protected override void LinkAdded(IMLink link, Parameters parameters, bool visualise)
 {
     findShortestPaths(TTL, "'" + link.Name + "' added", visualise);
     //If there was a packet which was received from the other end of the link that was added before
     //the link had been added process it.
     if (_unknownPacket != null && _unknownPacket.S.Equals(link.OtherEnd(ID)))
     {
         ProcessPacket(_unknownPacket);
         _unknownPacket = null;
     }
 }
예제 #2
0
        public MNode(INode node, ForwardDelegate forwardMethod, String defaultAlgorithm, IAlgorithm[] algorithms, IKeyTableFactory tableFactory)
            : base(node)
        {
            _passDownMethod = forwardMethod;
            _tableFactory   = tableFactory;
            _links          = tableFactory.MakeKeyTable <IMLink>();
            _neighbours     = tableFactory.MakeKeyTable <IMNodeInternal>();
            _algorithms     = new Dictionary <string, IAlgorithmNode>();

            foreach (IAlgorithm alg in algorithms)
            {
                IAlgorithmNode algNode = alg.MakeNode(this, SendPacket);
                _algorithms.Add(alg.Name, algNode);
                algNode.OnRouteChange     += RouteChangeListener;
                algNode.IsCurrentAlgorithm = alg.Name.Equals(defaultAlgorithm);
                if (algNode.IsCurrentAlgorithm)
                {
                    _currentAlgorithm = algNode;
                }
            }
            if (_currentAlgorithm == null)
            {
                throw new Exception("Test Node unable to set algorithm. '" + defaultAlgorithm + "' is not a valid algorithm.");
            }
            _currentAlgorithmName = defaultAlgorithm;

            _passDownMethod = forwardMethod;

            OnPacketReceived += (at, p) => {
                IMPacket packet = p as IMPacket;
                if (packet != null && packet.Type == PTypes.data)
                {
                    ReceiveData(packet);
                }
                else if (packet != null && _algorithms.ContainsKey(packet.Algorithm))
                {
                    _algorithms[packet.Algorithm].ProcessPacket(packet);
                }
            };
            _weightDelegate = (id, newWeight) => {
                if (OnWeightChange != null)
                {
                    OnWeightChange(id, newWeight);
                    Logger.Debug(Name + " triggered OnWeightChange for '" + Links[id].Name + "'.");
                }
            };
            _highlightDelegate = () => ResetHighlightAll();
            OnHighlightReset  += _highlightDelegate;
        }
예제 #3
0
        public override void ProcessPacket(IMPacket p)
        {
            LinkStatePacket packet = p as LinkStatePacket;

            if (packet == null)
            {
                Logger.Info(ToString() + " received unknown packet: " + p.Name);
                return;
            }
            if (!_processedEvents.Contains(packet.Event))
            {
                _changed = true;
                OnChange("Receiving packet from '" + p.Source.Name + "'", Links.ContainsKey(p.S) ? Links[p.S].ID : UUID.Zero, packet.Event, p.Visualise);
            }
        }
예제 #4
0
 /// <summary>
 ///   What to do when a data packet is received.
 ///
 ///   Will either forward the packet along the relevant link in the routing table or
 ///   print out that the packet was received in world.
 /// </summary>
 /// <param name = "packet">The packet</param>
 protected virtual void ReceiveData(IMPacket packet)
 {
     if (ID.Equals(packet.D))
     {
         Say("Received " + packet.Name);
         Util.Wake(this);
     }
     else if (packet.D != null && ForwardingTable.ContainsKey(packet.D))
     {
         packet.Hop = this;
         SendPacket(this.ID, ForwardingTable[packet.D].ID, packet);
     }
     else
     {
         dropped(packet);
     }
 }
예제 #5
0
        public override void ProcessPacket(IMPacket p)
        {
            if (!Links.ContainsKey(p.S))
            {
                _unknownPacket = p;
                return;
            }

            DVPacket packet = p as DVPacket;

            lock (neighbourVectors)
                //Add the new distance vector to the collection of known distance vectors
                if (!neighbourVectors.ContainsKey(p.S))
                {
                    neighbourVectors.Add(p.S, packet.DistanceVector);
                }
                else
                {
                    neighbourVectors[p.S] = packet.DistanceVector;
                }
            findShortestPaths(packet.TTL, "Distance Vector receiving '" + p.Name + "'", p.Visualise);
        }
예제 #6
0
 /// <inhertidoc />
 private void dropped(IMPacket packet)
 {
     Say("Unable to forward packet to " + packet.Destination.Name);
 }
예제 #7
0
 /// <summary>
 ///   What to do when a data packet is received.
 /// 
 ///   Will either forward the packet along the relevant link in the routing table or 
 ///   print out that the packet was received in world.
 /// </summary>
 /// <param name = "packet">The packet</param>
 protected virtual void ReceiveData(IMPacket packet)
 {
     if (ID.Equals(packet.D)) {
         Say("Received " + packet.Name);
         Util.Wake(this);
     } else if (packet.D != null && ForwardingTable.ContainsKey(packet.D)) {
         packet.Hop = this;
         SendPacket(this.ID, ForwardingTable[packet.D].ID, packet);
     } else
         dropped(packet);
 }
예제 #8
0
 public override void ProcessPacket(IMPacket packet)
 {
     //Do nothing
 }
예제 #9
0
 public override void ProcessPacket(IMPacket packet)
 {
     //Do nothing
 }
예제 #10
0
 /// <inhertidoc />
 private void dropped(IMPacket packet)
 {
     Say("Unable to forward packet to " + packet.Destination.Name);
 }
예제 #11
0
 /// <inhertidoc />
 public abstract void ProcessPacket(IMPacket packet);
예제 #12
0
 protected override void LinkAdded(IMLink link, Parameters parameters, bool visualise)
 {
     findShortestPaths(TTL, "'" + link.Name + "' added", visualise);
     //If there was a packet which was received from the other end of the link that was added before
     //the link had been added process it.
     if (_unknownPacket != null && _unknownPacket.S.Equals(link.OtherEnd(ID))) {
         ProcessPacket(_unknownPacket);
         _unknownPacket = null;
     }
 }
예제 #13
0
        public override void ProcessPacket(IMPacket p)
        {
            if (!Links.ContainsKey(p.S)) {
                _unknownPacket = p;
                return;
            }

            DVPacket packet = p as DVPacket;

            lock (neighbourVectors)
                //Add the new distance vector to the collection of known distance vectors
                if (!neighbourVectors.ContainsKey(p.S))
                    neighbourVectors.Add(p.S, packet.DistanceVector);
                else
                    neighbourVectors[p.S] = packet.DistanceVector;
            findShortestPaths(packet.TTL, "Distance Vector receiving '" + p.Name + "'", p.Visualise);
        }