/** * This method returns the desired RREQ entry OtherWise the method returns and remove the RREQ * entry from the table * * @param sourceAddress the originator of the RREQ broadcast * @param broadcastID the ID of the RREQ broadcast * @param removeEntry is set to true if the table also should remove the entry in the table * @return returns a RREQ entry * @throws NoSuchRouteException Thrown if no table information is known about the entry */ public RouteEntry getRouteRequestEntry(String sourceAddress, int broadcastID, boolean removeEntry) throws NoSuchRouteException { synchronized (tableLock) { RouteRequestEntry entry = (RouteRequestEntry) entries.get(new EntryKey(sourceAddress, broadcastID)); if (entry != null) { if (removeEntry) { removeEntry(entry.getSourceAddress(), entry.getBroadcastID()); } return entry; } throw new NoSuchRouteException(); } }
/** * Adds the given entry to the RREQ table * * @param rreqEntry the entry to be stored * @param setTimer is set to false if the timer should not start count down the entry's time * @return returns true if the route were added successfully. A successful add requires that no * matching entry exists in the table */ public boolean addRouteRequestEntry(RouteRequestEntry rreqEntry, boolean setTimer) { synchronized (tableLock) { EntryKey key = new EntryKey(rreqEntry.getSourceAddress(), rreqEntry.getBroadcastID()); if (!entries.containsKey(key)) { entries.put(key, rreqEntry); Debug.print(toString()); if (setTimer) { sortedEntries.addLast(rreqEntry); } return true; } return false; } }
public void setRouteRequestTimer(String sourceAddres, int broadcastID) throws NoSuchRouteException { RouteRequestEntry rreqEntry = entries.get(new EntryKey(sourceAddres, broadcastID)); // Debug.print("rreqEntry:"+ rreqEntry); if (rreqEntry != null) { rreqEntry.resetAliveTimeLeft(); synchronized (tableLock) { sortedEntries.addLast(rreqEntry); } return; } Debug.print("FFF222"); throw new NoSuchRouteException(); }
public String toString() { synchronized (tableLock) { if (entries.isEmpty()) { return "RouteRequestTable is empty\n"; } String returnString = "---------------------\n" + "|Route Request Table:\n" + "---------------------"; for (RouteRequestEntry f : entries.values()) { returnString += "\n" + "|Dest: " + f.getDestinationAddress() + " destSeqN: " + f.getDestinationSequenceNumber() + " src: " + f.getSourceAddress() + " broadID: " + f.getBroadcastID() + " retries left: " + f.getRetriesLeft() + " hopCount: " + f.getHopCount() + " TTL: " + (f.getAliveTimeLeft() - System.currentTimeMillis()); } return returnString + "\n---------------------\n"; } }