VLAN tests are working

This commit is contained in:
Tim Young 2016-10-20 14:53:23 -05:00
parent 4ffc40d0b3
commit 828387ba8a
9 changed files with 154 additions and 18 deletions

View File

@ -76,7 +76,54 @@ namespace EduNetworkBuilder
{ {
NetworkDevice ndCLonedItem = (NetworkDevice)ClonedItem; NetworkDevice ndCLonedItem = (NetworkDevice)ClonedItem;
if(ndCLonedItem.CanAddNics)
bool nicLocked = false;
bool interfacesLocked = false;
foreach (string nName in ndCLonedItem.NICNames())
{
NetworkCard nic = ndCLonedItem.NicFromName(nName);
if (theNet.ItemIsLocked(ClonedItem.hostname, nic.NicName(), NetTestType.LockNic) ||
theNet.ItemIsLocked(ClonedItem.hostname, "", NetTestType.LockVLANsOnHost))
{
nicLocked = true;
interfacesLocked = true;
}
}
//if the selected interface is locked
if (lbNics.SelectedIndex != -1 && theNet.ItemIsLocked(ClonedItem.hostname, StripNicName(lbNics.SelectedItem.ToString()), NetTestType.LockNicVLAN))
{
nicLocked = true;
interfacesLocked = true;
}
if (lbNics.SelectedIndex != -1)
{
string nic_name = StripNicName(lbNics.SelectedItem.ToString());
NetworkCard nic = ndCLonedItem.NicFromName(nic_name);
if (nic != null)
{
for (int i = 0; i < nic.IFCount; i++)
{
NetworkInterface nif = nic.GetInterface(i);
if (theNet.ItemIsLocked(ClonedItem.hostname, nif.nic_name, NetTestType.LockInterfaceVLAN) ||
theNet.ItemIsLocked(ClonedItem.hostname, nif.nic_name, NetTestType.LockVLANsOnHost))
{
nicLocked = true;
interfacesLocked = true;
}
}
}
}
if (interfacesLocked)
{
btnIfAdd.Visible = false;
btnIfMinus.Visible = false;
}
else
{
btnIfAdd.Visible = true;
btnIfMinus.Visible = true;
}
if (ndCLonedItem.CanAddNics && ! nicLocked)
{ {
btnNicPlus.Visible = true; btnNicPlus.Visible = true;
btnNicMinus.Visible = true; btnNicMinus.Visible = true;
@ -133,6 +180,7 @@ namespace EduNetworkBuilder
if (selectedLb >= lbNics.Items.Count) selectedLb = -1; if (selectedLb >= lbNics.Items.Count) selectedLb = -1;
lbNics.SelectedIndex = selectedLb; lbNics.SelectedIndex = selectedLb;
} }
if (lbNics.SelectedIndex >= 0) if (lbNics.SelectedIndex >= 0)
{ {
btnNicEdit.Enabled = true; btnNicEdit.Enabled = true;
@ -155,8 +203,9 @@ namespace EduNetworkBuilder
//Use the index of the nic //Use the index of the nic
string selectedNicName = ""; string selectedNicName = "";
if (lbNics.SelectedItem != null) selectedNicName = lbNics.SelectedItem.ToString(); if (lbNics.SelectedItem != null) selectedNicName = lbNics.SelectedItem.ToString();
selectedNicName = Regex.Replace(selectedNicName, " .*", ""); //selectedNicName = Regex.Replace(selectedNicName, " .*", "");
selectedNicName = Regex.Replace(selectedNicName, "\\*", ""); //selectedNicName = Regex.Replace(selectedNicName, "\\*", "");
selectedNicName = StripNicName(selectedNicName);
lists = ndCLonedItem.NetworkCardInterfaceStrings(selectedNicName); lists = ndCLonedItem.NetworkCardInterfaceStrings(selectedNicName);
//get the IPAddress string list from the nic //get the IPAddress string list from the nic
selectedLb = lbAddresses.SelectedIndex; selectedLb = lbAddresses.SelectedIndex;
@ -346,6 +395,14 @@ namespace EduNetworkBuilder
UpdateForm(); UpdateForm();
} }
private string StripNicName(string NIC)
{
string processed = NIC;
processed = Regex.Replace(processed, " .*", "");
processed = Regex.Replace(processed, "\\*", "");
return processed;
}
private void editInterface() private void editInterface()
{ {
if (ClonedItem.GetType().ToString() == "EduNetworkBuilder.NetworkDevice") if (ClonedItem.GetType().ToString() == "EduNetworkBuilder.NetworkDevice")
@ -353,9 +410,9 @@ namespace EduNetworkBuilder
NetworkDevice ndCLonedItem = (NetworkDevice)ClonedItem; NetworkDevice ndCLonedItem = (NetworkDevice)ClonedItem;
if (lbAddresses.SelectedIndex >= 0 && lbNics.SelectedIndex >= 0) if (lbAddresses.SelectedIndex >= 0 && lbNics.SelectedIndex >= 0)
{ {
string selectedNIC = lbNics.SelectedItem.ToString(); string selectedNIC = StripNicName( lbNics.SelectedItem.ToString());
selectedNIC = Regex.Replace(selectedNIC, " .*", ""); //selectedNIC = Regex.Replace(selectedNIC, " .*", "");
selectedNIC = Regex.Replace(selectedNIC, "\\*", ""); //selectedNIC = Regex.Replace(selectedNIC, "\\*", "");
ndCLonedItem.EditNicInterface(selectedNIC, lbAddresses.SelectedIndex); ndCLonedItem.EditNicInterface(selectedNIC, lbAddresses.SelectedIndex);
UpdateForm(); UpdateForm();

View File

@ -45,7 +45,7 @@ namespace EduNetworkBuilder
SuccessfullyPings, SuccessfullyPingsAgain, SuccessfullyArps, SuccessfullyDHCPs, HelpRequest, ReadContextHelp, FailedPing, SuccessfullyPings, SuccessfullyPingsAgain, SuccessfullyArps, SuccessfullyDHCPs, HelpRequest, ReadContextHelp, FailedPing,
DHCPServerEnabled, DHCPServerEnabled,
LockAll, LockIP, LockRoute, LockNic, LockDHCP, LockGateway, LockAll, LockIP, LockRoute, LockNic, LockDHCP, LockGateway,
LockVLAN, LockNicVLAN, LockInterfaceVLAN, LockVLANNames, LockVLANsOnHost, LockNicVLAN, LockInterfaceVLAN, LockVLANNames,
} }
public enum NetTestVerbosity { none, basic, hints, full } public enum NetTestVerbosity { none, basic, hints, full }
public enum LBContents { routes, messages, dhcp, puzzles } public enum LBContents { routes, messages, dhcp, puzzles }

View File

@ -73,6 +73,7 @@ namespace EduNetworkBuilder
case NetTestType.LockInterfaceVLAN: case NetTestType.LockInterfaceVLAN:
case NetTestType.LockNicVLAN: case NetTestType.LockNicVLAN:
case NetTestType.LockVLANNames: case NetTestType.LockVLANNames:
case NetTestType.LockVLANsOnHost:
TaskWasDone = true; TaskWasDone = true;
break; break;
} }
@ -182,7 +183,7 @@ namespace EduNetworkBuilder
case NetTestType.LockVLANNames: case NetTestType.LockVLANNames:
toreturn = NB.Translate("NT_TstDiscriptLockVLANNames"); toreturn = NB.Translate("NT_TstDiscriptLockVLANNames");
break; break;
case NetTestType.LockVLAN: case NetTestType.LockVLANsOnHost:
toreturn = NB.Translate("NT_TstDiscriptLockVLAN"); toreturn = NB.Translate("NT_TstDiscriptLockVLAN");
break; break;
case NetTestType.LockNicVLAN: case NetTestType.LockNicVLAN:
@ -263,7 +264,7 @@ namespace EduNetworkBuilder
case NetTestType.LockVLANNames: case NetTestType.LockVLANNames:
toreturn = NB.Translate("NT_TstDiscriptLockVLANNames") + ":"; toreturn = NB.Translate("NT_TstDiscriptLockVLANNames") + ":";
break; break;
case NetTestType.LockVLAN: case NetTestType.LockVLANsOnHost:
toreturn = NB.Translate("NT_TstDiscriptLockVLAN") + ":"; toreturn = NB.Translate("NT_TstDiscriptLockVLAN") + ":";
break; break;
case NetTestType.LockNicVLAN: case NetTestType.LockNicVLAN:
@ -493,7 +494,7 @@ namespace EduNetworkBuilder
case NetTestType.LockGateway: case NetTestType.LockGateway:
case NetTestType.LockInterfaceVLAN: case NetTestType.LockInterfaceVLAN:
case NetTestType.LockNicVLAN: case NetTestType.LockNicVLAN:
case NetTestType.LockVLAN: case NetTestType.LockVLANsOnHost:
case NetTestType.LockVLANNames: case NetTestType.LockVLANNames:
return true; //Nothing to solve. We just lock it so it cannot be changed. return true; //Nothing to solve. We just lock it so it cannot be changed.
} }

View File

@ -165,6 +165,37 @@ namespace EduNetworkBuilder
{ {
//No items for lockvlannames //No items for lockvlannames
cbDest.Items.Add(NB.Translate("_All")); cbDest.Items.Add(NB.Translate("_All"));
cbSource.Items.Clear();
cbSource.Items.Add(NB.Translate("_All"));
}
else if (ToEdit.TheTest == NetTestType.LockNicVLAN)
{
sItem = theNet.GetDeviceFromName(ToEdit.sHost);
foreach (string nname in sItem.NICNames())
{
NetworkCard nic = sItem.NicFromName(nname);
if (!nic.NicCanDoVLANs()) continue;
cbDest.Items.Add(nic.NicName());
}
}
else if (ToEdit.TheTest == NetTestType.LockVLANsOnHost)
{
//No items for lockvlannames
cbDest.Items.Add(NB.Translate("_All"));
}
else if (ToEdit.TheTest == NetTestType.LockInterfaceVLAN)
{
sItem = theNet.GetDeviceFromName(ToEdit.sHost);
foreach (string nname in sItem.NICNames())
{
NetworkCard nic = sItem.NicFromName(nname);
if (!nic.NicCanDoVLANs()) continue;
for (int i = 0; i < nic.IFCount; i++)
{
NetworkInterface nif = nic.GetInterface(i);
cbDest.Items.Add(nif.nic_name);
}
}
} }
else else
{ //List all the hosts { //List all the hosts
@ -242,6 +273,11 @@ namespace EduNetworkBuilder
{ {
//This uses a verbosity //This uses a verbosity
} }
else if(ntt == NetTestType.LockInterfaceVLAN || ntt == NetTestType.LockNicVLAN ||
ntt == NetTestType.LockVLANNames || ntt == NetTestType.LockVLANsOnHost)
{
return true;
}
else else
{ {
if (ntt == NetTestType.SuccessfullyPings) return true; if (ntt == NetTestType.SuccessfullyPings) return true;

View File

@ -740,12 +740,14 @@ namespace EduNetworkBuilder
{ {
foreach (NetTest nt in NetTests) foreach (NetTest nt in NetTests)
{ {
if(nt.sHost == host) if(nt.sHost == host || WhatToCheck == NetTestType.LockVLANNames)
{ {
if (nt.TheTest == NetTestType.LockAll) if (nt.TheTest == NetTestType.LockAll)
return true; return true;
if (WhatToCheck == nt.TheTest && WhatToCheck == NetTestType.LockVLANNames) //no dest to check if (WhatToCheck == nt.TheTest && WhatToCheck == NetTestType.LockVLANNames) //no dest to check
return true; return true;
if (WhatToCheck == nt.TheTest && WhatToCheck == NetTestType.LockVLANsOnHost) //no dest to check
return true;
if (WhatToCheck == nt.TheTest && dest == nt.dHost) if (WhatToCheck == nt.TheTest && dest == nt.dHost)
return true; return true;
} }

View File

@ -431,6 +431,15 @@ namespace EduNetworkBuilder
return null; return null;
} }
public bool NicCanDoVLANs()
{
if (myNicType == NicType.eth) return true;
if (myNicType == NicType.port) return true;
if (myNicType == NicType.wan) return true;
return false;
}
/*************************************** /***************************************
* *
* *************************************/ * *************************************/
@ -749,6 +758,17 @@ namespace EduNetworkBuilder
} }
} }
public NetworkInterface InterfaceFromVlanTag(Packet tPacket)
{
int ID = tPacket.VLANID;
foreach(NetworkInterface oneIF in interfaces)
{
if (oneIF.GetVLANTag(ID) != VLANTagType.Forbidden)
return oneIF;
}
return null;
}
public IPAddress FirstIP() public IPAddress FirstIP()
{ {
List<IPAddress> addresses = IPAddressList(); List<IPAddress> addresses = IPAddressList();

View File

@ -1825,7 +1825,7 @@ namespace EduNetworkBuilder
dst = RequestDHCPLease(tPacket.sourceMAC, tPacket.InboundInterface.myIP); dst = RequestDHCPLease(tPacket.sourceMAC, tPacket.InboundInterface.myIP);
} }
//if we the packet came in on a port... //if we the packet came in on a port...
if (tPacket.InboundNic.GetNicType == NicType.wport || tPacket.InboundNic.GetNicType == NicType.port) if (tPacket.InboundNic != null && (tPacket.InboundNic.GetNicType == NicType.wport || tPacket.InboundNic.GetNicType == NicType.port))
{ {
IPAddress theIP = HubManagementIP(); IPAddress theIP = HubManagementIP();
if (theIP != null) if (theIP != null)
@ -2300,6 +2300,7 @@ namespace EduNetworkBuilder
tPacket.WhereAmI = this; tPacket.WhereAmI = this;
tPacket.MyStatus = PacketStatus.processing; tPacket.MyStatus = PacketStatus.processing;
// //
tPacket.PacketDump(hostname, DebugPausePoint.packet_in); tPacket.PacketDump(hostname, DebugPausePoint.packet_in);
if(nc == null) if(nc == null)
{ {
@ -2317,6 +2318,7 @@ namespace EduNetworkBuilder
return; return;
} }
NetworkInterface nf = nc.LocalInterface(tPacket.sourceIP, tPacket.Tracking); NetworkInterface nf = nc.LocalInterface(tPacket.sourceIP, tPacket.Tracking);
if(nf == null) if(nf == null)
{ {
nf = nc.LocalInterface(tPacket.TsourceIP, tPacket.Tracking); nf = nc.LocalInterface(tPacket.TsourceIP, tPacket.Tracking);
@ -2325,8 +2327,14 @@ namespace EduNetworkBuilder
{ {
nf = nc.PrimaryInterface(); nf = nc.PrimaryInterface();
} }
if (nf == null && tPacket.MyType == PacketType.dhcp_request && isDHCPServer ) if (nf == null && tPacket.MyType == PacketType.dhcp_request && isDHCPServer )
{ {
//It is a broadcast. We need to figure out which nic it came in on
// And then, figure out which interface, so we know which IP to dole out
NetworkInterface inif = nc.InterfaceFromVlanTag(tPacket);
tPacket.InboundInterface = inif;
List<IPAddress> addresses = nc.IPAddressList(); List<IPAddress> addresses = nc.IPAddressList();
if (addresses.Count > 0) if (addresses.Count > 0)
{ {
@ -2366,9 +2374,11 @@ namespace EduNetworkBuilder
tPacket.MyStatus = PacketStatus.finished_failed; tPacket.MyStatus = PacketStatus.finished_failed;
return; return;
} }
//Now we pass it to the interface //Now we pass it to the interface
if (nf != null) if (nf != null)
nf.ProcessInboundPacket(tPacket); nf.ProcessInboundPacket(tPacket);
//Now we pass it to the nic //Now we pass it to the nic
if (nc != null) if (nc != null)
nc.ProcessInboundPacket(tPacket); nc.ProcessInboundPacket(tPacket);

View File

@ -52,6 +52,7 @@ namespace EduNetworkBuilder
public IPAddress payloadIP = null; public IPAddress payloadIP = null;
public PacketMessage Tracking = new PacketMessage(); public PacketMessage Tracking = new PacketMessage();
public NetworkComponent WhereAmI = null; public NetworkComponent WhereAmI = null;
public NetworkLink LastNetworkLink = null;
public nb_direction myDirection = nb_direction.none; public nb_direction myDirection = nb_direction.none;
public int myLinkPercent = 0; //How far along the path are we. 0%, 50%, 100%. For moving a dot along the link line public int myLinkPercent = 0; //How far along the path are we. 0%, 50%, 100%. For moving a dot along the link line
public bool packet_good = true; public bool packet_good = true;
@ -350,6 +351,7 @@ namespace EduNetworkBuilder
InboundNic = null; InboundNic = null;
InboundInterface = null; InboundInterface = null;
WhereAmI = theLink; WhereAmI = theLink;
LastNetworkLink = theLink;
MyStatus = PacketStatus.moving; MyStatus = PacketStatus.moving;
myLinkPercent = 0; myLinkPercent = 0;
TickTTL = 200; //We keep resetting this as we go. TickTTL = 200; //We keep resetting this as we go.

View File

@ -88,7 +88,8 @@ namespace EduNetworkBuilder
dgv_VLANNames.AllowUserToAddRows = true; dgv_VLANNames.AllowUserToAddRows = true;
if (TheDevice != null) if (TheDevice != null)
{ {
if (theNet.ItemIsLocked(hostname, "", NetTestType.LockVLANNames)) if (theNet.ItemIsLocked(hostname, "", NetTestType.LockVLANNames) ||
theNet.ItemIsLocked(hostname, "", NetTestType.LockVLANsOnHost))
LockedNames = true; LockedNames = true;
else else
LockedNames = false; LockedNames = false;
@ -103,6 +104,7 @@ namespace EduNetworkBuilder
VlanBindings.Rows.Clear(); VlanBindings.Rows.Clear();
List<string> theNics = TheDevice.NICNames(); List<string> theNics = TheDevice.NICNames();
//Fill out the interfaces
foreach (string oneNic in theNics) foreach (string oneNic in theNics)
{ {
NetworkCard NIC = TheDevice.NicFromName(oneNic); NetworkCard NIC = TheDevice.NicFromName(oneNic);
@ -115,6 +117,7 @@ namespace EduNetworkBuilder
if (NIC.GetNicType == NicType.tun) continue; if (NIC.GetNicType == NicType.tun) continue;
bool locked = false; bool locked = false;
//Lock the interface if it needs to be locked
if (TheDevice != null) { if (TheDevice != null) {
if (theNet.ItemIsLocked(hostname, oneNic, NetTestType.LockNic)) if (theNet.ItemIsLocked(hostname, oneNic, NetTestType.LockNic))
locked = true; locked = true;
@ -122,12 +125,17 @@ namespace EduNetworkBuilder
locked = true; locked = true;
if (theNet.ItemIsLocked(hostname, oneNic, NetTestType.LockNicVLAN)) if (theNet.ItemIsLocked(hostname, oneNic, NetTestType.LockNicVLAN))
locked = true; locked = true;
if (theNet.ItemIsLocked(hostname, oneNic, NetTestType.LockVLANsOnHost))
locked = true;
} }
bool pastlock = locked;
for (int i = 0; i < NIC.IFCount; i++) for (int i = 0; i < NIC.IFCount; i++)
{ {
locked = pastlock;
NetworkInterface nif = NIC.GetInterface(i); NetworkInterface nif = NIC.GetInterface(i);
if (TheDevice != null) if (TheDevice != null)
{ {
//If the interface itself is locked...
if (theNet.ItemIsLocked(hostname, nif.nic_name, NetTestType.LockInterfaceVLAN)) if (theNet.ItemIsLocked(hostname, nif.nic_name, NetTestType.LockInterfaceVLAN))
locked = true; locked = true;
} }