📄 mac-umts-nodeb.cc
字号:
/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- *//* By Pablo Martin and Paula Ballester, * Strathclyde University, Glasgow. * June, 2003.*//* Copyright (c) 2003 Strathclyde University of Glasgow, Scotland. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code and binary code must contain * the above copyright notice, this list of conditions and the following * disclaimer. * * 2. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed at Strathclyde University of * Glasgow, Scotland. * * 3. The name of the University may not be used to endorse or promote * products derived from this software without specific prior written * permission. * STRATHCLYDE UNIVERSITY OF GLASGOW, MAKES NO REPRESENTATIONS * CONCERNING EITHER THE MERCHANTABILITY OF THIS SOFTWARE OR THE * SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The software * is provided "as is" without express or implied warranty of any kind.*/#include "delay.h"#include "connector.h"#include "packet.h"#include "random.h"#include "mobilenode.h"#include "address.h"#include "arp.h"#include "ll.h"#include "queue.h"#include "mac-umts-nodeb.h"#include "cmu-trace.h"/* Timers */void MacNodebTimer::start(Packet *p, double time){ Scheduler &s = Scheduler::instance(); assert(busy_ == 0); busy_ = 1; paused_ = 0; stime = s.clock(); rtime = time; assert(rtime >= 0.0); s.schedule(this, p, rtime);}void MacNodebTimer::stop(Packet *p){ Scheduler &s = Scheduler::instance(); assert(busy_); if(paused_ == 0) s.cancel((Event *)p); busy_ = 0; paused_ = 0; stime = 0.0; rtime = 0.0;}void WaitNodebTimer::start(double time){ Scheduler &s = Scheduler::instance(); assert(busy_ == 0); busy_ = 1; paused_ = 0; stime = s.clock(); rtime = time; assert(rtime >= 0.0); s.schedule(this, &intr, rtime);}void WaitNodebTimer::stop(void){ Scheduler &s = Scheduler::instance(); assert(busy_); if(paused_ == 0) s.cancel(&intr); busy_ = 0; paused_ = 0; stime = 0.0; rtime = 0.0;}void WaitNodebTimer::handle(Event *e){ busy_ = 0; paused_ = 0; stime = 0.0; rtime = 0.0; mac->waitHandler();}// TCL Classstatic class MacUmtsNodebClass : public TclClass {public: MacUmtsNodebClass() : TclClass("Mac/UmtsNodeb") {} TclObject* create(int, const char*const*) { return (new MacUmtsNodeb()); }} class_mac_umts_nodeb;int MacUmtsNodeb::verbose_ = {0};//constructorMacUmtsNodeb::MacUmtsNodeb() : Mac(), mhwait_(this){ int i,j; bind("verbose_", &verbose_); mhwait_.start(0); // start timer for (j=0; j<MAX_NUM_UE; j++){ ul_interf[j].phyaddr_ = -1; ul_interf[j].ul_error_ = 1000000000; ul_interf[j].error_ = 0; }}int MacUmtsNodeb::command(int argc, const char*const* argv){ Tcl& tcl = Tcl::instance(); if (argc == 3) { if (strcmp(argv[1], "phy") == 0) { phy_ = (PhyUmtsNodeb*) TclObject::lookup(argv[2]); assert(phy_); return (TCL_OK); } } else if (argc == 2) { if (strcmp(argv[1], "phy") == 0) { tcl.resultf("%s", phy_->name()); return (TCL_OK); } } return Mac::command(argc, argv);}/* To handle incoming packet. */void MacUmtsNodeb::recv(Packet* p, Handler* h){ struct hdr_cmn *ch = HDR_CMN(p); struct hdr_phy *ph = HDR_PHY_UMTS(p); int i,j,len; switch (ch->channel_t()){ case PCH: ch->channel_t() = PCCH; ch->size() -= MAC_HDR_SZ; uptarget_->recv(p, this); break; case FACH: ch->channel_t() = CCCH; ch->size() -= MAC_HDR_SZ; uptarget_->recv(p, this); break; case DCH: ch->channel_t() = DTCH; ch->size() -= MAC_HDR_SZ; storepkt(p); // check if error break; case RACH: ch->channel_t() = CCCH; ch->size() -= MAC_HDR_SZ; uptarget_->recv(p, this); break; case PCCH: ch->channel_t() = PCH; ch->size() += MAC_HDR_SZ; downtarget_->recv(p, this); break; case CCCH: ch->channel_t() = FACH; ch->size() += MAC_HDR_SZ; downtarget_->recv(p, this); break; case DTCH: ch->channel_t() = DCH; ch->size() += MAC_HDR_SZ; downtarget_->recv(p, this); break; default: if (ch->direction() == hdr_cmn::UP){ ch->size() -= MAC_HDR_SZ; uptarget_->recv(p, this); } else { ch->size() += MAC_HDR_SZ; downtarget_->recv(p, this); } } return;}// if erroneous packet, drop it, if not, send it.void MacUmtsNodeb::storepkt(Packet *p){ int i; struct hdr_phy *ph = HDR_PHY_UMTS(p); for (i=0; i<MAX_NUM_UE; i++){ // find the UE if (ul_interf[i].phyaddr_ == ph->sa()){ if (ul_interf[i].error_){ drop(p); // error } else { uptarget_->recv(p, this); // not error, send it } return; } } // end of array, and ih->saddr() not found. Store the UE for (i=0; i<MAX_NUM_UE; i++){ if (ul_interf[i].phyaddr_ == -1){ ul_interf[i].phyaddr_ = ph->sa(); ul_interf[i].error_ = 0; uptarget_->recv(p, this); break; } } return;}// for passing results from PHYvoid MacUmtsNodeb::ul_interference(int addr[], unsigned long error[]){ int i,j; for (i=0; i<MAX_NUM_UE; i++) { if (addr[i] != -1) { for (j=0; j<MAX_NUM_UE; j++) { if (addr[i] == ul_interf[j].phyaddr_) { // UE found ul_interf[j].ul_error_ = error[i]; // update ul_error_ break; } } } else // UE not found break; } return;}// returns if the actual transport block is erroneousint MacUmtsNodeb::check_error(int pos){ int n = Random::integer(ul_interf[pos].ul_error_); // generate random number based on ul_error probability if (n == 0) { // error if (verbose_==1) printf("\nNodeB %d at %f MAC: ERROR in transport block____________________________________\n\n", phy_->ip_nodeb_, NOW); return(1); //ERROR } return(0); // not error}// free resources of ul_interf[]void MacUmtsNodeb::remove(int addr){ int i; for (i=0; i<MAX_NUM_UE; i++) { if (ul_interf[i].phyaddr_ == addr) { // UE found, update ul_interf[] ul_interf[i].error_ = 0; ul_interf[i].phyaddr_ = -1; ul_interf[i].ul_error_ = 1000000000; break; } } return;}// timer for error calculation, each tti_void MacUmtsNodeb::waitHandler(){ int i; mhwait_.start(tti_); // schedule the next tti_ for (i=0; i<MAX_NUM_UE; i++){ // update error_ for each UE if (ul_interf[i].phyaddr_ != -1){ ul_interf[i].error_ = check_error(i); } } return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -