Reference Manual (version 3.0)


Contents:


component

Defines a component class.
component component_name : base_classes { declarations };
A component class cannot be derived from another component class. (Implementation-imposed limit)
A component class can be 'templated'.
A component class cannot be defined within any namespace. (Implementation-imposed limit)

inport

Defines an inport. Must appear within a component class.
inport inlineopt return_type inport_name ( argument_listopt );
The implementation of an inport must appear outside the component body. (Implementation-imposed limit)

outport

Defines an outport. Must appear within a component class.
outport []opt return_type inport_name ( argument_listopt );
An outport doesn't need to have implementation. It can be called directly as if it had been defined.
If the keyword outport is followed by '[]', then it is an outport array. Each individual outport can be accessed by specifying an index, such as out[3].
A composite component can't have any outport array.

Component Instantiation

Defines a component instance. Must appear within a component class, or a nonmember function such as main(), or a member function of a non-component class.
component_class []opt instance_name; 
Only one component instance can be defined per each instantiation.
If the component instantiation appears within a component class then the component class becomes a composite component class.
If '[]' appears in the component instantiation, then it defines an array of component instances. Each individual components can be accessed by specifying an index, such as component[3].

connect

A connect statement can take one of four forms.
connect component_name []opt .outport_name[]opt, component_name []opt .inport_name; 
Connects an outport of a primitive component (non-composite component) to an inport of another primitive component.
connect component_name []opt .outport_name[]opt, inport_name ; 
Connects an outport of a primitive component to an inport. Must appear within a composite component class.
connect component_name []opt .outport_name[]opt, outport_name ; 
Connects an outport of a primitive component to an outport. Must appear within a composite component class.
connect inport_name , component_name []opt.inport_name; 
Connects an inport to an inport of a primitive component. Must appear within a composite component class.

trigger_t

Empty messages. As its name indicates, it behaves as a trigger and carries an empty signal, used when we want to notify a component that something has happened.
class trigger_t {};

simtime_t

The data type for simulated time. By default it is equivalent to double.
typedef double simtime_t;

Timer <DATATYPE>

