00001 /* 00002 * Copyright (c) 2007 Regents of the SIGNET lab, University of Padova. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the University of Padova (SIGNET lab) nor the 00014 * names of its contributors may be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00018 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00019 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00020 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00021 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00022 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00023 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00024 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00025 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00026 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00027 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 #include"umts-interference_miv.h" 00031 #include"mphy.h" 00032 #include <interference_miv.h> 00033 #include"umts-headers.h" 00034 00035 #include<iostream> 00036 #include <iomanip> 00037 00038 00039 #define POWER_PRECISION_THRESHOLD (- 1e-14) 00040 00041 static class UmtsMInterferenceMIVClass : public TclClass { 00042 public: 00043 UmtsMInterferenceMIVClass() : TclClass("MInterference/MIV/UMTS") {} 00044 TclObject* create(int, const char*const*) { 00045 return (new UmtsMInterferenceMIV); 00046 } 00047 } class_umts_minterference_miv; 00048 00049 00050 UmtsMInterferenceMIV::UmtsMInterferenceMIV() 00051 : MInterferenceMIV() 00052 { 00053 bind("alpha_",&alpha_); 00054 } 00055 00056 UmtsMInterferenceMIV::~UmtsMInterferenceMIV() 00057 { 00058 00059 } 00060 00061 00062 00063 00064 00065 void UmtsMInterferenceMIV::addToInterference(Packet* p) 00066 { 00067 hdr_MPhy* ph = HDR_MPHY(p); 00068 hdr_umtsphy* uh = HDR_UMTSPHY(p); 00069 double interfpower = 0; 00070 00071 if (uh->data==TRUE) 00072 { 00073 interfpower = ph->Pr; 00074 if (debug_ > 2) 00075 printf("UmtsMInterferenceMIV::addToInterference, DATA pkt -> add %e\n",interfpower); 00076 MInterferenceMIV::addToInterference(interfpower, NOW); 00077 00078 } 00079 else 00080 { 00081 // packets without data interfer only a fraction of the whole power 00082 interfpower = ph->Pr*(alpha_/(1+alpha_)); 00083 if (debug_ > 2) 00084 printf("UmtsMInterferenceMIV::addToInterference, CNTRL pkt -> add %e instead %e\n", interfpower, ph->Pr); 00085 MInterferenceMIV::addToInterference(interfpower, NOW); 00086 00087 } 00088 00089 PowerEvent* pe = new PowerEvent(interfpower); 00090 Scheduler::instance().schedule(&endinterftimer, pe, ph->duration); 00091 if (debug_) 00092 dump(std::string("UmtsMInterferenceMIV::addToInterference")); 00093 } 00094 00095 00096 00097 00098 double UmtsMInterferenceMIV::getInterferencePower(Packet* p) 00099 { 00100 hdr_MPhy *ph = HDR_MPHY(p); 00101 hdr_umtsphy* uh = HDR_UMTSPHY(p); 00102 if (uh->data==TRUE) 00103 return (MInterferenceMIV::getInterferencePower(ph->Pr, ph->rxtime, ph->duration)); 00104 else 00105 return (MInterferenceMIV::getInterferencePower(0.0, ph->rxtime, ph->duration)); 00106 } 00107 00108 00109 00110 00111 // double UmtsMInterferenceMIV::getInterferencePower(double power, double starttime, double duration) 00112 // { 00113 // 00114 // Function::reverse_iterator rit; 00115 // 00116 // double integral = 0; 00117 // double lasttime = NOW; 00118 // 00119 // assert(starttime<= NOW); 00120 // assert(duration > 0); 00121 // assert(maxinterval_ > duration); 00122 // 00123 // for (rit = pp.rbegin(); rit != pp.rend(); ++rit ) 00124 // { 00125 // if (starttime < rit->time) 00126 // { 00127 // integral += rit->value * (lasttime - rit->time); 00128 // lasttime = rit->time; 00129 // } 00130 // else 00131 // { 00132 // integral += rit->value * (lasttime - starttime); 00133 // break; 00134 // } 00135 // } 00136 // 00137 // double interference = (integral/duration) - power; 00138 // 00139 // // Check for cancellation errors 00140 // // which can arise when interference is subtracted 00141 // if (interference < 0) 00142 // { 00143 // assert(interference > POWER_PRECISION_THRESHOLD); // should be a cancellation error 00144 // interference = 0; 00145 // } 00146 // 00147 // 00148 // if (debug_) { 00149 // dump("MInterferenceMIV::getInterferencePower"); 00150 // std::cerr << "transmission from " << starttime 00151 // << " to " << starttime + duration 00152 // << " power " << power 00153 // << " gets interference " << interference 00154 // << std::endl; 00155 // } 00156 // 00157 // return interference; 00158 // } 00159 // 00160 //