📄 aodv.java
字号:
// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov Date: 10/5/2007 10:49:25 AM
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
package drcl.inet.protocol.aodv;
import drcl.comp.ActiveComponent;
import drcl.comp.Port;
import drcl.inet.InetPacket;
import drcl.inet.contract.IDLookup;
import drcl.inet.data.RTEntry;
import drcl.inet.data.RTKey;
import drcl.inet.protocol.Routing;
import drcl.inet.protocol.UnicastRouting;
import java.io.PrintStream;
import java.util.Random;
import java.util.Vector;
// Referenced classes of package drcl.inet.protocol.aodv:
// AODV_TimeOut_EVT, AODV_RERR, AODV_Packet, AODV_RREQ,
// AODV_RREP, AODV_RTEntry
public class AODV extends Routing
implements UnicastRouting, ActiveComponent
{
class AODV_Buffered_pkt
{
protected InetPacket ipkt;
protected double expire;
AODV_Buffered_pkt(InetPacket inetpacket, double d)
{
super();
ipkt = (InetPacket)inetpacket.clone();
expire = d;
}
}
class AODV_BroadcastID
{
public long src;
public int id;
public double expire;
AODV_BroadcastID(long l)
{
super();
src = l;
}
AODV_BroadcastID(long l, int i)
{
super();
src = l;
id = i;
}
}
public String getName()
{
return "aodv";
}
public String[] getDebugLevelNames()
{
return DEBUG_LEVELS;
}
public AODV()
{
router_id = 0x7fffffff;
AODV_link_layer_detection = false;
bcast_id_list = null;
aodv_rt_entry_list = null;
aodv_nbr_list = null;
bcast_id_EVT = null;
hello_EVT = null;
nbr_EVT = null;
route_EVT = null;
local_repair_EVT = null;
ifport = createIFQueryPort();
idport = createIDServicePort();
createLinkBrokenEventPort();
bcast_id_list = new Vector();
aodv_rt_entry_list = new Vector();
aodv_nbr_list = new Vector();
pkt_list = new Vector();
pkt_queue_limit_ = 64;
pkt_queue_timeout_ = 30D;
seqno = 2;
bid = 1;
}
public String info()
{
int i = (int)getTime();
StringBuffer stringbuffer = new StringBuffer();
return stringbuffer.toString();
}
public void reset()
{
super.reset();
router_id = 0x7fffffff;
bcast_id_list.removeAllElements();
aodv_rt_entry_list.removeAllElements();
aodv_nbr_list.removeAllElements();
pkt_list.removeAllElements();
if(bcast_id_EVT.handle != null)
{
cancelTimeout(bcast_id_EVT.handle);
bcast_id_EVT.setObject(null);
bcast_id_EVT.handle = null;
}
if(hello_EVT.handle != null)
{
cancelTimeout(hello_EVT.handle);
hello_EVT.setObject(null);
hello_EVT.handle = null;
}
if(nbr_EVT.handle != null)
{
cancelTimeout(nbr_EVT.handle);
nbr_EVT.setObject(null);
nbr_EVT.handle = null;
}
if(route_EVT.handle != null)
{
cancelTimeout(route_EVT.handle);
route_EVT.setObject(null);
route_EVT.handle = null;
}
}
public void duplicate(Object obj)
{
super.duplicate(obj);
AODV aodv = (AODV)obj;
}
protected void _start()
{
if(router_id == 0x7fffffff)
{
router_id = (int)IDLookup.getDefaultID(idport);
if(isDebugEnabled() && isDebugEnabledAt(1))
debug(" is constructed");
}
if(!AODV_link_layer_detection)
{
hello_EVT = new AODV_TimeOut_EVT(1, null);
double d = 0.75D + 0.5D * rand.nextDouble();
hello_EVT.handle = setTimeout(hello_EVT, d);
if(isDebugEnabled() && isDebugEnabledAt(7))
debug("setTimeout " + hello_EVT + " time " + d);
}
}
public void enable_link_detection()
{
AODV_link_layer_detection = true;
}
public void disable_link_detection()
{
AODV_link_layer_detection = false;
}
public void LinkBrokenEventHandler(InetPacket inetpacket, Port port)
{
long l = inetpacket.getNextHop();
AODV_RTEntry aodv_rtentry;
if((aodv_rtentry = rt_lookup(inetpacket.getDestination())) == null)
{
if(isDebugEnabled() && (isDebugEnabledAt(5) || isDebugEnabledAt(1)))
debug("LinkBrokenEventHandler: no route, drop pkt " + inetpacket);
if(isGarbageEnabled())
drop(inetpacket, "DROP_RTR_MAC_CALLBACK");
return;
}
if(inetpacket.getHops() > aodv_rtentry.rt_hops)
{
local_rt_repair(aodv_rtentry, inetpacket);
return;
}
if(isGarbageEnabled())
drop(inetpacket, "DROP_RTR_MAC_CALLBACK");
if(!AODV_link_layer_detection)
nb_delete(l);
handle_link_failure(l);
}
public int[] routeQueryHandler(InetPacket inetpacket, int i, Port port)
{
AODV_RTEntry aodv_rtentry = rt_lookup(inetpacket.getDestination());
if(aodv_rtentry == null)
aodv_rtentry = rt_add(inetpacket.getDestination());
if(aodv_rtentry.rt_flags == 1)
{
Object obj = retrieveRTEntryDest(aodv_rtentry.rt_dst);
if(obj != null && (obj instanceof RTEntry))
{
RTEntry rtentry = (RTEntry)obj;
return rtentry._getOutIfs();
}
if(obj != null && (obj instanceof RTEntry[]) && ((RTEntry[])obj).length > 0)
{
RTEntry artentry[] = (RTEntry[])obj;
debug("mul_rt length " + artentry.length);
return artentry[0]._getOutIfs();
}
debug("ERROR! inconsistency btw RT(empty) len: " + ((RTEntry[])obj).length + " and aodv_RT " + aodv_rtentry + " pkt: " + inetpacket);
aodv_rtentry.rt_down();
}
if(inetpacket.getSource() == (long)router_id)
{
aodv_pkt_enque(inetpacket);
sendRequest(aodv_rtentry.rt_dst);
} else
if(aodv_rtentry.rt_flags == 2)
{
aodv_pkt_enque(inetpacket);
} else
{
AODV_RERR aodv_rerr = new AODV_RERR();
aodv_rerr.DestCount = 0;
aodv_rerr.unreachable_dst[aodv_rerr.DestCount] = aodv_rtentry.rt_dst;
aodv_rerr.unreachable_dst_seqno[aodv_rerr.DestCount] = aodv_rtentry.rt_seqno;
aodv_rerr.DestCount++;
if(isDebugEnabled() && (isDebugEnabledAt(1) || isDebugEnabledAt(5)))
{
debug("sending RERR: " + aodv_rerr + " pkt:" + inetpacket);
if(aodv_rtentry != null)
debug("RERR RT: " + aodv_rtentry);
}
sendError(aodv_rerr, false);
if(isGarbageEnabled())
drop(inetpacket, "DROP_RTR_NO_ROUTE");
}
return null;
}
protected void timeout(Object obj)
{
if(isDebugEnabled() && (isDebugEnabledAt(0) || isDebugEnabledAt(7)))
debug("__timeout__ " + obj);
int i = ((AODV_TimeOut_EVT)obj).EVT_Type;
double d = getTime();
switch(i)
{
default:
break;
case 0: // '\0'
if(obj != bcast_id_EVT)
{
error("timeout()", " ** ERROR ** where does this come from? " + obj);
break;
}
id_purge();
bcast_id_EVT.handle = setTimeout(bcast_id_EVT, 6D);
if(isDebugEnabled() && isDebugEnabledAt(7))
debug("Time: " + d + " set BCAST timeout: " + 6);
break;
case 1: // '\001'
if(obj != hello_EVT)
{
error("timeout()", " ** ERROR ** where does this come from? " + obj);
break;
}
sendHello();
double d1 = 0.75D + 0.5D * rand.nextDouble();
hello_EVT.handle = setTimeout(hello_EVT, d1);
if(isDebugEnabled() && isDebugEnabledAt(7))
debug("Time: " + d + " set HELLO timeout: " + d1);
break;
case 2: // '\002'
if(obj != nbr_EVT)
{
error("timeout()", " ** ERROR ** where does this come from? " + obj);
break;
}
nb_purge();
nbr_EVT.handle = setTimeout(nbr_EVT, 1.0D);
if(isDebugEnabled() && isDebugEnabledAt(7))
debug("Time: " + d + " set NBR timeout: " + 1.0D);
break;
case 3: // '\003'
if(obj != route_EVT)
{
error("timeout()", " ** ERROR ** where does this come from? " + obj);
break;
}
rt_purge();
route_EVT.handle = setTimeout(route_EVT, 0.5D);
if(isDebugEnabled() && isDebugEnabledAt(7))
debug("Time: " + d + " set Route timeout: " + 0.5D);
break;
case 4: // '\004'
InetPacket inetpacket = (InetPacket)((AODV_TimeOut_EVT)obj).getObject();
AODV_RTEntry aodv_rtentry = rt_lookup(inetpacket.getDestination());
if(aodv_rtentry == null || aodv_rtentry.rt_flags == 1)
break;
if(isDebugEnabled() && (isDebugEnabledAt(5) || isDebugEnabledAt(7)))
{
debug("Time: " + d + " failed local repair; dst: " + aodv_rtentry.rt_dst);
debug(" local repair timeoutnexthop: " + aodv_rtentry.rt_nexthop + " pkt: " + inetpacket);
}
if(!AODV_link_layer_detection)
nb_delete(inetpacket.getDestination());
handle_link_failure(inetpacket.getDestination());
break;
case 5: // '\005'
InetPacket inetpacket1 = (InetPacket)((AODV_TimeOut_EVT)obj).getObject();
downPort.doSending(inetpacket1);
break;
case 6: // '\006'
AODV_Packet aodv_packet = (AODV_Packet)((AODV_TimeOut_EVT)obj).getObject();
broadcast(aodv_packet, router_id, 0x7ffffffffffffffeL, true, 1, 1L, 0x7ffffffffffffffeL);
break;
}
}
protected void process(Object obj, Port port)
{
lock(this);
super.process(obj, port);
unlock(this);
}
public void dataArriveAtDownPort(Object obj, Port port)
{
InetPacket inetpacket = (InetPacket)obj;
AODV_Packet aodv_packet = (AODV_Packet)inetpacket.getBody();
int i = aodv_packet.getRouterID();
int j = aodv_packet.getRouterID();
int k = aodv_packet.getType();
switch(k)
{
case 1: // '\001'
AODV_RREQ aodv_rreq = (AODV_RREQ)aodv_packet.getBody();
recvRequest(aodv_rreq, inetpacket);
break;
case 2: // '\002'
AODV_RREP aodv_rrep = (AODV_RREP)aodv_packet.getBody();
recvReply(aodv_rrep, inetpacket);
break;
case 3: // '\003'
AODV_RERR aodv_rerr = (AODV_RERR)aodv_packet.getBody();
recvError(aodv_rerr, inetpacket);
break;
case 5: // '\005'
AODV_RREP aodv_rrep1 = (AODV_RREP)aodv_packet.getBody();
recvHello(aodv_rrep1, inetpacket);
break;
case 4: // '\004'
default:
if(isDebugEnabled())
debug(" Invalid AODV type" + k);
System.exit(1);
break;
}
}
protected void recvRequest(AODV_RREQ aodv_rreq, InetPacket inetpacket)
{
int i = inetpacket.getIncomingIf();
if(isDebugEnabled() && (isDebugEnabledAt(3) || isDebugEnabledAt(1)))
debug(" aodv: receive RREQ: " + aodv_rreq + " ipkt " + inetpacket + " from " + inetpacket.getIncomingIf());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -