Example #1
0
        // Assigning a route to each destination node
        public List <RoutingPacket> DSRRouteDiscovery(MobileNode destNode, SimulationEnvironment env)
        {
            RoutingPacket        rPacket = new RoutingPacket();
            List <RoutingPacket> routes  = DSRDiscovery(destNode, env, rPacket);

            if (knownRoutes.ContainsKey(destNode.GetNodeID()))
            {
                foreach (RoutingPacket r in routes)
                {
                    bool exists = false;
                    foreach (RoutingPacket r2 in knownRoutes[destNode.GetNodeID()])
                    {
                        if (r2.RouteCompare(r))
                        {
                            exists = true;
                            break;
                        }
                    }
                    if (!exists)
                    {
                        knownRoutes[destNode.GetNodeID()].Add(r);
                    }
                }
            }
            else
            {
                knownRoutes.Add(destNode.GetNodeID(), routes);
            }
            return(routes);
        }
Example #2
0
        public List <RoutingPacket> RouteDiscoveryDSR(MobileNode destNode, SimulationEnvironment env)
        {
            Console.WriteLine("Performing Route Discovery from Node {0} to Node {1}.", nodeID, destNode.GetNodeID());
            RoutingPacket        rPacket = new RoutingPacket();
            List <RoutingPacket> routes  = DSRDicovery(destNode, env, rPacket);

            if (knownRoutes.ContainsKey(destNode.GetNodeID()))
            {
                foreach (RoutingPacket r in routes)
                {
                    bool exists = false;
                    foreach (RoutingPacket r2 in knownRoutes[destNode.GetNodeID()])
                    {
                        if (r2.RouteCompare(r))
                        {
                            exists = true;
                            break;
                        }
                    }
                    if (!exists)
                    {
                        knownRoutes[destNode.GetNodeID()].Add(r);
                    }
                }
            }
            else
            {
                knownRoutes.Add(destNode.GetNodeID(), routes);
            }
            return(routes);
        }
Example #3
0
 public List <RoutingPacket> GetRoutesToNode(MobileNode node)
 {
     // If there are no known routes for this destination, return null.
     if (!knownRoutes.ContainsKey(node.GetNodeID()))
     {
         return(null);
     }
     // Otherwise, return the list of known routes.
     return(knownRoutes[node.GetNodeID()]);
 }
Example #4
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);
        }
        // Adding SendMessageSADSR here

        public bool SendMessageDSR(Message message)
        {
            MobileNode    sourceNode      = message.GetSourceNode();
            MobileNode    destinationNode = message.GetDestinstationNode();
            RoutingPacket route           = sourceNode.GetBestRouteDSR(destinationNode);

            // If no known route found
            if (route == null)
            {
                Console.WriteLine("No Known Route to Destination.");
                sourceNode.RouteDiscoveryDSR(destinationNode, this); // Perform Route Discovery
                route = sourceNode.GetBestRouteDSR(destinationNode); // Attempt to assign newly found best route
                if (route == null)
                {
                    Console.WriteLine("No Route to Destination.");
                    return(false);
                }
            }

            Console.WriteLine("Sending Message:");
            Console.WriteLine("Source Node: " + sourceNode.GetNodeID());
            Console.WriteLine("Destination Node: " + destinationNode.GetNodeID());
            Console.WriteLine("Route Chosen: " + route.GetRouteAsString());

            List <MobileNode> nodes = route.GetNodeRoute();

            Console.WriteLine("Beginning Message Transmission from Source Node " + sourceNode.GetNodeID());
            for (int i = 1; i < nodes.Count; i++)
            {
                Console.WriteLine("Sending Message from {0} to {1}.", nodes[i - 1].GetNodeID(), nodes[i].GetNodeID());
                nodes[i - 1].TransmitPacket();
                nodes[i].ReceiveProcessPacket();
            }
            Console.WriteLine("Received Message at Destination Node " + destinationNode.GetNodeID());
            return(true);
        }
Example #6
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);
        }
Example #7
0
 public void Print() => Console.WriteLine("Message from Node {0} to Node {1}.", sourceNode.GetNodeID(), destinationNode.GetNodeID());