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 #include"rlc-module.h"
00031 #include<iostream>
00032
00033 class ModuleRlcClass : public TclClass {
00034 public:
00035 ModuleRlcClass() : TclClass("Module/UMTS/RLC") {}
00036 TclObject* create(int, const char*const*) {
00037 return (new RlcModule());
00038 }
00039 } class_module_rlc;
00040
00041
00042 RlcModule::RlcModule()
00043 {
00044 rlc_id_counter++;
00045 rlc_id_ = rlc_id_counter;
00046 bind("ipAddr_",&ipAddr_);
00047 bind("destIpAddr_",&destIpAddr_);
00048 }
00049
00050
00051
00052 RlcModule::~RlcModule()
00053 {
00054
00055
00056 }
00057
00058
00059 int RlcModule::rlc_id_counter = 0;
00060
00061
00062 int RlcModule::command (int argc, const char *const *argv)
00063 {
00064
00065
00066 Tcl& tcl = Tcl::instance();
00067
00068 if(argc == 2)
00069 {
00070 if (strcasecmp(argv[1],"getRlcId")==0)
00071 {
00072 tcl.resultf("%d",rlc_id_);
00073 return TCL_OK;
00074 }
00075 if (strcasecmp(argv[1],"getRlc")==0)
00076 {
00077 if(rlc_)
00078 {
00079 tcl.result(rlc_->name());
00080 return TCL_OK;
00081 }
00082 else return TCL_ERROR;
00083 }
00084 }
00085 else if(argc == 3)
00086 {
00087 if(strcasecmp(argv[1], "setRlc")==0)
00088 {
00089 rlc_ = dynamic_cast<RLC*>(TclObject::lookup(argv[2]));
00090
00091 if(!rlc_)
00092 return TCL_ERROR;
00093
00094 tcl.evalf("%s down-target %s",rlc_->name(), name());
00095 tcl.evalf("%s up-target %s",rlc_->name(), name());
00096
00097 return TCL_OK;
00098 }
00099 if (strcasecmp(argv[1],"setDestRlcId")==0)
00100 {
00101 int id = atoi(argv[2]);
00102 assert(id>0);
00103 assert(id<=rlc_id_counter);
00104 assert(id != rlc_id_);
00105 dst_rlc_id_ = id;
00106 return TCL_OK;
00107 }
00108 if (strcasecmp(argv[1],"setMeCodeId")==0)
00109 {
00110 int id = atoi(argv[2]);
00111 me_code_id_ = id;
00112 return TCL_OK;
00113 }
00114 }
00115
00116
00117 return Module::command(argc,argv);
00118
00119 }
00120
00121
00122
00123
00124 void RlcModule::recv(Packet* p)
00125 {
00126 hdr_cmn *ch = HDR_CMN(p);
00127 hdr_rlc *rh = HDR_RLC(p);
00128 hdr_ip *iph = HDR_IP(p);
00129 if (ch->direction() == hdr_cmn::UP)
00130 {
00131
00132 if (rh->dst_rlc_id_ != rlc_id_)
00133 {
00134
00135 Packet::free(p);
00136 return;
00137 }
00138
00139 if (ch->error())
00140 {
00141 if (debug_)
00142 std::cerr << "RlcModule::recv(p,h) packet with errors" << std::endl;
00143
00144 drop(p, 1, "ERR");
00145 return;
00146 }
00147 }
00148 if (ch->direction() == hdr_cmn::DOWN)
00149 {
00150
00151 if ((iph->daddr() != destIpAddr_)
00152 &&(ch->next_hop_ != destIpAddr_)
00153 &&(iph->daddr() != IP_BROADCAST))
00154 {
00155
00156 if (debug_>1)
00157 cerr << NOW << "RlcModule::recv()"
00158 << " iph->daddr()=" << iph->daddr()
00159 << " ch->next_hop_=" << ch->next_hop_
00160 << " destIpAddr_=" << destIpAddr_
00161 << endl;
00162 Packet::free(p);
00163 return;
00164 }
00165 }
00166
00167
00168
00169
00170
00171 if (debug_>1) std::cerr << "RlcModule::recv(p) Received Packet " << std::endl;
00172
00173 assert(rlc_);
00174
00175
00176
00177 rlc_->recv(p, (Handler*) 0);
00178 }
00179
00180
00181
00182
00183
00195 void RlcModule::recv(Packet* p, Handler* callback)
00196 {
00197 hdr_cmn *ch = HDR_CMN(p);
00198 hdr_rlc *rh = HDR_RLC(p);
00199 hdr_umtsphy *uh = HDR_UMTSPHY(p);
00200
00201 if(ch->direction() == hdr_cmn::DOWN)
00202 {
00203
00204 rh->src_rlc_id_ = rlc_id_;
00205 assert(dst_rlc_id_>0);
00206 rh->dst_rlc_id_ = dst_rlc_id_;
00207
00208 uh->me_code_id = me_code_id_;
00209
00210 if (debug_>1) std::cerr << "RlcModule::recv(p,h) Forwarding packet to lower modules" << std::endl;
00211 uh->data = TRUE;
00212 sendDown(p);
00213 }
00214 else
00215 {
00216 assert(ch->direction() == hdr_cmn::UP);
00217
00218 if (debug_>1) std::cerr << "RlcModule::recv(p,h) Forwarding packet to upper modules" << std::endl;
00219 sendUp(p);
00220
00221 }
00222 }
00223
00224 AM* RlcModule::getAM()
00225 {
00226 AM* ptr = dynamic_cast<AM*>(rlc_);
00227 assert(ptr);
00228 return ptr;
00229 }
00230
00231 int RlcModule::getTotPDUs()
00232 {
00233 return (getAM()->getTotPDUs());
00234 }
00235
00236 int RlcModule::getErrPDUs()
00237 {
00238 return (getAM()->getErrPDUs());
00239 }
00240
00241 int RlcModule::getAckPDUs()
00242 {
00243 return (getAM()->getAckPDUs());
00244 }
00245
00246 int RlcModule::getAckSDUs()
00247 {
00248 return (getAM()->getAckSDUs());
00249 }
00250
00251 int RlcModule::getDropPDUs()
00252 {
00253 return (getAM()->getDropPDUs());
00254 }
00255
00256 int RlcModule::getDropSDUs()
00257 {
00258 return (getAM()->getDropSDUs());
00259 }
00260
00261