📄 aodv.java
字号:
}
public void nb_delete(long l)
{
seqno += 2;
int i = aodv_nbr_list.size();
for(int j = 0; j < i; j++)
{
AODV_BroadcastID aodv_broadcastid = (AODV_BroadcastID)aodv_nbr_list.elementAt(j);
if(aodv_broadcastid.src != l)
continue;
aodv_nbr_list.removeElement(aodv_broadcastid);
break;
}
}
private void handle_link_failure(long l)
{
double d = getTime();
AODV_RERR aodv_rerr = new AODV_RERR();
aodv_rerr.DestCount = 0;
int i = aodv_rt_entry_list.size();
for(int j = 0; j < i; j++)
{
AODV_RTEntry aodv_rtentry = (AODV_RTEntry)aodv_rt_entry_list.elementAt(j);
if(aodv_rtentry.rt_hops != 0x7fffffff && aodv_rtentry.rt_nexthop == l)
{
aodv_rtentry.rt_seqno++;
aodv_rerr.unreachable_dst[aodv_rerr.DestCount] = aodv_rtentry.rt_dst;
aodv_rerr.unreachable_dst_seqno[aodv_rerr.DestCount] = aodv_rtentry.rt_seqno;
if(isDebugEnabled() && (isDebugEnabledAt(5) || isDebugEnabledAt(1)))
debug(" unreach dst: " + aodv_rerr.unreachable_dst[aodv_rerr.DestCount] + " unreach dst seq: " + aodv_rerr.unreachable_dst_seqno[aodv_rerr.DestCount] + "nexthop: " + aodv_rtentry.rt_nexthop);
aodv_rerr.DestCount++;
aodv_rtentry.rt_down();
aodv_removeRTEntry(aodv_rtentry.rt_dst);
}
aodv_rtentry.pc_delete(l);
}
if(aodv_rerr.DestCount > 0)
sendError(aodv_rerr, false);
}
private void local_rt_repair(AODV_RTEntry aodv_rtentry, InetPacket inetpacket)
{
double d = getTime();
if(isDebugEnabled() && (isDebugEnabledAt(5) || isDebugEnabledAt(1)))
debug(" repair route; dst: " + aodv_rtentry.rt_dst);
aodv_pkt_enque(inetpacket);
aodv_rtentry.rt_flags = 2;
if(isDebugEnabled() && (isDebugEnabledAt(5) || isDebugEnabledAt(1)))
debug("sendRequest from local_rt_repair" + aodv_rtentry.rt_dst);
sendRequest(aodv_rtentry.rt_dst);
local_repair_EVT = new AODV_TimeOut_EVT(4, inetpacket);
local_repair_EVT.handle = setTimeout(local_repair_EVT, aodv_rtentry.rt_req_timeout);
}
protected void id_insert(long l, int i)
{
double d = getTime();
if(bcast_id_EVT == null)
{
bcast_id_EVT = new AODV_TimeOut_EVT(0, null);
if(bcast_id_EVT != null)
{
bcast_id_EVT.handle = setTimeout(bcast_id_EVT, 6D);
if(isDebugEnabled() && isDebugEnabledAt(7))
debug(" set BCAST timeout: 6");
} else
{
System.out.println("Error! Null bcast_id_EVT");
}
}
AODV_BroadcastID aodv_broadcastid = new AODV_BroadcastID(l, i);
aodv_broadcastid.expire = d + 6D;
bcast_id_list.addElement(aodv_broadcastid);
}
protected boolean id_lookup(long l, int i)
{
int j = bcast_id_list.size();
for(int k = 0; k < j; k++)
{
AODV_BroadcastID aodv_broadcastid = (AODV_BroadcastID)bcast_id_list.elementAt(k);
if(aodv_broadcastid.src == l && aodv_broadcastid.id == i)
return true;
}
return false;
}
private void id_purge()
{
double d = getTime();
for(int i = 0; i < bcast_id_list.size();)
{
AODV_BroadcastID aodv_broadcastid = (AODV_BroadcastID)bcast_id_list.elementAt(i);
if(aodv_broadcastid.expire <= d)
bcast_id_list.removeElement(aodv_broadcastid);
else
i++;
}
}
protected AODV_RTEntry rt_lookup(long l)
{
int i = aodv_rt_entry_list.size();
for(int j = 0; j < i; j++)
{
AODV_RTEntry aodv_rtentry = (AODV_RTEntry)aodv_rt_entry_list.elementAt(j);
if(aodv_rtentry.rt_dst == l)
return aodv_rtentry;
}
return null;
}
private void rt_delete(long l)
{
AODV_RTEntry aodv_rtentry = rt_lookup(l);
if(aodv_rtentry != null)
aodv_rt_entry_list.removeElement(aodv_rtentry);
}
protected AODV_RTEntry rt_add(long l)
{
double d = getTime();
if(route_EVT == null)
{
route_EVT = new AODV_TimeOut_EVT(3, null);
route_EVT.handle = setTimeout(route_EVT, 0.5D);
if(isDebugEnabled() && isDebugEnabledAt(7))
debug(" set Route timeout: 0.5" + route_EVT);
}
AODV_RTEntry aodv_rtentry = rt_lookup(l);
if(aodv_rtentry != null)
{
return aodv_rtentry;
} else
{
AODV_RTEntry aodv_rtentry1 = new AODV_RTEntry(l);
aodv_rt_entry_list.addElement(aodv_rtentry1);
return aodv_rtentry1;
}
}
private void rt_purge()
{
double d = getTime();
double d1 = 0.0D;
int i = aodv_rt_entry_list.size();
for(int j = 0; j < i; j++)
{
AODV_RTEntry aodv_rtentry = (AODV_RTEntry)aodv_rt_entry_list.elementAt(j);
InetPacket inetpacket1;
if(aodv_rtentry.rt_flags == 1 && aodv_rtentry.rt_expire < d)
{
InetPacket inetpacket;
while((inetpacket = aodv_pkt_deque(aodv_rtentry.rt_dst)) != null)
{
if(isDebugEnabled() && (isDebugEnabledAt(5) || isDebugEnabledAt(1)))
debug(" drop pkt dst: " + aodv_rtentry.rt_dst);
if(isGarbageEnabled())
drop(inetpacket, "DROP_RTR_NO_ROUTE");
}
aodv_rtentry.rt_seqno++;
aodv_rtentry.rt_down();
aodv_removeRTEntry(aodv_rtentry.rt_dst);
} else
if(aodv_rtentry.rt_flags == 1)
while((inetpacket1 = aodv_pkt_deque(aodv_rtentry.rt_dst)) != null)
{
aodv_delay_forward(aodv_rtentry, inetpacket1, d1, false);
d1 += 0.01D;
}
else
if(aodv_pkt_find(aodv_rtentry.rt_dst))
sendRequest(aodv_rtentry.rt_dst);
}
}
public void aodv_addRTEntry(long l, long l1, double d)
{
aodv_addRTEntry(l, l1, d, 0);
}
public void aodv_addRTEntry(long l, long l1, double d, int i)
{
if(isDebugEnabled() && isDebugEnabledAt(9) || isDebugEnabledAt(1))
debug("addRTEntry: dst" + l + " nexthop " + l1 + " timeout " + d + " if: " + i);
RTKey rtkey = new RTKey(0L, 0L, l, -1L, 0, 0);
AODV_RTEntry aodv_rtentry = rt_lookup(l);
addRTEntry(rtkey, l1, i, aodv_rtentry, d + 1.0D);
}
public Object aodv_removeRTEntry(long l)
{
if(isDebugEnabled() && isDebugEnabledAt(9) || isDebugEnabledAt(1))
debug("removeRTEntry: dst" + l);
return removeRTEntry(l);
}
private void aodv_pkt_enque(InetPacket inetpacket)
{
double d = getTime();
aodv_pkt_purge();
if(pkt_list.size() == pkt_queue_limit_)
{
AODV_Buffered_pkt aodv_buffered_pkt = aodv_pkt_remove_head();
if(aodv_buffered_pkt.expire > d)
{
if(isGarbageEnabled())
drop(aodv_buffered_pkt, "DROP_RTR_NO_ROUTE");
} else
if(isGarbageEnabled())
drop(aodv_buffered_pkt, "DROP_RTR_QTIMEOUT");
}
AODV_Buffered_pkt aodv_buffered_pkt1 = new AODV_Buffered_pkt(inetpacket, d + pkt_queue_timeout_);
pkt_list.addElement(aodv_buffered_pkt1);
}
protected InetPacket aodv_pkt_deque()
{
aodv_pkt_purge();
AODV_Buffered_pkt aodv_buffered_pkt = (AODV_Buffered_pkt)pkt_list.firstElement();
pkt_list.removeElementAt(0);
return aodv_buffered_pkt.ipkt;
}
protected InetPacket aodv_pkt_deque(long l)
{
aodv_pkt_purge();
int i = pkt_list.size();
for(int j = 0; j < i; j++)
{
AODV_Buffered_pkt aodv_buffered_pkt = (AODV_Buffered_pkt)pkt_list.elementAt(j);
if(aodv_buffered_pkt.ipkt.getDestination() == l)
{
pkt_list.removeElementAt(j);
return aodv_buffered_pkt.ipkt;
}
}
return null;
}
private boolean aodv_pkt_find(long l)
{
int i = pkt_list.size();
for(int j = 0; j < i; j++)
{
AODV_Buffered_pkt aodv_buffered_pkt = (AODV_Buffered_pkt)pkt_list.elementAt(j);
if(aodv_buffered_pkt.ipkt.getDestination() == l)
return true;
}
return false;
}
private AODV_Buffered_pkt aodv_pkt_remove_head()
{
if(pkt_list.size() == 0)
{
return null;
} else
{
AODV_Buffered_pkt aodv_buffered_pkt = (AODV_Buffered_pkt)pkt_list.firstElement();
pkt_list.removeElementAt(0);
return aodv_buffered_pkt;
}
}
private void aodv_pkt_purge()
{
double d = getTime();
for(int i = 0; i < pkt_list.size();)
{
AODV_Buffered_pkt aodv_buffered_pkt = (AODV_Buffered_pkt)pkt_list.elementAt(i);
if(aodv_buffered_pkt.expire <= d)
pkt_list.removeElement(aodv_buffered_pkt);
else
i++;
}
}
private double PerHopTime(AODV_RTEntry aodv_rtentry)
{
int i = 0;
double d = 0.0D;
if(aodv_rtentry == null)
return 0.029999999999999999D;
for(int j = 0; j < 3; j++)
if(aodv_rtentry.rt_disc_latency[j] > 0.0D)
{
i++;
d += aodv_rtentry.rt_disc_latency[j];
}
if(i > 0)
return d / (double)i;
else
return 0.029999999999999999D;
}
public void setSeed(long l)
{
rand.setSeed(l);
}
public static boolean debug = false;
public static boolean debug2 = false;
protected static final int AODVTYPE_RREQ = 1;
protected static final int AODVTYPE_RREP = 2;
protected static final int AODVTYPE_RERR = 3;
protected static final int AODVTYPE_RREP_ACK = 4;
protected static final int AODVTYPE_HELLO = 5;
static final double ACTIVE_ROUTE_TIMEOUT = 30D;
static final int ALLOWED_HELLO_LOSS = 3;
static final double ARP_DELAY = 0.01D;
static final double DELAY = 1D;
static final int BAD_LINK_LIFETIME = 3;
static final int BCAST_ID_SAVE = 6;
static final double HELLO_INTERVAL = 1D;
static final double MaxHelloInterval = 1.25D;
static final double MinHelloInterval = 0.75D;
static final double LOCAL_REPAIR_WAIT_TIME = 0.14999999999999999D;
static final int MAX_RREQ_TIMEOUT = 10;
static final double MY_ROUTE_TIMEOUT = 30D;
static final double NODE_TRAVERSAL_TIME = 0.029999999999999999D;
static final int NETWORK_DIAMETER = 35;
static final int RREP_WAIT_TIME = 1;
static final int REV_ROUTE_LIFE = 6;
static final int RREQ_RETRIES = 3;
static final int TTL_START = 1;
static final int TTL_INCREMENT = 2;
static final int TTL_THRESHOLD = 7;
static final double ROUTE_CACHE_FREQUENCY = 0.5D;
static final int AODV_RTQ_MAX_LEN = 64;
static final int AODV_RTQ_TIMEOUT = 30;
static final String PKT_TYPES[] = {
"NULL", "RREQ", "RREP", "RERR", "RREP_ACK", "HELLO"
};
static final long CONTROL_PKT_TYPE = 1L;
static Random rand = new Random(7777L);
protected int router_id;
protected int seqno;
private int bid;
private boolean AODV_link_layer_detection;
protected Vector bcast_id_list;
protected Vector aodv_rt_entry_list;
protected Vector aodv_nbr_list;
protected Vector pkt_list;
protected int pkt_queue_limit_;
protected double pkt_queue_timeout_;
AODV_TimeOut_EVT bcast_id_EVT;
AODV_TimeOut_EVT hello_EVT;
AODV_TimeOut_EVT nbr_EVT;
AODV_TimeOut_EVT route_EVT;
AODV_TimeOut_EVT local_repair_EVT;
Port ifport;
Port idport;
public static final int DEBUG_SAMPLE = 0;
public static final int DEBUG_AODV = 1;
public static final int DEBUG_SEND = 2;
public static final int DEBUG_RREQ = 3;
public static final int DEBUG_RREP = 4;
public static final int DEBUG_RERR = 5;
public static final int DEBUG_HELLO = 6;
public static final int DEBUG_TIMEOUT = 7;
public static final int DEBUG_DATA = 8;
public static final int DEBUG_ROUTE = 9;
static final String DEBUG_LEVELS[] = {
"sample", "aodv", "send", "rreq", "rrep", "rerr", "hello", "timeout", "data", "route"
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -