コード例 #1
0
        // Add DSR here
        public List <RoutingPacket> RouteDiscoveryDSR(MobileNode destNode, SimulationEnvironment env)
        {
            new OutputPaneController().PrintToOutputPane("DSR", "Performing Route Discovery from Node " + nodeID + " to Node " + destNode.GetNodeID() + ".");
            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);
        }
コード例 #2
0
        // Add modified SA-DSR here
        public List <RoutingPacket> RouteDiscoveryMSADSR(MobileNode destNode, SimulationEnvironment env)
        {
            RoutingPacket        rPacket = new RoutingPacket();
            List <RoutingPacket> routes  = DSRDiscovery(destNode, env, rPacket);

            routes = TwoAck(routes);
            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);
        }
コード例 #3
0
        public RoutingPacket Copy()
        {
            RoutingPacket packet = new RoutingPacket();

            foreach (MobileNode node in nodeRoute)
            {
                packet.AddNodeToRoute(node);
            }
            return(packet);
        }
コード例 #4
0
 public bool RouteCompare(RoutingPacket route)
 {
     if (nodeRoute.Count != route.GetNodeRoute().Count)
     {
         return(false);
     }
     else
     {
         for (int i = 0; i < nodeRoute.Count; i++)
         {
             if (!nodeRoute[i].Equals(route.GetNodeRoute()[i]))
             {
                 return(false);
             }
         }
         return(true);
     }
 }
コード例 #5
0
        // Add send message DSR 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)
            {
                new OutputPaneController().PrintToOutputPane("DSR", "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)
                {
                    new OutputPaneController().PrintToOutputPane("DSR", "No Route to Destination.");
                    return(false);
                }
            }

            new OutputPaneController().PrintToOutputPane("DSR", "Sending Message:");
            new OutputPaneController().PrintToOutputPane("DSR", "Source Node: " + sourceNode.GetNodeID());
            new OutputPaneController().PrintToOutputPane("DSR", "Destination Node: " + destinationNode.GetNodeID());
            new OutputPaneController().PrintToOutputPane("DSR", "Route Chosen: " + route.GetRouteAsString());

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

            new OutputPaneController().PrintToOutputPane("DSR", "Beginning Message Transmission from Source Node " + sourceNode.GetNodeID());
            for (int i = 1; i < nodes.Count; i++)
            {
                new OutputPaneController().PrintToOutputPane("DSR", "Sending Message from " + nodes[i - 1].GetNodeID() + " to " + nodes[i].GetNodeID() + ".");
                TransmitData(nodes[i - 1], nodes[i], 2000, DATA_COLOUR);
            }
            new OutputPaneController().PrintToOutputPane("DSR", "Received Message at Destination Node " + destinationNode.GetNodeID());

            new OutputPaneController().PrintToOutputPane("DSR", "Beginning ACK Transmission from Destination Node " + destinationNode.GetNodeID());
            for (int i = nodes.Count - 2; i >= 0; i--)
            {
                new OutputPaneController().PrintToOutputPane("DSR", "Sending ACK from " + nodes[i + 1].GetNodeID() + " to " + nodes[i].GetNodeID());
                TransmitData(nodes[i + 1], nodes[i], 500, ACK_COLOUR);
            }
            new OutputPaneController().PrintToOutputPane("DSR", "Received ACK at Source Node " + sourceNode.GetNodeID());
            return(true);
        }
コード例 #6
0
        // Get the route with the least number of selfish nodes
        public RoutingPacket GetLeastSelfishRouteMSADSR(MobileNode node)
        {
            List <RoutingPacket> routes   = GetRoutesToNode(node);
            RoutingPacket        optRoute = new RoutingPacket();
            int minMisbehavedNodes        = 999999;

            if (routes == null)
            {
                return(null);
            }
            foreach (RoutingPacket r in routes)
            {
                if (minMisbehavedNodes >= r.GetMisbehavedNodes().Count)
                {
                    minMisbehavedNodes = r.GetMisbehavedNodes().Count;
                    optRoute           = r;
                }
            }
            return(optRoute);
        }
コード例 #7
0
        // Get the optimal route for SA-DSR
        public RoutingPacket GetOptimalRouteSADSR(MobileNode node)
        {
            List <RoutingPacket> routes   = GetRoutesToNode(node);
            RoutingPacket        optRoute = new RoutingPacket();
            double sdp = 0;

            if (routes == null)
            {
                return(null);
            }
            foreach (RoutingPacket r in routes)
            {
                r.CalcSDP();
            }
            foreach (RoutingPacket r in routes)
            {
                if (sdp < r.getSDP())
                {
                    sdp      = r.getSDP();
                    optRoute = r;
                }
            }
            return(optRoute);
        }
コード例 #8
0
        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 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
                        new OutputPaneController().PrintToOutputPane("DSR", string.Format("Sending RREQ from Node {0} to Node {1}.", nodeID, node.GetNodeID()));
                        env.TransmitData(this, node, 500, env.RREQ_COLOUR);
                        new OutputPaneController().PrintToOutputPane("DSR", string.Format("Sending RREP from Node {0} to Node {1}.", node.GetNodeID(), nodeID));
                        env.TransmitData(node, this, 500, env.RREP_COLOUR);
                    }
                    else
                    {
                        RoutingPacket rPacket = route.Copy();
                        rPacket.AddNodeToRoute(this);
                        new OutputPaneController().PrintToOutputPane("DSR", string.Format("Sending RREQ from Node {0} to Node {1}.", nodeID, node.GetNodeID()));
                        env.TransmitData(this, node, 500, env.RREQ_COLOUR);
                        routes.AddRange(node.DSRDiscovery(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)
                        {
                            new OutputPaneController().PrintToOutputPane("DSR", string.Format("Sending RREP from Node {0} to Node {1}.", nodeID, rList[i - 1].GetNodeID()));
                            env.TransmitData(this, rList[i - 1], 500, env.RREP_COLOUR);
                        }
                    }
                }
            }
            return(routes);
        }