📄 floodidqueue.java
字号:
package dsr;//this class is implemented to store the info about the RREQ packets that have been sent out//so that we don't have duplicate entries floating around in the networkimport java.io.*;import java.util.*;import java.net.*;public class FloodIDQueue { public static List IDQueue; //List //constructor public FloodIDQueue() { IDQueue = Collections.synchronizedList(new LinkedList()); } //print out the entries in the flood Queue public static void PrintFloodIDQueue() { Iterator r = IDQueue.iterator(); System.out.println("************************************************************************"); System.out.println("The entries in the flood id queue are"); System.out.println("************************************************************************"); while (r.hasNext()) { System.out.println(((FloodIDQueueEntry)r.next()).toString()); } System.out.println("************************************************************************"); } //find a particular Entry in the queue. Returns the entry if found, null otherwise public static FloodIDQueueEntry findFloodIDQueueEntry(InetAddress dstIP, int floodID) { FloodIDQueueEntry tmpEntry = new FloodIDQueueEntry(); for (int i = 0; i < IDQueue.size(); ++i) { tmpEntry = (FloodIDQueueEntry)IDQueue.get(i); //the combination of destination address and the flood ID uniquely identifies an entry if (tmpEntry.dstIP.equals(dstIP) && tmpEntry.floodID == floodID) return tmpEntry; } return null; } //clean up the whole queue public void cleanUpFloodIDQueue() { IDQueue.clear(); } //insert an entry into the FloodID Queue public static void insertFloodIDQueueEntry(InetAddress srcIP, InetAddress dstIP, int floodID, long lifetime) { FloodIDQueueEntry tmpEntry = new FloodIDQueueEntry(srcIP, dstIP, lifetime); IDQueue.add(tmpEntry); } //find out if this entry is valid. After the lifetime is over the entry is no more valid public boolean isFloodIDQueueEntryValid(FloodIDQueueEntry tmpEntry) { if (tmpEntry.lifetime < System.currentTimeMillis()) return false; else return true; } //goes through the list and deletes the entries that are no more valid public void deleteInvalidFloodIDQueueEntry() { FloodIDQueueEntry tmpEntry = new FloodIDQueueEntry(); for (int i=0; i < IDQueue.size(); ++i) { tmpEntry = (FloodIDQueueEntry)IDQueue.get(i); if (tmpEntry.lifetime < System.currentTimeMillis()) IDQueue.remove(i); } } //delete this particular entry in the food ID queue public void deleteThisFloodIDQueueEntry(FloodIDQueueEntry tmpEntry) { IDQueue.remove(tmpEntry); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -