/// <summary>
        /// Handles an incoming RERR packet.
        /// </summary>
        /// <param name="incomingPacket"></param>
        private void HandleRerr(Message incomingPacket)
        {
            //Section 6.11 (iii)
            var rerr = (Rerr)incomingPacket.Payload;
            var unreachableDestinations = new List <UnreachableDestination>();

            //For each of the received unreachable destinations
            foreach (var unreachableDestination in rerr.UnreachableDestinations)
            {
                var invalidRoute = _aodvHelper.RoutingTable.GetEntry(unreachableDestination.UnreachableDestinationAddress);

                //If I have an active route to that destination, and the route uses the transmitter of the RREP as the next-hop (then route is also invalid for me)
                if (invalidRoute != null && invalidRoute.Valid && invalidRoute.NextHop == incomingPacket.PreviousHop)
                {
                    //Create a list of destinations from the RERR, for which i have a routing entry, that uses the rerr.previoushop as next hop.
                    var ud = new UnreachableDestination(invalidRoute.DestinationAddress, invalidRoute.DestinationSequenceNumber);
                    unreachableDestinations.Add(ud);

                    //Perform invalidation actions from RFC
                    _aodvHelper.RoutingTable.UpdateDestinationSequenceNumber(invalidRoute.DestinationAddress, unreachableDestination.UnreachableDestinationSequenceNumber); //Section 6.11 (iii)
                    _aodvHelper.RoutingTable.InvalidateEntry(invalidRoute.DestinationAddress);
                }
            }


            //Find route with largest number of precursors
            var minCount   = 0;
            var precursors = new List <string>();

            foreach (var ud in unreachableDestinations)
            {
                var route          = _aodvHelper.RoutingTable.GetEntry(ud.UnreachableDestinationAddress);
                var precursorCount = route.Precursors.Count;
                if (precursorCount > minCount)
                {
                    minCount   = precursorCount;
                    precursors = route.Precursors;
                }
            }

            if (precursors.Count > 0)
            {
                var msg = new Message(new Rerr(rerr), precursors[0], _localAddress, _conf.MessageTtlValue);
                SendAodvMessage(msg, precursors[0]);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Called when an RERR is to be sent. It invalidates any routing entries that have broken as a result of the missing neighbour,
        /// and returns a list of destinations now unreachable.
        /// </summary>
        /// <param name="missingNextHop"></param>
        /// <returns>List of destinations that are now unreachable due to the missing next hop</returns>
        public List <UnreachableDestination> HandleAndGetUnreachableDestinations(string missingNextHop)
        {
            var unreachableDestinations = new List <UnreachableDestination>();

            //Per section 6.11 (i) and (ii)
            foreach (var destination in _table.Keys)
            {
                //If this is an entry for a now unreachable destination or the missing neighbour
                if (_table[destination].NextHop == missingNextHop)
                {
                    var ud = new UnreachableDestination(destination, _table[destination].DestinationSequenceNumber);
                    unreachableDestinations.Add(ud);

                    if (_table[destination].Valid)
                    {
                        _table[destination].DestinationSequenceNumber++;
                    }

                    _table[destination].Invalidate(_conf);
                }
            }

            return(unreachableDestinations);
        }