Skip to content

PIE Pseudo code

Vichitr Gandas edited this page Nov 9, 2018 · 3 revisions
//Called on each packet arrival     
enque(Packet packet) {          
    if (PIE->drop_prob_ == 0 && current_qdelay < QDELAY_REF/2 && PIE->qdelay_old_ < QDELAY_REF/2) {
        PIE->burst_allowance_ = MAX_BURST;          
    }          
    if (PIE->burst_allowance_ == 0 && drop_early() == DROP) {                   
        drop(packet);          
    } 
    else {                   
        queue_.enque(packet);          
    }     
}

drop_early() {
    //Safeguard PIE to be work conserving         
    if ( (PIE->qdelay_old_ < QDELAY_REF/2 && PIE->drop_prob_ < 0.2) || (queue_.byte_length() <= 2 * MEAN_PKTSIZE) ) {
        return ENQUE;         
    }
    double u = random();         
    if (u < PIE->drop_prob_) {              
        return DROP;         
    } 
    else {
        return ENQUE;         
    }      
}

//We choose the timestamp option of obtaining latency for clarity   
//Rate estimation method can be found in the extended PIE pseudocode
deque(Packet packet) {
    current_qdelay = packet.timestamp_delay();     
}

//Update periodically, T_UPDATE = 15 milliseconds
calculate_drop_prob() {
    //Can be implemented using integer multiply
    p = alpha * (current_qdelay - QDELAY_REF) + beta * (current_qdelay - PIE->qdelay_old_);
    if (PIE->drop_prob_ < 0.000001) {              
        p /= 2048;          
    } 
    else if (PIE->drop_prob_ < 0.00001) {              
        p /= 512;          
    } 
    else if (PIE->drop_prob_ < 0.0001) {              
        p /= 128;          
    } 
    else if (PIE->drop_prob_ < 0.001) {              
        p /= 32;          
    } 
    else if (PIE->drop_prob_ < 0.01) {              
        p /= 8;
    } 
    else if (PIE->drop_prob_ < 0.1) {              
        p /= 2;          
    } 
    else {              
        p = p;          
    }
    
    PIE->drop_prob_ += p;
    //Exponentially decay drop prob when congestion goes away          
    if (current_qdelay == 0 && PIE->qdelay_old_ == 0) {              
        PIE->drop_prob_ *= 0.98;      //1 - 1/64 is sufficient          
    }
    //Bound drop probability          
    if (PIE->drop_prob_ < 0)                   
        PIE->drop_prob_ = 0.0          
    if (PIE->drop_prob_ > 1)                   
        PIE->drop_prob_ = 1.0
    PIE->qdelay_old_ = current_qdelay;
    PIE->burst_allowance_ = max(0,PIE->burst_allowance_ - T_UPDATE);       
}   

Clone this wiki locally