Fixed numerous small glitches with switches, dhcp, and ping

This commit is contained in:
Tim Young 2015-09-19 11:09:51 -04:00
parent 211fa6f2bb
commit ea480fe7d7
3 changed files with 41 additions and 9 deletions

View File

@ -367,6 +367,12 @@ namespace EduNetworkBuilder
} }
return null; return null;
} }
public NetworkInterface PrimaryInterface()
{
if (interfaces.Count == 1)
return interfaces[0];
return null;
}
/*************************************** /***************************************
* *
@ -392,8 +398,6 @@ namespace EduNetworkBuilder
case NicType.eth: case NicType.eth:
case NicType.wlan: case NicType.wlan:
//see if it the packet dest is local to this nic //see if it the packet dest is local to this nic
if (WhereFrom.hostname == "router0")
Console.WriteLine("wearehere");
foreach (NetworkInterface nf in interfaces.ToList()) foreach (NetworkInterface nf in interfaces.ToList())
{ {
if (tPacket.InboundNic != null && tPacket.InboundNic == this && if (tPacket.InboundNic != null && tPacket.InboundNic == this &&
@ -407,6 +411,7 @@ namespace EduNetworkBuilder
if ((nf != null && nf.myIP.GetIPString != NB.ZeroIPString) || nPacket.MyType == PacketType.dhcp_request) if ((nf != null && nf.myIP.GetIPString != NB.ZeroIPString) || nPacket.MyType == PacketType.dhcp_request)
{ {
//this means we have a local interface to send it out of //this means we have a local interface to send it out of
if(nPacket.sourceMAC == null || nPacket.sourceMAC == "" || nPacket.isFresh)
nPacket.sourceMAC = MAC; nPacket.sourceMAC = MAC;
//If the source IP is empty then it is a new packet. We set the source to be us //If the source IP is empty then it is a new packet. We set the source to be us
if (nPacket.sourceIP == null || nPacket.sourceIP.GetIPString == NB.ZeroIPString) if (nPacket.sourceIP == null || nPacket.sourceIP.GetIPString == NB.ZeroIPString)
@ -527,6 +532,7 @@ namespace EduNetworkBuilder
if((tPacket.InboundNic != null && tPacket.InboundNic.GetNicType == NicType.wan) || tPacket.InboundNic == null || tPacket.destMAC == "") if((tPacket.InboundNic != null && tPacket.InboundNic.GetNicType == NicType.wan) || tPacket.InboundNic == null || tPacket.destMAC == "")
{ {
//We need to find destination MAC and set source MAC //We need to find destination MAC and set source MAC
if(nPacket.sourceMAC == null || nPacket.sourceMAC == "" || nPacket.isFresh)
nPacket.sourceMAC = MAC; nPacket.sourceMAC = MAC;
//Update the MAC //Update the MAC
string getMAC=""; string getMAC="";
@ -562,10 +568,11 @@ namespace EduNetworkBuilder
//Need to find the managament interface MAC //Need to find the managament interface MAC
nPacket.sourceMAC = WhereFrom.HubManagementMAC(); nPacket.sourceMAC = WhereFrom.HubManagementMAC();
} }
if(nPacket.sourceIP == null || nPacket.sourceIP.GetIPString == NB.ZeroIPString && (nPacket.MyType != PacketType.dhcp_request && !tPacket.isFresh)) if((nPacket.sourceIP == null || nPacket.sourceIP.GetIPString == NB.ZeroIPString) && !(nPacket.MyType == PacketType.dhcp_request && tPacket.isFresh))
{ {
//set it to be the ip of management interface //set it to be the ip of management interface
nPacket.sourceIP = WhereFrom.HubManagementIP(); nPacket.sourceIP = WhereFrom.HubManagementIP();
nPacket.sourceMAC = MAC;
} }
if (nPacket.destMAC == null || nPacket.destMAC == "" && tPacket.OutboundIP != null) if (nPacket.destMAC == null || nPacket.destMAC == "" && tPacket.OutboundIP != null)
{ {
@ -616,7 +623,12 @@ namespace EduNetworkBuilder
{ {
HostNicID otherid = nd.NicIDFromArp(tPacket.destMAC); HostNicID otherid = nd.NicIDFromArp(tPacket.destMAC);
if (otherid.HostID != -1) if (otherid.HostID != -1)
nd.StoreArp(tPacket.destMAC, tPacket.payloadIP.GetIP.ToIpString(), otherid); {
string ipstring = NB.ZeroIPString;
if (tPacket.payloadIP != null)
ipstring = tPacket.payloadIP.GetIPString;
nd.StoreArp(tPacket.destMAC, ipstring, otherid);
}
} }
return; return;
} }

View File

@ -1682,9 +1682,20 @@ namespace EduNetworkBuilder
nPacket.Tracking = new PacketMessage(); nPacket.Tracking = new PacketMessage();
myNet.addPacket(nPacket); myNet.addPacket(nPacket);
//We need to find a dhcp IP for this. //We need to find a dhcp IP for this.
IPAddress dst = RequestDHCPLease(tPacket.sourceMAC, tPacket.OutboundIP); IPAddress dst;
if (tPacket.InboundInterface == null)
{
dst = RequestDHCPLease(tPacket.sourceMAC, tPacket.OutboundIP);
}
else
{
dst = RequestDHCPLease(tPacket.sourceMAC, tPacket.InboundInterface.myIP);
}
string tmac = nPacket.sourceMAC; string tmac = nPacket.sourceMAC;
nPacket.sourceMAC = tPacket.OutboundMAC; nPacket.sourceMAC = tPacket.OutboundMAC;
if (tPacket.InboundInterface != null)
nPacket.sourceIP = tPacket.InboundInterface.myIP;
else
nPacket.sourceIP = tPacket.OutboundIP; nPacket.sourceIP = tPacket.OutboundIP;
nPacket.destMAC = tmac; nPacket.destMAC = tmac;
nPacket.OutboundDestMAC = tmac; nPacket.OutboundDestMAC = tmac;
@ -1713,7 +1724,7 @@ namespace EduNetworkBuilder
if (response == ResponseToPacket.accept) if (response == ResponseToPacket.accept)
{ {
NetworkCard tnic = tPacket.OutboundNic; NetworkCard tnic = tPacket.OutboundNic;
if (tnic == null) if (tnic == null || tnic.GetNicType == NicType.port || tnic.GetNicType == NicType.wport)
tnic = HubManagementCard(); tnic = HubManagementCard();
if (tnic != null) if (tnic != null)
{ {
@ -2145,6 +2156,10 @@ namespace EduNetworkBuilder
{ {
//We are entering into the computer //We are entering into the computer
NetworkCard nc = NicFromID(arrivalNic); NetworkCard nc = NicFromID(arrivalNic);
//Say tell the packet that we are no longer on the link
tPacket.WhereAmI = this;
tPacket.MyStatus = PacketStatus.processing;
//
tPacket.PacketDump(hostname, DebugPausePoint.packet_in); tPacket.PacketDump(hostname, DebugPausePoint.packet_in);
if(nc == null) if(nc == null)
{ {
@ -2166,6 +2181,10 @@ namespace EduNetworkBuilder
{ {
nf = nc.LocalInterface(tPacket.TsourceIP, tPacket.Tracking); nf = nc.LocalInterface(tPacket.TsourceIP, tPacket.Tracking);
} }
if(nf == null)
{
nf = nc.PrimaryInterface();
}
if (nf == null && tPacket.MyType == PacketType.dhcp_request && isDHCPServer) if (nf == null && tPacket.MyType == PacketType.dhcp_request && isDHCPServer)
{ {
List<IPAddress> addresses = nc.IPAddressList(); List<IPAddress> addresses = nc.IPAddressList();

View File

@ -340,6 +340,7 @@ namespace EduNetworkBuilder
myDirection = nb_direction.to_dst; myDirection = nb_direction.to_dst;
else else
myDirection = nb_direction.to_src; myDirection = nb_direction.to_src;
Console.WriteLine("Starting on link. SMAC: " + sourceMAC + " DMAC: " + destMAC);
AddMessage(DebugLevel.debug, " Starting on link"); AddMessage(DebugLevel.debug, " Starting on link");
} }