00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "BS_mac.h"
00012 #include "BS_table.h"
00013 #include "BS_queue.h"
00014 #include "User_Interface.h"
00015 #include "DATA_m.h"
00016 #include <string.h>
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 Define_Module(BS_mac);
00029
00031
00032
00033
00034
00036 void BS_mac::initialize()
00037 {
00038
00039 top.extractByParameter("aux");
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 top_node = top.getNodeFor((cModule*)this->getParentModule());
00051
00052
00053
00054
00055
00056 if(strcmp(top_node->getLinkOut(1)->getRemoteNode()->getModule()->getName(),"onu")==0){ esPasarela=1; }
00057 else{ esPasarela=0; }
00058
00059
00060 int indice_esta_bs = (int)this->getParentModule()->par("indice");
00061
00062
00063 prioridades = (int)this->getParentModule()->par("numcolas");
00064 ind_primero = 0;
00065 int estaciones = (int) this->getParentModule()->par("numBS");
00066 int num_pasarelas = (int) this->getParentModule()->par("numGW");
00067 int usuarios = (int) this->getParentModule()->par("numUser");
00068 int criterio = (int) this->getParentModule()->par("criterio");
00069
00070 extraction_method = (int) this->getParentModule()->par("user_extractionmethod_StrictPQ0_Centralized1");
00071 media_saltos = 0;
00072 nodos_actualizados = 0;
00073 actualizaciones = 0;
00074 txrate = (double) this->getParentModule()->par("tasabinaria");
00075 rxrate = (double) this->getParentModule()->par("tasabinaria");
00076
00077
00078
00079 enlaces_intermedios = (int) top_node->getNumOutLinks() - 1;
00080 if(esPasarela == 1)
00081 {
00082 double opt_txrate = (double) this->getParentModule()->par("txrate");
00083 txrate = opt_txrate/10;
00084 enlaces_intermedios = enlaces_intermedios - prioridades;
00085 }
00086
00087 C_i = (double) rxrate/enlaces_intermedios;
00088
00089
00090 double init_weight = 0.0;
00091 int long_pckt = (int) this->getParentModule()->par("longitud_media_paquete");
00092 int bits_pckt = 8*long_pckt;
00093
00094 int primer_indice;
00095 BS_mac *aux_control;
00096 if(indice_esta_bs == estaciones-1)
00097 {
00098
00099 for(int i=0; i<(int)top.getNumNodes(); i++)
00100 {
00101 if(strpbrk(top.getNode(i)->getModule()->getFullName(),"b")!=NULL)
00102 {
00103 primer_indice = 1;
00104 if(strcmp(top.getNode(i)->getLinkOut(1)->getRemoteNode()->getModule()->getName(),"onu")==0)
00105 {
00106
00107 primer_indice = primer_indice + prioridades;
00108 }
00109 for(int a=primer_indice; a<(int)top.getNode(i)->getNumOutLinks(); a++)
00110 {
00111 aux_control = check_and_cast<BS_mac *>(top.getNode(i)->getModule()->getSubmodule("bs_mac"));
00112 switch(criterio)
00113 {
00114 case 0:
00115 init_weight = (double) 1/aux_control->C_i;
00116
00117 break;
00118 case 1:
00119
00120 init_weight = (double) (3*bits_pckt)/(2*aux_control->C_i);
00121 break;
00122 case 2:
00123 init_weight = (double) 1;
00124 break;
00125 }
00126 (check_and_cast<cDelayChannel*>(top.getNode(i)->getLinkOut(a)->getLocalGate()->getChannel()))->par(3)
00127 = (double)init_weight;
00128 }
00129 }
00130 }
00131 }
00132
00133 Tabla = check_and_cast<BS_table *>(getParentModule()->getSubmodule("bs_table"));
00134
00135 filas = Tabla->filas;
00136 columnas = Tabla->columnas;
00137
00138
00139 nombres_bs.resize(estaciones);
00140 nombres_bs[0] = "bs0";
00141 nombres_bs[1] = "bs1";
00142 nombres_bs[2] = "bs2";
00143 nombres_bs[3] = "bs3";
00144 nombres_bs[4] = "bs4";
00145 nombres_bs[5] = "bs5";
00146 nombres_bs[6] = "bs6";
00147 nombres_bs[7] = "bs7";
00148 nombres_bs[8] = "bs8";
00149 nombres_bs[9] = "bs9";
00150 nombres_bs[10] = "bs10";
00151 nombres_bs[11] = "bs11";
00152 nombres_bs[12] = "bs12";
00153 nombres_bs[13] = "bs13";
00154 nombres_bs[14] = "bs14";
00155 nombres_bs[15] = "bs15";
00156 nombres_bs[16] = "bs16";
00157 nombres_bs[17] = "bs17";
00158 nombres_bs[18] = "bs18";
00159 nombres_bs[19] = "bs19";
00160 nombres_bs[20] = "bs20";
00161 nombres_bs[21] = "bs21";
00162 nombres_bs[22] = "bs22";
00163 nombres_bs[23] = "bs23";
00164 nombres_bs[24] = "bs24";
00165
00166
00167 indices_pasarelas.resize(num_pasarelas);
00168 indices_pasarelas[0] = 7;
00169 indices_pasarelas[1] = 9;
00170 indices_pasarelas[2] = 13;
00171 indices_pasarelas[3] = 19;
00172 indices_pasarelas[4] = 24;
00173
00174
00175
00176
00177
00178 for(int i=0; i<num_pasarelas; i++)
00179 {
00180 Tabla->rutas_optimas_pasarelas[i].resize(usuarios);
00181 for(int n=0;n<usuarios;n++)
00182 {
00183 Tabla->rutas_optimas_pasarelas[i][n].resize(columnas," ");
00184 }
00186 }
00187
00188
00189 if(indice_esta_bs == estaciones-1)
00190 {
00191 BS_mac *route;
00192 for(int i=0; i<estaciones; i++)
00193 {
00194 route = check_and_cast<BS_mac *>(this->getParentModule()->getParentModule()->getSubmodule(nombres_bs[i])->getSubmodule("bs_mac"));
00195
00196 route->routing();
00197 }
00198 }
00199
00201 sumcolas = 0;
00202 int conex = (int) this->getParentModule()->par("conexiones");
00203 int colas = conex-1;
00204 index_used_queues.resize(colas,-1);
00205
00206 t_frame = (double) this->getParentModule()->par("delta_time");
00207 get_num_used_queues();
00208
00209 time_frame = (simtime_t) t_frame;
00210
00211
00212 timepacket = 0;
00213 cMessage *msg = new cMessage ("TDMA",1);
00214 scheduleAt((simtime_t)0, msg);
00215 }
00216
00218
00219
00220
00221
00222
00224 void BS_mac::handleMessage(cMessage *msg)
00225 {
00226 int type = msg->getKind();
00227 switch(type)
00228 {
00229 case 1:
00230
00231 scheduleAt(simTime()+time_frame, msg);
00232 get_num_used_queues();
00233 timepacket = 0;
00234
00235 for(int q=0; q<used_queues; q++)
00236 {
00237 queue = check_and_cast<BS_queue *>(this->getParentModule()->getSubmodule("bs_queue",index_used_queues[q]));
00238 queue->sumcheckedpacket = 0;
00239 queue->sumextractedpacket = 0;
00240 }
00241 extract_packets();
00242 break;
00243 default:
00244 delete msg;
00245 break;
00246 }
00247 }
00248
00250
00251
00253 int BS_mac::is_an_empty_row(int row)
00254 {
00255 int ocupado = 0;
00256 if (strcmp(" ",Tabla->array_de_rutas[row][0])!=0)
00257 {
00258 ocupado = 1;
00259 }
00260 return ocupado;
00261 }
00262
00264
00266 int BS_mac::get_index_first_empty_row()
00267 {
00268 int i=0, indice=0;
00269 int coincide = 1;
00270 while(i<filas && coincide !=0)
00271 {
00272 coincide = strcmp(" ", Tabla->array_de_rutas[i][0]);
00273 indice = i;
00274 i++;
00275 }
00276 return indice;
00277 }
00278
00280
00281
00283 int BS_mac::get_index_last_element(int row)
00284 {
00285
00286 int i=1, encontrado = 0, ocupado, vacio, indice=1;
00287 while(encontrado == 0 && i<columnas)
00288 {
00289 ocupado = strcmp(" ", Tabla->array_de_rutas[row][i]);
00290 vacio = strcmp(" ", Tabla->array_de_rutas[row][i + 1]);
00291 if(ocupado !=0 && vacio ==0)
00292 {
00293 encontrado = 1;
00294 indice = i;
00295 }
00296 i++;
00297 }
00298 return indice;
00299 }
00300
00302
00303
00305 int BS_mac::ya_aparece(char* nombre_nodo, int fila, int indice)
00306 {
00307 int iguales=0, b=indice, aparece=0;
00308 while(b>=0 && aparece==0)
00309 {
00310 iguales = strcmp(nombre_nodo,Tabla->array_de_rutas[fila][b]);
00311 if(iguales==0)
00312 {
00313 aparece = 1;
00314 }
00315 b--;
00316 }
00317 return aparece;
00318 }
00319
00321
00322
00323
00325 int BS_mac::es_pasarela(cModule *node)
00326 {
00327 cModule *nodo_ = check_and_cast<cModule*>(node);
00328 cTopology::Node * nodo = top.getNodeFor(nodo_);
00329 char* nombre_enlace = (char*) nodo->getLinkOut(1)->getRemoteNode()->getModule()->getName();
00330 int encontrado = -1;
00331 if (strcmp(nombre_enlace,"onu")==0)
00332 {
00333 encontrado = 1;
00334 }
00335 return encontrado;
00336 }
00337
00339
00340
00342 int BS_mac::conseguir_siguiente_puerta(int init_ind, int puertas, cModule *node)
00343 {
00344 cModule *nodo = check_and_cast<cModule*>(node);
00345 int i = init_ind, encontrado = 0;
00346 int indice = init_ind;
00347 while(i<puertas && encontrado ==0)
00348 {
00349 if(nodo->gate("physicalBS$o",i)->isConnected())
00350 {
00351 if(strcmp("user",nodo->gate("physicalBS$o",i)->getNextGate()->getOwnerModule()->getName())!=0)
00352 {
00353 encontrado = 1;
00354 indice = i;
00355 }
00356 }
00357 i++;
00358 }
00359 return indice;
00360 }
00361
00363
00364
00366 int BS_mac::puerta_entrada_libre (cModule *node, int puertas)
00367 {
00368 cModule *nodo = check_and_cast<cModule*>(node);
00369 int i=0, encontrado = -1;
00370 while (i<puertas && encontrado ==-1)
00371 {
00372 if(!nodo->gate("physicalBS$i",i)->isConnected())
00373 {
00374 encontrado = i;
00375 }
00376 i++;
00377 }
00378 return encontrado;
00379 }
00380
00382
00383
00385 int BS_mac::puerta_salida_libre (cModule *node, int puertas)
00386 {
00387 cModule *nodo = check_and_cast<cModule*>(node);
00388 int i=0, encontrado = -1;
00389 while (i<puertas && encontrado ==-1)
00390 {
00391 if(!nodo->gate("physicalBS$o",i)->isConnected())
00392 {
00393 encontrado = i;
00394 }
00395 i++;
00396 }
00397 return encontrado;
00398 }
00399
00401
00402
00404 void BS_mac::finish()
00405 {
00406 if(strcmp(this->getParentModule()->getFullName(),"bs0")==0)
00407
00408 {
00409 retardo_wireless = fopen("results/retardo_wireless.txt", "a+");
00410 fprintf(retardo_wireless, "TIEMPO SIMULADO: T=%g\n", (double)SIMTIME_DBL(simTime()));
00411 fprintf(retardo_wireless, "RETARDO MEDIO TOTAL: %g\n", (double)retardo.average());
00412 fclose(retardo_wireless);
00413 }
00414 int criterio = this->getParentModule()->par("criterio");
00415 int este_indice = this->getParentModule()->par("indice");
00416
00417 int estaciones = this->getParentModule()->par("numBS");
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446 }
00447
00449
00450
00452 void BS_mac::get_num_used_queues()
00453 {
00454 used_queues = 0;
00455 int num_conexiones = (int) this->getParentModule()->par("conexiones");
00456 int queues = num_conexiones - 1;
00457 int auxiliar = 0, contador = 0;
00458
00459
00460 for(int q=0; q<queues; q++)
00461 {
00462 queue = check_and_cast<BS_queue *>(this->getParentModule()->getSubmodule("bs_queue",q));
00463 if(queue->uso==1 && queue->usado==1)
00464 {
00465 used_queues++;
00466 index_used_queues[contador]=q;
00467 contador++;
00468 if(auxiliar==0)
00469 {
00470 ind_primero = q;
00471 auxiliar = 1;
00472 }
00473 }
00474 }
00475
00476 for(int h=used_queues; h<(int)index_used_queues.size(); h++)
00477 {
00478 index_used_queues[h] = -1;
00479 }
00480
00481 t_slot = t_frame/used_queues;
00482
00483 eff_cap = (double) txrate/used_queues;
00484
00485 double bw = (double) (txrate*t_slot)/8;
00486
00487 for(int h=0; h<used_queues; h++)
00488 {
00489
00490 check_and_cast<BS_queue *>(this->getParentModule()->getSubmodule("bs_queue",index_used_queues[h]))->used_index = h;
00491
00492 check_and_cast<BS_queue *>(this->getParentModule()->getSubmodule("bs_queue",index_used_queues[h]))->bandwidth = bw;
00493
00494 check_and_cast<BS_queue *>(this->getParentModule()->getSubmodule("bs_queue",index_used_queues[h]))->t_slot = t_slot;
00495
00496 check_and_cast<BS_queue *>(this->getParentModule()->getSubmodule("bs_queue",index_used_queues[h]))->used_bs_queues = used_queues;
00497 }
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510 }
00511
00513
00515 void BS_mac::extract_packets()
00516 {
00517
00518 switch(extraction_method)
00519 {
00520 case 0:
00521 sumcolas = 0;
00522 for(int w=0; w<used_queues; w++)
00523 {
00524 queue = check_and_cast<BS_queue *>(this->getParentModule()->getSubmodule("bs_queue",index_used_queues[w]));
00525 queue->tamsumcola = 0;
00526 for (int h=0; h<prioridades; h++)
00527 {
00528 queue->tamsumcola = queue->tamsumcola + queue->tamqueue[h];
00529
00530 }
00531
00532
00533
00534 if(queue->tamsumcola==0)
00535 {
00536 queue->contador++;
00537 if(queue->contador>=1)
00538 {
00539 queue->usado=0;
00540
00541 }
00542 }
00543
00544
00545 sumcolas = sumcolas + queue->tamsumcola;
00546 }
00547
00548
00549
00550 for(int j=0; j<used_queues; j++)
00551 {
00552 queue = check_and_cast<BS_queue *>(this->getParentModule()->getSubmodule("bs_queue",index_used_queues[j]));
00553 queue->strictpriorityqueue();
00554
00555
00556 }
00557 break;
00558 case 1:
00559 sumcolas = 0;
00560 for(int w=0; w<used_queues; w++)
00561 {
00562 queue = check_and_cast<BS_queue *>(this->getParentModule()->getSubmodule("bs_queue",index_used_queues[w]));
00563 queue->tamsumcola = 0;
00564 for (int h=0; h<prioridades; h++)
00565 {
00566 queue->tamsumcola = queue->tamsumcola + queue->tamqueue[h];
00567
00568 }
00569
00570
00571
00572 if(queue->tamsumcola==0)
00573 {
00574 queue->contador++;
00575 if(queue->contador>=1)
00576 {
00577 queue->usado=0;
00578
00579 }
00580 }
00581
00582
00583 sumcolas = sumcolas + queue->tamsumcola;
00584 }
00585
00586
00587 for(int j=0; j<used_queues; j++)
00588 {
00589 queue = check_and_cast<BS_queue *>(this->getParentModule()->getSubmodule("bs_queue",index_used_queues[j]));
00590
00591 queue->centralizedmethod();
00592
00593
00594 }
00595 break;
00596 default:
00597 break;
00598 }
00599 }
00600
00602
00603
00605 void BS_mac::relleno_arrays_retardos()
00606 {
00607
00608 top.extractByParameter("aux");
00610 for(int i=0; i<max_fila; i++)
00611 {
00612 for(int j=0; j<columnas; j++)
00613 {
00614 if(strcmp(Tabla->array_de_rutas[i][j]," ")!=0 && strpbrk(Tabla->array_de_rutas[i][j],"on")==NULL)
00615 {
00616 int ind_1=0,ind_2=0;
00617 for(int p=0; p<(int)top.getNumNodes(); p++)
00618 {
00619 if(strcmp(top.getNode(p)->getModule()->getFullName(),Tabla->array_de_rutas[i][j])==0)
00620 {
00621 ind_1=p;
00622 }
00623 if(strcmp(top.getNode(p)->getModule()->getFullName(),Tabla->array_de_rutas[i][j+1])==0)
00624 {
00625 ind_2=p;
00626 }
00627 }
00628 top_node = top.getNode(ind_1);
00630 int ind_aux=-1, k=0;
00631 while(ind_aux<0 && k<(int)top_node->getNumOutLinks())
00632 {
00635 if(strcmp(top_node->getLinkOut(k)->getRemoteGate()->getOwnerModule()->getFullName(),top.getNode(ind_2)->getModule()->getFullName())==0)
00636 {
00637 ind_aux=k;
00638 }
00639 k++;
00640 }
00641
00642
00643
00644
00645
00646
00647
00648
00649 if(strcmp(top_node->getLinkOut(ind_aux)->getRemoteNode()->getModule()->getName(),"onu")!=0)
00650 {
00651 Tabla->array_de_pesos[i][j] = (check_and_cast<cDelayChannel*>(top_node->getLinkOut(ind_aux)->getLocalGate()->getChannel()))->par(3);
00652 }
00653 }
00654 }
00655 }
00657
00659 for(int a=0; a<max_fila; a++)
00660 {
00661 for(int b=0; b<columnas; b++)
00662 {
00663 Tabla->peso_total_rutas[a] = 0;
00664 }
00665 }
00666 for(int a=0; a<max_fila; a++)
00667 {
00668 for(int b=0; b<columnas; b++)
00669 {
00670 Tabla->peso_total_rutas[a] = Tabla->peso_total_rutas[a] + Tabla->array_de_pesos[a][b];
00671 }
00672 }
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687 }
00688
00690
00691
00692
00694 void BS_mac::get_routes_for_each_user(int index)
00695 {
00696
00697 cModule *user;
00698 user = (cModule*) this->getParentModule()->getParentModule()->getSubmodule("user",index);
00699 int pasarelas = (int) this->getParentModule()->par("numGW");
00700 int indice_esta_bs = (int)this->getParentModule()->par("indice");
00701
00702 int estaciones = (int) this->getParentModule()->par("numBS");
00703 int connections = (int) this->getParentModule()->par("conexiones");
00704 int rutas_user = estaciones*pasarelas*connections*pasarelas;
00705 Tabla->indices_rutas[index].resize(rutas_user);
00706
00707 for (int w=0; w<rutas_user; w++)
00708 {
00709 Tabla->indices_rutas[index][w].resize(pasarelas,-1);
00710 }
00712 char* nombre_user = (char*) user->getFullName();
00713 char* nombre_pasarela;
00714 int auxiliar, ultimo;
00715 for(int i=0; i<pasarelas; i++)
00716 {
00717 auxiliar=0;
00718
00719 nombre_pasarela = (char*) nombres_bs[indices_pasarelas[i]];
00720
00721
00722
00723 for(int a=0; a<max_fila; a++)
00724 {
00725 ultimo = get_index_last_element(a);
00726 if(strcmp(nombre_user, Tabla->array_de_rutas[a][0])==0 && strcmp(nombre_pasarela, Tabla->array_de_rutas[a][ultimo-1])==0)
00727 {
00728 Tabla->indices_rutas[index][auxiliar][i] = a;
00729 auxiliar++;
00730 }
00731 }
00732 }
00733
00734 int contador;
00735 for(int t=0; t<pasarelas; t++)
00736 {
00737 contador=0;
00738
00739 for(int y=0; y<rutas_user; y++)
00740 {
00741 if(Tabla->indices_rutas[index][y][t]!=-1)
00742 {
00743 contador++;
00744 }
00745 }
00746 Tabla->num_rutas[index][t] = contador;
00747 if(indice_esta_bs == estaciones-1)
00748 {
00749
00750 }
00751 }
00752 }
00753
00755
00756
00758 void BS_mac::calculo_ruta_shortest_path(int ind_usr)
00759 {
00760 int indice_esta_bs = (int) this->getParentModule()->par("indice");
00761
00762 int estaciones = (int) this->getParentModule()->par("numBS");
00763 int usuarios = (int) this->getParentModule()->par("numUser");
00764 int pasarelas = (int) this->getParentModule()->par("numGW");
00766 for(int j=0; j<pasarelas; j++)
00767 {
00768 int min_index = Tabla->indices_rutas[ind_usr][0][j];
00769 if(Tabla->num_rutas[ind_usr][j]>1)
00770 {
00771 for(int i=0; i<Tabla->num_rutas[ind_usr][j]; i++)
00772 {
00774
00775
00776 if(Tabla->peso_total_rutas[Tabla->indices_rutas[ind_usr][i][j]] < Tabla->peso_total_rutas[min_index])
00777 {
00778 min_index=Tabla->indices_rutas[ind_usr][i][j];
00779 }
00780 }
00781 opt_route[j]=min_index;
00783 }
00784 else if(Tabla->num_rutas[ind_usr][j]==1)
00785 {
00787 min_index = Tabla->indices_rutas[ind_usr][0][j];
00788 opt_route[j]=min_index;
00790 }
00791 else if(Tabla->num_rutas[ind_usr][j]==0)
00792 {
00793 opt_route[j]= -1;
00794 }
00795 }
00796
00797 for(int q=0; q<pasarelas; q++)
00798 {
00799 if(opt_route[q]!=-1)
00800 {
00801 Tabla->rutas_optimas_pasarelas[q][ind_usr] = Tabla->array_de_rutas[opt_route[q]];
00802 auxiliar_matrix[q][ind_usr] = Tabla->peso_total_rutas[opt_route[q]];
00803 }
00804 }
00805 if(ind_usr == usuarios-1 && indice_esta_bs==estaciones-1)
00806 {
00807 for(int k=0; k<pasarelas; k++)
00808 {
00809
00810
00811 for(int a=0; a<usuarios; a++)
00812 {
00813 for(int b=0; b<columnas; b++)
00814 {
00815
00816 }
00817
00818 }
00819
00820 }
00821 }
00822
00823 int aux1=0, first_index=0, first_onu=0;
00824 for(int h=0; h<pasarelas; h++)
00825 {
00826 if(opt_route[h]>0 && aux1==0)
00827 {
00828 aux1=1;
00829 first_index=opt_route[h];
00830 first_onu=indices_pasarelas[h];
00832 }
00833 else if(opt_route[h]>0 && aux1!=0)
00834 {
00836
00837 if(Tabla->peso_total_rutas[opt_route[h]]<Tabla->peso_total_rutas[first_index])
00838
00839 {
00840 first_index=opt_route[h];
00841 first_onu=indices_pasarelas[h];
00842 }
00843 }
00844 }
00846
00847 Tabla->rutas_optimas[ind_usr] = Tabla->array_de_rutas[first_index];
00848 media_saltos = (double)(media_saltos + get_index_last_element(first_index)-1);
00849 auxiliar_array[ind_usr] = Tabla->longitud_total_rutas[first_index];
00850
00851
00852 if(ind_usr == usuarios-1)
00853
00854 {
00855
00856
00857
00858 for(int a=0; a<usuarios; a++)
00859 {
00860 for(int b=0; b<columnas; b++)
00861 {
00862
00863 }
00864
00865 }
00866
00867 }
00868 }
00869
00871
00872
00874 void BS_mac::calculo_ruta_minimum_hop(int ind_usr)
00875 {
00876 int indice_esta_bs = (int)this->getParentModule()->par("indice");
00877
00878 int estaciones = (int) this->getParentModule()->par("numBS");
00879 int usuarios = (int) this->getParentModule()->par("numUser");
00880 int pasarelas = (int) this->getParentModule()->par("numGW");
00882 for(int j=0; j<pasarelas; j++)
00883 {
00884 int min_index = Tabla->indices_rutas[ind_usr][0][j];
00885 if(Tabla->num_rutas[ind_usr][j]>1)
00886 {
00887 for(int i=0; i<Tabla->num_rutas[ind_usr][j]; i++)
00888 {
00890
00891 if(Tabla->peso_total_rutas[Tabla->indices_rutas[ind_usr][i][j]] < Tabla->peso_total_rutas[min_index])
00892 {
00893 min_index=Tabla->indices_rutas[ind_usr][i][j];
00894 }
00895 }
00896 opt_route[j]=min_index;
00898 }
00899 else if(Tabla->num_rutas[ind_usr][j]==1)
00900 {
00902 min_index = Tabla->indices_rutas[ind_usr][0][j];
00903 opt_route[j]=min_index;
00905 }
00906 else if(Tabla->num_rutas[ind_usr][j]==0)
00907 {
00908 opt_route[j]= -1;
00909 }
00910 }
00911
00912 for(int q=0; q<pasarelas; q++)
00913 {
00914 if(opt_route[q]!=-1)
00915 {
00916 Tabla->rutas_optimas_pasarelas[q][ind_usr] = Tabla->array_de_rutas[opt_route[q]];
00917 auxiliar_matrix[q][ind_usr] = Tabla->peso_total_rutas[opt_route[q]];
00918 }
00919 }
00920 if(ind_usr == usuarios-1 && indice_esta_bs==estaciones-1)
00921 {
00922 for(int k=0; k<pasarelas; k++)
00923 {
00924
00925
00926 for(int a=0; a<usuarios; a++)
00927 {
00928 for(int b=0; b<columnas; b++)
00929 {
00930
00931 }
00932
00933 }
00934
00935 }
00936 }
00937
00938 int aux1=0, first_index=0, first_onu=0;
00939 for(int h=0; h<pasarelas; h++)
00940 {
00941 if(opt_route[h]>0 && aux1==0)
00942 {
00943 aux1=1;
00944 first_index=opt_route[h];
00945 first_onu=indices_pasarelas[h];
00947 }
00948 else if(opt_route[h]>0 && aux1!=0)
00949 {
00951
00952 if(Tabla->peso_total_rutas[opt_route[h]]<Tabla->peso_total_rutas[first_index])
00953 {
00954 first_index=opt_route[h];
00955 first_onu=indices_pasarelas[h];
00956 }
00957 }
00958 }
00960
00961 Tabla->rutas_optimas[ind_usr] = Tabla->array_de_rutas[first_index];
00962 media_saltos = (double)(media_saltos + get_index_last_element(first_index) - 1);
00963 auxiliar_array[ind_usr] = Tabla->saltos_total_rutas[first_index];
00964
00965
00966 if(ind_usr == usuarios-1)
00967
00968 {
00969
00970
00971
00972 for(int a=0; a<usuarios; a++)
00973 {
00974 for(int b=0; b<columnas; b++)
00975 {
00976
00977 }
00978
00979 }
00980
00981 }
00982 }
00983
00985
00986
00988 void BS_mac::recalculo_ruta_delay_aware(int ind_usr)
00989 {
00990 int indice_esta_bs = (int)this->getParentModule()->par("indice");
00991
00992 int estaciones = (int) this->getParentModule()->par("numBS");
00993 int usuarios = (int) this->getParentModule()->par("numUser");
00994 int pasarelas = (int) this->getParentModule()->par("numGW");
00995
00997 for(int j=0; j<pasarelas; j++)
00998 {
00999 int min_index = Tabla->indices_rutas[ind_usr][0][j];
01000 if(Tabla->num_rutas[ind_usr][j]>1)
01001 {
01002 for(int i=0; i<Tabla->num_rutas[ind_usr][j]; i++)
01003 {
01005 if(Tabla->peso_total_rutas[Tabla->indices_rutas[ind_usr][i][j]] < Tabla->peso_total_rutas[min_index])
01006 {
01007 min_index=Tabla->indices_rutas[ind_usr][i][j];
01008 }
01009 }
01010 opt_route[j]=min_index;
01012 }
01013 else if(Tabla->num_rutas[ind_usr][j]==1)
01014 {
01016 min_index = Tabla->indices_rutas[ind_usr][0][j];
01017 opt_route[j]=min_index;
01019 }
01020 else if(Tabla->num_rutas[ind_usr][j]==0)
01021 {
01022 opt_route[j]= -1;
01023 }
01024 }
01025
01026 for(int q=0; q<pasarelas; q++)
01027 {
01028 if(opt_route[q]!=-1)
01029 {
01030 Tabla->rutas_optimas_pasarelas[q][ind_usr] = Tabla->array_de_rutas[opt_route[q]];
01031 auxiliar_matrix[q][ind_usr] = Tabla->peso_total_rutas[opt_route[q]];
01032 }
01033 }
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065 int aux1=0, first_index=0, first_onu=0;
01066 for(int h=0; h<pasarelas; h++)
01067 {
01068 if(opt_route[h]>0 && aux1==0)
01069 {
01070 aux1=1;
01071 first_index=opt_route[h];
01072 first_onu=indices_pasarelas[h];
01074 }
01075 else if(opt_route[h]>0 && aux1!=0)
01076 {
01078 if(Tabla->peso_total_rutas[opt_route[h]]<Tabla->peso_total_rutas[first_index])
01079 {
01080 first_index=opt_route[h];
01081 first_onu=indices_pasarelas[h];
01082 }
01083 }
01084 }
01086
01087 Tabla->rutas_optimas[ind_usr] = Tabla->array_de_rutas[first_index];
01088 media_saltos = (double)(media_saltos + get_index_last_element(first_index)-1);
01089 auxiliar_array[ind_usr] = Tabla->peso_total_rutas[first_index];
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127 }
01128
01130
01131
01132
01133
01134
01136 void BS_mac::routing()
01137 {
01138
01139 int indice_esta_bs = (int)this->getParentModule()->par("indice");
01140
01141 int estaciones = (int) this->getParentModule()->par("numBS");
01142 int num_pasarelas = (int) this->getParentModule()->par("numGW");
01143 int usuarios = (int) this->getParentModule()->par("numUser");
01144 int criterio = (int) this->getParentModule()->par("criterio");
01145 cModule *red = (cModule*) this->getParentModule()->getParentModule();
01146 cModule *nodo, *sig_nodo;
01147 cTopology::Node *topo_nodo;
01148 int enlaces;
01149 char* nombre_usuario;
01150 char* nombre_nodo;
01151 char* nombre_sig_nodo;
01152 double dist_user_bs = 0, distancia = 0, del_user_bs = 0.0, retardo = 0.0, wei_user_bs = 0.0, peso = 0.0;
01153
01155
01156 for(int a=0; a<usuarios; a++)
01157 {
01158
01159 nombre_usuario = (char*) red->getSubmodule("user",a)->getFullName();
01160
01161 nodo = red->getSubmodule("user",a)->gate("physicalUser$o")->getNextGate()->getOwnerModule();
01162 nombre_nodo = (char*) nodo->getFullName();
01163 dist_user_bs = (double) red->getSubmodule("user",a)->gate("physicalUser$o")->getChannel()->par(2);
01164 del_user_bs = (double) red->getSubmodule("user",a)->gate("physicalUser$o")->getChannel()->par(4);
01165
01166 topo_nodo = top.getNodeFor((cModule*)nodo);
01167 enlaces = topo_nodo->getNumOutLinks();
01168 int primero = get_index_first_empty_row();
01169
01170
01171 if(strcmp(topo_nodo->getLinkOut(1)->getRemoteNode()->getModule()->getName(),"onu")==0)
01172 {
01173 sig_nodo = topo_nodo->getLinkOut(1)->getRemoteNode()->getModule();
01174 nombre_sig_nodo = (char*)sig_nodo->getFullName();
01175 distancia = (double) (check_and_cast<cDelayChannel*>(topo_nodo->getLinkOut(1)->getLocalGate()->getChannel()))->par(2);
01176 retardo = (double) (check_and_cast<cDelayChannel*>(topo_nodo->getLinkOut(1)->getLocalGate()->getChannel()))->par(4);
01177
01178 peso = 0.0;
01179
01180 Tabla->array_de_rutas[primero][0] = nombre_usuario;
01181 Tabla->array_de_rutas[primero][1] = nombre_nodo;
01182 Tabla->array_de_rutas[primero][2] = nombre_sig_nodo;
01183 Tabla->array_de_longitudes[primero][0] = dist_user_bs;
01184 Tabla->array_de_longitudes[primero][1] = distancia;
01185 Tabla->array_de_retardos[primero][0] = del_user_bs;
01186 Tabla->array_de_retardos[primero][1] = retardo;
01187 Tabla->array_de_pesos[primero][0] = wei_user_bs;
01188 Tabla->array_de_pesos[primero][1] = peso;
01189 }
01190 else
01191 {
01192
01193 for(int b=1; b<(int)topo_nodo->getNumOutLinks(); b++)
01194 {
01195 sig_nodo = topo_nodo->getLinkOut(b)->getRemoteNode()->getModule();
01196 nombre_sig_nodo = (char*)sig_nodo->getFullName();
01197 distancia = (double) (check_and_cast<cDelayChannel*>(topo_nodo->getLinkOut(b)->getLocalGate()->getChannel()))->par(2);
01198 retardo = (double) (check_and_cast<cDelayChannel*>(topo_nodo->getLinkOut(b)->getLocalGate()->getChannel()))->par(4);
01199 peso = (double) (check_and_cast<cDelayChannel*>(topo_nodo->getLinkOut(b)->getLocalGate()->getChannel()))->par(3);
01200
01201 Tabla->array_de_rutas[primero+b-1][0] = nombre_usuario;
01202 Tabla->array_de_rutas[primero+b-1][1] = nombre_nodo;
01203 Tabla->array_de_rutas[primero+b-1][2] = nombre_sig_nodo;
01204 Tabla->array_de_longitudes[primero+b-1][0] = dist_user_bs;
01205 Tabla->array_de_longitudes[primero+b-1][1] = distancia;
01206 Tabla->array_de_retardos[primero+b-1][0] = del_user_bs;
01207 Tabla->array_de_retardos[primero+b-1][1] = retardo;
01208 Tabla->array_de_pesos[primero+b-1][0] = wei_user_bs;
01209 Tabla->array_de_pesos[primero+b-1][1] = peso;
01210 }
01211 }
01212 }
01213
01214
01215
01216
01217
01218 int bucle = 0;
01219 while(bucle<=15)
01220 {
01221
01222 int c=0, ultimo_nodo=0;
01223 char *elemento;
01224 char* nom_onu;
01225 double dist_onu=0.0, ret_onu=0.0, pes_onu=0.0;
01226 cModule *bs_intermedia;
01227 cTopology::Node *top_inter_bs;
01228
01229 while(c<filas)
01230 {
01231
01232 if(strcmp(Tabla->array_de_rutas[c][0]," ")!=0)
01233 {
01234 ultimo_nodo = get_index_last_element(c);
01235
01236
01237 if(strpbrk(Tabla->array_de_rutas[c][ultimo_nodo],"on") == NULL)
01238 {
01239 elemento = (char*) Tabla->array_de_rutas[c][ultimo_nodo];
01240 bs_intermedia = (cModule*) red->getSubmodule(elemento);
01241
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01254
01255 top_inter_bs = top.getNodeFor(bs_intermedia);
01256
01257 if(strcmp(top_inter_bs->getLinkOut(1)->getRemoteNode()->getModule()->getName(),"onu")==0)
01258 {
01259 nom_onu = (char*) top_inter_bs->getLinkOut(1)->getRemoteNode()->getModule()->getFullName();
01260 dist_onu = (double) (check_and_cast<cDelayChannel*>(top_inter_bs->getLinkOut(1)->getLocalGate()->getChannel()))->par(2);
01261 ret_onu = (double) (check_and_cast<cDelayChannel*>(top_inter_bs->getLinkOut(1)->getLocalGate()->getChannel()))->par(4);
01262
01263 pes_onu = 0.0;
01264 Tabla->array_de_rutas[c][ultimo_nodo+1] = nom_onu;
01265 Tabla->array_de_longitudes[c][ultimo_nodo] = dist_onu;
01266 Tabla->array_de_retardos[c][ultimo_nodo] = ret_onu;
01267 Tabla->array_de_pesos[c][ultimo_nodo] = pes_onu;
01268 }
01269
01270 else if(strcmp(top_inter_bs->getLinkOut(1)->getRemoteNode()->getModule()->getName(),"onu")!=0)
01271 {
01272 int primera_vez = 0, indice_auxiliar = 0;
01273 for(int d=1;d<(int)top_inter_bs->getNumOutLinks();d++)
01274 {
01275 cModule *aux_mod = top_inter_bs->getLinkOut(d)->getRemoteNode()->getModule();
01276 char *aux_nom = (char*)aux_mod->getFullName();
01277 if(ya_aparece(aux_nom,c,ultimo_nodo)==0)
01278 {
01279 double dist_aux = (double) (check_and_cast<cDelayChannel*>(top_inter_bs->getLinkOut(d)->getLocalGate()->getChannel()))->par(2);
01280 double ret_aux = (double) (check_and_cast<cDelayChannel*>(top_inter_bs->getLinkOut(d)->getLocalGate()->getChannel()))->par(4);
01281 double pes_aux = (double) (check_and_cast<cDelayChannel*>(top_inter_bs->getLinkOut(d)->getLocalGate()->getChannel()))->par(3);
01282 if(primera_vez == 1)
01283 {
01284 indice_auxiliar = get_index_first_empty_row();
01285 Tabla->array_de_rutas[indice_auxiliar] = Tabla->array_de_rutas[c];
01286 Tabla->array_de_longitudes[indice_auxiliar] = Tabla->array_de_longitudes[c];
01287 Tabla->array_de_retardos[indice_auxiliar] = Tabla->array_de_retardos[c];
01288 Tabla->array_de_pesos[indice_auxiliar] = Tabla->array_de_pesos[c];
01289 }
01290 else if(primera_vez == 0)
01291 {
01292 indice_auxiliar = c;
01293 primera_vez = 1;
01294 }
01295 Tabla->array_de_rutas[indice_auxiliar][ultimo_nodo+1] = aux_nom;
01296 Tabla->array_de_longitudes[indice_auxiliar][ultimo_nodo] = dist_aux;
01297 Tabla->array_de_retardos[indice_auxiliar][ultimo_nodo] = ret_aux;
01298 Tabla->array_de_pesos[indice_auxiliar][ultimo_nodo] = pes_aux;
01299 }
01300 }
01301 if(primera_vez==0)
01302 {
01303 for(int i=c; i<filas-1; i++)
01304 {
01305 Tabla->array_de_rutas[i] = Tabla->array_de_rutas[i+1];
01306 Tabla->array_de_longitudes[i] = Tabla->array_de_longitudes[i+1];
01307 Tabla->array_de_retardos[i] = Tabla->array_de_retardos[i+1];
01308 Tabla->array_de_pesos[i] = Tabla->array_de_pesos[i+1];
01309 }
01310 c--;
01311 }
01312 }
01313 }
01314 }
01315 c++;
01316 }
01317 bucle++;
01318 }
01320 max_fila = get_index_first_empty_row();
01321
01323 for(int a=0; a<max_fila; a++)
01324 {
01325 for(int b=0; b<columnas; b++)
01326 {
01327 Tabla->longitud_total_rutas[a] = Tabla->longitud_total_rutas[a] + Tabla->array_de_longitudes[a][b];
01328 }
01329 }
01330 for(int a=0; a<max_fila; a++)
01331 {
01332 for(int b=0; b<columnas; b++)
01333 {
01334 Tabla->retardo_total_rutas[a] = Tabla->retardo_total_rutas[a] + Tabla->array_de_retardos[a][b];
01335 }
01336 }
01337 for(int a=0; a<max_fila; a++)
01338 {
01339 for(int b=0; b<columnas; b++)
01340 {
01341 Tabla->peso_total_rutas[a] = Tabla->peso_total_rutas[a] + Tabla->array_de_pesos[a][b];
01342 }
01343 }
01344 for(int a=0; a<max_fila; a++)
01345 {
01346 Tabla->saltos_total_rutas[a] = get_index_last_element(a) - 1;
01347 }
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370 auxiliar_array.resize(usuarios);
01371 auxiliar_matrix.resize(num_pasarelas);
01372 for(int n=0;n<num_pasarelas;n++)
01373 {
01374 auxiliar_matrix[n].resize(usuarios,0.0);
01375 }
01376 opt_route.resize(num_pasarelas,-1);
01377 for(int r=0; r<usuarios; r++)
01378 {
01379 get_routes_for_each_user(r);
01380 switch(criterio)
01381 {
01382 case 0:
01383 calculo_ruta_shortest_path(r);
01384 break;
01385 case 1:
01386 recalculo_ruta_delay_aware(r);
01387 break;
01388 case 2:
01389 calculo_ruta_minimum_hop(r);
01390 break;
01391 }
01392 }
01393
01394
01395 for(int n=0;n<num_pasarelas;n++)
01396 {
01397 auxiliar_matrix[n].resize(0);
01398 }
01399 opt_route.resize(0);
01400
01401 media_saltos = (double)(media_saltos/usuarios);
01403
01404
01405 Tabla->saltos_total_rutas.resize(max_fila);
01406 Tabla->longitud_total_rutas.resize(max_fila);
01407 Tabla->retardo_total_rutas.resize(max_fila);
01408 Tabla->peso_total_rutas.resize(max_fila);
01409 Tabla->array_de_rutas.resize(max_fila);
01410 Tabla->array_de_longitudes.resize(max_fila);
01411 Tabla->array_de_retardos.resize(max_fila);
01412 Tabla->array_de_pesos.resize(max_fila);
01413
01414
01415 if(indice_esta_bs == estaciones-1)
01416 {
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01491
01493
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01541
01543 }
01544
01545
01546
01547 Tabla->longitud_total_rutas.clear();
01548 Tabla->retardo_total_rutas.clear();
01549 Tabla->array_de_longitudes.clear();
01550 Tabla->array_de_retardos.clear();
01551
01552
01553 }