From Agentgroup
Jump to: navigation, search

Pseudo-code

Here you have the pseudo code of some of the most important modules in the PIM architecture. Some of these components are far from being approved, but still they give an idea of what we want for the new PIM architecture.

main

int main (int argc, char *argv[])
{
    create ConfigManager
    read config files
    compute class path
    create and init LocalRobot
}

LocalRobot

LocalRobot::init
{
    load libraries
    set basic variables (timeslice, node type, bootstrap node, ...)
    create and init VirtualMachine
    create, init and start NodeMonitor

    // I'm not sure if this is in the right place (maybe it goes in the MigrationManager init method
    get a handle to the PIM class
    // initializing the PIM object will initialize also the following modules:
    // - NodeLifeCycleListener
    // - MigrationScheduler
    // - NodeManager 

    create and init MigrationManager
    MigrationManager -> go
}

NodeMonitor

NodeMonitor::start
{
    create neighbour list
    broadcastInfo
    while true then
        receive info from other nodes
        check neighbour list
        if new neighbour then
            add neighbour to neighbour list
            broadcastInfo
        endif
    endwhile
}

NodeMonitor::broadcastInfo
{
    broadCast type and IP address (also negletTolerance value ?)
}

NodeMonitor::removeNeighbor
{
    remove neighbour from neighbour list
}

NodeMonitor::getNeighbourList
{
    return neighbour list
}

MigrationScheduler

// The NegletToleranceList will be something like:
// nodeUUID currentTimeout assignedTimeout
// where:
// nodeUUID is the unique node identifier
// currenTimeout is the time left to visit that node
// assignedTimeout is the maximum time between two presences of the CP
//
// the list will be sorted following the currentTimeout field in ascending order

MigrationScheduler::arrivedOnNode
{
    getList -> updateList
    getList -> updateMember(LocalRobot -> getNodeUUID)
}

MigrationScheduler::updateList
{
    for each element on the list do
        subtract one timeslice from the timeout
    endfor
}

MigrationScheduler::updateMember(member)
{
    if member is not in the list then
        insert it in the list at the position corresponding its defaultTimeout (LocalRobot -> defaultTimeout)
        assignedTimeout = defaultTimeout
    else
        put it in the place corresponding its assignedTimeout
    endif
}

MigrationScheduler::assignTimeout(member, timeout)
{
    set assigned timeout to the specified member
}

MigrationManager

MigrationManager::go
{
    if bootstrap node then
        loadCP
        startCP
        sleep 2 sec
        while sendToNextNode == -1 then
            sleep 2 sec
        endwhile
    endif
    while true then
        receive info with timeout
        if timeout then
            NodeMonitor -> broadcastInfo
            continue;
        endif
        if next node info and I'm the next node then
            receive CP broadcast with packet retransmission and timeout
            if timeout then
                NodeMonitor -> removeNeighbour
                NodeMonitor -> broadcastInfo
                continue;
            endif
        else if next node info and I'm not the next node then
            receive CP broadcast without packet retransmission and with timeout
            if timeout then
                NodeMonitor -> removeNeighbour
                NodeMonitor -> broadcastInfo
                continue;
            endif
        else if request for CP version then
            send CP version
            receive answer with timeout
            if timeout then
                NodeMonitor -> removeNeighbour
                NodeMonitor -> broadcastInfo
                continue;
            endif
            if answer == OK then
                defrost CP backup copy
            else
                receive CP broadcast with packet retransmission and timeout
                if timeout then
                    NodeMonitor -> removeNeighbour
                    NodeMonitor -> broadcastInfo
                    continue;
                endif
            endif
        endif
        PIM -> arriveOnNode
        sleep timeslice
        while sendToNextNode == -1 then
            sleep 2 sec                                        
        endwhile            
    endwhile
}                    

MigrationManager::sendToNextNode
{
    negletToleranceList =  MigrationScheduler -> getList
    neighbourList = NodeMonitor -> getNeighbourList
    found = null
    for i:= 1 to neighbourList.lenght do
        if neighbourList[i] not in negletToleranceList then
            found = neighbourList[i]
        endif
    endfor
    if !found then
        for i:=1 to negletToleranceList.lenght do
            for j:= 1 to neighbourList.lenght do
                if negletToleranceList[i] == neighbourList[j] then
                    if(neightbourList[j].assignedTimeout != -1 then
                        found = negletToleranceList[i]
                        break
                    endif
                endif
            endfor
        endfor
    endif
    if !found then
        return -1
    endif
    broadcast info about the chosen destination node
    broadcast CP
    receive next node response with timeout
    if response == OK then
        update CP backup copy
        return 0
    else if response == KO then
        selective retransmit
        update CP backup copy
        return 0
    else if timeout then
        NodeMonitor -> removeNeighbour
        return -1;    
    endif
}

The next release of the pseudo-code

In the next release of the pseudo-code, we would like to try using the same communication port for the NodeMonitor and the MigrationManager. Furthermore, we will have to improve the fault-tolerance mechanism.