Ejemplo n.º 1
0
    /// <summary>Performs work in order to find optimum location in new constellation for given node
    /// <para>Recieves planrequest, finds best free location, or trades locations with other node in order to optimize net cost</para>
    /// </summary>
    public static void GeneratePlan(INode myNode, PlanRequest request)
    {
        // Remove failure detection requests in queue as we are planning to make changes to network structure anyway, which might solve the failure
        myNode.CommsModule.RequestList.RemoveAll(x => x.Command == Request.Commands.DETECTFAILURE);

        if (request.DestinationID != myNode.Id)
        {
            return;
        }
        else
        {
            myNode.ExecutingPlan  = false;
            myNode.State          = Node.NodeState.PLANNING;
            myNode.GeneratingPlan = request.Plan;

            PlanRequest newRequest = request.DeepCopy();
            newRequest.AckExpected = true;


            if (newRequest.Plan.Entries.Any(entry => entry.NodeID == myNode.Id == false))
            {
                List <NodeLocationMatch> matches = CalculatePositions(myNode, newRequest);
                ConstellationPlan        newPlan = ProcessPlan(matches, newRequest, myNode);
                newRequest.Plan = newPlan;
            }


            Transmit(newRequest, myNode);
        }
    }
Ejemplo n.º 2
0
    private static void ForwardRequest(INode myNode, PlanRequest request)
    {
        PlanRequest newRequest = request.DeepCopy();
        uint?       nextSeq    = myNode.Router.NextSequential(myNode, newRequest.Dir);

        if (nextSeq == null)
        {
            newRequest.Dir = newRequest.Dir == Router.CommDir.CW ? Router.CommDir.CCW : Router.CommDir.CW;
            nextSeq        = myNode.Router.NextSequential(myNode, newRequest.Dir);
        }

        if (nextSeq != null)
        {
            newRequest.SenderID      = myNode.Id;
            newRequest.DestinationID = nextSeq;
            uint?nextHop = myNode.Router.NextHop(myNode.Id, nextSeq);
            myNode.CommsModule.SendAsync(nextHop, newRequest, Constants.COMMS_TIMEOUT, Constants.COMMS_ATTEMPTS);
        }
    }