/// <summary> /// What to do when a packet relevant to the highlight flooding algorithm is received /// /// If the node has not already received one of the highlight flooding packets flood highlight packets along all links and send a new /// highlight all packet back towards the source of the received packet /// </summary> /// <param name = "packet"></param> public void HighlightAll(IMNodeInternal hop) { if (HighlightingAll) { return; } lock (HighlightLock) { _highlightedLink = ForwardingTable.ContainsKey(_globalTargetKey) ? ForwardingTable[_globalTargetKey] : null; _highlightState = HighlghtState.HighlightingAll; if (_highlightedLink != null) { _highlightedLink.Colour = _globalHighlightColour; } foreach (IMLink l in _links) { IMNode neighbour = l.OtherEnd(this); if (!neighbour.Equals(hop)) { neighbour.HighlightAll(this); } } } }
/// <inhertidoc /> public void TriggerHighlight(string alg, IMNodeInternal target) { if (Equals(_globalHighlightTarget) || Equals(_globalHighlightRoot)) { TriggerHighlightReset(); return; } ClearOld(); _globalTargetKey = target.ID; _globalHighlightTarget = (IMNode)target; _globalHighlightRoot = this; _globalHighlightColour = Colour; _globalHighlightState = HighlghtState.HighlightingSingle; _highlightState = HighlghtState.HighlightingSingle; //If there is a route if (ForwardingTable.ContainsKey(_globalTargetKey)) { lock (HighlightLock) { _highlightedLink = ForwardingTable[_globalTargetKey]; _highlightedLink.Colour = _globalHighlightColour; IMNode node = ForwardingTable[_globalTargetKey].OtherEnd(this); node.Highlight(this); } } else { _highlightedLink = null; } }
/// <Inheritdoc /> public void Send(IMNodeExternal destination, Parameters parameters) { if (!ForwardingTable.ContainsKey(destination.ID)) { Say("Unable to forward packet to " + destination.Name); return; } IMLink link = ForwardingTable[destination.ID]; SendPacket(ID, link.ID, new MPacket(this, destination, this, parameters)); }
/// <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); } }
/// <summary> /// What to do when notified that it should highlight /// /// Will highlight the link and forward the packet on if necessary /// </summary> /// <param name = "packet">The packet received</param> public void Highlight(IMNodeInternal hop) { _highlightedLink = ForwardingTable.ContainsKey(_globalTargetKey) ? ForwardingTable[_globalTargetKey] : null; if (HighlightingSingle || (_highlightedLink != null && _highlightedLink.OtherEnd(this).Equals(hop))) { return; } lock (HighlightLock) { _highlightState = HighlghtState.HighlightingSingle; if (_highlightedLink != null) { _highlightedLink.Colour = _globalHighlightColour; _highlightedLink.OtherEnd(this).Highlight(this); } } }
private Network.Network ExampleNetwork() { // Simple network: [R1] --i1--i2-- [R2] --i3--i4-- [R3] // setup interfaces Interface i1 = new Interface(); i1.Name = "i1"; i1.GreTunnel = (Ip.Parse("1.2.3.4"), Ip.Parse("5.6.7.8")); i1.PortNumber = 1; Interface i2 = new Interface(); i2.Name = "i2"; i2.PortNumber = 1; Interface i3 = new Interface(); i3.Name = "i3"; i3.PortNumber = 2; Interface i4 = new Interface(); i4.Name = "i4"; i4.GreTunnel = (Ip.Parse("5.6.7.8"), Ip.Parse("1.2.3.4")); i4.PortNumber = 1; i4.InboundAcl = new Acl { Lines = new AclLine[] { new AclLine { DstIp = new Prefix { Address = Ip.Parse("172.0.0.0").Value, Length = 24 }, SrcIp = new Prefix { Address = Ip.Parse("63.1.0.0").Value, Length = 16 }, Permitted = true, DstPortLow = 53, DstPortHigh = 53, }, }, }; // attach neighbors i1.Neighbor = i2; i2.Neighbor = i1; i3.Neighbor = i4; i4.Neighbor = i3; // setup devices Device d1 = new Device(); d1.Name = "R1"; d1.Interfaces = new Interface[] { i1 }; Device d2 = new Device(); d2.Name = "R2"; d2.Interfaces = new Interface[] { i2, i3 }; Device d3 = new Device(); d3.Name = "R3"; d3.Interfaces = new Interface[] { i4 }; // associate owners i1.Owner = d1; i2.Owner = d2; i3.Owner = d2; i4.Owner = d3; // create and associate forwarding tables var table1 = new ForwardingTable { Rules = new ForwardingRule[] { new ForwardingRule { DstIpLow = Ip.Parse("5.0.0.0"), DstIpHigh = Ip.Parse("6.0.0.0"), Interface = i1, }, }, }; var table2 = new ForwardingTable { Rules = new ForwardingRule[] { new ForwardingRule { DstIpLow = Ip.Parse("5.0.0.0"), DstIpHigh = Ip.Parse("6.0.0.0"), Interface = i3, }, new ForwardingRule { DstIpLow = Ip.Parse("1.0.0.0"), DstIpHigh = Ip.Parse("2.0.0.0"), Interface = i2, }, }, }; var table3 = new ForwardingTable { Rules = new ForwardingRule[] { new ForwardingRule { DstIpLow = Ip.Parse("1.0.0.0"), DstIpHigh = Ip.Parse("2.0.0.0"), Interface = i4, }, }, }; d1.Table = table1; d2.Table = table2; d3.Table = table3; // create the network var network = new Network.Network { Devices = new Dictionary <string, Device>() }; network.Devices["R1"] = d1; network.Devices["R2"] = d2; network.Devices["R3"] = d3; return(network); }