/// <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> /// Sets the switch interface count. /// </summary> /// <param name="NodeName">Name of the node.</param> /// <param name="NewCount">The new count.</param> public void SetSwitchInterfaceCount(string NodeName, int NewCount) { Switch nodeSwitch = network.GetHardwarenodeByName(NodeName) as Switch; if (nodeSwitch == null) { Debug.Assert(nodeSwitch != null, "Node with the name " + NodeName + " could not be found"); return; } if (NewCount == nodeSwitch.GetInterfaceCount()) { return; } var interfaceDiff = nodeSwitch.SetInterfaceCount(NewCount); foreach (var i in interfaceDiff) { string connnectionName = nodeSwitch.Connections.FirstOrDefault(C => C.Key.Equals(i.Name)).Value?.Name; if (connnectionName != null) { RemoveConnection(connnectionName); } } NetworkViewController.Instance.SwitchChanged(nodeSwitch); }
/// <summary> /// Adds a new interface to the switch. /// </summary> /// <param name="SwitchName">The name of the switch</param> public void AddInterfaceToSwitch(string SwitchName) { Switch nodeSwitch = network.GetHardwarenodeByName(SwitchName) as Switch; if (nodeSwitch == null) { Debug.Assert(nodeSwitch != null, "Switch with the name " + SwitchName + " could not be found"); return; } var iface = nodeSwitch.AddInterface(null, null); NetworkViewController.Instance.AddInterfaceToHardwareNode(nodeSwitch.Name, iface.Name); }