📄 routemanager.java
字号:
// given destination, then add the packet to the list; // don't do anything else rde = rdList.get(pkt.toIPAddr); if(rde != null) { // dont add if packet buffering is not // enabled if(cfgInfo.packetBufferingVal) { rde.pktBuffer.add(pkt); } return; } //find route to dest in table dest = rtList.get(pkt.toIPAddr); // if route made, this means that this is a // bufferred packet ; therefore, send the packet out // don't do anything else if(dest != null && dest.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_VALID) { // send buffered packets only if parameter is set // as this too is related to packet buffering if(cfgInfo.packetBufferingVal) { pktSender.sendPkt(pkt); } return; } // log curInfo.log.write(Logging.INFO_LOGGING, "Route Manager - Route discovey started for " + pkt.toIPAddr.getHostAddress()); // generate RREQ //( found means (route status = invalid) ) if(dest != null) { // multicast RREQ // set TTL to (hop count of route + TTL_INCREMENT) // join flag & repair flag is not set as simple dest search // G flag from parameters // D flag from parameters // dest seq num known // hop count = 0 // increment RREQ ID, RREQ ID of originator = RREQ ID // destination adr from the IP packet // dest seq = last know seq num // has to be always my own IP adr // increment own seq num, orig seq num = own num sendto = cfgInfo.ipAddressMulticastVal; ttl = (short) (dest.hopCount + cfgInfo.TTLIncrementVal); jf = false; rf = false; gf = cfgInfo.gratuitousRREPVal; df = cfgInfo.onlyDestinationVal; usnf = false; hc = 0; ri = curInfo.incrementOwnRREQID(); da = pkt.toIPAddr; dsn = dest.destSeqNum; oa = pkt.fromIPAddr; osn = curInfo.incrementOwnSeqNum(); } else { //if not found // multicast RREQ // set TTL to TTL_START // join flag & repair flag is not set as simple dest search // G flag from parameters // D flag from parameters // since not in route, dest seq num not known // hop count = 0 // increment RREQ ID, RREQ ID of originator = RREQ ID // destination adr from the IP packet // dest seq not known // has to be always my own IP adr // increment own seq num, orig seq num = own num sendto = cfgInfo.ipAddressMulticastVal; ttl = (short) cfgInfo.TTLStartVal; jf = false; rf = false; gf = cfgInfo.gratuitousRREPVal; df = cfgInfo.onlyDestinationVal; usnf = true; hc = 0; ri = curInfo.incrementOwnRREQID(); da = pkt.toIPAddr; dsn = 0; oa = pkt.fromIPAddr; osn = curInfo.incrementOwnSeqNum(); } rreq = new RREQ(cfgInfo, curInfo, true, sendto, ttl, jf, rf, gf, df, usnf, hc, ri, da, dsn, oa, osn); // put RREQ ID + originator ip in list for RREQ minder with PATH_DISCOVERY_TIME idList.add(oa, ri); // multicast the RREQ pktSender.sendMessage(rreq); // if route discovery is ERS if(cfgInfo.routeDiscoveryModeVal == ConfigInfo.ROUTE_DISCOVERY_ERS_VAL) { initialSleep = 2 * cfgInfo.nodeTraversalTimeVal * ( ttl + cfgInfo.timeoutBufferVal); // else assumes, route discovery is non-ERS } else { initialSleep = cfgInfo.netTraversalTimeVal; } // start route discoverer rdThread = new DiscoveryMinder(cfgInfo, curInfo, this, da, initialSleep); rdThread.start(); // add the fist packet to the packet buffer (if enabled) and // update the route dioscovery list rde = new RouteDiscoveryEntry(cfgInfo, curInfo, da, rreq, rdThread, initialSleep); if(cfgInfo.packetBufferingVal) { rde.pktBuffer.add(pkt); } rdList.update(da, rde); } catch(Exception e) { // log curInfo.log.write(Logging.CRITICAL_LOGGING, "Route Manager - Route discovey failed " + e); } } /** * Method to be called to resend a RREQ after the specified duration. This method * is called by the Route Discovering thread. * * @param int retries - the number of RREQ retries done * @param InetAddress destIP - the destination for which route being searched * @return int - returns > 0 if the route discovery should continue (this being * the next wait time, or else 0 to stop route discovery * @exception Exception - due to any error when calling other methods */ public synchronized int continueRouteDiscovery(InetAddress destIP) throws Exception { RouteEntry entry; RREQ newRREQ; RouteDiscoveryEntry rde; InetAddress sendto, da, oa; short ttl; boolean jf, rf, gf, df, usnf; byte hc; int ri, dsn, osn; entry = rtList.get(destIP); // if route made, stop discovery if(entry != null && entry.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_VALID) { return 0; } // get entry from the discovery list rde = rdList.get(destIP); if(rde == null) { // log curInfo.log.write(Logging.INFO_LOGGING, "Route Manager - Route discovery terminated due to no RDE entry "); return 0; } // if max retries exceeded, stop discovery if((rde.rreqRetries + 1) > cfgInfo.RREQRetriesVal) { rdList.remove(destIP); // log curInfo.log.write(Logging.INFO_LOGGING, "Route Manager - Route discovery terminated as max retries reached (" + rde.rreqRetries + ")"); return 0; } // create the new RREQ, using the old RREQ (except for TTL and RREQID) sendto = rde.rreq.toIPAddr; // increment TTL by TTL_INCREMENT, but it should not exceed TTL_THRESHHOLD ttl = (short) (rde.rreq.ttlValue + cfgInfo.TTLIncrementVal); if(ttl >= cfgInfo.TTLThresholdVal) { ttl = (short) cfgInfo.netDiameterVal; } jf = rde.rreq.joinFlag; rf = rde.rreq.repairFlag; gf = rde.rreq.gratRREPFlag; df = rde.rreq.destOnlyFlag; usnf = rde.rreq.unknownSeqNumFlag; hc = rde.rreq.hopCount; // Increment RREQID and use this value ri = curInfo.incrementOwnRREQID(); da = rde.rreq.destIPAddr; dsn = rde.rreq.destSeqNum; oa = rde.rreq.origIPAddr; osn = rde.rreq.origSeqNum; newRREQ = new RREQ(cfgInfo, curInfo, true, sendto, ttl, jf, rf, gf, df, usnf, hc, ri, da, dsn, oa, osn); rde.rreq = newRREQ; // put RREQ ID + originator ip in list for RREQ minder with PATH_DISCOVERY_TIME idList.add(oa, ri); // multicast the RREQ again pktSender.sendMessage(newRREQ); // increment the number of RREQs re-send rde.rreqRetries++; // if route discovery is ERS if(cfgInfo.routeDiscoveryModeVal == ConfigInfo.ROUTE_DISCOVERY_ERS_VAL) { if(ttl >= cfgInfo.TTLThresholdVal) { rde.sleepTime = cfgInfo.netTraversalTimeVal; } else { rde.sleepTime = 2 * cfgInfo.nodeTraversalTimeVal * ( ttl + cfgInfo.timeoutBufferVal); } // else assumes, route discovery is non-ERS } else { rde.sleepTime = rde.sleepTime * 2; } return rde.sleepTime; } /*--------------------------------------------------------------------------------------*/ /** //curInfo.log.write(Logging.INFO_LOGGING, // "Route Manager - Updating route use for " // + pkt.toIPAddr.getHostAddress()); // get routes to dest & nextop to dest // update lifetime = curr time + ACTIVE_ROUTE_TIMEOUT // get routes to originator & next hop to orig // update lifetime = curr time + ACTIVE_ROUTE_TIMEOUT */ public synchronized void processExistingRouteUse(IPPkt pkt) throws Exception { RouteEntry origRte, destRte, nextHopRte; long currTime; currTime = (new Date()).getTime(); // if I am not the originator of the packet, then update route to originator // of packet and also the next hop, if one exists if(!(pkt.fromIPAddr.equals(cfgInfo.ipAddressVal))) { origRte = rtList.get(pkt.fromIPAddr); if(origRte != null && origRte.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_VALID) { origRte.expiryTime = currTime + cfgInfo.activeRouteTimeoutVal; rtList.update(pkt.fromIPAddr, origRte); if(origRte.hopCount > 1) { nextHopRte = rtList.get(origRte.nextHopIPAddr); if(nextHopRte != null && nextHopRte.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_VALID) { nextHopRte.expiryTime = currTime + cfgInfo.activeRouteTimeoutVal; rtList.update(origRte.nextHopIPAddr, nextHopRte); } } } } // if I am not the destination of the packet, then update route to destination // of packet and also the next hop, if one exists if(!(pkt.toIPAddr.equals(cfgInfo.ipAddressVal))) { destRte = rtList.get(pkt.toIPAddr); if(destRte != null && destRte.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_VALID) { destRte.expiryTime = currTime + cfgInfo.activeRouteTimeoutVal; rtList.update(pkt.toIPAddr, destRte); if(destRte.hopCount > 1) { nextHopRte = rtList.get(destRte.nextHopIPAddr); if(nextHopRte != null && nextHopRte.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_VALID) { nextHopRte.expiryTime = currTime + cfgInfo.activeRouteTimeoutVal; rtList.update(destRte.nextHopIPAddr, nextHopRte); } } } } } /*--------------------------------------------------------------------------------------*/ // Methods invoked by the GUI // -------------------------- /** * Method to provide a reinitization of the routing environment * if required. * @param int level - The initialization level * 0 = full initialization level * 1 - 100 = other init levels * @return int - route count */ public synchronized int reInitRouteEnvironment(int level) { return osOps.initializeRouteEnvironment(level); } /*--------------------------------------------------------------------------------------*/ // Methods invoked by the GUI // -------------------------- /** * Method to provide the number of routes in the routing * environment(related to protocol handler) to the GUI. * @return int - route count */ public synchronized int getRouteCount() { return rtList.getRouteCount(); } /** * Method to get the number of fields (i.e. route info) * that would be shown on the GUI. * @return int - field count */ public synchronized int getFieldCount() { return 10; } /** * Method to return the value related to a field in the * routing table to the GUI. * @param int row - the data row (route entry) * @param int column - data column (field) * @return String - string value of data */ public synchronized String getRouteValueAt(int row, int column) { Object array[]; RouteEntry rte; long lifetimeLong; String str; int i; // return spaces if the route entry count // changed before comming here if(row >= rtList.getRouteCount()) return " "; try { array = rtList.getRouteArray(); } catch(Exception e) { return " "; } rte = (RouteEntry) array[row]; if(column == 0) { return rte.destIPAddr.getHostAddress(); } else if(column == 1) { return "" + rte.destSeqNum; } else if(column == 2) { if(rte.validDestSeqNumFlag == RouteEntry.DEST_SEQ_FLAG_VALID) return "Valid"; else return "Invalid"; } else if(column == 3) { if(rte.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_BEING_REPAIRED) return "Being Repaired"; else if(rte.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_REPAIRABLE) return "Repairable"; else if(rte.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_VALID) return "Valid"; else return "Invalid"; } else if(column == 4) { return rte.ifaceName; } else if(column == 5) { return "" + rte.hopCount; } else if(column == 6) { return rte.nextHopIPAddr.getHostAddress(); } else if(column == 7) { lifetimeLong = rte.expiryTime - (new Date()).getTime(); return (lifetimeLong >= 0 ? "" + lifetimeLong : "expired"); } else if(column == 8) { if(rte.precursorList != null && rte.precursorList.size() > 0) { str = ""; for(i = 0; i < rte.precursorList.size(); i++) { str += ((InetAddress) rte.precursorList.get(i)).getHostAddress() + " "; } return str; } return ""; } else if(column == 9) { lifetimeLong = rte.nextHelloReceiveTime - (new Date()).getTime(); return (lifetimeLong >= 0 ? "" + lifetimeLong : " "); } else return " "; } /** * Method to return the name of the information field * in the routing table, to the GUI * @param int column - field column * @return String - string value of the field name */ public synchronized String getFieldName(int column) { if(column == 0) return "Destination"; else if(column == 1) return "Sequence"; else if(column == 2) return "Sequence Flag"; else if(column == 3) return "Route Flag"; else if(column == 4) return "Interface"; else if(column == 5) return "Hop Count"; else if(column == 6) return "Next Hop"; else if(column == 7) return "Lifetime"; else if(column == 8) return "Precursors"; else if(column == 9) return "Hello Lifetime"; else return " "; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -