Fixed numerous small glitches with switches, dhcp, and ping
This commit is contained in:
parent
211fa6f2bb
commit
ea480fe7d7
@ -367,6 +367,12 @@ namespace EduNetworkBuilder
|
||||
}
|
||||
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.wlan:
|
||||
//see if it the packet dest is local to this nic
|
||||
if (WhereFrom.hostname == "router0")
|
||||
Console.WriteLine("wearehere");
|
||||
foreach (NetworkInterface nf in interfaces.ToList())
|
||||
{
|
||||
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)
|
||||
{
|
||||
//this means we have a local interface to send it out of
|
||||
if(nPacket.sourceMAC == null || nPacket.sourceMAC == "" || nPacket.isFresh)
|
||||
nPacket.sourceMAC = MAC;
|
||||
//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)
|
||||
@ -527,6 +532,7 @@ namespace EduNetworkBuilder
|
||||
if((tPacket.InboundNic != null && tPacket.InboundNic.GetNicType == NicType.wan) || tPacket.InboundNic == null || tPacket.destMAC == "")
|
||||
{
|
||||
//We need to find destination MAC and set source MAC
|
||||
if(nPacket.sourceMAC == null || nPacket.sourceMAC == "" || nPacket.isFresh)
|
||||
nPacket.sourceMAC = MAC;
|
||||
//Update the MAC
|
||||
string getMAC="";
|
||||
@ -562,10 +568,11 @@ namespace EduNetworkBuilder
|
||||
//Need to find the managament interface MAC
|
||||
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
|
||||
nPacket.sourceIP = WhereFrom.HubManagementIP();
|
||||
nPacket.sourceMAC = MAC;
|
||||
}
|
||||
if (nPacket.destMAC == null || nPacket.destMAC == "" && tPacket.OutboundIP != null)
|
||||
{
|
||||
@ -616,7 +623,12 @@ namespace EduNetworkBuilder
|
||||
{
|
||||
HostNicID otherid = nd.NicIDFromArp(tPacket.destMAC);
|
||||
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;
|
||||
}
|
||||
|
@ -1682,9 +1682,20 @@ namespace EduNetworkBuilder
|
||||
nPacket.Tracking = new PacketMessage();
|
||||
myNet.addPacket(nPacket);
|
||||
//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;
|
||||
nPacket.sourceMAC = tPacket.OutboundMAC;
|
||||
if (tPacket.InboundInterface != null)
|
||||
nPacket.sourceIP = tPacket.InboundInterface.myIP;
|
||||
else
|
||||
nPacket.sourceIP = tPacket.OutboundIP;
|
||||
nPacket.destMAC = tmac;
|
||||
nPacket.OutboundDestMAC = tmac;
|
||||
@ -1713,7 +1724,7 @@ namespace EduNetworkBuilder
|
||||
if (response == ResponseToPacket.accept)
|
||||
{
|
||||
NetworkCard tnic = tPacket.OutboundNic;
|
||||
if (tnic == null)
|
||||
if (tnic == null || tnic.GetNicType == NicType.port || tnic.GetNicType == NicType.wport)
|
||||
tnic = HubManagementCard();
|
||||
if (tnic != null)
|
||||
{
|
||||
@ -2145,6 +2156,10 @@ namespace EduNetworkBuilder
|
||||
{
|
||||
//We are entering into the computer
|
||||
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);
|
||||
if(nc == null)
|
||||
{
|
||||
@ -2166,6 +2181,10 @@ namespace EduNetworkBuilder
|
||||
{
|
||||
nf = nc.LocalInterface(tPacket.TsourceIP, tPacket.Tracking);
|
||||
}
|
||||
if(nf == null)
|
||||
{
|
||||
nf = nc.PrimaryInterface();
|
||||
}
|
||||
if (nf == null && tPacket.MyType == PacketType.dhcp_request && isDHCPServer)
|
||||
{
|
||||
List<IPAddress> addresses = nc.IPAddressList();
|
||||
|
@ -340,6 +340,7 @@ namespace EduNetworkBuilder
|
||||
myDirection = nb_direction.to_dst;
|
||||
else
|
||||
myDirection = nb_direction.to_src;
|
||||
Console.WriteLine("Starting on link. SMAC: " + sourceMAC + " DMAC: " + destMAC);
|
||||
AddMessage(DebugLevel.debug, " Starting on link");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user