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 "random.h"
00051 #include "marker.h"
00052
00053 static class MarkerClass : public TclClass {
00054 public:
00055 MarkerClass() : TclClass("Queue/Marker") {}
00056 TclObject* create(int, const char*const*) {
00057 return (new Marker);
00058 }
00059 } class_marker;
00060
00061
00062
00063 Marker::Marker() {
00064 q_ = new PacketQueue;
00065 for (int i=0; i<=NO_CLASSES; i++) marker_arrvs_[i]=0;
00066
00067 if (NO_CLASSES!=4) {
00068 printf("Change Marker's code!!!\n\n");
00069 abort();
00070 }
00071 bind("marker_arrvs1_", &(marker_arrvs_[1]));
00072 bind("marker_arrvs2_", &(marker_arrvs_[2]));
00073 bind("marker_arrvs3_", &(marker_arrvs_[3]));
00074 bind("marker_arrvs4_", &(marker_arrvs_[4]));
00075
00076
00077 marker_frc_[0]=0.0;
00078 marker_frc_[1]=0.4;
00079 marker_frc_[2]=0.7;
00080 marker_frc_[3]=0.9;
00081 marker_frc_[4]=1.0;
00082 }
00083
00084
00085
00086 int Marker::command(int argc, const char*const* argv) {
00087 if (argc == 3) {
00088 if (!strcmp(argv[1], "marker_type")) {
00089 marker_type_ = atoi(argv[2]);
00090 if ((marker_type_ != DETERM) && (marker_type_ != STATIS)) {
00091 printf("Wrong Marker Type\n");
00092 abort();
00093 }
00094 return (TCL_OK);
00095 }
00096 if (!strcmp(argv[1], "marker_class")) {
00097 marker_class_ = atoi(argv[2]);
00098 if (marker_class_<1 || marker_class_>NO_CLASSES) {
00099 printf("Wrong Marker Class:%d\n", marker_class_);
00100 abort();
00101 }
00102 return (TCL_OK);
00103 }
00104 if (!strcmp(argv[1], "init-seed")) {
00105 rn_seed_ = atoi(argv[2]);
00106 Random::seed(rn_seed_);
00107 srand48((long)(rn_seed_));
00108 return (TCL_OK);
00109 }
00110 }
00111 if (argc == NO_CLASSES+2) {
00112 if (!strcmp(argv[1], "marker_frc")) {
00113 double sum = 0.0;
00114 for (int i=1; i<=NO_CLASSES; i++) {
00115 marker_frc_[i] = sum + atof(argv[1+i]);
00116 sum = marker_frc_[i];
00117
00118
00119 }
00120 if (sum > 1.0) {
00121 printf("Class marking thresholds should add to 1.0 \n");
00122 abort();
00123 }
00124 return (TCL_OK);
00125 }
00126 }
00127 return Queue::command(argc, argv);
00128 }
00129
00130
00131
00132 void Marker::enque(Packet* p) {
00133 hdr_ip* iph = hdr_ip::access(p);
00134 hdr_cmn* cm_h = hdr_cmn::access(p);
00135
00136
00137
00138
00139 double cur_time = Scheduler::instance().clock();
00140 cm_h->ts_arr_ = cur_time;
00141
00142 if (marker_type_ == DETERM) {
00143
00144 iph->prio_ = marker_class_;
00145 } else {
00146
00147
00148 double rn = drand48();
00149 int i=0;
00150 do i++; while (rn >= marker_frc_[i]);
00151 iph->prio_ = i;
00152 }
00153
00154
00155
00156 marker_arrvs_[iph->prio_] += 1.;
00157
00158 q_->enque(p);
00159 if (q_->length() >= qlim_) {
00160 q_->remove(p);
00161 drop(p);
00162 printf("Packet drops in Marker of type:%d\n", marker_type_);
00163 }
00164 }
00165
00166
00167 Packet* Marker::deque() {
00168 return q_->deque();
00169 }