/// <summary> /// Initializes a new instance of the /// <see cref="NSA.Model.BusinessLogic.TestscenarioRunnables.OnlyTestscenarioRunnable"/> class. /// </summary> /// <param name="Rule">Rule object</param> /// <param name="N">Network</param> public OnlyTestscenarioRunnable(Rule Rule, Network N) { rule = Rule; startNode = Rule.StartNode; endNodes = Rule.EndNodes; network = N; }
/// <summary> /// Creates and executes a simulation /// </summary> /// <param name="Source">The name of the sourcenode</param> /// <param name="Destination">The name of the destinationnode</param> /// <param name="Ttl">Time-To-Life</param> /// <param name="ExpectedResult">The expected result</param> /// <param name="Broadcast">Indicates if it is a broadcast</param> /// <param name="Subnet">The subnetmask of the broadcast</param> /// <returns>The result of this simulation</returns> public Result CreateAndExecuteSimulation(string Source, string Destination, int Ttl = 255, bool ExpectedResult = true, bool Broadcast = false, string Subnet = "") { Simulation sim; Hardwarenode start = NetworkManager.Instance.GetHardwarenodeByName(Source); if (Broadcast) { sim = new Simulation(Guid.NewGuid().ToString("N"), Source, "Broadcast", ExpectedResult); List <Workstation> allWorkstations = NetworkManager.Instance.GetHardwareNodesForSubnet(Subnet); foreach (Workstation w in allWorkstations) { if (w.Name.Equals(Source)) { continue; } sim.AddPacketSend(new Packet(start, w, Ttl, ExpectedResult)); } } else { sim = new Simulation(Guid.NewGuid().ToString("N"), Source, Destination, ExpectedResult); Hardwarenode end = NetworkManager.Instance.GetHardwarenodeByName(Destination); sim.AddPacketSend(new Packet(start, end, Ttl, ExpectedResult)); } var res = sim.GetAllPackets().Any() ? sim.Execute() : new Result(Result.Errors.NoPackets, Result.ResultStrings[(int)Result.Errors.NoPackets], null); AddSimulationToHistory(sim); return(res); }
/// <summary> /// Creates a hardwarenode and adds it to the Network and to the NetworkViewController. /// </summary> /// <param name="Type">Type of the node</param> /// <param name="Name">The name.</param> /// <returns> /// The new created hardwarenode. /// </returns> public Hardwarenode CreateHardwareNode(HardwarenodeType Type, string Name = null) { Hardwarenode node = null; string nodeName = Name ?? CreateUniqueName(Type); switch (Type) { case HardwarenodeType.Switch: node = new Switch(nodeName); break; case HardwarenodeType.Workstation: node = new Workstation(nodeName); break; case HardwarenodeType.Router: node = new Router(nodeName); break; } // Add node to the Network and to the NetworkViewController network.AddHardwarenode(node); NetworkViewController.Instance.AddHardwarenode(node); return(node); }
/// <summary> /// Removes an interface from the workstation or as switch. /// </summary> /// <param name="NodeName">The name of the workstation or a switch</param> /// <param name="InterfaceName">The name of the interface.</param> public void RemoveInterface(string NodeName, string InterfaceName) { Hardwarenode node = network.GetHardwarenodeByName(NodeName); if (node == null) { Debug.Assert(node != null, "Node with the name " + NodeName + " could not be found"); return; } Workstation workstation = node as Workstation; Switch nodeSwitch = node as Switch; if (workstation != null) { workstation.RemoveInterface(InterfaceName); NetworkViewController.Instance.RemoveInterfaceFromNode(workstation.Name, InterfaceName); Connection c = workstation.GetConnectionAtPort(InterfaceName); if (c != null) { RemoveConnection(c.Name); } } else if (nodeSwitch != null) { nodeSwitch.RemoveInterface(InterfaceName); NetworkViewController.Instance.RemoveInterfaceFromNode(nodeSwitch.Name, InterfaceName); Connection c = nodeSwitch.GetConnectionAtPort(InterfaceName); if (c != null) { RemoveConnection(c.Name); } } }
/// <summary> /// Gets the connection by nodes. /// </summary> /// <param name="N1">The first node</param> /// <param name="N2">The second node</param> /// <returns>The Connection or null if no connection was found</returns> public Connection GetConnectionByNodes(Hardwarenode N1, Hardwarenode N2) { foreach (Connection c in GetAllConnections()) { if ((c.Start == N1 && c.End == N2) || (c.End == N1 && c.Start == N2)) { return(c); } } return(null); }
/// <summary> /// Removes the hardwarenode from the Network and from the NetworkViewController. /// </summary> /// <param name="Name">The name of the node to be removed</param> public void RemoveHardwarenode(string Name) { Hardwarenode node = network.GetHardwarenodeByName(Name); if (node == null) { Debug.Assert(node != null, "Hardwarenode with name " + Name + "could not be found"); return; } network.RemoveHardwarnode(Name); NetworkViewController.Instance.RemoveHardwarenode(Name); }
/// <summary> /// Load properties of a hardwarenode for editing in the PropertyConfigControl /// </summary> /// <param name="ElementName"></param> public void LoadElementProperties(string ElementName) { selectedNode = NetworkManager.Instance.GetHardwarenodeByName(ElementName); propertyControl.ClearControls(); if (selectedNode is Workstation) { var station = selectedNode as Workstation; // load workstation ethernet interface config controls foreach (var eth in station.Interfaces) { propertyControl.AddInterfaceConfigControl(eth.Name, eth.IpAddress, eth.Subnetmask); } // Set InterfaceList in RouteConfigControl RouteConfigControl.SetInterfaces(station.Interfaces.Select(i => i.Name).ToList()); // load route controls foreach (var route in station.GetRoutes()) { propertyControl.AddRouteConfigControl(route.Name, route.Destination, route.Gateway, route.Subnetmask, route.Iface.Name); } // load workstation Layerstack controls propertyControl.AddLayerStackConfigControl(); foreach (ILayer layer in station.Layerstack.GetAllLayers()) { propertyControl.AddLayerToLayerConfigControl(layer.GetLayerName(), layer is CustomLayer); } GwConfigControl.SetInterfaces(station.Interfaces.Select(i => i.Name).ToList()); if (selectedNode is Router) { // load gateway config control propertyControl.AddGatewayConfigControl(station.StandardGateway ?? IPAddress.None, station.StandardGatewayPort?.Name, true, (selectedNode as Router).IsGateway); } else { propertyControl.AddGatewayConfigControl(station.StandardGateway ?? IPAddress.None, station.StandardGatewayPort?.Name, false); } propertyControl.DisplayElements(); } else if (selectedNode is Switch) { Switch selectedSwitch = selectedNode as Switch; propertyControl.AddSwitchConfigControl(selectedSwitch.GetInterfaceCount()); } }
/// <summary> /// Constructor for Packet /// </summary> /// <param name="Src">Source-Node</param> /// <param name="Dest">Destination-Node</param> /// <param name="T">TTL</param> /// <param name="ExpRes">Expected Result</param> public Packet(Hardwarenode Src, Hardwarenode Dest, int T, bool ExpRes) { Source = Src; Destination = Dest; if (Source == null || Destination == null) { Result.ErrorId = Result.Errors.SourceDestinationNull; Result.Res = Result.ResultStrings[(int)Result.ErrorId]; Result.SendError = true; } Ttl = T; ExpectedResult = ExpRes; Hops.Add(Source); }
public void AddHardwarenode(Hardwarenode node) { var randomLoc = new Point(10 + (int)((networkViewControl.Width - 100) * rnd.NextDouble()), 10 + (int)((networkViewControl.Height - 100) * rnd.NextDouble())); if (node is Switch) { networkViewControl.AddElement(new SwitchControl(randomLoc, node.Name)); } else if (node is Router) { networkViewControl.AddElement(new RouterControl(randomLoc, node.Name)); } else if (node is Workstation) { networkViewControl.AddElement(new WorkstationControl(randomLoc, node.Name)); } }
/// <summary> /// Returns the result for both nodes of one hop /// </summary> /// <param name="IsSendPacket">bool, which indicates, if its a sendpacket</param> /// <param name="PacketIndex">The index of the packet</param> /// <param name="NodeOneName">Name of the first node of the hop</param> /// <param name="NodeTwoName">Name of the second node of the Hop</param> /// <returns>A Tuple, which contains the two results. Item1 is for NodeOneName, Item2 for NodeTwoName</returns> public Tuple <Result, Result> GetHopResult(bool IsSendPacket, int PacketIndex, string NodeOneName, string NodeTwoName = null) { Tuple <Result, Result> res; Packet p = IsSendPacket ? Simulations[Simulations.Count - 1].PacketsSend?[PacketIndex] : Simulations[Simulations.Count - 1].PacketsReceived?[PacketIndex]; if (p == null || Simulations.Count == 0) { return(null); } Hardwarenode nodeOne = NetworkManager.Instance.GetHardwarenodeByName(NodeOneName); if (NodeTwoName == null && nodeOne != null) { res = new Tuple <Result, Result>(p.Result, new Result()); return(res); } Hardwarenode nodeTwo = NetworkManager.Instance.GetHardwarenodeByName(NodeTwoName); if (nodeOne == null || nodeTwo == null) { return(null); } List <Hardwarenode> hops = p.Hops; if (hops.Count < 2) { return(null); } if (hops.Last().Equals(nodeTwo)) { res = new Tuple <Result, Result>(new Result(), p.Result); } else if (hops.Last().Equals(nodeOne)) { res = new Tuple <Result, Result>(p.Result, new Result()); } else { res = new Tuple <Result, Result>(new Result(), new Result()); } return(res); }
/// <summary> /// Creates a new connection. Adds the connection to the Network and to the NetworkViewController. /// </summary> /// <param name="Start">The start node of the connection</param> /// <param name="StartNodeInterfaceName">The name of the Interface at which the Connection is pluged in at the start node</param> /// <param name="End">The end node of the connection</param> /// <param name="EndNodeInterfaceName">The name of the Interface at which the Connection is pluged in at the end node</param> public void CreateConnection(string Start, string StartNodeInterfaceName, string End, string EndNodeInterfaceName) { Hardwarenode a = GetHardwarenodeByName(Start); Hardwarenode b = GetHardwarenodeByName(End); if (a == null || b == null) { Debug.Assert(false, "Hardwarenode could not be found"); return; } if (a == b) { return; } Connection connection = new Connection(a, b); if (network.AddConnection(StartNodeInterfaceName, EndNodeInterfaceName, connection)) { NetworkViewController.Instance.AddConnection(connection); } }
/// <summary> /// Validates the layer while receiving a packet. /// </summary> /// <param name="CurrentNode"></param> /// <param name="ValInfo"></param> /// <param name="Tags"></param> /// <param name="Destination"></param> /// <param name="LayerIndex"></param> /// <returns> /// Boolean value indicating if the validation was successfull /// </returns> public bool ValidateReceive(Workstation CurrentNode, ValidationInfo ValInfo, Dictionary <string, object> Tags, Hardwarenode Destination, int LayerIndex) { if (CurrentNode.Equals(Destination) && Tags.ContainsKey(name) && LayerIndex == (int)Tags[name]) { Tags.Remove(name); } if (CurrentNode.Equals(Destination) && Tags.ContainsKey(name) && LayerIndex != (int)Tags[name]) { ValInfo.Res.ErrorId = Result.Errors.CustomLayerIndexError; ValInfo.Res.SendError = false; ValInfo.Res.LayerError = this; ValInfo.Res.Res = String.Format(Result.ResultStrings[(int)Result.Errors.CustomLayerIndexError], name); return(false); } return(true); }
/// <summary> /// Validates the layer while receiving a packet. /// </summary> /// <param name="CurrentNode">Current node</param> /// <param name="ValInfo">Validation Info</param> /// <param name="Tags">Tags</param> /// <param name="Destination">Destinationnode</param> /// <param name="LayerIndex">Index of the Layer</param> /// <returns> /// Boolean value indicating if the validation was successfull /// </returns> public bool ValidateReceive(Workstation CurrentNode, ValidationInfo ValInfo, Dictionary <string, object> Tags, Hardwarenode Destination, int LayerIndex) { return(true); }
/// <summary> /// Initializes a new instance of the /// <see cref="NSA.Model.BusinessLogic.TestscenarioRunnables.HasInternetTestscenarioRunnable"/> class. /// </summary> /// <param name="Rule">Rule object</param> public HasInternetTestscenarioRunnable(Rule Rule) { rule = Rule; startNode = Rule.StartNode; endNodes = Rule.EndNodes; }
/// <summary> /// Initializes a new instance of the /// <see cref="NSA.Model.BusinessLogic.TestscenarioRunnables.SimpleTestscenarioRunnable"/> class. /// </summary> /// <param name="Rule">Rule object</param> public SimpleTestscenarioRunnable(Rule Rule) { rule = Rule; startNode = Rule.StartNode; endNodes = Rule.EndNodes; }
/// <summary> /// Validates the layer while receiving a packet. /// </summary> /// <param name="CurrentNode">Current node</param> /// <param name="ValInfo">Validation Info</param> /// <param name="Tags">Tags</param> /// <param name="Destination">Destinationnode</param> /// <param name="LayerIndex">Index of the Layer</param> /// <returns> /// Boolean value indicating if the validation was successfull /// </returns> public bool ValidateReceive(Workstation CurrentNode, ValidationInfo ValInfo, Dictionary <string, object> Tags, Hardwarenode Destination, int LayerIndex) { //if nextNodeIp is null, the sending node is in the same subnet with currentNode and wanted to send it to him if (ValInfo.NextNodeIp == null) { return(true); } List <Interface> ifaces = CurrentNode.Interfaces; if (ifaces.Any(I => ValInfo.NextNodeIp.Equals(I.IpAddress))) { ValInfo.NextNodeIp = null; return(true); } ValInfo.Res.ErrorId = Result.Errors.PacketNotForThisNode; ValInfo.Res.Res = Result.ResultStrings[(int)ValInfo.Res.ErrorId]; ValInfo.Res.LayerError = new DataLinkLayer(index); ValInfo.Res.SendError = false; return(false); }