Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

fec.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Daedalus Research
00017  *      Group at the University of California Berkeley.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * Contributed by the Daedalus Research Group, UC Berkeley 
00035  * (http://daedalus.cs.berkeley.edu)
00036  *
00037  * Multi-state error model patches contributed by Jianping Pan 
00038  * (jpan@bbcr.uwaterloo.ca).
00039  *
00040  * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/queue/fec.cc,v 1.1 2001/03/07 18:30:02 jahn Exp $ (UCB)
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"                // to get the hdr_srm structure
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         //      firstTime_ = 0;
00118 
00119         // printf("FEC Down = %d \n", hdr_cmn::access(p)->size());      
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         // printf("FEC Up = %d \n", hdr_cmn::access(p)->size());        
00130 }
00131 

Generated on Tue Apr 20 12:14:16 2004 for NS2.26SourcesOriginal by doxygen 1.3.3