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; } }
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; }
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); } }
/// <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); } }
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); }
/// <inhertidoc /> private void dropped(IMPacket packet) { Say("Unable to forward packet to " + packet.Destination.Name); }
/// <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); }
public override void ProcessPacket(IMPacket packet) { //Do nothing }
/// <inhertidoc /> public abstract void ProcessPacket(IMPacket packet);
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); }