diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index c38f793..180979e 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -1193,6 +1193,7 @@ namespace EduNetworkBuilder ItemClickedOn.ClearIPs(); //reset the device ItemClickedOn.IsBurned = false; //If it had been burned before, it is no longer burned ItemClickedOn.PowerOff = true; + ItemClickedOn.BadSprayCount = 0; //Mark the replace test as "done" myNetwork.RegisterDeviceReset(ItemClickedOn.hostname); //replacing something powers it off diff --git a/EduNetworkBuilder/NetworkCard.cs b/EduNetworkBuilder/NetworkCard.cs index c22a2e2..4053257 100644 --- a/EduNetworkBuilder/NetworkCard.cs +++ b/EduNetworkBuilder/NetworkCard.cs @@ -8,7 +8,7 @@ using System.Runtime.Serialization; using System.IO; using System.Xml; using System.Windows.Forms; - +using System.Text.RegularExpressions; namespace EduNetworkBuilder { @@ -49,6 +49,30 @@ namespace EduNetworkBuilder SetIPForDHCP(); } + public NetworkCard(NetworkCard old, bool duplicateID = false) + { + if (old == null) return; + MAC = old.MAC; + foreach(NetworkInterface one in old.interfaces) + { + NetworkInterface nInterface = new NetworkInterface(one); + interfaces.Add(nInterface); + } + UsesDHCP = old.UsesDHCP; + CanUseDHCP = old.CanUseDHCP; + MustUseDHCP = old.MustUseDHCP; + myNicType = old.myNicType; + myID = old.myID; + if(duplicateID == false) + myID = new HostNicID(old.myID.HostID, UniqueIdentifier, old.myID.HostName, old.NicName()); + ConnectedLink = old.ConnectedLink; + if (duplicateID == false) + ConnectedLink = -1; //It should be a new card, not connected to anything. + TunnelEndpoint = old.TunnelEndpoint; + EncryptionKey = old.EncryptionKey; + SSID = old.SSID; + } + public NetworkCard(XmlNode theNode) { foreach (XmlNode Individual in theNode.ChildNodes) @@ -98,6 +122,25 @@ namespace EduNetworkBuilder SetIPForDHCP(); } + public void ChangeType(NicType newtype) + { + NicType oldType = myNicType; + myNicType = newtype; + string index = Regex.Match(_nic_name, @"\d+$").Value; + if (index == "") index = "0"; + string OldName = oldType.ToString() + index.ToString(); + _nic_name = myNicType.ToString() + index.ToString(); + foreach (NetworkInterface NI in interfaces) + { + //NI.nic_name = Regex.Replace(NI.nic_name, OldName, _nic_name); + NI.nic_name = _nic_name; //This does not work when we have eth0:1... + NI.AttachedToHostNic.NicName = _nic_name; + } + myID.NicName = _nic_name; + if (newtype == NicType.port || newtype == NicType.wport) + interfaces.Clear(); + } + public bool Equals(NetworkCard compareWith) { if (MAC != compareWith.MAC) return false; diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index bb63bf0..3412b3a 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -103,9 +103,10 @@ namespace EduNetworkBuilder NICs.Clear(); tnic = new NetworkCard(0, GetUniqueIdentifier, hostname, NicType.lo); NICs.Add(tnic); + tnic = new NetworkCard(0, GetUniqueIdentifier, hostname, NicType.management_interface); + NICs.Add(tnic); //tnic = new NetworkCard(0, GetUniqueIdentifier, hostname, NicType.management_interface); - //NICs.Add(tnic); --we use the wlan port for this - tnic = new NetworkCard(NICs.Count(), GetUniqueIdentifier, hostname, NicType.eth); //Add a physical network card + tnic = new NetworkCard(NICs.Count(), GetUniqueIdentifier, hostname, NicType.port); //Add a physical network card NICs.Add(tnic); //A bridge is a switch with an ethernet nic, add some wireless ports for (int a = 0; a < 6; a++) @@ -446,6 +447,16 @@ namespace EduNetworkBuilder break; case "nic": newNic = new NetworkCard(Individual); + //if (myType == NetworkComponentType.wap && newNic.GetNicType == NicType.eth) + //{ + // //This happened once upon a time. Waps did not have management interfaces. + // //Make a management interface for the wap and move the IP from the eth to that. + // //Then, change the nic to a port instead of an eth. + // NetworkCard tNic = new NetworkCard(newNic); + // tNic.ChangeType(NicType.management_interface); + // NICs.Add(tNic); + // newNic.ChangeType(NicType.port); + //} NICs.Add(newNic); break; case "route": @@ -576,7 +587,7 @@ namespace EduNetworkBuilder continue; foreach(string addr in nic.IPAddresses()) { - answer += "\n" + addr; + answer += System.Environment.NewLine + addr; } } if(BackgroundColor != Color.Empty) @@ -586,7 +597,7 @@ namespace EduNetworkBuilder List DeviceMessages = myNet.GetTestMessages(hostname); foreach (string tString in DeviceMessages) { - answer += "\n" + tString; + answer += System.Environment.NewLine + tString; } } return answer; @@ -1433,7 +1444,8 @@ namespace EduNetworkBuilder { if (myType == NetworkComponentType.router) return true; if (myType == NetworkComponentType.firewall) return true; - if (myType == NetworkComponentType.wap) return true; + //We changed this to a port so it forwards, not routes + //if (myType == NetworkComponentType.wap) return true; return false; } @@ -1875,7 +1887,7 @@ namespace EduNetworkBuilder { NicType NT = nic.GetNicType; //bridges and waps are basically switches - if (myType == NetworkComponentType.wap || myType == NetworkComponentType.wbridge) + if ((myType == NetworkComponentType.wap || myType == NetworkComponentType.wbridge) && NT != NicType.management_interface) NT = NicType.port; switch(NT) { diff --git a/EduNetworkBuilder/NetworkInterface.cs b/EduNetworkBuilder/NetworkInterface.cs index 3136e7e..b78cb2c 100644 --- a/EduNetworkBuilder/NetworkInterface.cs +++ b/EduNetworkBuilder/NetworkInterface.cs @@ -56,6 +56,16 @@ namespace EduNetworkBuilder } } + public NetworkInterface(NetworkInterface CopyFrom) + { + myIP = new NB_IPAddress(CopyFrom.myIP.GetIPString, CopyFrom.myIP.GetMaskString, CopyFrom.myIP.GetAddressType); + nic_name = CopyFrom.nic_name; + foreach(VLANInfo VLI in CopyFrom.VLANs) + { + VLANs.Add(new VLANInfo(VLI.ID, VLI.Tag)); + } + } + public VLANInfo GetVLANInfo(int id) { foreach(VLANInfo one in VLANs)