示例#1
0
        // Adding nodes to routes
        private List <RoutingPacket> DSRDiscovery(MobileNode destNode, SimulationEnvironment env, RoutingPacket route)
        {
            List <RoutingPacket> routes = new List <RoutingPacket>();

            if (knownRoutes.ContainsKey(destNode.GetNodeID()))
            {
                foreach (RoutingPacket r in knownRoutes[destNode.GetNodeID()])
                {
                    RoutingPacket r2 = route.Copy();
                    r2.AddNodesToRoute(r.GetNodeRoute());
                    routes.Add(r2);
                }
                return(routes);
            }

            List <MobileNode> nodesWithinRange = GetNodesWithinRange(env);

            if (nodesWithinRange.Count == 0 && !destNode.Equals(this))
            {
                return(null);
            }

            foreach (MobileNode node in nodesWithinRange)
            {
                if (!route.IsInRouteAlready(node))
                {
                    if (node.Equals(destNode))
                    {
                        RoutingPacket rPacket = route.Copy();
                        rPacket.AddNodeToRoute(this);
                        rPacket.AddNodeToRoute(node);
                        routes.Add(rPacket);
                    }
                    else
                    {
                        RoutingPacket rPacket = route.Copy();
                        rPacket.AddNodeToRoute(this);
                        routes.AddRange(node.DSRDiscovery(destNode, env, rPacket));
                    }
                }
            }
            return(routes);
        }
示例#2
0
        private List <RoutingPacket> DSRDicovery(MobileNode destNode, SimulationEnvironment env, RoutingPacket route)
        {
            List <RoutingPacket> routes = new List <RoutingPacket>();

            if (knownRoutes.ContainsKey(destNode.GetNodeID()))
            {
                foreach (RoutingPacket r in knownRoutes[destNode.GetNodeID()])
                {
                    RoutingPacket r2 = route.Copy();
                    r2.AddNodesToRoute(r.GetNodeRoute());
                    routes.Add(r2);
                }
                return(routes);
            }

            List <MobileNode> nodesWithinRange = GetNodesWithinRange(env);

            if (nodesWithinRange.Count == 0 && !destNode.Equals(this))
            {
                return(null);
            }

            foreach (MobileNode node in nodesWithinRange)
            {
                // If node isn't in route yet...
                if (!route.IsInRouteAlready(node))
                {
                    // If node is the destination node...
                    if (node.Equals(destNode))
                    {
                        //Obtaining all possible routes
                        RoutingPacket rPacket = route.Copy();
                        rPacket.AddNodeToRoute(this); // Adding nodes to route
                        rPacket.AddNodeToRoute(node);
                        routes.Add(rPacket);          // Adding all possible routes
                        Console.WriteLine("Sending RREQ from Node {0} to Node {1}.", nodeID, node.GetNodeID());
                        TransmitPacket();
                        node.ReceiveProcessPacket();
                        Console.WriteLine("Sending RREP from Node {0} to Node {1}.", node.GetNodeID(), nodeID);
                        node.TransmitPacket();
                        ReceiveProcessPacket();
                    }
                    else
                    {
                        RoutingPacket rPacket = route.Copy();
                        rPacket.AddNodeToRoute(this);
                        Console.WriteLine("Sending RREQ from Node {0} to Node {1}.", nodeID, node.GetNodeID());
                        TransmitPacket();
                        node.ReceiveProcessPacket();
                        routes.AddRange(node.DSRDicovery(destNode, env, rPacket)); // Recursive call
                    }
                }
            }
            foreach (RoutingPacket r in routes)
            {
                if (r.GetNodeRoute().Contains(destNode))
                {
                    List <MobileNode> rList = r.GetNodeRoute();
                    for (int i = 0; i < rList.Count; i++)
                    {
                        if (rList[i] == this && i != 0)
                        {
                            Console.WriteLine("Sending RREP from Node {0} to Node {1}.", nodeID, rList[i - 1].GetNodeID());
                            TransmitPacket();
                            rList[i - 1].GetNodeID();
                        }
                    }
                }
            }
            return(routes);
        }