Skip to content

Incorrect order of operations in CoDel control law implementation 🤦 #2478

@robgjansen

Description

@robgjansen

In Shadow's implementation of the CoDel control law, the order of operations is incorrect.

The CoDel RFC defines the control law as the following function:

time_t codel_queue_t::control_law(time_t t, uint32_t count)
   {
       return t + INTERVAL / sqrt(count);
   }

The following expression is equivalent but makes the correct order of operations explicit:

       return t + (INTERVAL / sqrt(count));

Shadow's implementation orders things the wrong way: it does the addition operation first, and then the division:

static CSimulationTime _routerqueuecodel_controlLaw(guint count, CSimulationTime ts) {
CSimulationTime newTS = ts + CODEL_PARAM_INTERVAL_SIMTIME;
double result = ((double)newTS) / sqrt((double)count);
double rounded = round(result);
return (CSimulationTime)rounded;
}

The result is that the schedule for dropping packets will be incorrect and unexpected.

Metadata

Metadata

Assignees

Labels

Component: MainComposing the core Shadow executableType: BugError or flaw producing unexpected results

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions