public void run() { // variables int randomTime, i; Stopwatch timer = new Stopwatch(); // start simulation running = true; timer.start(); while ((timer.elapsedTime() * 1000) < this.runtime) { // request packets from the internet at random times (1-30 sec) randomTime = AccessPoint.randInt(1000, 3200); // request a series of packets from random webpage for (i = 0; i < AccessPoint.randInt(1, 10); i++) { RequestFromInternet(); } // delay try { Thread.sleep(randomTime); } catch (InterruptedException e) { } } running = false; }
public void RequestFromInternet() { // load frame and header with information Frame frame = new Frame(); frame.loadNetworkData("request for webpage from " + Websites.getRandom() + ".com"); frame.macHeader.sourceMAC = this.MAC; frame.macHeader.destinationMAC = this.AP.getMAC(); frame.setAssociatedDevice(this); frame.size = 20 + frame.networkData.length(); // "sense" the channel to see if it's in use while (AP.channel_2G.inUse) { // there was a collision so increase counter & wait random amnt of time MainSimulation.numCollisions++; try { Thread.sleep(AccessPoint.randInt(50, 150)); } catch (InterruptedException e) { } } // send request frame to the AP AP.channel_2G.inUse = true; stopwatch.start(); AP.channel_2G.sendFrameToAP(frame); try { Thread.sleep((100 - signalStrength)); } catch (InterruptedException e) { } AP.channel_2G.inUse = false; AP.getRequestedFromInternet(); }
public void receiveAssociationReply(AccessPoint ap, int distance) { this.AP = ap; this.metersAwayFromAP = distance; obstacles = AccessPoint.randInt(0, 2); getIPFromDHCP(); calculateSignalStrength(); }
public void ReceiveReplyFromInternet() { // for parsing content in frame Frame IPdatagram[] = new Frame[4]; int i = 0; // "sense" the channel to see if it's in use while (AP.channel_2G.inUse) { // there was a collision so increase counter & wait random amnt of time MainSimulation.numCollisions++; try { Thread.sleep(AccessPoint.randInt(50, 200)); } catch (InterruptedException e) { } } // receive frames from the access point AP.channel_2G.inUse = true; // package frames into IP datagram and send to network layer in wireless device while (!AP.channel_2G.isEmpty()) { IPdatagram[i] = AP.channel_2G.getFrameFromAP(); System.out.println(Name + " received " + IPdatagram[i].networkData); i++; } try { Thread.sleep((100 - signalStrength)); } catch (InterruptedException e) { } AP.channel_2G.inUse = false; updateThroughput(IPdatagram[0].size, stopwatch.elapsedTime()); }
public void getIPFromDHCP() { // variables String localIP = AP.getLocalIP(); int num; String tokens[] = localIP.split("\\."); // look for last number num = Integer.parseInt(tokens[3]); num++; num += AP.getLocationInAP(this) + 1; tokens[3] = "" + num; // set new local ip this.localIPaddress = tokens[0] + '.' + tokens[1] + '.' + tokens[2] + '.' + tokens[3]; // set public ip this.publicIPaddress = AP.getPublicIP(); }
public WirelessDevice(String name) { this.Name = name; this.AP = null; this.MAC = Integer.toHexString(AccessPoint.randInt(0, 255)) + "-" + Integer.toHexString(AccessPoint.randInt(0, 255)) + "-" + Integer.toHexString(AccessPoint.randInt(0, 255)) + "-" + Integer.toHexString(AccessPoint.randInt(0, 255)) + "-" + Integer.toHexString(AccessPoint.randInt(0, 255)) + "-" + Integer.toHexString(AccessPoint.randInt(0, 255)); this.localIPaddress = null; this.publicIPaddress = null; this.stopwatch = new Stopwatch(); this.throughput = 0.0; this.runtime = 0; running = false; }
public void sendAssociationReq(AccessPoint ap) { // System.out.println(Name + " sending association request frame to " + AP.getSSID()); ap.requestConnection(this); }