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 #ifndef lint
00044 static const char rcsid[] =
00045 "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/queue/fec.cc,v 1.1 2001/03/07 18:30:02 jahn Exp $ (UCB)";
00046 #endif
00047
00048 #include "config.h"
00049 #include <stdio.h>
00050 #include <ctype.h>
00051 #include "packet.h"
00052 #include "flags.h"
00053 #include "mcast_ctrl.h"
00054 #include "fec.h"
00055 #include "srm-headers.h"
00056 #include "classifier.h"
00057
00058 static class FECModelClass : public TclClass {
00059 public:
00060 FECModelClass() : TclClass("FECModel") {}
00061 TclObject* create(int, const char*const*) {
00062 return (new FECModel);
00063 }
00064 } class_fecmodel;
00065
00066 FECModel::FECModel() : firstTime_(1), FECstrength_(1)
00067 {
00068 }
00069
00070 int FECModel::command(int argc, const char*const* argv)
00071 {
00072 Tcl& tcl = Tcl::instance();
00073 if (argc == 3) {
00074 if (strcmp(argv[1], "FECstrength") == 0) {
00075 FECstrength_ = atoi(argv[2]);
00076 return (TCL_OK);
00077 }
00078 } else if (argc == 2) {
00079 if (strcmp(argv[1], "FECstrength") == 0) {
00080 tcl.resultf("%d", FECstrength_);
00081 return (TCL_OK);
00082 }
00083 }
00084 return BiConnector::command(argc, argv);
00085 }
00086
00087 int fix_ = 0;
00088 void FECModel::recv(Packet* p, Handler* h)
00089 {
00090 hdr_cmn* ch = hdr_cmn::access(p);
00091
00092 if(ch->direction() == hdr_cmn::DOWN) {
00093 addfec(p);
00094 downtarget_->recv(p, h);
00095 return;
00096 } else {
00097 if(ch->errbitcnt() > FECstrength_) {
00098 Packet::free(p);
00099 return;
00100 } else if (ch->errbitcnt() && (ch->errbitcnt() <= FECstrength_)) {
00101 ch->errbitcnt() = 0;
00102 ch->error() = 0;
00103 printf("FEC: %d fixed\n", fix_++);
00104 }
00105 subfec(p);
00106 uptarget_->recv(p, h);
00107 }
00108 }
00109
00110 void FECModel::addfec(Packet* p)
00111 {
00112 int bit = hdr_cmn::access(p)->size() * 8;
00113 FECbyte_ = (int)(log(bit) / log(2));
00114 FECbyte_ *= FECstrength_;
00115 FECbyte_ = (FECbyte_ + 7) / 8;
00116
00117
00118
00119
00120
00121 hdr_cmn::access(p)->size() += FECbyte_;
00122 hdr_cmn::access(p)->fecsize() = FECbyte_;
00123 }
00124
00125 void FECModel::subfec(Packet* p)
00126 {
00127 FECbyte_ = hdr_cmn::access(p)->fecsize();
00128 hdr_cmn::access(p)->size() -= FECbyte_;
00129
00130 }
00131