Example #1
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);
        }
Example #2
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);
        }
 private void NRO(SimulationEnvironment sim)
 {
     // Calculate total control packets divided by the total packets received in the network
     // Get the number of control and received packets
     // Sum up all the control and received packets and divide them to obtain nro
     // Return calculated result
 }
        public void export(SimulationEnvironment sim)
        {
            // Append metrics to the end of the csv file
            StringBuilder data = new StringBuilder();
            string        path = "D:\\data.csv";

            data.AppendFormat("{0}, {1}, {2}", 0, 0, 0);
            data.AppendLine();
            File.AppendAllText(path, data.ToString());
        }
Example #5
0
        public List <MobileNode> GetNodesWithinRange(SimulationEnvironment env)
        {
            List <MobileNode> nodes = new List <MobileNode>();

            foreach (MobileNode node in env.GetNodes())
            {
                if (IsWithinRangeOf(node) && !node.Equals(this))
                {
                    nodes.Add(node);
                }
            }
            return(nodes);
        }
        public List <Route> SADSRRouteDiscovery(MobileNode destNode, SimulationEnvironment env, SessionData sData, int delay, bool modVersion)
        {
            string tag = "";

            if (modVersion)
            {
                tag = OutputTag.TAG_MSADSR;
            }
            else
            {
                tag = OutputTag.TAG_SADSR;
            }
            controller.PrintToOutputPane(tag, "Performing " + tag + " Route Discovery from Node " + nodeID + " to Node " + destNode.GetNodeID() + ".");
            List <Route> routes = SADSRRouteDiscoveryHelper(destNode, env, new Route(), sData, delay, modVersion, tag);

            if (routes == null)
            {
                return(null);
            }
            /* If there are already known routes, add if unique */
            if (knownRoutes.ContainsKey(destNode.GetNodeID()))
            {
                foreach (Route r in routes)
                {
                    bool exists = false;
                    // for each route in the routing table corresponding to the destination node
                    foreach (Route r2 in knownRoutes[destNode.GetNodeID()])
                    {
                        // if they are equivalent routes, don't bother adding to routing table
                        if (r2.RouteCompare(r))
                        {
                            exists = true;
                            break;
                        }
                    }
                    // if the route isn't in the routing table, add it
                    if (!exists)
                    {
                        knownRoutes[destNode.GetNodeID()].Add(r);
                    }
                }
            }
            /* Otherwise, add all routes to routing table */
            else
            {
                knownRoutes.Add(destNode.GetNodeID(), routes);
            }
            return(routes);
        }
Example #7
0
 public void PrintNodesWithinRange(SimulationEnvironment env)
 {
     foreach (MobileNode n in env.GetNodes())
     {
         if (!this.Equals(n))
         {
             if (IsWithinRangeOf(n))
             {
                 new OutputPaneController().PrintToOutputPane("Node_Range", "Node " + n.GetNodeID() + " is within range. Distance: " + GetDistance(n));
             }
             else
             {
                 new OutputPaneController().PrintToOutputPane("Node_Range", "Node " + n.GetNodeID() + " is not within range. Distance: " + GetDistance(n));
             }
         }
     }
 }
        // DSR implementation
        public List <Route> DSRRouteDiscovery(MobileNode destNode, SimulationEnvironment env, SessionData sData, int delay)
        {
            controller.PrintToOutputPane(OutputTag.TAG_DSR, "Performing Route Discovery from Node " + nodeID + " to Node " + destNode.GetNodeID() + ".");
            /* Perform Recursive Route Discovery to Collect all Valid Routes to the Destination */
            List <Route> routes = DSRRouteDiscoveryHelper(destNode, env, new Route(), sData, delay);

            if (routes == null)
            {
                return(null);
            }
            /* If there are already known routes, add if unique */
            if (knownRoutes.ContainsKey(destNode.GetNodeID()))
            {
                foreach (Route r in routes)
                {
                    bool exists = false;
                    foreach (Route r2 in knownRoutes[destNode.GetNodeID()]) // for each route in the routing table corresponding to the destination node
                    {
                        if (r2.RouteCompare(r))                             // if they are equivalent routes, don't bother adding to routing table
                        {
                            exists = true;
                            break;
                        }
                    }
                    if (!exists) // if the route isn't in the routing table, add it
                    {
                        knownRoutes[destNode.GetNodeID()].Add(r);
                    }
                }
            }
            /* Otherwise, add all routes to routing table */
            else
            {
                knownRoutes.Add(destNode.GetNodeID(), routes);
            }
            return(routes);
        }
Example #9
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);
        }
Example #10
0
 private void BDD(SimulationEnvironment sim)
 {
     // This will be considered later
 }
Example #11
0
 private void PDR(SimulationEnvironment sim)
 {
     // Get information about the amount of packets received and sent
     // Look at the packets sent and received and calculate the ratio
     // Return calculated result
 }
Example #12
0
 private void AEED(SimulationEnvironment sim)
 {
     // Calculate the average time it takes for a data packet to get delivered
     // Get the speed of each message in the simulate environment and calculate average speed
     // Return calculated result
 }
        private List <Route> SADSRRouteDiscoveryHelper(MobileNode destNode, SimulationEnvironment env, Route route, SessionData sData, int delay, bool modVersion, string tag)
        {
            /* Collect all known routes from here  to destination */
            List <Route> routes = new List <Route>();

            if (knownRoutes.ContainsKey(destNode.GetNodeID()) && knownRoutes[destNode.GetNodeID()] != null)
            {
                foreach (Route r in knownRoutes[destNode.GetNodeID()])
                {
                    // create copy of route, add current node, and add to routes list
                    Route r2 = route.Copy();
                    r2.AddNodesToRoute(r.GetNodeRoute());
                    routes.Add(r2);
                }
                return(routes);
            }

            /* Flood RREQ's to Nodes within Range */
            List <MobileNode> nodesWithinRange = GetNodesWithinRange(env);

            if (nodesWithinRange.Count == 0 && !destNode.Equals(this))
            {
                return(null);
            }
            /* For all nodes within range... */
            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))
                    {
                        /* Send RREQ from current node to the destination node */
                        if (SendRREQPacketSelfish(node, delay, sData, tag))
                        {
                            // Add current node and dest node to route
                            Route rPacket = route.Copy();
                            rPacket.AddNodeToRoute(this);
                            rPacket.AddNodeToRoute(node);
                            // Add new route to routes collection
                            routes.Add(rPacket);
                        }
                        else
                        {
                            continue;
                        }
                        /* Send RREQ from destination node to the current node */
                        node.SendRREPPacket(this, delay, sData, tag);
                    }
                    // If node is not the destination node...
                    else
                    {
                        /* Send RREQ from this node to node */
                        if (SendRREQPacketSelfish(node, delay, sData, tag))
                        {
                            // Add current node to the route
                            Route rPacket = route.Copy();
                            rPacket.AddNodeToRoute(this);
                            /* Recursively perform discovery from this node, and collect all returned valid routes */
                            if (routes != null)
                            {
                                routes.AddRange(node.SADSRRouteDiscoveryHelper(destNode, env, rPacket, sData, delay, modVersion, tag));
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }

            foreach (Route r in routes)
            {
                if (r.GetNodeRoute().Contains(destNode))
                { // redundancy check
                    List <MobileNode> rList = r.GetNodeRoute();
                    for (int i = 0; i < rList.Count; i++)
                    {
                        if (rList[i] == this && i != 0)
                        {
                            SendRREPPacket(rList[i - 1], delay, sData, OutputTag.TAG_SADSR);
                        }
                    }
                }
            }
            return(routes);
        }