[Javanetsim-cvs] javaNetSim/core CommandProcessor.java, 1.16, 1.17 DeviceConfig.java, 1.13, 1.14 W8
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2008-10-03 14:50:07
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31069/core Modified Files: CommandProcessor.java DeviceConfig.java W80211_packet.java WiFiPort.java Log Message: Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** CommandProcessor.java 29 Sep 2008 19:14:15 -0000 1.16 --- CommandProcessor.java 3 Oct 2008 14:49:54 -0000 1.17 *************** *** 1371,1375 **** String role = params.get(1); if(role.equalsIgnoreCase("client")){ ! wi.setMode(wi.MODE_STANTION); if(wi.isActive()) wi.DOWN(); wi.UP(); --- 1371,1375 ---- String role = params.get(1); if(role.equalsIgnoreCase("client")){ ! wi.setMode(wi.MODE_STATION); if(wi.isActive()) wi.DOWN(); wi.UP(); Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** DeviceConfig.java 29 Sep 2008 19:14:15 -0000 1.13 --- DeviceConfig.java 3 Oct 2008 14:49:54 -0000 1.14 *************** *** 438,442 **** else if(wfi.getMode()==wfi.MODE_REPEATER) conf.add("interface "+intName+" station-role repeater"); ! else if(wfi.getMode()==wfi.MODE_STANTION) conf.add("interface "+intName+" station-role client"); conf.add("interface "+intName+" authentication "+(wfi.isSharedAuth()?"shared":"open")); --- 438,442 ---- else if(wfi.getMode()==wfi.MODE_REPEATER) conf.add("interface "+intName+" station-role repeater"); ! else if(wfi.getMode()==wfi.MODE_STATION) conf.add("interface "+intName+" station-role client"); conf.add("interface "+intName+" authentication "+(wfi.isSharedAuth()?"shared":"open")); Index: W80211_packet.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/W80211_packet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** W80211_packet.java 28 Sep 2008 14:04:15 -0000 1.1 --- W80211_packet.java 3 Oct 2008 14:49:54 -0000 1.2 *************** *** 3,13 **** public class W80211_packet extends Packet { private String srcBSSID; ! private String dstBSSID; ! ! public W80211_packet(Packet inPacket, String inDst, String inSrc) { dstBSSID = inDst; Data = inPacket; ! srcBSSID = inSrc; } --- 3,42 ---- public class W80211_packet extends Packet { private String srcBSSID; ! private String dstBSSID; ! ! public int Type; ! public int subType; ! public String SSID; ! ! public String WEP; ! public int keyNum; ! ! private static long pCnt = 0; ! ! private long pID; ! ! public Long getID(){ ! return Long.valueOf(pID); ! } ! ! public void Cypher(String inWEP, int inkeyNum){ ! WEP = inWEP; ! keyNum = inkeyNum; ! } ! ! public W80211_packet(Packet inPacket, String inDst, String inSrc, int inType, int inSubType, String inSSID) { dstBSSID = inDst; Data = inPacket; ! srcBSSID = inSrc; ! Type = inType; ! subType = inSubType; ! SSID = inSSID; ! WEP = ""; ! keyNum = 0; ! ! pID = pCnt; ! pCnt++; ! if(pCnt > 6500000) pCnt=0; } Index: WiFiPort.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/WiFiPort.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WiFiPort.java 29 Sep 2008 19:14:16 -0000 1.5 --- WiFiPort.java 3 Oct 2008 14:49:54 -0000 1.6 *************** *** 3,6 **** --- 3,7 ---- import core.protocolsuite.tcp_ip.ARP_packet; import core.protocolsuite.tcp_ip.IP_packet; + import java.util.Hashtable; public class WiFiPort extends EthernetNetworkInterface { *************** *** 8,12 **** protected int channel = 1; ! protected String BSSID; protected String SSID = "default"; --- 9,13 ---- protected int channel = 1; ! protected String BSSID; protected String SSID = "default"; *************** *** 15,19 **** public static final int MODE_AP = 0; ! public static final int MODE_STANTION = 1; public static final int MODE_REPEATER = 2; --- 16,20 ---- public static final int MODE_AP = 0; ! public static final int MODE_STATION = 1; public static final int MODE_REPEATER = 2; *************** *** 23,27 **** protected String WEP_keys[] = {"", "", "", ""}; ! public WiFiPort(long UID, String inName, Node inParent) { --- 24,76 ---- protected String WEP_keys[] = {"", "", "", ""}; ! ! protected static final int OFFLINE = 0; ! protected static final int PROBE = 1; ! protected static final int AUTH = 2; ! protected static final int ASSOC = 3; ! protected static final int DATA = 4; ! protected static final int DATA_ACK = 5; ! ! // resend block ! ! class ResendPacket{ ! public int cnt; ! public W80211_packet packet; ! public long nextTime; ! public long period; ! ! public ResendPacket(W80211_packet p, long period){ ! cnt = 5; ! this.period = period; ! packet = p; ! nextTime = System.currentTimeMillis() + period; ! } ! } ! ! Hashtable<Long, ResendPacket> ResendPackets = new Hashtable<Long, ResendPacket>(); ! ! // station block ! ! protected boolean associated; ! protected boolean failed; ! protected int state; ! protected String apBSSID; ! ! // AP block ! ! class APClient{ ! public String BSSID; ! public int state; ! ! public APClient(String BSSID){ ! this.BSSID = BSSID; ! state = PROBE; ! } ! } ! ! Hashtable<String, APClient> APClients = new Hashtable<String, APClient>(); ! ! ! // Contructor public WiFiPort(long UID, String inName, Node inParent) { *************** *** 30,37 **** --- 79,148 ---- BSSID = MACAddress; + + associated = false; + + state = OFFLINE; + failed = false; //channel = 0; } + + public void associate() throws LowLinkException{ + failed = false; + associated = false; + + Mode = PROBE; + + sendProbeReq(); + } + + void sendWirelessPacket(W80211_packet inWP, long resendTime) throws LowLinkException{ + ResendPacket p = new ResendPacket(inWP, resendTime); + + ResendPackets.put(p.packet.getID(), p); + + Simulation.Sim.sendWirelessPacket(this, inWP, channel); + } + + void sendWirelessPacket(W80211_packet inWP) throws LowLinkException{ + sendWirelessPacket(inWP, 100); + } + + void sendProbeReq() throws LowLinkException{ + W80211_packet tempWiFi = new W80211_packet(null, BSSID, "FF:FF:FF:FF:FF:FF", 0, 4, SSID); + + Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 Packet", + "Link", "Sending probe req packet from interface "+ name); + + sendWirelessPacket(tempWiFi, 5000); + } + + void sendProbeReply(String inBSSID) throws LowLinkException{ + W80211_packet tempWiFi = new W80211_packet(null, BSSID, inBSSID, 0, 4, SSID); + + Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 Packet", + "Link", "Sending probe reply packet from interface "+ name); + + sendWirelessPacket(tempWiFi); + } + + void sendAuthReq(String inBSSID) throws LowLinkException{ + W80211_packet tempWiFi = new W80211_packet(null, BSSID, inBSSID, 0, 4, SSID); + + Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 Packet", + "Link", "Sending auth req packet from interface "+ name); + + sendWirelessPacket(tempWiFi); + } + + void sendAssocReq(String inBSSID) throws LowLinkException{ + W80211_packet tempWiFi = new W80211_packet(null, BSSID, inBSSID, 0, 0, SSID); + + Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 Packet", + "Link", "Sending assoc req packet from interface "+ name); + + sendWirelessPacket(tempWiFi); + } public void Timer(int temp){ } *************** *** 114,121 **** super.UP(); ! if(!active) Mode = 0; Simulation.Sim.connectWireless(this); ! parentNode.startTimerTask(this, 500); } --- 225,247 ---- super.UP(); ! if(!active) Mode = MODE_AP; ! ! failed = false; ! apBSSID = ""; ! ! ResendPackets = new Hashtable<Long, ResendPacket>(); ! ! if(Mode != MODE_STATION){ ! APClients = new Hashtable<String, APClient>(); ! } Simulation.Sim.connectWireless(this); ! parentNode.startTimerTask(this, 500); ! ! if(Mode == MODE_STATION){ ! try{ ! associate(); ! }catch(Exception e){} ! } } *************** *** 132,135 **** --- 258,310 ---- } + protected void receiveDataPacket( W80211_packet tempWiFi) throws LowLinkException { + if((tempWiFi.getDstBSSID() != BSSID && tempWiFi.getDstBSSID()!="FF:FF:FF:FF:FF:FF") || tempWiFi.SSID!=SSID || tempWiFi.WEP != WEP_keys[tempWiFi.keyNum] ){ + Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 packet", "Link", "Recieved and discarded packet at interface " + name); + + return; + } + + if(tempWiFi.SSID!=SSID || tempWiFi.WEP != WEP_keys[tempWiFi.keyNum] ){ + Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 packet", "Link", "Recieved and discarded packet: Wrong 802.11 protocol params."); + + return; + } + + Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 packet", "Link", "Recieved and accepted packet at interface " + name); + + Ethernet_packet tempPacket = (Ethernet_packet) tempWiFi.getData(); + + if(MACAddress.equals(tempPacket.getDestinationMACAddress()) + || tempPacket.getDestinationMACAddress().equals("FF:FF:FF:FF:FF:FF") || !active){ + //Packet is For this Interface or is broadcast so send it to the Parent Node + + Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "Ethernet Packet", + "Link", "Recieved and accepted packet at interface " + MACAddress); + + boolean allowReceive = true; + + Packet temp = tempPacket; + + if(active){ + + temp = tempPacket.getData(); + + NetworkLayerDevice device = (NetworkLayerDevice) parentNode; + if(device!=null && getACLin()!=0 && temp instanceof IP_packet && !(temp instanceof ARP_packet)){ + allowReceive = device.getACL().passACL(getACLin(), temp); + } + } + + if(allowReceive) + parentNode.receivePacket(temp, name); + + }else{ + //Packet is not for the Interface Drop Packet and record something in + //the Layerinfo object + Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "Ethernet Packet", + "Link", "Recieved and dropped packet at interface " + MACAddress); + } + } + protected void receivePacket(Packet inPacket) throws LowLinkException { if(!parentNode.On) return; *************** *** 138,176 **** W80211_packet tempWiFi = (W80211_packet) inPacket; ! //if() ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 packet", "Link", "Recieved and accepted packet at interface " + name); ! ! Ethernet_packet tempPacket = (Ethernet_packet) tempWiFi.getData(); ! ! if(MACAddress.equals(tempPacket.getDestinationMACAddress()) ! || tempPacket.getDestinationMACAddress().equals("FF:FF:FF:FF:FF:FF") || !active){ ! //Packet is For this Interface or is broadcast so send it to the Parent Node ! ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "Ethernet Packet", ! "Link", "Recieved and accepted packet at interface " + MACAddress); ! ! boolean allowReceive = true; ! ! Packet temp = tempPacket; ! ! if(active){ ! ! temp = tempPacket.getData(); ! ! NetworkLayerDevice device = (NetworkLayerDevice) parentNode; ! if(device!=null && getACLin()!=0 && temp instanceof IP_packet && !(temp instanceof ARP_packet)){ ! allowReceive = device.getACL().passACL(getACLin(), temp); ! } ! } ! ! if(allowReceive) ! parentNode.receivePacket(temp, name); ! ! }else{ ! //Packet is not for the Interface Drop Packet and record something in ! //the Layerinfo object ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "Ethernet Packet", ! "Link", "Recieved and dropped packet at interface " + MACAddress); ! } return; --- 313,371 ---- W80211_packet tempWiFi = (W80211_packet) inPacket; ! if(tempWiFi.Type == 2 && tempWiFi.subType == 0){ ! receiveDataPacket(tempWiFi); ! ! }else{ ! ! if(Mode == MODE_STATION){ ! if(tempWiFi.getDstBSSID() != BSSID || tempWiFi.SSID != SSID){ ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 packet", "Link", "Recieved and discarded packet at interface " + name); ! ! return; ! } ! ! if(state == PROBE && tempWiFi.Type == 0 && tempWiFi.Type == 5){ ! ResendPackets.remove(tempWiFi.getID()); ! apBSSID = tempWiFi.getSrcBSSID(); ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 Packet", ! "Link", "Recieved probe reply from " + apBSSID + " on interface "+ name); ! state = ASSOC; ! sendAssocReq(apBSSID); ! }else if(state == ASSOC && tempWiFi.Type == 0 && tempWiFi.Type == 1){ ! ResendPackets.remove(tempWiFi.getID()); ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 Packet", ! "Link", "Recieved assoc reply from " + apBSSID + " on interface "+ name + ". Association successfull."); ! state = DATA; ! associated = true; ! } ! ! }else if(Mode == MODE_AP){ ! if((tempWiFi.getDstBSSID() != BSSID && tempWiFi.getDstBSSID()!="FF:FF:FF:FF:FF:FF") || tempWiFi.SSID != SSID){ ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 packet", "Link", "Recieved and discarded packet at interface " + name); ! ! return; ! } ! ! if(tempWiFi.Type == 0 && tempWiFi.Type == 4){ ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 Packet", ! "Link", "Recieved probe req from " + tempWiFi.getSrcBSSID() + " on interface "+ name); ! ! if(APClients.get(tempWiFi.getSrcBSSID()) != null){ ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 Packet", ! "Link", "Connection state with " + tempWiFi.getSrcBSSID() + " cleared."); ! APClients.remove(tempWiFi.getSrcBSSID()); ! } ! ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 Packet", ! "Link", "Sending probe reply to " + tempWiFi.getSrcBSSID() + " on interface "+ name); ! ! APClients.put(tempWiFi.getSrcBSSID() , new APClient(tempWiFi.getSrcBSSID())); ! ! sendProbeReply(tempWiFi.getSrcBSSID()); ! } ! ! } ! ! } return; *************** *** 180,195 **** if(!parentNode.On) return; ! ! Ethernet_packet tempPacket = (Ethernet_packet)outPacket; ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "Ethernet Packet", ! "Link", "Sending packet from interface "+ MACAddress); ! W80211_packet tempWiFi = new W80211_packet(tempPacket, BSSID, "FF:FF:FF:FF:FF:FF"); ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 Packet", "Link", "Sending packet from interface "+ name); ! Simulation.Sim.sendWirelessPacket(this, tempWiFi, channel); } --- 375,413 ---- if(!parentNode.On) return; ! ! if(Mode == MODE_AP){ ! ! ! }else if(Mode == MODE_STATION){ ! ! if(failed){ ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "Ethernet Packet", ! "Link", "Can't send over air: all AP connections failed"); ! return; ! } ! ! if(!associated && state == OFFLINE){ ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "Ethernet Packet", ! "Link", "Can't send over air: no AP; AP searching process will be started immediately"); ! ! associate(); ! ! return; ! } ! ! // else put packet to buffer.... ! ! Ethernet_packet tempPacket = (Ethernet_packet)outPacket; ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "Ethernet Packet", ! "Link", "Sending packet from interface "+ MACAddress); ! //W80211_packet tempWiFi = new W80211_packet(tempPacket, BSSID, "FF:FF:FF:FF:FF:FF"); ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "802.11 Packet", "Link", "Sending packet from interface "+ name); ! //Simulation.Sim.sendWirelessPacket(this, tempWiFi, channel); ! } } |