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

📄 routemanager.java

📁 UoB JADhoc is an AODV Implementation in Java. This is a GZIPed TAR file for the Linux/Unix environme
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	*/	public synchronized void processAODVMsgRREP(RREP rrep) throws Exception {		RouteEntry prevHopRte, destRte, origRte;		boolean	mf, rf, af;		InetAddress sendto;		short ttl;		byte ps, hc;		InetAddress da, oa;		int lt, dsn;		long activeRouteExpiryTime;		RREP newRREP;		RouteDiscoveryEntry rde;		// log		curInfo.log.write(Logging.INFO_LOGGING,				"Route Manager - RREP Received "+  rrep.toString());		// find route to prev hop (who sent RREP, i.e dest=prev hop)		// if not, create route without a valid seq num		prevHopRte = rtList.get(rrep.fromIPAddr);		// if no route entry available		if(prevHopRte == null) {			// create entry			prevHopRte = new RouteEntry(cfgInfo, curInfo);			prevHopRte.destIPAddr = rrep.fromIPAddr;			prevHopRte.destSeqNum = 0;			prevHopRte.validDestSeqNumFlag = RouteEntry.DEST_SEQ_FLAG_INVALID;			prevHopRte.routeStatusFlag = RouteEntry.ROUTE_STATUS_FLAG_VALID;			prevHopRte.ifaceName = rrep.ifaceName ;			prevHopRte.hopCount = 1;			prevHopRte.nextHopIPAddr = rrep.fromIPAddr;			prevHopRte.precursorList = new LinkedList();			prevHopRte.expiryTime = (new Date()).getTime() + cfgInfo.activeRouteTimeoutVal;			prevHopRte.activeMinder = new RouteMinder(cfgInfo, curInfo, this, rrep.fromIPAddr,							cfgInfo.activeRouteTimeoutVal);			prevHopRte.activeMinder.start();		// if available and not expired		} else if(prevHopRte.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_VALID) {			  // route is active, only extend lifetime			prevHopRte.expiryTime = (new Date()).getTime() + cfgInfo.activeRouteTimeoutVal;		// if available but expired		} else {			// set kernel route, start the minder and extend lifetime			prevHopRte.hopCount = 1;			prevHopRte.nextHopIPAddr = rrep.fromIPAddr;			prevHopRte.expiryTime = (new Date()).getTime() + cfgInfo.activeRouteTimeoutVal;			prevHopRte.routeStatusFlag = RouteEntry.ROUTE_STATUS_FLAG_VALID;			prevHopRte.activeMinder = new RouteMinder(cfgInfo, curInfo, this, rrep.fromIPAddr,							cfgInfo.activeRouteTimeoutVal);			prevHopRte.activeMinder.start();		}		rtList.update(rrep.fromIPAddr, prevHopRte);		// increment hop count in RREP		rrep.hopCount++;		// find route to dest		destRte = rtList.get(rrep.destIPAddr);		// if route found ( compare dest seq num)			// AND (seq num invalid in route			//    OR (dest seq in RREP > what is in route (2s comp) AND dest seq valid)			//    OR (seq == seq AND route is inactive route)			//    OR (seq num == seq num AND active route AND hop count in RREP is < hop count in route))				// update route		if(destRte != null		    && (destRte.validDestSeqNumFlag == RouteEntry.DEST_SEQ_FLAG_INVALID			|| (curInfo.destSeqCompare(rrep.destSeqNum, destRte.destSeqNum) == curInfo.GREATER				&& destRte.validDestSeqNumFlag == RouteEntry.DEST_SEQ_FLAG_VALID)			|| (curInfo.destSeqCompare(rrep.destSeqNum, destRte.destSeqNum) == curInfo.EQUAL				&& destRte.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_INVALID)			|| (curInfo.destSeqCompare(rrep.destSeqNum, destRte.destSeqNum) == curInfo.EQUAL				&& destRte.routeStatusFlag == RouteEntry.ROUTE_STATUS_FLAG_VALID				&& rrep.hopCount < destRte.hopCount))) {			destRte.destIPAddr = rrep.destIPAddr;			destRte.destSeqNum = rrep.destSeqNum;			destRte.validDestSeqNumFlag = RouteEntry.DEST_SEQ_FLAG_VALID;			destRte.routeStatusFlag = RouteEntry.ROUTE_STATUS_FLAG_VALID;			destRte.ifaceName = rrep.ifaceName ;			destRte.hopCount = rrep.hopCount;			destRte.nextHopIPAddr = rrep.fromIPAddr;			destRte.expiryTime = (new Date()).getTime() + rrep.lifeTime;			destRte.activeMinder = new RouteMinder(cfgInfo, curInfo, this, rrep.destIPAddr,							rrep.lifeTime);			destRte.activeMinder.start();			rtList.update(rrep.destIPAddr, destRte);			// log		// if route not found		} else if(destRte == null) {			// (100) create route - route flag = active, dest seq flag = valid,			// 	 next hop = src ip in RREP, hop count = hop count in RREP			// 	 expiry time = current time + lifetime in RREP			// 	 dest seq num = dest seq num of RREP			// 	 dest ip = dest ip in RREP			// 	 iface = iface from which RREP recvd			destRte = new RouteEntry(cfgInfo, curInfo);			destRte.destIPAddr = rrep.destIPAddr;			destRte.destSeqNum = rrep.destSeqNum;			destRte.validDestSeqNumFlag = RouteEntry.DEST_SEQ_FLAG_VALID;			destRte.routeStatusFlag = RouteEntry.ROUTE_STATUS_FLAG_VALID;			destRte.ifaceName = rrep.ifaceName ;			destRte.hopCount = rrep.hopCount;			destRte.nextHopIPAddr = rrep.fromIPAddr;			destRte.precursorList = new LinkedList();			destRte.expiryTime = (new Date()).getTime() + rrep.lifeTime;			destRte.activeMinder = new RouteMinder(cfgInfo, curInfo, this, rrep.destIPAddr,							rrep.lifeTime);			destRte.activeMinder.start();			rtList.update(rrep.destIPAddr, destRte);		} else {			destRte.expiryTime = (new Date()).getTime() + rrep.lifeTime;			rtList.update(rrep.destIPAddr, destRte);		}		// if i am not originator of RREP		if(!(cfgInfo.ipAddressVal.equals(rrep.origIPAddr))) {			//find route to originator			origRte = rtList.get(rrep.origIPAddr);			if(origRte == null) {				// somethin wrong				//log				curInfo.log.write(Logging.CRITICAL_LOGGING,					"Route Manager - No originator route entry found ; try extending lifetime ");				return;			} else {				// update lifetime of route to max of (existing lifetime, currtime + ACTIVE_ROUTE_TIMEOUT)				// update precursor list - using from the src ip from whom the RREP was				// 							recvd (i.e. next hop)				activeRouteExpiryTime = cfgInfo.activeRouteTimeoutVal + (new Date()).getTime();				if(activeRouteExpiryTime > origRte.expiryTime) {					origRte.expiryTime = activeRouteExpiryTime;				}				origRte.precursorList.add(rrep.fromIPAddr);				rtList.update(rrep.origIPAddr, origRte);				// find route to dest				// update precuror list to dest (i.e. next hop to dest) - put ip of				//  next hop to which RREP is forwarded (not necessarily originator)				destRte.precursorList.add(origRte.nextHopIPAddr);				rtList.update(rrep.destIPAddr, destRte);				// send RREP to next hop to originator				mf = false;				sendto = origRte.nextHopIPAddr;				ttl = 225;				rf = rrep.repairFlag;				af = rrep.ackFlag;				ps = rrep.prefixSize;				hc = rrep.hopCount;				da = rrep.destIPAddr;				dsn = rrep.destSeqNum;				oa = rrep.origIPAddr;				lt = rrep.lifeTime;				newRREP = new RREP(cfgInfo, curInfo, mf, sendto, ttl, rf,						af, ps, hc, da, dsn, oa, lt);				pktSender.sendMessage(newRREP);			}		// if i am originator		} else {			//	unicast RREP-ACK to dest		}		// due to this RREP, if a route was made for a route being		// discovered, start the BufferMinder to release the packets		// at a given time after the route is made		// if buffering is not set, simply delete the route discovery		// entry		rde = rdList.get(rrep.destIPAddr);		if(rde != null) {			if(cfgInfo.packetBufferingVal) {				(new BufferMinder(cfgInfo, curInfo, this,							rrep.destIPAddr)).start();			} else {				rdList.remove(rrep.destIPAddr);			}			// log			curInfo.log.write(Logging.INFO_LOGGING,				"Route Manager - Route discovery terminated as route made to "				+ rrep.destIPAddr.getHostAddress());		}	}	/**		// RERR			// compile list of routes to (unrechable dest in RERR			//	AND that have the sender of RERR as next hop)			//			// send RERR to all precursors of the above list			//			{ copy dest seq from RERR			//			  set route status = INVALID			//			  set lifetime to DELETE_PERIOD			//			  start route deleters for all }			//	*/	public synchronized void processAODVMsgRERR(RERR rerr) throws Exception {		LinkedList unreachableIPList;		LinkedList unreachableSeqList;		RouteEntry entry;		int i, j;		InetAddress adrList[];		int seqList[];		RERR newRERR;		// if RERR unicast, send a RERR to each precursor in a		// invalidating route		if(cfgInfo.RERRSendingModeVal == ConfigInfo.RERR_UNICAST_VAL) {			adrList = new InetAddress[1];			seqList = new int[1];			for(i = 0; i < rerr.destCount; i++) {				entry = rtList.get(rerr.destIPAddr[i]);				// regenerate RERR only if the nexthop of this route is the				// sender of the RERR but dont remove the route to the				// sender of the RERR				if(entry != null				   && entry.nextHopIPAddr.equals(rerr.fromIPAddr)				   && !entry.destIPAddr.equals(rerr.fromIPAddr) ) {					entry.destSeqNum = rerr.destSeqNum[i];					adrList[0] = entry.destIPAddr;					seqList[0] = entry.destSeqNum;					// regenerate RERR to each precursor					for(j = 0; j < entry.precursorList.size(); j++) {						newRERR = new RERR(cfgInfo, curInfo, false,							(InetAddress) entry.precursorList.get(j), (short) 1,							false, (byte) 1, adrList, seqList);						pktSender.sendMessage(newRERR);					}					// invalidate route & start route delete					entry.routeStatusFlag = RouteEntry.ROUTE_STATUS_FLAG_INVALID;					entry.expiryTime = (new Date()).getTime()								    + cfgInfo.deletePeriodVal;					entry.activeMinder = new DeleteMinder(cfgInfo, curInfo, this,								entry.destIPAddr, cfgInfo.deletePeriodVal);					entry.activeMinder.start();					rtList.update(entry.destIPAddr, entry);				}			}		// if RERR multicast, regenerate one RERR with all the invalidating		// destinations		} else {			unreachableIPList = new LinkedList();			unreachableSeqList = new LinkedList();			// collect all the destinations that become			// invalid & start route delete			for(i = 0; i < rerr.destCount; i++) {				entry = rtList.get(rerr.destIPAddr[i]);				// collect dest only if the 'link break' (destRte) route				// was the next hop				if(entry != null				   && !entry.destIPAddr.equals(rerr.fromIPAddr)				   && entry.nextHopIPAddr.equals(rerr.fromIPAddr)) {					entry.destSeqNum = rerr.destSeqNum[i];					unreachableIPList.add(entry.destIPAddr);					unreachableSeqList.add(new Integer(entry.destSeqNum));					// invalidate route & start route delete					entry.routeStatusFlag = RouteEntry.ROUTE_STATUS_FLAG_INVALID;					entry.expiryTime = (new Date()).getTime()								    + cfgInfo.deletePeriodVal;					entry.activeMinder = new DeleteMinder(cfgInfo, curInfo, this,								entry.destIPAddr, cfgInfo.deletePeriodVal);					entry.activeMinder.start();					rtList.update(entry.destIPAddr, entry);				}			}			if(unreachableIPList.size() > 0) {				adrList = (InetAddress []) unreachableIPList.toArray();				seqList = new int[unreachableSeqList.size()];				for(i = 0; i < seqList.length; i++) {					seqList[i] = ((Integer) unreachableSeqList.get(i)).intValue();				}				newRERR = new RERR(cfgInfo, curInfo, true,						cfgInfo.ipAddressMulticastVal, (short) 1,						false, (byte) unreachableIPList.size(),						adrList, seqList);				pktSender.sendMessage(newRERR);			}		}	}	public synchronized void processAODVMsgRREPACK(RREPACK rrepack) throws Exception {		// RREP-ACK		// not implemented		return;	}	/**	* Method to process HELLO messages received by this node.	*	* @param RREP rrep - HELLO message to process. A RREP becomes	*			a HELLO message when it's	*			DestIPAddr = OrigIPAddr and when it comes	*			from a next hop	* @exception Exception - thrown in case of errors	*/	public synchronized void processAODVMsgHELLO(RREP rrep) throws Exception {		RouteEntry prevHopRte;		// log		curInfo.log.write(Logging.INFO_LOGGING,				"Route Manager - HELLO Received "+  rrep.toString());		// if no active routes exist, don't react to HELLOs		if(!doUnexpiredRoutesExist()) {			return;		}		// find route to prev hop (who sent RREP, i.e dest=prev hop)		// if not, create route with a valid seq num		prevHopRte = rtList.get(rrep.fromIPAddr);		// if no route found, means no active		// route for this destination, so dont do anything		if(prevHopRte == null) {			return;		}		prevHopRte.nextHelloReceiveTime = (new Date()).getTime() + rrep.lifeTime;		prevHopRte.destSeqNum = rrep.destSeqNum;		prevHopRte.validDestSeqNumFlag = RouteEntry.DEST_SEQ_FLAG_VALID;		// start the thread, if not started already		if(prevHopRte.helloReceiptMinder == null) {			prevHopRte.helloReceiptMinder = new HelloReceiptMinder(cfgInfo,								curInfo, this, rrep.fromIPAddr,								rrep.lifeTime);			prevHopRte.helloReceiptMinder.start();		}		rtList.update(rrep.fromIPAddr, prevHopRte);	}	/**	* This method releases the packets in a buffer when given the	* destination IP address. This method is called by the BufferMinder	* that is responsible for releasing the buffer.	*	* @param InetAddress dest - Destination IP	*/	public synchronized void releaseBuffer(InetAddress dest) throws Exception {		RouteDiscoveryEntry rde;		IPPkt pkt;		rde = rdList.get(dest);		if(rde != null) {			// send buffered packets only if parameter is set			if(cfgInfo.packetBufferingVal) {				while(rde.pktBuffer.size() > 0) {					pkt = (IPPkt) rde.pktBuffer.remove(0);					pktSender.sendPkt(pkt);				}			}			rdList.remove(dest);		}	}	/*--------------------------------------------------------------------------------------*/	public synchronized void sendHelloMessage() throws Exception {		// RREP - hello ????			// find route to hello sender			// if found				// update				//	lifetime increased to ALLOWED_HELLO_LOSS * HELLO_INTERVAL				//	dest seq num = from hello			// if not found				// create				//	get from Hello msg	}	/*--------------------------------------------------------------------------------------*/	// After rebooting	// ---------------	/*--------------------------------------------------------------------------------------*/	// Route discoverer interface	//---------------------------	/**	* Method to be called when the local(my) machine requires a route	* to some destination. This method is called by the packet listener	* when it receives a packet with the given destination MAC address.	*	* The following text defines the procedure	*	find route to dest in table	*	if found( found means (route status = valid AND expired) OR (route status = invalid) )	*		(200) dest seq = last know seq num	*		increment own seq num	*		orig seq num = own num	*		increment RREQ ID	*		RREQ ID of originator = RREQ ID	*		hop count = 0	*		G flag from parameters	*		D flag from parameters	*		set TTL to (hop count of route + TTL_INCREMENT)	*	*	if not found	*		do as (200)	*		U flag = true	*		set TTL to TTL_START	*	*	put RREQ ID + originator ip in list for RREQ minder with PATH_DISCOVERY_TIME	*	multicast RREQ	*	start route discoverer with NET_TRAVERSAL_TIME and RREQ packet	*	* @param IPPkt pkt - the packet for which a route was required	*/	public synchronized void processRouteDiscovery(IPPkt pkt) {		RouteEntry dest;		RREQ rreq;		InetAddress sendto, da, oa;		short ttl;		boolean jf, rf, gf, df, usnf;		byte hc;		int ri, dsn, osn;		RouteDiscoveryEntry rde;		DiscoveryMinder rdThread;		int initialSleep;		try {			// if already a route is being discovered for the

⌨️ 快捷键说明

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