vlans are working

This commit is contained in:
Tim Young 2016-10-10 19:31:57 -05:00
parent 3632432f02
commit 14bcc075a3
4 changed files with 78 additions and 12 deletions

View File

@ -238,6 +238,7 @@ namespace EduNetworkBuilder
public static int WirelessMaxUnsuccessfulLink = 120; //The link will connect, but the packet will drop
public static int WirelessMaxSuccessfulLink = 100; //Packets will drop after this distance
public static int WirelessReconnectDistance = 70; //Try to find a closer AP if we are this far out.
public static int UntaggedVLAN = -1; //If the packet is not tagged.
/// <summary>
/// Find the global random number generator.

View File

@ -1399,9 +1399,13 @@ namespace EduNetworkBuilder
break;
string tMAC = tPacket.destMAC;
string ttMAC = tPacket.OutboundDestMAC;
tPacket.VLANID = NB.UntaggedVLAN; //we are routing, so we adopt the outgoing vlanID - state it needs to be tagged
if (BroadcastMatch && tPacket.MyType != PacketType.dhcp_answer)
tPacket.OutboundDestMAC = NB.BroadcastMACString;
tPacket.destMAC = tPacket.OutboundDestMAC;
tPacket.destMAC = tPacket.OutboundDestMAC;
//wearehere; //set the vlan id to 1 probably so we adopt the outgoing vlan
if(nic.SendPacketOutNIC(tPacket))
{
count++;
@ -2277,6 +2281,8 @@ namespace EduNetworkBuilder
//Now we pass it to the nic
if(nc != null)
nc.ProcessInboundPacket(tPacket);
if (hostname != null)
Console.WriteLine("Starting on device: " + hostname + " VLANID = " + tPacket.VLANID.ToString());
if(!tPacket.ready_to_delete)
tPacket.StartOnDevice(this);
}

View File

@ -163,7 +163,7 @@ namespace EduNetworkBuilder
// tPacket.sourceIP = new IPAddress(myIP.GetIP.ToIpString(), "", IPAddressType.ip_only); //We only want the IP address
//}
//VLAN stuff
VLANInfo VI = GetVLANInfo(tPacket.VLANID);
VLANInfo VI = OutgoingVLAN(tPacket.VLANID);
VLANTagType What = VI.Tag;
Network theNet = NB.GetNetwork();
NetworkDevice HD = theNet.GetDeviceFromID(AttachedToHostNic);
@ -172,6 +172,7 @@ namespace EduNetworkBuilder
if (What == VLANTagType.Forbidden)
{
//we drop it silently
Console.WriteLine(" -- Forbidding outbound packet. " + tPacket.VLANID + " " + HD.hostname + " " + VI.ID);
string errString = string.Format(NB.Translate("NI_VLANOut"), hostname, tPacket.destIP.GetIPString);
tPacket.AddMessage(DebugLevel.switching, errString);
tPacket.Tracking.Status = errString;
@ -181,7 +182,7 @@ namespace EduNetworkBuilder
if(What == VLANTagType.Untagged)
{
//We strip off the tagging
tPacket.VLANID = 1; //set to the default vlan
tPacket.VLANID = NB.UntaggedVLAN; //set to the default vlan
}
if(What == VLANTagType.Tagged)
{
@ -196,18 +197,24 @@ namespace EduNetworkBuilder
//If the packet is tagged with the ID, and the port is tagged, return that
//If the packet is untagged, return the one that is untagged
VLANInfo newVLANinfo = null;
if (ID != 1) //It is tagged
if (ID != NB.UntaggedVLAN) //It is tagged
{
foreach(VLANInfo vi in VLANs)
{
if (vi.ID == ID) return vi;
if (vi.ID == ID)
{
if (vi.Tag == VLANTagType.Forbidden)
Console.WriteLine(" About to be forbidden.");
return vi;
}
}
//We do not have one set yet. Add a new one
newVLANinfo = new VLANInfo(ID, VLANTagType.Forbidden);
Console.WriteLine(" Creating forbidden vlan - " + ID);
VLANs.Add(newVLANinfo);
return newVLANinfo;
}
else //the packet is the default vlan (1) so appears untagged.
else //the packet is untagged.
{
foreach (VLANInfo vi in VLANs)
{
@ -225,6 +232,54 @@ namespace EduNetworkBuilder
return newVLANinfo;
}
private VLANInfo OutgoingVLAN(int ID)
{
//Search through outgoing vlan stuff to find the right one
//If the packet is tagged with the ID, and the port is tagged, return that
//If the packet is untagged, return the one that is untagged
VLANInfo newVLANinfo = null;
if (ID != NB.UntaggedVLAN) //the packet is tagged
{
foreach (VLANInfo vi in VLANs)
{
if (vi.ID == ID)
{
if (vi.Tag == VLANTagType.Forbidden)
Console.WriteLine(" About to be outbound forbidden.");
return vi;
}
}
//We do not have one set yet. Add a new one
newVLANinfo = new VLANInfo(ID, VLANTagType.Forbidden);
Console.WriteLine(" Creating outbound forbidden vlan - " + ID);
VLANs.Add(newVLANinfo);
return newVLANinfo;
}
else //the packet is untagged.
{
//we should find the untagged vlan
//if no untagged vlan, find the tagged vlan
foreach (VLANInfo vi in VLANs)
{
if (vi.Tag == VLANTagType.Untagged) return vi;
}
foreach (VLANInfo vi in VLANs)
{
if (vi.Tag == VLANTagType.Tagged) return vi;
}
//We do not have an "untagged" vlan. Return the settings for vlan1
foreach (VLANInfo vi in VLANs)
{
if (vi.ID == 1) return vi;
}
}
//We should never get here. This is just a fall-through
newVLANinfo = new VLANInfo(ID, VLANTagType.Forbidden);
VLANs.Add(newVLANinfo);
return newVLANinfo;
}
public void ProcessInboundPacket(Packet tPacket)
{
bool isgood = false;
@ -255,9 +310,9 @@ namespace EduNetworkBuilder
}
if (What == VLANTagType.Untagged)
{
//If it is 1 (default vlan), this is OK. Otherwise drop.
//Untagged means we expect it to be vlan of 1 on the cable side
if(tPacket.VLANID != 1)
//If it is (default vlan), this is OK. Otherwise drop.
//Untagged means we expect it to be vlan of (untagged) on the cable side
if(tPacket.VLANID != NB.UntaggedVLAN)
{
//Oops. We need to reject the packet
string errString = string.Format(NB.Translate("NI_VLANInUntagged"), hostname, tPacket.destIP.GetIPString);
@ -268,13 +323,13 @@ namespace EduNetworkBuilder
}
else //We need to tag the packet with the new VLAN-ID
{
tPacket.VLANID = VI.ID; //The packet is ow tagged
tPacket.VLANID = VI.ID; //The packet is now tagged
}
}
if (What == VLANTagType.Tagged)
{
//If the packet is tagged, and the vlan expected tagged, all is good.
if(tPacket.VLANID != VI.ID)
if (tPacket.VLANID != NB.UntaggedVLAN && tPacket.VLANID != VI.ID)
{
//Oops. We need to reject the packet
string errString = string.Format(NB.Translate("NI_VLANInMisMatch"), hostname, tPacket.destIP.GetIPString);
@ -283,6 +338,8 @@ namespace EduNetworkBuilder
tPacket.MyStatus = PacketStatus.finished_ok;
return;
}
else
tPacket.VLANID = VI.ID; //Make sure it is properly tagged.
}
}

View File

@ -36,7 +36,7 @@ namespace EduNetworkBuilder
}
}
public int packetID;
public int VLANID = 1; //starts on the management vlan
public int VLANID = NB.UntaggedVLAN; //starts on the management vlan
public int TTL = 20;
public int TickTTL = 50;
public int health = 100;
@ -109,6 +109,7 @@ namespace EduNetworkBuilder
StartTime = copyfrom.StartTime;
OriginalDestIP = copyfrom.OriginalDestIP;
packetID = copyfrom.packetID;
VLANID = copyfrom.VLANID;
Tracking.AddMessage(DebugLevel.debug, WhereAmI, NB.Translate("P_PacketDuplicated"));
}
@ -345,6 +346,7 @@ namespace EduNetworkBuilder
public void StartOnLink(NetworkLink theLink, NetworkDevice start_device)
{
if (theLink == null) return;
Console.WriteLine("Starting on link: " + theLink.GetUniqueIdentifier + " vlanID = " + VLANID.ToString());
InboundNic = null;
InboundInterface = null;
WhereAmI = theLink;