Professional Documents
Culture Documents
MASTER OF TECHNOLOGY
in
Computer Science & Engineering
Submitted by
RACHNA
Reg. No. 1079162660
Roll No.14M116
May 2016
CHAPTER 1
1.1 INTRODUCTION:
Mobile ad-hoc networks (MANETs) are particular type of networks in which the nodes
mobility is quite high. No node can join or leave to the network any time as there is no
centralized control and static infrastructure in MANETs. All nodes are considered to be
equal in processing power. The network is needed to have self configuration by means of
the cooperation among the mobile devices: all nodes works as routers and are able of
finding and managing paths to forward packets to their destinations node. The mobile
nodes movement needs the help of quite complicated routing algorithms, as routes are not
stable and require to be updated in a continuous way. Because of the dynamic behaviour
of MANETs, route management is quite complex task. Generally, Routing is the
phenomenon of selecting network paths along which the source can forward data packets
to the destination. Routing is a significant part of network communication because the
features i.e. reliability, throughput and congestion based upon the information of routing.
An ideal routing algorithm is one which is capable to send the packet to its destination
node with least network overhead and least amount of delay. The nodes maintain the
routing tables by exchanging routing information between the other network nodes. In
opposite with infrastructure networks, MANETs do not require centralized infrastructures
i.e. base stations. MANETs should be self-configured, self-built and adaptive to dynamic
modifications. In a traditional routing algorithm, which is unknown of energy budget,
links between two nodes are set up among nodes by the shortest path routes. The battery
power of mobile nodes is a restricted resource, and there is no way to permit a device to
live always, thus mechanisms to increase life of battery are relevant. Since, it results in a
frequent reduction of the battery energy of the nodes along the most usually utilized
network routes. A power-awareness routing protocol is the one that maintains the traffic
load inside the network so as to improve the nodes battery lifetime and thus the total
useful life of the ad hoc network.
C. ROUTE CACHE:
A host may utilize its route cache to neglect forwarding a route request packet obtained
from another host.
Consider a host obtains a route request packet for which it is not the destination, and is not
already stored in the packet route record, and for which the pair initiator address, request
id is not discovered in its list of currently viewed requests. If the host has a route cache
entry for the destination of the request, it may add this cache route to the accumulated
route record in the packet, and may return this route in a route response packet to the
initiator without forwarding the route request.
Before replying from its route cache a host performs the following actions.
1. Picks a delay period.
2. If packet is obtained by this host at the time of the delay period addressed to the
destination of this route discovery, and If the route length on this packet is less (delay
Table-driven On-demand
Route Discovery Procedure RREQ and RREP are used Pheromone value is used
Light Weight Terminals:Generally, the MANET nodes are mobile devices which
have less CPU processing capability, less memory size, and low power storage.
These devices require optimized algorithms and procedure that execute the
computing functions andcommunicating.
CHAPTER 2
LITERATURE REVIEW
Ammar Odeh et al.[1]:In this paper, authors analyze a MANETs performance for two
proactive protocols; Ad Hoc On-Demand Distance Vector (AODV) Protocol, and
Dynamic Source Routing (DSR) Protocol. By using network simulator NS2, we setup and
evaluate the performance of AODV and DSR protocols with respect to the packets size.
The different performance metrics were investigated with respect to packets size. DSR
has shown better performance in terms of efficiency for a packet size less than 700 bytes.
Aarti et al.[2]: In this paper, authors explained the characteristics, challenge, application,
security goal and different types of security attacks in mobile ad-hoc network. Ad-Hoc
network routing protocols are commonly divided into three main classes; Proactive ,
reactive and hybrid protocols .In MANET, all networking functions such as routing and
packet forwarding, are performed by nodes themselves in a self-organizing manner.
MANET vulnerable to various kinds of security attacks like warm hole, black hole,
rushing attack. Attacks are classified into two categories. Active attack and passive
attacks.
Chintan kanani et al.[3]: In this paper, authors modified the ad hoc on demand multipath
distance vector (AOMDV) for multipath routing using ant colony for MANET. In these
authors describe the difference between ant-AODV and AOMDV on their working that in
case of ant-AODV, RREQ message packets are sent to single path, in case of ant
AOMDV RREQ message packet are sent to multiple path. The differences between both
protocols are shown by using performance matrices packet delivery fraction, normal
routing load and packet drop. The main focus of the work is to reduce the routing
overhead, congestion and increase the performance Cygurin and NS-allinane 2.34
simulation tool is used.
Dweepna Garg et al.[4]:In this paper, authors present a new routing algorithm for
mobile, multi-hop ad-hoc networks. The protocol is based on swarm intelligence. Ant
colony Algorithms are a subset of swarm intelligence and consider the ability of simple
ants to solve complex problems by cooperation. The biggest challenge in this kind of
networks is to find a path between the communication end points, what is aggravated
through the node mobility. Routing of data packets is only through optimal path which is
generated by route discovery phase as defined by ACOR. Route maintenance is done
periodically to retain optimal path. The main goal in the design of the protocol is to reduce
the overhead for routing and refer to the protocol as the Ant Colony Optimization Routing
(ACOR).
G.vijaya kumar et al.[7]: In this paper, authors explain the number of routing protocol of
MANET. In MANET, nodes move arbitratily.nodes has limited transmission ranged by
which some nodes cannot communicate directly with each other. Authors describe
proactive and reactive routing protocol. Proactive routing protocol is used when the
network is relatively static, on the other hand, when mobility of nodes in network
increase, reactive protocol is used. In any network, selection of routing protocol is based
on mobility and traffic pattern of the network.
Neha bora et al.[28]: In this paper, authors proposed a new routing algorithm for
MANETs, which combines the idea of ant colony optimization (ACO) with split multipath
routing (SMR) protocol. This new routing algorithm is used to overcome the disadvantage
of single path routing. As single path routing protocol causes increase the call blocking
probability and decrease overall network utilization. to alleviate these problem, new
multipath routing algorithm for MANET is proposed, that is called ACO-SMR routing
algorithm. It based on swarm intelligence and especially on the ant colony based Meta
heuristics. This algorithm improved the performance of network such as delay and packet
delivery ratio than traditional routing algorithm.
Puneet Mittal et al.[34]:In this paper, authors showed the comparison between 825km,
1000km and 1300km distance in DSR protocol with traffic load FTP with respect to data
dropped, load, media access delay and network load by utilizing OPNET simulator.Inthis
paper, by changing their internodes distances, we compare the performance of Mobile ad
hoc network (MANET). In this paper, we compare protocols DSR by using changing their
internodes distances. The resultsare taken in tabular form as well as graphical form by
using OPNET Simulator 14.5. The results show that which distance area is better for DSR
protocol corresponding to FTP traffic load for some important parameters.
Richa Sharma et al.[36]: Authors explained the mobile adhoc network, dynamic source
routing protocol and ant colony optimization technique.DSR protocol is used for finding
the available route that does not gives the best path to send the packet from source to
destination, for that, to find the best path, ACO technique is used. By using ACO
technique, the efficiency of network or lifetime of network can be increased.ACO is a
natured inspired algorithm. it has been found that ACO gives better result as it is based
upon the technique of swarm intelligence(SI) which is capable for finding the adaptive
routing for such type of network.
Smriti Sofat et al.[47]: In This paper, Authors outlines the experience with the
implementation of Ant colony Technique on reactive routing protocol DSR and improves
the performance of it. In this paper, the comparative analysis of the two routing protocols,
namely DSR and ANT-DSR (ADSR) has been shown. By simulation using network
simulator shows that this method improves the performance of DSR. Authors evaluated
and compared ACO based algorithm to the original ones and obtained better results in
terms of throughput and delay jitter etc. for environments of dynamic topology.
Singh Ajay Vikram et al.[48]: In this research paper, authors proposed a new search
strategy for reactive route discovery which is based on two Qos parameters minimum
bandwidth requirement and maximum allowable end to end delay. DSR has less overhead
CHAPTER 3
BACKGROUND STUDY
Mobile Ad-Hoc network topology is active that can change rapidly because the nodes
move freely and can organize themselves randomly. This possession of the nodes makes
Use of cooperative routing algorithm: Because each node in MANETs has to act as
a router i.e. forward packets for other nodes, participate in route discovery and
route maintenance procedures. Nodes with harmful intention can cause severe
disruption exploiting this property of routing protocols.
3.5.1 Confidentiality
Confidentiality is also known as secrecy or privacy. Confidentiality is the process of
concealing information on the network, i.e. it ensures that information content cannot be
revealed by unauthorized entities that are normally known as internal or external attacker
or intruders. It can also be described as a security service that ensures only intended
receivers could interpret the information transmitted on the network. Confidentiality is
very important security service in MANETs considering wireless links in such networks
are easily susceptible to eavesdropping. In a security protocol for reliable data delivery is
Figure 3.5: Ants take the shortest path after an initial searching time
APPENDIX A
#include "dsr_hello.h"
#include "dsr_timeout.h"
#include "dsr_rrep.h"
#include "dsr_rreq.h"
#include "routing_table.h"
#include "timer_queue.h"
#include "params.h"
#include "dsr_socket.h"
#include "defs.h"
#include "debug.h"
#endif
long NS_CLASS hello_jitter()
{
if (hello_jittering) {
#ifdef NS_PORT
return (long) (((float) Random::integer(RAND_MAX + 1) / RAND_MAX - 0.5)
* JITTER_INTERVAL);
#else
return (long) (((float) random() / RAND_MAX - 0.5) * JITTER_INTERVAL);
#endif
} else
return 0;
}
gettimeofday(&this_host.fwd_time, NULL);
hello_send(NULL);
}
gettimeofday(&now, NULL);
if (optimized_hellos &&
timeval_diff(&now, &this_host.fwd_time) > ACTIVE_ROUTE_TIMEOUT) {
hello_stop();
return;
}
if (ext)
ext = DSR_EXT_NEXT(ext);
else
ext = (DSR_ext *) ((char *) rrep + RREP_SIZE);
ext->type = RREP_HELLO_NEIGHBOR_SET_EXT;
ext->length = 0;
if (rt->hello_timer.used) {
#ifdef DEBUG_HELLO
DEBUG(LOG_INFO, 0,
"Adding %s to hello neighbor set ext",
ip_to_str(rt->dest_addr));
#endif
memcpy(DSR_EXT_DATA(ext), &rt->dest_addr,
sizeof(struct in_addr));
ext->length += sizeof(struct in_addr);
}
}
}
if (ext->length)
msg_size = RREP_SIZE + DSR_EXT_SIZE(ext);
}
dest.s_addr = DSR_BROADCAST;
dsr_socket_send((DSR_msg *) rrep, dest, msg_size, 1, &DEV_NR(i));
}
gettimeofday(&now, NULL);
hello_dest.s_addr = hello->dest_addr;
hello_seqno = ntohl(hello->dest_seqno);
rt = rt_table_find(hello_dest);
if (rt)
flags = rt->flags;
if (unidir_hack)
} else
alog(LOG_WARNING, 0,
__FUNCTION__, "Bad hello interval extension!");
break;
case RREP_HELLO_NEIGHBOR_SET_EXT:
#ifdef DEBUG_HELLO
DEBUG(LOG_INFO, 0, "RREP_HELLO_NEIGHBOR_SET_EXT");
#endif
for (i = 0; i < ext->length; i = i + 4) {
ext_neighbor.s_addr =
*(in_addr_t *) ((char *) DSR_EXT_DATA(ext) + i);
if (ext_neighbor.s_addr == DEV_IFINDEX(ifindex).ipaddr.s_addr)
flags &= ~RT_UNIDIR;
}
break;
default:
alog(LOG_WARNING, 0, __FUNCTION__,
"Bad extension!! type=%d, length=%d", ext->type, ext->length);
ext = NULL;
break;
}
if (ext == NULL)
break;
rreplen -= DSR_EXT_SIZE(ext);
ext = DSR_EXT_NEXT(ext);
}
#ifdef DEBUG_HELLO
DEBUG(LOG_DEBUG, 0, "rcvd HELLO from %s, seqno %lu",
ip_to_str(hello_dest), hello_seqno);
#endif
/* This neighbor should only be valid after receiving 3
consecutive hello messages... */
if (receive_n_hellos)
state = INVALID;
else
state = VALID;
if (!rt) {
rt = rt_table_insert(hello_dest, hello_dest, 1,
hello_seqno, timeout, state, flags, ifindex);
} else {
hello_update:
return rrep;
}
return rrep_ack;
}
if (rt == NULL) {
DEBUG(LOG_WARNING, 0, "No RREP_ACK expected for %s", ip_to_str(ip_src));
return;
}
DEBUG(LOG_DEBUG, 0, "Received RREP_ACK from %s", ip_to_str(ip_src));
ext->type = type;
ext->length = len;
return ext;
}
if (!rev_rt) {
DEBUG(LOG_WARNING, 0, "Can't send RREP, rev_rt = NULL!");
return;
}
dest.s_addr = rrep->dest_addr;
rrep_flags |= RREP_ACK;
neighbor->flags |= RT_UNIDIR;
timer_remove(&neighbor->hello_timer);
timer_set_timeout(&neighbor->ack_timer, NEXT_HOP_WAIT);
}
}
if (!rrep) {
DEBUG(LOG_WARNING, 0, "No RREP to forward!");
return;
}
rt_table_t *neighbor;
if (rev_rt->dest_addr.s_addr != rev_rt->next_hop.s_addr)
neighbor = rt_table_find(rev_rt->next_hop);
else
neighbor = rev_rt;
rrep->a = 1;
neighbor->flags |= RT_UNIDIR;
precursor_add(fwd_rt, rev_rt->next_hop);
precursor_add(rev_rt, fwd_rt->next_hop);
rt_table_update_timeout(rev_rt, ACTIVE_ROUTE_TIMEOUT);
}
fwd_rt = rt_table_find(rrep_dest);
rev_rt = rt_table_find(rrep_orig);
if (!fwd_rt) {
/* We didn't have an existing entry, so we insert a new one. */
fwd_rt = rt_table_insert(rrep_dest, ip_src, rrep_new_hcnt, rrep_seqno,
rrep_lifetime, VALID, rt_flags, ifindex);
} else if (fwd_rt->dest_seqno == 0 ||
(int32_t) rrep_seqno > (int32_t) fwd_rt->dest_seqno ||
(rrep_seqno == fwd_rt->dest_seqno &&
(fwd_rt->state == INVALID || fwd_rt->flags & RT_UNIDIR ||
rrep_new_hcnt < fwd_rt->hcnt))) {
pre_repair_hcnt = fwd_rt->hcnt;
pre_repair_flags = fwd_rt->flags;
RREP_ack *rrep_ack;
rrep_ack = rrep_ack_create();
dsr_socket_send((DSR_msg *) rrep_ack, fwd_rt->next_hop,
NEXT_HOP_WAIT, MAXTTL, &DEV_IFINDEX(fwd_rt->ifindex));
/* Remove RREP_ACK flag... */
rrep->a = 0;
}
if (rrep_orig.s_addr == DEV_IFINDEX(ifindex).ipaddr.s_addr) {
#ifdef CONFIG_GATEWAY
if (inet_rrep) {
rt_table_t *inet_rt;
inet_rt = rt_table_find(inet_dest_addr);
if (!inet_rt)
rt_table_insert(inet_dest_addr, rrep_dest, rrep_new_hcnt, 0,
rrep_lifetime, VALID, RT_INET_DEST, ifindex);
else if (inet_rt->state == INVALID || rrep_new_hcnt < inet_rt->hcnt) {
rt_table_update(inet_rt, rrep_dest, rrep_new_hcnt, 0,
rrep_lifetime, VALID, RT_INET_DEST |
inet_rt->flags);
} else {
DEBUG(LOG_DEBUG, 0, "INET Response, but no update %s",
ip_to_str(inet_dest_addr));
}
}
#endif
if (pre_repair_flags & RT_REPAIR) {
if (fwd_rt->hcnt > pre_repair_hcnt) {
RERR *rerr;
u_int8_t rerr_flags = 0;
struct in_addr dest;
dest.s_addr = DSR_BROADCAST;
rerr_flags |= RERR_NODELETE;
rerr = rerr_create(rerr_flags, fwd_rt->dest_addr,
fwd_rt->dest_seqno);
if (fwd_rt->nprec)
dsr_socket_send((DSR_msg *) rerr, dest,
RERR_CALC_SIZE(rerr), 1,
&DEV_IFINDEX(fwd_rt->ifindex));
}
}
} else {
if (rev_rt && rev_rt->state == VALID) {
endif /* NS_PORT */
#ifndef NS_PORT
#define SO_RECVBUF_SIZE 256*1024
return __ptr;
}
#endif /* NS_PORT */
if (this_host.nif == 0) {
fprintf(stderr, "No interfaces configured\n");
exit(-1);
}
/* DSR socket */
DEV_NR(i).sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (DEV_NR(i).sock < 0) {
perror("");
exit(-1);
}
#ifdef CONFIG_GATEWAY
/* Data packet send socket */
DEV_NR(i).psock = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
if (DEV_NR(i).psock < 0) {
perror("");
exit(-1);
}
#endif
/* Bind the socket to the DSR port number */
memset(&dsr_addr, 0, sizeof(dsr_addr));
dsr_addr.sin_family = AF_INET;
dsr_addr.sin_port = htons(DSR_PORT);
dsr_addr.sin_addr.s_addr = htonl(INADDR_ANY);
if (retval < 0) {
perror("Bind failed ");
exit(-1);
}
if (setsockopt(DEV_NR(i).sock, SOL_SOCKET, SO_BROADCAST,
&on, sizeof(int)) < 0) {
perror("SO_BROADCAST failed ");
exit(-1);
}
bufsize = 4 * 65535;
if (retval < 0) {
perror("register input handler failed ");
exit(-1);
}
}
#endif /* NS_PORT */
num_rreq = 0;
num_rerr = 0;
}
switch (dsr_msg->type) {
case DSR_RREQ:
rreq_process((RREQ *) dsr_msg, len, src, dst, ttl, ifindex);
break;
case DSR_RREP:
DEBUG(LOG_DEBUG, 0, "Received RREP");
rrep_process((RREP *) dsr_msg, len, src, dst, ttl, ifindex);
break;
case DSR_RERR:
DEBUG(LOG_DEBUG, 0, "Received RERR");
rerr_process((RERR *) dsr_msg, len, src, dst);
break;
case DSR_RREP_ACK:
DEBUG(LOG_DEBUG, 0, "Received RREP_ACK");
rrep_ack_process((RREP_ack *) dsr_msg, len, src, dst);
break;
default:
alog(LOG_WARNING, 0, __FUNCTION__,
"Unknown msg type %u rcvd from %s to %s", dsr_msg->type,
ip_to_str(src), ip_to_str(dst));
#ifdef NS_PORT
void NS_CLASS recvDSRUUPacket(Packet * p)
{
int len, i, ttl = 0;
struct in_addr src, dst;
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
hdr_dsruu *ah = HDR_DSRUU(p);
src.s_addr = ih->saddr();
dst.s_addr = ih->daddr();
len = ch->size() - IP_HDR_LEN;
ttl = ih->ttl();
dst.s_addr = -1;
if (len < 0) {
alog(LOG_WARNING, 0, __FUNCTION__, "receive ERROR len=%d!", len);
return;
}
src.s_addr = src_addr.sin_addr.s_addr;
/* Get the ttl and destination address from the control message */
for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
cmsg = CMSG_NXTHDR_FIX(&msgh, cmsg)) {
if (cmsg->cmsg_level == SOL_IP) {
switch (cmsg->cmsg_type) {
case IP_TTL:
ttl = *(CMSG_DATA(cmsg));
break;
case IP_PKTINFO:
{
struct in_pktinfo *pi = (struct in_pktinfo *)CMSG_DATA(cmsg);
dst.s_addr = pi->ipi_addr.s_addr;
}
}
}
}
if (ttl < 0) {
DEBUG(LOG_DEBUG, 0, "No TTL, packet ignored!");
return;
}
dev = devfromsock(fd);
if (!dev) {
DEBUG(LOG_ERR, 0, "Could not get device info!\n");
return;
}
#ifndef NS_PORT
memset(&dst_addr, 0, sizeof(dst_addr));
dst_addr.sin_family = AF_INET;
dst_addr.sin_addr = dst;
dst_addr.sin_port = htons(DSR_PORT);
/* Set ttl */
if (setsockopt(dev->sock, SOL_IP, IP_TTL, &ttl, sizeof(ttl)) < 0) {
alog(LOG_WARNING, 0, __FUNCTION__, "ERROR setting ttl!");
return;
}
#else
Packet *p = allocpkt();
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
hdr_dsruu *ah = HDR_DSRUU(p);
// Note: Port number for routing agents, not DSR port number!
ih->sport() = RT_PORT;
// Fake success
retval = len;
#endif
gettimeofday(&now, NULL);
switch (dsr_msg->type) {
case DSR_RREQ:
if (num_rreq == (RREQ_RATELIMIT - 1)) {
if (timeval_diff(&now, &rreq_ratel[0]) < 1000) {
DEBUG(LOG_DEBUG, 0, "RATELIMIT: Dropping RREQ %ld ms",
timeval_diff(&now, &rreq_ratel[0]));
#ifdef NS_PORT
Packet::free(p);
#endif
return;
} else {
memmove(rreq_ratel, &rreq_ratel[1],
sizeof(struct timeval) * (num_rreq - 1));
memcpy(&rreq_ratel[num_rreq - 1], &now,
sizeof(struct timeval));
}
} else {
memcpy(&rreq_ratel[num_rreq], &now, sizeof(struct timeval));
num_rreq++;
}
break;
case DSR_RERR:
if (num_rerr == (RERR_RATELIMIT - 1)) {
if (timeval_diff(&now, &rerr_ratel[0]) < 1000) {
DEBUG(LOG_DEBUG, 0, "RATELIMIT: Dropping RERR %ld ms",
timeval_diff(&now, &rerr_ratel[0]));
#ifdef NS_PORT
Packet::free(p);
#endif
return;
} else {
memmove(rerr_ratel, &rerr_ratel[1],
sizeof(struct timeval) * (num_rerr - 1));
memcpy(&rerr_ratel[num_rerr - 1], &now,
sizeof(struct timeval));
}
} else {
memcpy(&rerr_ratel[num_rerr], &now, sizeof(struct timeval));
num_rerr++;
}
break;
}
}
if (dst.s_addr == DSR_BROADCAST) {
gettimeofday(&this_host.bcast_time, NULL);
#ifdef NS_PORT
if (retval < 0) {
} else {
#ifdef NS_PORT
ch->addr_type() = NS_AF_INET;
/* We trust the decision of next hop for all DSR messages... */
if (dst.s_addr == DSR_BROADCAST)
sendPacket(p, dst, 0.001 * Random::uniform());
else
sendPacket(p, dst, 0.0);
#else
retval = sendto(dev->sock, send_buf, len, 0,
(struct sockaddr *) &dst_addr, sizeof(dst_addr));
if (retval < 0) {
alog(LOG_WARNING, errno, __FUNCTION__, "Failed send to %s",
ip_to_str(dst));
return;
}
#endif
}
return;
}
void dsr_socket_cleanup(void)
{
#ifndef NS_PORT
int i;
rt_tbl.num_entries = 0;
rt_tbl.num_active = 0;
rt_table_delete(rt);
}
}
}
return NULL;
}
}
memset(rt, 0, sizeof(rt_table_t));
rt->dest_addr = dest_addr;
rt->next_hop = next;
rt->dest_seqno = seqno;
rt->flags = flags;
rt->hcnt = hops;
rt->ifindex = ifindex;
rt->hash = hash;
rt->state = state;
rt->last_hello_time.tv_sec = 0;
rt->last_hello_time.tv_usec = 0;
rt->hello_cnt = 0;
rt->nprec = 0;
INIT_LIST_HEAD(&rt->precursors);
rt_tbl.num_entries++;
list_add(&rt_tbl.tbl[index], &rt->l);
if (state == INVALID) {
} else {
rt_tbl.num_active++;
#ifndef NS_PORT
nl_send_add_route_msg(dest_addr, next, hops, life, flags,
ifindex);
#endif
}
#ifdef CONFIG_GATEWAY_DISABLE
if (rt->flags & RT_GATEWAY)
rt_table_update_inet_rt(rt, life);
#endif
//#ifdef NS_PORT
DEBUG(LOG_INFO, 0, "New timer for %s, life=%d",
ip_to_str(rt->dest_addr), life);
if (life != 0)
timer_set_timeout(&rt->rt_timer, life);
//#endif
/* In case there are buffered packets for this destination, we
* send them on the new route. */
if (rt->state == VALID && seek_list_remove(seek_list_find(dest_addr))) {
#ifdef NS_PORT
if (rt->flags & RT_INET_DEST)
packet_queue_set_verdict(dest_addr, PQ_ENC_SEND);
else
packet_queue_set_verdict(dest_addr, PQ_SEND);
#endif
}
return rt;
}
rt_tbl.num_active++;
#ifndef NS_PORT
nl_send_add_route_msg(rt->dest_addr, next, hops, lifetime,
flags, rt->ifindex);
#endif
#ifndef NS_PORT
nl_send_add_route_msg(rt->dest_addr, next, hops, lifetime,
flags, rt->ifindex);
#endif
}
neighbor_link_break(rt);
}
rt->flags = flags;
rt->dest_seqno = seqno;
rt->next_hop = next;
rt->hcnt = hops;
#ifdef CONFIG_GATEWAY
if (rt->flags & RT_GATEWAY)
rt_table_update_inet_rt(rt, lifetime);
#endif
//#ifdef NS_PORT
rt->rt_timer.handler = &NS_CLASS route_expire_timeout;
if (rt->state == VALID
if (!rt)
return NULL;
if (rt->state == VALID) {
gettimeofday(&new_timeout, NULL);
timeval_add_msec(&new_timeout, lifetime);
return rt;
}
next_hop_rt = rt_table_find(fwd_rt->next_hop);
next_hop_rt = rt_table_find(rev_rt->next_hop);
if (rt_tbl.num_entries == 0)
return NULL;
/* Calculate index */
index = hashing(&dest_addr, &hash);
/* Handle collisions: */
list_foreach(pos, &rt_tbl.tbl[index]) {
rt_table_t *rt = (rt_table_t *) pos;
if (rt->hash != hash)
continue;
}
return NULL;
}
#ifdef CONFIG_GATEWAY
int NS_CLASS rt_table_update_inet_rt(rt_table_t * gw, u_int32_t life)
{
int n = 0;
int i;
if (!gw)
return -1;
gettimeofday(&now, NULL);
if (rt == NULL)
return -1;
if (rt->hello_timer.used) {
DEBUG(LOG_DEBUG, 0, "last HELLO: %ld",
timeval_diff(&now, &rt->last_hello_time));
}
rt->hello_cnt = 0;
rt->last_hello_time.tv_sec = 0;
rt->last_hello_time.tv_usec = 0;
#ifndef NS_PORT
nl_send_del_route_msg(rt->dest_addr, rt->next_hop, rt->hcnt);
#endif
#ifdef CONFIG_GATEWAY
if (rt2->state == VALID
&& (rt2->flags & RT_INET_DEST)
&& (rt2->next_hop.s_addr ==
rt->dest_addr.s_addr)) {
if (0) {
DEBUG(LOG_DEBUG, 0,
"Invalidated GW %s but found new GW %s for
%s",
ip_to_str(rt->dest_addr),
ip_to_str(gw->dest_addr),
ip_to_str(rt2->
dest_addr));
rt_table_update(rt2,
gw->dest_addr,
gw->hcnt, 0,
timeval_diff
(&rt->rt_timer.
timeout, &now),
VALID,
rt2->flags);
} else {
rt_table_invalidate(rt2);
precursor_list_destroy(rt2);
}
}
return 0;
}
list_detach(&rt->l);
precursor_list_destroy(rt);
if (rt->state == VALID) {
#ifndef NS_PORT
nl_send_del_route_msg(rt->dest_addr, rt->next_hop, rt->hcnt);
#endif
rt_tbl.num_active--;
}
/* Make sure timers are removed... */
timer_remove(&rt->rt_timer);
timer_remove(&rt->hello_timer);
timer_remove(&rt->ack_timer);
rt_tbl.num_entries--;
free(rt);
return;
}
/* Sanity check */
if (!rt)
return;
list_foreach(pos, &rt->precursors) {
pr = (precursor_t *) pos;
if (pr->neighbor.s_addr == addr.s_addr)
return;
}
pr->neighbor.s_addr = addr.s_addr;
list_add(&rt->precursors, &pr->l);
rt->nprec++;
return;
}
/* Sanity check */
if (!rt)
return;
list_foreach(pos, &rt->precursors) {
precursor_t *pr = (precursor_t *) pos;
if (pr->neighbor.s_addr == addr.s_addr) {
DEBUG(LOG_INFO, 0, "Removing precursor %s from rte %s",
ip_to_str(addr), ip_to_str(rt->dest_addr));
list_detach(pos);
rt->nprec--;
free(pr);
return;
}
}
}
/* Sanity check */
if (!rt)
return;