//========================================================================== // SSM_IFS.CC - Simple module definitions of the SSM I/O interfaces for // Discrete System Simulation in OMNeT++ // // Author: Gabor.Lencse@hit.bme.hu //========================================================================== /*--------------------------------------------------------------* Copyright (C) 1996,97 Gabor Lencse, Technical University of Budapest, Dept. of Telecommunications, Stoczek u.2, H-1111 Budapest, Hungary. This file is distributed WITHOUT ANY WARRANTY. See the file `license' for details on this and other legal matters. *--------------------------------------------------------------*/ #include #include #include "ssmifdef.h" #include "fddi_def.h" #include "ssm_ifs.h" //Define_Module( SSM_OIF ) Define_Module_Like( SSM_OIF_by_frequency, SSM_OIF ) Define_Module_Like( SSM_OIF_by_time, SSM_OIF ) Define_Module( SSM_IIF ) void SSM_OIF_by_frequency::activity() { //cOutVector packet_length("OIF-packet-length",1); long frequency, counter=0; // if counter reaches frequency: send statistics simtime_t last_arrival=0; // time of last packet arrivial, must be initialised to 0 cLongHistogram *length; // the collected distribution of packet length cDoubleHistogram *delay; // the collected distribution of inter-arrival time // parameters for the histograms: unsigned numcells=20; // number of cell in the histograms double range_ext_factor=1; // the the observed range is extended by this value unsigned num_firstvals=99; // number of samples collected before transform is done frequency = par("frequency"); simtime_t now; length = new cLongHistogram("length",numcells); length->setRangeAuto(num_firstvals,range_ext_factor); delay = new cDoubleHistogram("inter-arrival time",numcells); delay->setRangeAuto(num_firstvals,range_ext_factor); for(;;) { cMessage *msg = receive(); // int length = msg->length()-idle_bytes; //packet_length.record(length); now = simTime(); delay->collect(now-last_arrival); last_arrival=now; length->collect(msg->length()/*-idle_bytes*/); // DO NOT substract the (no of idle symbols)/2 if ( ++counter == frequency ) { // FILE *debug=fopen(fullPath(),"a"); // length->saveToFile(debug); // delay->saveToFile(debug); // fclose(debug); counter = 0; cMessage *m = new cMessage("SSM Statistics",SSM_STATISTICS); m->parList().add( length ); m->parList().add( delay ); // snapshot("OIF", m); // DEBUG send(m,"out"); length = new cLongHistogram("length",numcells); length->setRangeAuto(num_firstvals,range_ext_factor); delay = new cDoubleHistogram("inter-arrival time",numcells); delay->setRangeAuto(num_firstvals,range_ext_factor); } delete msg; } } void SSM_OIF_by_time::activity() { //ev.printf("OIF start %s\n",fullPath()); // DEBUG // Read the control parameters from file and schedule activities like // "send" and "delete", send the necessary syncpoints. // This code is ment to be run when simTime()==0 otherwise backschedule may // be done. char filepathname[100]; strcpy(filepathname,par("OIFControlFile")); FILE *f=fopen(filepathname,"r"); if ( !f ) { ev.printf("OIF Warning: Cannot open input file %s\n",filepathname); ev.printf("No Statistics will be collected by %s\n",fullPath()); //endSimulation(); return; } char line[101]; fgets(line,101,f); // the first line is a comment with the ID and namestr of the ring while ( !feof(f) ) // process all the lines of the file { // one line may contain one command or it may be a comment line if ( !fgets(line,101,f) ) break; // !! This is a hack: EOF is detected too late... // "#" or ";" as a beginning character means: this line is a comment if ( line[0]=='#' || line[0]==';' ) continue; // if the word "delete" occurs, then isdelelete:=true, otherwise it is set // to false and send is assumed int isdelete = strstr(line,"delete") != NULL; // both "delete" and "send" may be followed by one of the next 3 constructs // every