Using GREEN in ns-2

This page provides an ns-2 implementation of GREEN based on the following publication:
Apu Kapadia, Wu-chun Feng, Roy H. Campbell, "GREEN: A TCP Equation-Based Approach to Active Queue Management," Technical Report: UIUCDCS-R-2004-2408/UILU-ENG-2004-1710, February 2004 (bibtex)


Note: This code was last tested on ns-2.27, and ns-2's organization may have changed since I last worked on this project.
Because I haven't used ns-2 since then, regretfully I cannot provide support with respect to compilation.

  1. Add and green.h to the queue/ directory, and "queue/green.o" in the appropriate Makefile

  2. Add this to ns-default.tcl

    Queue/Green set greenForcedDrops_ 0
    Queue/Green set greenAllDrops_ 0
    Queue/Green set greenEarlyDrops_ 0
    Queue/Green set greenArrivals_ 0
    Queue/Green set greenDepartures_ 0
    Queue/Green set mss_ 8000
    Queue/Green set c_ 1.31
    Queue/Green set bw_ 0.0
    Queue/Green set idmaps_ 0

  3. TCP senders must be modified to include estimated RTTs within the header. For now we use the IP priority field as a convenience (or "convenient hack"). Make the following (one-line) change in tcp/
    void TcpAgent::output(int seqno, int reason)
    	int force_set_rtx_timer = 0;
    	Packet* p = allocpkt();
    	hdr_tcp *tcph = hdr_tcp::access(p);
    	hdr_flags* hf = hdr_flags::access(p);
    	hdr_ip *iph = hdr_ip::access(p);
    	int databytes = hdr_cmn::access(p)->size();
    	tcph->seqno() = seqno;
    	tcph->ts() = Scheduler::instance().clock();
    	// GREEN addition
    	iph->prio() = (int) t_srtt_;
    	// end GREEN addition

Using GREEN in simulations

  1. TCP flows must be given unique flow id's in your simulation. GREEN uses this to maintain IDMaps RTT information, and for active flow estimation. Flow id's should be less than 2000. If you would like to simulate more flows, change the maxFlows definition in green.h.

  2. Set the appropriate GREEN parameters
    set greenq [[$ns link $n1 $n2] queue]
    $greenq set bw_ [expr $bneck_bw_mbps*1000000]
    //Use appropriate constant based on TCP implementation. We assume TCP-Reno
    $greenq set c_ 1.31
    //To use the IDMaps estimation method set $idmaps to 1, otherwise 0 (default, embedded RTT method)
    $greenq set idmaps_ $idmaps
  3. If you choose to use the IDMaps RTT estimation method, be sure to set the actual RTT of each flow (based on your topology) using the "set-rtt" command:
    $greenq set-rtt $fid $rtt
    GREEN will randomize $rtt to be between 0.5 and 2 times the supplied value

  4. Refer to green.tcl for details. Start by the following test:
    ns green.tcl Green 155 200 0 0 
    This will simulate 200 sender/receiver pairs using a bottleneck link of 155 Mbps. IDMaps is set to 0 (estimation is based on embedded RTTs in the header). Background pareto traffic is set to 0. This simulation will show verbose output. This can be suppressed by commenting out the appropriate printf's from

    After the simulation, you will find two files: statsGreen200.out, tcp_sentGreen200.out. The first file provides overall statistics for fairness, utilization, etc. The second file shows the packets sent by each TCP flow. Here is sample output for statsGreen200.out under ns-2.27:

    green forced drops 5069
    green early drops 7567
    link_packet_loss 0.0050671795557475459
    avg_queue_size 174.76868571428571
    queue_size_std 164.08240432169117
    util 95.952037161290335
    fairness 0.95901644962302945