⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 availability.java

📁 The WLAN Traffic Visualizer is a platform independent Java program providing accurate measurement of
💻 JAVA
字号:
package model;//Copyright (C) 2008 Harald Unander, Wang Wenjuan////    This file is part of WlanTV.////    WlanTV is free software: you can redistribute it and/or modify//    it under the terms of the GNU General Public License as published by//    the Free Software Foundation, either version 3 of the License, or//    (at your option) any later version.////    WlanTV is distributed in the hope that it will be useful,//    but WITHOUT ANY WARRANTY; without even the implied warranty of//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//    GNU General Public License for more details.////    You should have received a copy of the GNU General Public License//    along with WlanTV.  If not, see <http://www.gnu.org/licenses/>.import java.util.ArrayList;import main.Main;import model.Packet.CH_MODES;import model.Packet.FType;import model.Transaction.OneTransaction;public class Availability {	public ArrayList<Packet> extraPackets = new ArrayList<Packet>();	private long captureTime;	private long busyTime;	private long freeTime;	private long accessTime;	private long byteCount;	private float usedBandwidth;	private float availableBandwidth;	private int transactionCount;	private int packetCount;	private int extraCount;	private int availableTransactionCount;	private int altAvailableTransactionCount;	private float altAvailableBandwidth;	private int transactionSpace;	private int payloadLen;	private long overlapTime;	private Packet dummyR;	private int oneAccessTime;	private Packet.CH_MODES mode;	private int shortSlotTime;	private int extraByteCount;	private float extraBandwidth;	private Load load;		protected long startTime;	protected long endTime;	public Availability(int firstTransactionNo, int lastTransactionNo, Transaction transaction,int _payloadLen, int _oneAccessTime, boolean fill) {		this.payloadLen = _payloadLen;		this.oneAccessTime = _oneAccessTime;		OneTransaction firstT = transaction.list.get(firstTransactionNo);		OneTransaction lastT = transaction.list.get(lastTransactionNo);		startTime = firstT.timeStamp;		endTime = lastT.timeStamp + lastT.totalDur;		load = new Load(startTime, endTime);		// Find busy time, transaction count and packet count				mode = firstT.packetList.get(0).chMode;		shortSlotTime = firstT.packetList.get(0).mgmtShortSlotTime;		dummyR = makeDummyDataPacket(mode,shortSlotTime,payloadLen,0,FType.UNKNOWN);		if (oneAccessTime == 0) {			oneAccessTime = dummyR.getDifsDur()+dummyR.getBackoffDur();		}		transactionSpace = oneAccessTime + dummyR.frameDur + dummyR.wlanDuration;		for (int j=firstTransactionNo; j<=lastTransactionNo; j++) {			OneTransaction one = transaction.list.get(j);			if (!one.hide) {				for (Packet r : one.packetList) {					if (r.fType.equals(FType.RECONSTRUCTED)) {						extraByteCount += r.frameLen;						extraCount++;					}					else {						byteCount += r.frameLen + RawPacket.getWiresharkLenCompensation();						packetCount++;					}					if (getLoad()!=null) getLoad().addRealLoad(r.frameTimeRel,r.frameLen);				}				busyTime += one.totalDur;				transactionCount++;				lastT = one;			}		}		//		System.out.println("======="+packetCount);		if (transactionCount == 0) return;		// Correct start and end times to include full transactions		if (firstT.timeStamp-oneAccessTime <= startTime) startTime = firstT.timeStamp-accessTime;		if (lastT.timeStamp+lastT.totalDur >= endTime) endTime = lastT.timeStamp+lastT.totalDur;		// Find free space and access time		long t = startTime;			for (int j=firstTransactionNo; j<=lastTransactionNo; j++) {			OneTransaction one = transaction.list.get(j);			if (!one.hide) {				long space = one.timeStamp-t;				if (space > 0) {					addPackets(t, one.timeStamp, endTime-startTime, mode, shortSlotTime);					if (space > oneAccessTime) {						freeTime += space-oneAccessTime;						accessTime += oneAccessTime;					}					else {						accessTime += space;					}				}				else {					accessTime += space;					overlapTime -= space;				}				t = one.timeStamp + one.totalDur;			}		}		// Consider free space after last transaction		t = lastT.timeStamp+lastT.totalDur;		long space = endTime - t;		addPackets(t,endTime,endTime-startTime,mode,shortSlotTime);		freeTime += space;		captureTime = endTime - startTime;		usedBandwidth = ((float)8*byteCount)/captureTime;		extraBandwidth = ((float)8*extraByteCount)/captureTime;		availableBandwidth = ((float)8*payloadLen*availableTransactionCount)/captureTime;		altAvailableTransactionCount = (int) (freeTime/transactionSpace);		altAvailableBandwidth = ((float)8*payloadLen*altAvailableTransactionCount)/captureTime;		//		if (fill && captureTime>1000000)		//			Main.myLogging.addWarning(this,"Reduce view span to below 1 sec. to see fill packets.");		if (getLoad() != null) getLoad().calculate();		if (getOverlapTimePercent() > 1)			Main.myLogging.addWarning(this, "Please note overlap time of "					+ getOverlapTimePercent()					+ "%. This may be caused by wrong channel mode.");	}	private void addPackets(long t0, long t1, long span, CH_MODES mode, int shortSlotTime) {		while (t1-t0 > transactionSpace+oneAccessTime) {			availableTransactionCount++;			Packet r = makeDummyDataPacket(mode,shortSlotTime,payloadLen,t0+oneAccessTime+dummyR.frameDur,FType.FILL);			if (span < 1000000)				extraPackets.add(r);			if (getLoad()!=null) getLoad().addExtraLoad(r.frameTimeRel,r.frameLen);			t0 += transactionSpace;		}	}	public String getAvailability() {		StringBuffer sb = new StringBuffer();		sb.append("Frame count\t" + packetCount+"\n");		sb.append("View span\t" + Main.usToSec(startTime) + " ... " + Main.usToSec(endTime) + "\n");		//		sb.append("View time\t"+ "100%\t" + captureTime + "us\n");		//		sb.append("Busy time\t"+getBusyTimePercent()+"%\t" + getBusyTime() + "us\n");		//		sb.append("Free time\t"+getFreeTimePercent()+"%\t" + getFreeTime() + "us\n");		//		sb.append("Access time\t"+getAccessTimePercent()+"%\t" + getAccessTime() + "us\n");		sb.append("Overlap time\t"+getOverlapTimePercent()+"%\n"); //\t" + getOverlapTime() + "us\n");		sb.append("Transaction count\t" + transactionCount+"\n");		sb.append("Reconstr. trans. count\t" + extraCount+"\n");		//		sb.append("Capture duration\t" + String.format("%.6fsec\n",captureTime/1000000f));		sb.append("Byte count\t"+byteCount+"\n");		sb.append("Reconstr. byte count\t"+extraByteCount+"\n");		sb.append("Avg. throughput\t"+ String.format("%.3fMbps",usedBandwidth)+"\n");		sb.append("Reconstr. throughput\t"+ String.format("%.3fMbps",extraBandwidth));		//		sb.append("Check time\t"+  (busyTime + accessTime + freeTime) + "us\n");		//		sb.append("Busy time\t"+ busyTime + "us\n");		//		sb.append("Access time\t"+ accessTime + "us\n");		//		sb.append("Check time\t"+  (busyTime + accessTime + freeTime) + "us\n");		return sb.toString();	}	public String getFillTransactionDetails() {		StringBuffer sb = new StringBuffer();		sb.append("Duration\t"+ transactionSpace+"us\n");		sb.append("Mode\t"+ mode+"\n"); 		sb.append("SlotTime\t"+ Packet.getSlotTime(shortSlotTime)+"\n");		sb.append("Payload length\t" + payloadLen+"\n");		sb.append("Access time\t"+ oneAccessTime+"us");				return sb.toString();	}	public String getExtra() {		StringBuffer sb = new StringBuffer();		sb.append("Optimistic:\n");		sb.append("  Fill trans. count\t" + altAvailableTransactionCount+"\n");		sb.append("  Fill throughput\t"+ String.format("%.3fMbps",altAvailableBandwidth)+"\n");		sb.append("  Total throughput\t"+ String.format("%.3fMbps",altAvailableBandwidth+usedBandwidth+extraBandwidth)+"\n");		sb.append("Pessimistic:\n");		sb.append("  Fill trans. count\t" + availableTransactionCount+"\n");		sb.append("  Fill throughput\t"+ String.format("%.3fMbps",availableBandwidth)+"\n");		sb.append("  Total throughput\t"+ String.format("%.3fMbps",availableBandwidth+usedBandwidth+extraBandwidth));		return sb.toString();	}	private static Packet newPacket(int len,int channelType,int shortSlotTime,long t,int ackDuration,String prot,int rate,FType fType) {		Packet newPacket = new Packet();		newPacket.frameLen = len;		newPacket.frameProtocols = prot;		newPacket.frameRate = rate;		newPacket.channelType = channelType;		newPacket.frameTimeRel = t;		newPacket.wlanDuration = ackDuration;		newPacket.mgmtShortSlotTime = shortSlotTime;		newPacket.calculate(CH_MODES.auto);		newPacket.fType = fType;		return newPacket;	}	public static Packet makeDummyDataPacket(CH_MODES chMode, int shortSlotTime, int l,long time,FType fType) {		Packet packet = null;		if (chMode==CH_MODES.m11g)			packet = newPacket(l,0xC0,shortSlotTime,time,44,"radiotap",54,fType);		else if (chMode == CH_MODES.m11b_long)				packet = newPacket(l,0xA0,shortSlotTime,time,258,"radiotap",11,fType);		else if (chMode == CH_MODES.m11b_short)				packet = newPacket(l,0xA0,shortSlotTime,time,117,"radiotap",11,fType);		else // (chMode == CH_MODES.m11a)			packet = newPacket(l,0x100,shortSlotTime,time,44,"radiotap",54,fType);		//		else if (chMode == CH_MODES.m11)		//		v = getMinimumTransactionSpace(LEN,0x480,54,44);		return packet;	}	public long getBusyTime() {		return busyTime;	}	public long getFreeTime() {		return freeTime;	}	public long getAccessTime() {		return accessTime;	}	public long getCaptureTime() {		return captureTime;	}	public int getBusyTimePercent() {		return Math.round(100f*busyTime/captureTime);	}	public int getFreeTimePercent() {		return Math.round(100f*freeTime/captureTime);	}	public int getAccessTimePercent() {		return Math.round(100f*accessTime/captureTime);	}	public int getOverlapTimePercent() {		return Math.round(100f*overlapTime/captureTime);	}	public long getOverlapTime() {		return overlapTime;	}	public int getFillAccessTime() {		return oneAccessTime;	}	public Load getLoad() {		return load;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -