Appendix III: Topology Simulator Implementation Overview


Classes

The critical classes involved in this simulation are roughly organized as:

The node class collects all the simulation data:
class node {
  [statistic collecting vars]

  // collect the statistics for this simulation cycle
  clk();   
};

The topology base class handles the nodes and the packet heap:
class topology {
  [per-topology statistics]

  // pointer to the array of node objects 
  node ** nodes;              

  // heap that holds all simulated packets in the network
  PktS *pkts;     
  [pkts heap variables]
  [pkts heap inline functions]
  // inject a packet into the into the pkts heap
  inject_packet(...);
  // update the per-topology statistics with the data collected
  //  by a completed packet, then clears its spot in the pkts heap 
  finish_packet(...);

  [output to file functions]
  [traffic generators]
  virtual router(...) = 0;
};

The derived topology classes implement a specific topology:
class derived_topology: public topology {
  [class specific vars (e.g. routing vars)]

  // constructor that builds and links the nodes
  derived_topology(...); 
  
  virtual router(...);
};


Critical Functions

The critical functions in this simulator implement the following basic steps:

A traffic generator function provided by the base topology class:
traffic_generator(...) {
  (initiate the output file)
  while(more pkts are needed) {
    for(each node) {
      (choose a packet length from input length array)
      if(packet length == 0) continue;
      (construct a packet)
      (inject the packet)
    }
    (run the router on each packet in the heap)    
  }
  (continue routing until the packet heap empties)
  (dump the collected data to an output file)
}

A router function provided by a derived topology class:
pkt_router(...) {
  (read the node location pkt)
  (calculate the link to traverse in order to make progress) 
  if(there is no bandwidth available for that link) {
    (increment a wait counter)
    (return without making progress)
  } else {
    (write the new location into the pkt)
    (increment the pkt hops counter)
    (update all applicable per-link statistics)
    if(pkt is at destination) 
      (clear the pkt valid flag, this triggers the packet to finish)
    (return)
  }
}