Ejemplo n.º 1
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);
     }
 }
        // 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);
        }