A simulated time related object that schedules and receives events of type DATATYPE. Only one single event is associated with a timer, so at any time there is only one event that can be scheduled through a timer. If there is already an active event at the time of scheduling, the previous event will be canceled first.
template <class DATATYPE> class Timer;
void outport to_component (DATATYPE const& d);
Defines an outport which be called when the schedule time is reached. The argument d contains the data assigned to the event.
void Set(double time);
Schedules the associated event to be active when the specified time is reached by the simulation engine. The scheduled event will then invoke the outport to_component at the scheduled time, which will in turn invoke any member functions that have been connected to it. Notice that this function is usually used when DATATYPE is trigger_t , because it leaves the event data unassigned.
void Set(DATATYPE const& data, double time);
Similar to the above Set() function, except that event data can be saved to the specified slot.
void Cancel();
Cancels if the scheduled event has been scheduled before.
bool Active();
Returns a boolean value indicating whether or not the associated event is active (the Set function has been called previously and the event time hasn't been reached).
simtime_t GetTime();
Returns the timestamp of the event scheduled. Invalid if the slot is inactive.
DATATYPE& GetData();
Gets the reference of the data previously stored.
void SetData(DATATYPE const& data);
Stores the data without scheduling the event. This function can be used together with the first Set() function.

MultiTimer <DATATYPE>

Timer can only schedule at most one event, so MultiTimer is designed to schedule multiple events. The number of events, or the size of the multitimer, can automatically grow without a bound as needed, so there is no need to set the size of the multitimer before use. Each event is assigned a unique slot, ranging from 0 to one less the number of events. Almost every function of a multitimer must be called with an extra argument to indicate the slot number. Beside that, the usage of a multitimer is almost the same as that of a timer.
template <class DATATYPE> class Timer;
void outport to_component (DATATYPE const& d, unsigned int index);
Defines an outport which be called when the schedule time is reached. The argument d contains the data assigned to the event, and index is the slot number of the activated event.
void Set(double time, unsigned int index);
Schedules the event in the slot index to be active when the specified time is reached by the simulation engine. The scheduled event will then invoke the outport to_component at the scheduled time, which will in turn invoke any member functions that have been connected to it. Notice that this function is usually used when DATATYPE is trigger_t , because it leaves the event data unassigned.
void Set(DATATYPE const& data, double time, unsigned int index);
Similar to the above Set() function, except that event data can be assigned.
void Cancel(unsigned int index);
Cancels if the event with the specified index was scheduled before.
bool Active(unsigned int index);
Returns a boolean value indicating whether or not the event at the specified slot is active (the Set function has been called to schedule an event on this slot previously).
simtime_t GetTime(unsigned int index);
Returns the timestamp of the event scheduled on this slot. Invalid if the slot is inactive.
DATATYPE& GetData(unsigned int index);
Gets the reference of the data previously stored in the slot.
void SetData(DATATYPE const& data, unsigned int index);
Stores the data without scheduling the event. This function can be used together with the first Set() function.

InfiTimer<DATATYPE>

InfiTimer is used when it is difficult to associate each event with a unique integer id. Like a multitimer, an infitimer can automatically grow when a new event is being scheduled.
template <class DATATYPE> class Timer;
void outport to_component (DATATYPE const& d, unsigned int index);
Defines an outport which be called when the schedule time is reached. The argument d contains the data assigned to the event, and index is the slot number of the activated event.
unsigned int Set(double time);
Schedules the new event to be active when the specified time is reached by the simulation engine. No slot number is specified, since the infitimer will automatically find an empty slot number, which is returned.
unsigned int Set( DATATYPE const& data, double time);
Similar the above Set() function, except that some event data can be assigned.
void Cancel(unsigned int index);
Cancels if the event with the specified index was scheduled before.
bool Active(unsigned int index);
Returns a boolean value indicating whether or not the event at the specified slot is active (the Set function has been called to schedule an event on this slot previously)
simtime_t GetTime(unsigned int index);
Returns the timestamp of the event scheduled on this slot. Invalid if the slot is inactive.
DATATYPE& GetData(unsigned int index);
Obtains the reference of the data previously stored in the slot.
void SetData( DATATYPE const& data, unsigned int index);
Stores the data without scheduling the event. This function can be used together with the first Set() function.

TypeII

Represents components that are aware of the existence of the simulated time.
class TypeII;
Called at the simulated time 0.
Override this function to initialize variables or to set timers.
Called when the simulation is done.
Override this function to collect and print statistics.
double Random(double r=1.0);
Returns a random real number drawn from a uniform distribution between 0.0 and r (exclusive).
int Random(int n);
Returns a random integer between 0 and n-1 (inclusive) .
double Exponential(double mean);
Returns a random real number drawn from an exponential distribution with the given mean.

CostSimEng

A sequential simulation engine. The system to be simulated must be a derived class from this simulation engine.
class CostSimEng;
Called at the simulated time 0 (before the start() function of components).
Override this function to initialize variables or to set timers.
Called when the simulation is done (after the stop() function of components).
Override this function to collect and display statistics.
Returns the current simulation time.
The seed for the random number generator.
The end time of the simulation.
double Random(double r=1.0);
Returns a random real number drawn from a uniform distribution between 0.0 and r (exclusive).
int Random(int n);
Returns a random integer between 0 and n-1 (inclusive) .
double Exponential(double mean);
Returns a random real number drawn from an exponential distribution with the given mean.

ether_addr_t

Represents ethernet addresses.
Specifies the size of the port. Components contained within this array are created by this function.
Sets the name for each component it contains.
Constructor.
Compare with another address.
An in-class functor that is mainly used by STL containers.

coordinate_t

Represents two dimensional coordinates.
Constructors.
Member variables.

triple <T1, T2, T3>

Similar to stl::pair, except that it takes three template parameters .
template <class T1, class T2, class T3> class triple;
Constructors;
Member variables;
Creates a new triple.

smart_packet_t < H, P>

Smart packets were designed for the layered network architecture. H is the header of the packet existing in the current layer, P is the payload, usually the packet from or to the higher layer.
template <class H, class P> class smart_packet_t;
Returns a new smart packet.
Indicates that the current component no long needs this packet. This function may or may not actually release the memory allocated for the packet, depending on whether or not the reference count of the packet goes to zero. It also decreases the reference count of the payload packet, if the payload packet is also a smart packet. Besides, this function also call the @free@ function of the header, if the reference count is zero.
Immediately destroys the packet and its header and releases the associated memory. It also decreases the reference count of the payload packet, if the payload packet is also a smart packet.
Despite what its name implies, this function doesn't make a new copy of the packet. Instead, in only increases the reference count to indicate that the calling component now owns the packet, possibly sharing it with many other components. A pointer to the packet is returned for convenience.
Similarly, this function increases the reference count of the payload packet.
static void free_pld();
This function will return a reference to the header of the payload packet. T is the type of the payload header.
A member variable that stores the header.
A member variable that stores the payload, which could be an encapsulated payload packet or simply a pointer to the payload packet stored elsewhere.
Display the content of the packet.

queue_t

The type of priority queue that is used for the event list management. It must be defined before including the header file sense.h. If not defined SimpleQueue will be used which is a linked list based priority queue. Normally:
#define queue_t HeapQueue

CORSA_DEBUG

If defined, shows the number of allocations and releases with each CorsaAllocator. Can be helpful in detecting memory leak. Usually defined in command line

COST_DEBUG

If defined, allows each component to print out information. Can be helpful in debugging. Usually defined in command line