00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include <string.h>
00049 #include <queue.h>
00050 #include "demarker.h"
00051 #include "tcp.h"
00052
00053 static class DemarkerClass : public TclClass {
00054 public:
00055 DemarkerClass() : TclClass("Queue/Demarker") {}
00056 TclObject* create(int, const char*const*) {
00057 return (new Demarker);
00058 }
00059 } class_demarker;
00060
00061 Demarker::Demarker() {
00062 q_ = new PacketQueue;
00063
00064 last_monitor_update_=0.0;
00065 monitoring_window_ = 0.1;
00066
00067 for (int i=0; i<=NO_CLASSES; i++) {
00068 demarker_arrvs_[i]=0;
00069 arrived_Bits_[i] = 0;
00070 }
00071
00072 if (NO_CLASSES != 4) {
00073 printf("Change Demarker's code!!!\n\n");
00074 abort();
00075 }
00076 bind("demarker_arrvs1_", &(demarker_arrvs_[1]));
00077 bind("demarker_arrvs2_", &(demarker_arrvs_[2]));
00078 bind("demarker_arrvs3_", &(demarker_arrvs_[3]));
00079 bind("demarker_arrvs4_", &(demarker_arrvs_[4]));
00080 }
00081
00082
00083
00084 int Demarker::command(int argc, const char*const* argv) {
00085 if (argc == 3) {
00086 if (strcmp(argv[1], "trace-file") == 0) {
00087 file_name_ = new(char[500]);
00088 strcpy(file_name_,argv[2]);
00089 if (strcmp(file_name_,"null") != 0) {
00090 demarker_type_ = VERBOSE;
00091 for (int i=1; i<=NO_CLASSES; i++) {
00092 char filename[500];
00093 sprintf(filename,"%s.%d", file_name_,i);
00094 if ((delay_tr_[i] = fopen(filename,"w"))==NULL) {
00095 printf("Problem with opening the trace files\n");
00096 abort();
00097 }
00098 }
00099 } else {
00100 demarker_type_ = QUIET;
00101 }
00102 return (TCL_OK);
00103 } else if (strcmp(argv[1], "id") == 0) {
00104 link_id_ = (int)atof(argv[2]);
00105 return (TCL_OK);
00106 }
00107 }
00108 return Queue::command(argc, argv);
00109 }
00110
00111
00112
00113 void Demarker::enque(Packet* p) {
00114 q_->enque(p);
00115 if (q_->length() >= qlim_) {
00116 q_->remove(p);
00117 drop(p);
00118 printf("Packet drops in Demarker of type:%d\n", demarker_type_);
00119 }
00120 }
00121
00122
00123
00124 Packet* Demarker::deque() {
00125 Packet* p= q_->deque();
00126 if (p==NULL) return p;
00127
00128 hdr_ip* iph = hdr_ip::access(p);
00129 hdr_cmn* cm_h = hdr_cmn::access(p);
00130 double cur_time = Scheduler::instance().clock();
00131
00132 int cls = iph->prio_;
00133 if ((cls<1) || (cls>NO_CLASSES)) {
00134 printf("Wrong class type in Demarker-deque (S=%d, D=%d, FID=%d, Class=%d)\n",
00135 (int)(iph->src().addr_), (int)(iph->dst().addr_),
00136 iph->fid_, iph->prio_);
00137
00138 fflush(stdout);
00139 abort();
00140 }
00141 demarker_arrvs_[cls] += 1.;
00142
00143
00144 if (demarker_type_ == VERBOSE) {
00145
00146 if (cur_time > START_STATISTICS) {
00147 double pack_del = cur_time - cm_h->ts_arr_;
00148 cm_h->ts_arr_=0;
00149
00150 fprintf(delay_tr_[cls], "%.5f %.5f\n",
00151 cur_time, pack_del);
00152 }
00153
00154 return p;
00155 }
00156
00157 return p;
00158 }