Alex Bikfalvi
SimStream Documentation
ModelPushSelect.cpp
00001 #include "Headers.h" 00002 #include "ModelPushSelect.h" 00003 #include "Shuffle.h" 00004 #include "Rand.h" 00005 00006 #include "EventServerStart.h" 00007 #include "EventClientArrive.h" 00008 #include "EventClientWatch.h" 00009 #include "EventClientLeave.h" 00010 00011 #pragma warning(disable : 4996) 00012 00013 CModelPushSelect::CModelPushSelect( 00014 CModelBandwidth* modelBandwidthUplink, 00015 CModelBandwidth* modelBandwidthDownlink, 00016 CModelChannel* modelChannel, 00017 CModelSelect* modelSelect, 00018 char* name, 00019 __time maxTime, 00020 CTopo* topology, 00021 __uint32 topologyNumber, 00022 __uint32 numHosts, 00023 __uint32 numGateways, 00024 __time delayAccessUpLink, 00025 __time delayAccessDownLink, 00026 __bitrate bwServerUpLink, 00027 __bitrate bwServerDownLink, 00028 __time delayServerUpLink, 00029 __time delayServerDownLink, 00030 __uint32 queueLink, 00031 __uint32 queueLinkServer, 00032 __uint32 numChannels, 00033 __uint32 numLayers, 00034 __uint32 numLayersMin, 00035 __bitrate channelBw, 00036 __byte channelFps, 00037 __byte mpegGopDistanceItoI, 00038 __byte mpegGopDistanceItoP, 00039 __uint32 streamBufferSize, 00040 __uint32 streamBufferSizeHistory, 00041 __uint32 streamBufferSizeBuffering, 00042 __time streamBufferUnderrunTimeout, 00043 double streamBwMargin, 00044 __uint32 bootQueryMax, 00045 __uint32 bootRefreshThreshold, 00046 __time bootQueryTimeout, 00047 __time bootRegisterDelay 00048 ) : CModel(maxTime, topology) 00049 { 00050 assert(modelBandwidthUplink); 00051 assert(modelBandwidthDownlink); 00052 assert(modelChannel); 00053 assert(modelSelect); 00054 00055 assert(numHosts > 0); 00056 assert(numGateways > 0); 00057 00058 // Models 00059 this->modelBandwidthUplink = modelBandwidthUplink; 00060 this->modelBandwidthDownlink = modelBandwidthDownlink; 00061 this->modelChannel = modelChannel; 00062 this->modelSelect = modelSelect; 00063 00064 // Simulator 00065 this->sim = NULL; 00066 this->name = name; 00067 this->topology = topology; 00068 this->topologyNumber = topologyNumber; 00069 this->modelChannel = modelChannel; 00070 00071 // Nodes 00072 this->numHosts = numHosts; 00073 this->numServers = 1; 00074 this->numGateways = (numGateways <= this->topology->Nodes())?numGateways:this->topology->Nodes(); 00075 this->delayAccessUpLink = delayAccessUpLink; 00076 this->delayAccessDownLink = delayAccessDownLink; 00077 this->bwServerUpLink = bwServerUpLink; 00078 this->bwServerDownLink = bwServerDownLink; 00079 this->delayServerUpLink = delayServerUpLink; 00080 this->delayServerDownLink = delayServerDownLink; 00081 this->queueLink = queueLink; 00082 this->queueLinkServer = queueLinkServer; 00083 00084 this->hosts = NULL; 00085 this->routers = NULL; 00086 this->server = NULL; 00087 this->linksCore = NULL; 00088 this->linksAccess = NULL; 00089 this->linkServer = NULL; 00090 00091 // Channels 00092 this->numChannels = numChannels; 00093 this->numLayers = numLayers; 00094 this->numLayersMin = numLayersMin; 00095 00096 this->channelBw = channelBw; 00097 this->channelFps = channelFps; 00098 00099 // Stream 00100 this->streamBufferSize = streamBufferSize; 00101 this->streamBufferSizeHistory = streamBufferSizeHistory; 00102 this->streamBufferSizeBuffering = streamBufferSizeBuffering; 00103 this->streamBufferUnderrunTimeout = streamBufferUnderrunTimeout; 00104 this->streamBwMargin = streamBwMargin; 00105 00106 // Stream sources 00107 this->mpegGopDistanceItoI = mpegGopDistanceItoI; 00108 this->mpegGopDistanceItoP = mpegGopDistanceItoP; 00109 00110 // Bootstrap 00111 this->bootQueryMax = bootQueryMax; 00112 this->bootRefreshThreshold = bootRefreshThreshold; 00113 this->bootQueryTimeout = bootQueryTimeout; 00114 this->bootRegisterDelay = bootRegisterDelay; 00115 00116 // Generate gateways 00117 this->gateways = new __uint32[this->numHosts]; 00118 00119 // Generate gateway links (the number of access links for each gateway) 00120 this->routerAccessLinks = new __uint32[this->topology->Nodes()]; 00121 00122 for(__uint32 index = 0; index < this->topology->Nodes(); index++) 00123 this->routerAccessLinks[index] = 0; 00124 00125 // Generate gateway for server 00126 this->gatewayServer = CRand::Generate(this->topology->Nodes()); 00127 00128 // Shuffle routers 00129 CShuffle shuffleRouters(this->topology->Nodes()); 00130 00131 // Assign a gateway for each host 00132 for(__uint32 index = 0; index < this->numHosts; index++) 00133 { 00134 __uint32 gw = shuffleRouters[CRand::Generate(this->numGateways)]; 00135 assert(gw < this->topology->Nodes()); 00136 00137 this->gateways[index] = gw; 00138 this->routerAccessLinks[gw]++; 00139 } 00140 00141 // Generate route 00142 this->routeNodes = this->topology->Nodes(); 00143 this->routeDst = this->topology->Nodes() + this->numHosts + this->numServers; 00144 00145 this->route = new int*[this->routeNodes]; 00146 00147 for(__uint32 index = 0; index < this->routeNodes; index++) 00148 { 00149 this->route[index] = new int[this->routeDst]; 00150 } 00151 00152 // Create channels 00153 this->channels = new CChannel[this->numChannels]; 00154 for(__uint32 index = 0; index < this->numChannels; index++) 00155 this->channels[index] = CChannel(index, CChannel::CHANNEL_UNICAST, SERVER_INDEX_ADDRESS(0), this->channelBw, this->channelFps); 00156 00157 // Create stream sources for all channels 00158 this->streamSources = new CStreamSourceMpeg*[this->numChannels]; 00159 00160 // Create stream sources 00161 for(__uint32 index = 0; index < this->numChannels; index++) 00162 { 00163 this->streamSources[index] = new CStreamSourceMpeg( 00164 this->Channel(index), 00165 mpegGopDistanceItoI, 00166 mpegGopDistanceItoP); 00167 } 00168 00169 // Generate access bandwidth 00170 this->bwAccessHostUpLink = new __bitrate[this->numHosts]; 00171 this->bwAccessHostDownLink = new __bitrate[this->numHosts]; 00172 00173 for(unsigned int index = 0; index < this->numHosts; index++) 00174 { 00175 this->bwAccessHostUpLink[index] = this->modelBandwidthUplink->Bandwidth(index); 00176 this->bwAccessHostDownLink[index] = this->modelBandwidthDownlink->Bandwidth(index); 00177 } 00178 00179 // Data 00180 this->data = new CData( 00181 this->name, 00182 this->topologyNumber, 00183 0 00184 ); 00185 00186 // Set peers address in the selection model 00187 for(__uint32 index = 0; index < this->numHosts; index++) 00188 this->modelSelect->Address(index, HOST_INDEX_ADDRESS(index)); 00189 } 00190 00191 CModelPushSelect::~CModelPushSelect() 00192 { 00193 // Delete gateways 00194 delete[] this->gateways; 00195 delete[] this->routerAccessLinks; 00196 00197 // Delete routes 00198 for(__uint32 index = 0; index < this->routeNodes; index++) 00199 delete[] this->route[index]; 00200 delete[] this->route; 00201 00202 // Delete stream sources 00203 for(__uint32 index = 0; index < this->numChannels; index++) 00204 delete this->streamSources[index]; 00205 delete[] this->streamSources; 00206 00207 // Delete channels 00208 delete[] this->channels; 00209 00210 // Delete access bandwidth 00211 delete[] this->bwAccessHostUpLink; 00212 delete[] this->bwAccessHostDownLink; 00213 00214 // Delete data 00215 delete this->data; 00216 } 00217 00218 void CModelPushSelect::Init(CSimHandler* sim) 00219 { 00220 this->sim = sim; 00221 00222 // Generate hosts 00223 this->hosts = new CHostClientPushSelect*[this->numHosts]; 00224 00225 for(__uint32 index = 0; index < this->numHosts; index++) 00226 { 00227 this->hosts[index] = new CHostClientPushSelect( 00228 HOST_ID(index), 00229 this->sim, 00230 HOST_INDEX_ADDRESS(index), 00231 this, 00232 this->data, 00233 this->bwAccessHostUpLink[index] 00234 ); 00235 } 00236 00237 // Generate server 00238 this->server = new CHostServerPushSelect( 00239 SERVER_ID(0), 00240 this->sim, 00241 SERVER_INDEX_ADDRESS(0), 00242 this, 00243 this->data); 00244 00245 // Generate routers 00246 this->routers = new CRouter*[this->topology->Nodes()]; 00247 00248 for(__uint32 index = 0; index < this->topology->Nodes(); index++) 00249 { 00250 this->routers[index] = new CRouter( 00251 ROUTER_ID(this->topology->Node(index)->Id()), 00252 this->sim, 00253 ROUTER_INDEX_ADDRESS(index), 00254 this->topology->Node(index)->Degree() + this->routerAccessLinks[index] + ((index == this->gatewayServer)?1:0), 00255 this, 00256 this, 00257 NULL 00258 ); 00259 } 00260 00261 // Generate core links 00262 this->linksCore = new CLink*[this->topology->Edges()]; 00263 00264 for(__uint32 index = 0; index < this->topology->Edges(); index++) 00265 { 00266 assert(this->topology->Edge(index)->Nodes()[0] < this->topology->Nodes()); 00267 assert(this->topology->Edge(index)->Nodes()[1] < this->topology->Nodes()); 00268 00269 this->linksCore[index] = new CLink( 00270 LINK_CORE_ID(this->topology->Edge(index)->Id()), 00271 this->sim, 00272 this->queueLink, 00273 this->topology->Edge(index)->Bandwidth(), 00274 this->topology->Edge(index)->Bandwidth(), 00275 this->topology->Edge(index)->Delay(), 00276 this->topology->Edge(index)->Delay()); 00277 } 00278 00279 // Generate access links 00280 this->linksAccess = new CLink*[this->numHosts]; 00281 00282 for(__uint32 index = 0; index < this->numHosts; index++) 00283 { 00284 this->linksAccess[index] = new CLink( 00285 LINK_ACCESS_ID(index), 00286 this->sim, 00287 this->queueLink, 00288 this->bwAccessHostUpLink[index], 00289 this->bwAccessHostDownLink[index], 00290 this->delayAccessUpLink, 00291 this->delayAccessDownLink 00292 ); 00293 } 00294 00295 // Generate server link 00296 this->linkServer = new CLink( 00297 LINK_SERVER_ID(0), 00298 this->sim, 00299 this->queueLinkServer, 00300 this->bwServerUpLink, 00301 this->bwServerDownLink, 00302 this->delayServerUpLink, 00303 this->delayServerDownLink 00304 ); 00305 00306 // Generate node-link mappings 00307 // Generate for routers and core links 00308 for(__uint32 index = 0; index < this->topology->Nodes(); index++) 00309 for(__uint32 idx = 0; idx < this->topology->Node(index)->Degree(); idx++) 00310 this->routers[index]->AddLink(this->linksCore[this->topology->Node(index)->Edge(idx)]); 00311 00312 // Generate for hosts, gateway routers and access links 00313 for(__uint32 index = 0; index < this->numHosts; index++) 00314 { 00315 // Add link to the host: entry 0 corresponds to the host (uplink) 00316 this->hosts[index]->AddLink(this->linksAccess[index]); 00317 00318 // Add link to the corresponding gateway: entry 1 corresponds to the router (downlink) 00319 this->routers[this->gateways[index]]->AddLink(this->linksAccess[index]); 00320 } 00321 00322 // Generate for server : add link to server 00323 this->server->AddLink(this->linkServer); 00324 // Generate for server gateway 00325 this->routers[this->gatewayServer]->AddLink(this->linkServer); 00326 00327 // Calculate routes 00328 for(__uint32 node = 0; node < this->routeNodes; node++) 00329 { 00330 // Routes: node to node 00331 for(__uint32 dst = 0; dst < this->routeNodes; dst++) 00332 if(dst == node) this->route[ROUTER_INDEX_ADDRESS(node)][ROUTER_INDEX_ADDRESS(dst)] = -1; 00333 else this->route[ROUTER_INDEX_ADDRESS(node)][ROUTER_INDEX_ADDRESS(dst)] = this->routers[node]->LinkIndex(this->linksCore[this->topology->Route()->NextEdge(node, dst)]->Id()); 00334 00335 // Routes: node to host 00336 for(__uint32 host = 0; host < this->numHosts; host++) 00337 { 00338 if(this->gateways[host] == node) 00339 { 00340 // If the node is the gateway of the destination 00341 this->route[ROUTER_INDEX_ADDRESS(node)][HOST_INDEX_ADDRESS(host)] = this->routers[node]->LinkIndex(this->linksAccess[host]->Id()); 00342 } 00343 else 00344 { 00345 // Else: the route to the gateway 00346 this->route[ROUTER_INDEX_ADDRESS(node)][HOST_INDEX_ADDRESS(host)] = this->routers[node]->LinkIndex(this->linksCore[this->topology->Route()->NextEdge(node, this->gateways[host])]->Id()); 00347 } 00348 } 00349 00350 // Routes: node to server 00351 if(this->gatewayServer == node) 00352 // If the node is the gateway of the server 00353 this->route[ROUTER_INDEX_ADDRESS(node)][SERVER_INDEX_ADDRESS(0)] = this->routers[node]->LinkIndex(this->linkServer->Id()); 00354 else 00355 // Else: the route to the server gateway 00356 this->route[ROUTER_INDEX_ADDRESS(node)][SERVER_INDEX_ADDRESS(0)] = this->routers[node]->LinkIndex(this->linksCore[this->topology->Route()->NextEdge(node, this->gatewayServer)]->Id()); 00357 } 00358 00359 #if _DEBUG_CHECK 00360 // Verify routers 00361 for(__uint32 index = 0; index < this->topology->Nodes(); index++) 00362 { 00363 // Check the links 00364 for(__uint32 idx = 0; idx < this->routers[index]->NumLinks(); idx++) 00365 { 00366 CLink* link = this->routers[index]->Link(idx); 00367 __uint32 entry = this->routers[index]->LinkEntry(idx); 00368 00369 assert(link); 00370 assert(link->Node(entry) == this->routers[index]); 00371 assert(link->NodeEntry(entry) == idx); 00372 } 00373 } 00374 // Verify hosts 00375 for(__uint32 index = 0; index < this->numHosts; index++) 00376 { 00377 CLink* link = this->hosts[index]->Link(); 00378 __uint32 entry = this->hosts[index]->LinkEntry(); 00379 00380 assert(link); 00381 assert(link->Node(entry) == this->hosts[index]); 00382 assert(link->NodeEntry(entry) == 0); 00383 } 00384 // Verify core links 00385 for(__uint32 index = 0; index < this->topology->Edges(); index++) 00386 { 00387 for(__uint32 idx = 0; idx < 2; idx++) 00388 { 00389 CRouter* router = type_cast<CRouter*>(this->linksCore[index]->Node(idx)); 00390 __uint32 entry = this->linksCore[index]->NodeEntry(idx); 00391 00392 assert(router); 00393 assert(router->Link(entry) == this->linksCore[index]); 00394 assert(router->LinkEntry(entry) == idx); 00395 } 00396 } 00397 // Verify access links 00398 for(__uint32 index = 0; index < this->numHosts; index++) 00399 { 00400 CHost* host = type_cast<CHost*>(this->linksAccess[index]->Node(0)); 00401 __uint32 entryHost = this->linksAccess[index]->NodeEntry(0); 00402 CRouter* router = type_cast<CRouter*>(this->linksAccess[index]->Node(1)); 00403 __uint32 entryRouter = this->linksAccess[index]->NodeEntry(1); 00404 00405 assert(host); 00406 assert(host->Link() == this->linksAccess[index]); 00407 assert(host->LinkEntry() == 0); 00408 assert(router); 00409 assert(router->Link(entryRouter) == this->linksAccess[index]); 00410 assert(router->LinkEntry(entryRouter) == 1); 00411 } 00412 // Verify routes 00413 // router-to-router 00414 00415 for(__uint32 src = 0; src < this->routeNodes; src++) 00416 for(__uint32 dst = 0; dst < this->routeNodes; dst++) 00417 { 00418 CNode* node = this->routers[src]; 00419 CLink* link; 00420 __uint32 linkEntry; 00421 int index; 00422 00423 while(node != this->routers[dst]) 00424 { 00425 index = this->route[node->Address().Address()][this->routers[dst]->Address().Address()]; 00426 link = type_cast<CRouter*>(node)->Link(index); 00427 linkEntry = type_cast<CRouter*>(node)->LinkEntry(index); 00428 node = type_cast<CNode*>(link->Node(linkEntry ^ 1)); 00429 } 00430 // Check the destination was reached 00431 assert(node == this->routers[dst]); 00432 } 00433 00434 // router-to-hosts 00435 for(__uint32 src = 0; src < this->routeNodes; src++) 00436 for(__uint32 dst = 0; dst < this->numHosts; dst++) 00437 { 00438 CNode* node = this->routers[src]; 00439 CLink* link; 00440 __uint32 linkEntry; 00441 int index; 00442 00443 while(node != this->hosts[dst]) 00444 { 00445 index = this->route[node->Address().Address()][this->hosts[dst]->Address().Address()]; 00446 link = type_cast<CRouter*>(node)->Link(index); 00447 linkEntry = type_cast<CRouter*>(node)->LinkEntry(index); 00448 node = type_cast<CNode*>(link->Node(linkEntry ^ 1)); 00449 } 00450 // Check the destination was reached 00451 assert(node == this->hosts[dst]); 00452 } 00453 #endif 00454 } 00455 00456 __uint32 CModelPushSelect::Events() 00457 { 00458 return 1 + this->numHosts; 00459 } 00460 00461 CSimEvent* CModelPushSelect::Event(__uint32 index, __time& time) 00462 { 00463 switch(index) 00464 { 00465 case 0: // Server init event 00466 time = 0; 00467 return new CEventServerStart(this->server); 00468 default: // Peer arrive 00469 time = 1; 00470 return new CEventClientArrive(this->hosts[index-1]); 00471 } 00472 } 00473 00474 void CModelPushSelect::Finalize() 00475 { 00476 ofstream out; 00477 char fileName[1024]; 00478 00479 /* 00480 * Simple statistics 00481 */ 00482 00483 // Calculate data 00484 00485 // Data : bandwidth 00486 this->dataBwTotal = 0; 00487 00488 // Data : bandwidth core 00489 this->dataBwCoreTotal = 0; 00490 00491 // Data : bandwidth access 00492 this->dataBwAccessTotal = 0; 00493 00494 // Data : bandwidth access uplink 00495 this->dataBwAccessUpTotal = 0; 00496 00497 // Data : bandwidth access downlink 00498 this->dataBwAccessDownTotal = 0; 00499 00500 // Data : bandwidth server 00501 this->dataBwServerTotal = 0; 00502 00503 // Data : bandwidth stream 00504 this->dataBwStreamTotal = 0; 00505 00506 // Data : bandwidth core stream 00507 this->dataBwCoreStreamTotal = 0; 00508 00509 // Data : bandwidth access stream 00510 this->dataBwAccessStreamTotal = 0; 00511 00512 // Data : bandwidth access uplink stream 00513 this->dataBwAccessUpStreamTotal = 0; 00514 00515 // Data : bandwidth access downlink stream 00516 this->dataBwAccessDownStreamTotal = 0; 00517 00518 // Data : bandwidth server stream 00519 this->dataBwServerStreamTotal = 0; 00520 00521 // Data : bandwidth control 00522 this->dataBwControlTotal = 0; 00523 00524 // Data : bandwidth core control 00525 this->dataBwCoreControlTotal = 0; 00526 00527 // Data : bandwidth access control 00528 this->dataBwAccessControlTotal = 0; 00529 00530 // Data : bandwidth access uplink control 00531 this->dataBwAccessUpControlTotal = 0; 00532 00533 // Data : bandwidth access downlink control 00534 this->dataBwAccessDownControlTotal = 0; 00535 00536 // Data : bandwidth server control 00537 this->dataBwServerControlTotal = 0; 00538 00539 // Data : host statistics 00540 this->dataCoderEncodedPackets = 0; 00541 this->dataCoderDecodedPackets = 0; 00542 this->dataCoderDiscardedPackets = 0; 00543 00544 this->dataCoderEncodedFrames = 0; 00545 this->dataCoderDecodedFrames = 0; 00546 this->dataCoderDiscardedFrames = 0; 00547 00548 this->dataClientRecvFrames = 0; 00549 this->dataClientDiscardedFrames = 0; 00550 this->dataClientExpectedFrames = 0; 00551 00552 00553 // Server link 00554 this->dataBwTotal += this->linkServer->StatBits(0,0) + this->linkServer->StatBits(0,1) + this->linkServer->StatBits(1,0) + this->linkServer->StatBits(1,1); 00555 this->dataBwServerTotal += this->linkServer->StatBits(0,0) + this->linkServer->StatBits(0,1) + this->linkServer->StatBits(1,0) + this->linkServer->StatBits(1,1); 00556 this->dataBwStreamTotal += this->linkServer->StatBits(1,0) + this->linkServer->StatBits(1,1); 00557 this->dataBwServerStreamTotal += this->linkServer->StatBits(1,0) + this->linkServer->StatBits(1,1); 00558 this->dataBwServerControlTotal += this->linkServer->StatBits(0,0) + this->linkServer->StatBits(0,1); 00559 00560 // Core links 00561 for(__uint32 index = 0; index < this->topology->Edges(); index++) 00562 { 00563 this->dataBwTotal += this->linksCore[index]->StatBits(0,0) + this->linksCore[index]->StatBits(0,1) + this->linksCore[index]->StatBits(1,0) + this->linksCore[index]->StatBits(1,1); 00564 this->dataBwCoreTotal += this->linksCore[index]->StatBits(0,0) + this->linksCore[index]->StatBits(0,1) + this->linksCore[index]->StatBits(1,0) + this->linksCore[index]->StatBits(1,1); 00565 this->dataBwStreamTotal += this->linksCore[index]->StatBits(1,0) + this->linksCore[index]->StatBits(1,1); 00566 this->dataBwCoreStreamTotal += this->linksCore[index]->StatBits(1,0) + this->linksCore[index]->StatBits(1,1); 00567 this->dataBwControlTotal += this->linksCore[index]->StatBits(0,0) + this->linksCore[index]->StatBits(0,1); 00568 this->dataBwCoreControlTotal += this->linksCore[index]->StatBits(0,0) + this->linksCore[index]->StatBits(0,1); 00569 } 00570 00571 // Access links 00572 for(__uint32 index = 0; index < this->numHosts; index++) 00573 { 00574 this->dataBwTotal += this->linksAccess[index]->StatBits(0,0) + this->linksAccess[index]->StatBits(0,1) + this->linksAccess[index]->StatBits(1,0) + this->linksAccess[index]->StatBits(1,1); 00575 this->dataBwAccessTotal += this->linksAccess[index]->StatBits(0,0) + this->linksAccess[index]->StatBits(0,1) + this->linksAccess[index]->StatBits(1,0) + this->linksAccess[index]->StatBits(1,1); 00576 this->dataBwAccessUpTotal += this->linksAccess[index]->StatBits(0,0) + this->linksAccess[index]->StatBits(1,0); 00577 this->dataBwAccessDownTotal += this->linksAccess[index]->StatBits(0,1) + this->linksAccess[index]->StatBits(1,1); 00578 this->dataBwStreamTotal += this->linksAccess[index]->StatBits(1,0) + this->linksAccess[index]->StatBits(1,1); 00579 this->dataBwAccessStreamTotal += this->linksAccess[index]->StatBits(1,0) + this->linksAccess[index]->StatBits(1,1); 00580 this->dataBwAccessUpStreamTotal += this->linksAccess[index]->StatBits(1,0); 00581 this->dataBwAccessDownStreamTotal += this->linksAccess[index]->StatBits(1,1); 00582 this->dataBwControlTotal += this->linksAccess[index]->StatBits(0,0) + this->linksAccess[index]->StatBits(0,1); 00583 this->dataBwAccessControlTotal += this->linksAccess[index]->StatBits(0,0) + this->linksAccess[index]->StatBits(0,1); 00584 this->dataBwAccessUpControlTotal += this->linksAccess[index]->StatBits(0,0); 00585 this->dataBwAccessDownControlTotal += this->linksAccess[index]->StatBits(0,1); 00586 } 00587 00588 this->dataBwAvg = this->dataBwTotal/this->maxTime; 00589 this->dataBwCoreAvg = this->dataBwCoreTotal/this->maxTime; 00590 this->dataBwAccessAvg = this->dataBwAccessTotal/this->maxTime; 00591 this->dataBwAccessUpAvg = this->dataBwAccessUpTotal/this->maxTime; 00592 this->dataBwAccessDownAvg = this->dataBwAccessDownTotal/this->maxTime; 00593 this->dataBwServerAvg = this->dataBwServerTotal/this->maxTime; 00594 this->dataBwStreamAvg = this->dataBwStreamTotal/this->maxTime; 00595 this->dataBwCoreStreamAvg = this->dataBwCoreStreamTotal/this->maxTime; 00596 this->dataBwAccessStreamAvg = this->dataBwAccessStreamTotal/this->maxTime; 00597 this->dataBwAccessUpStreamAvg = this->dataBwAccessUpStreamTotal/this->maxTime; 00598 this->dataBwAccessDownStreamAvg = this->dataBwAccessDownStreamTotal/this->maxTime; 00599 this->dataBwServerStreamAvg = this->dataBwServerStreamTotal/this->maxTime; 00600 this->dataBwControlAvg = this->dataBwControlTotal/this->maxTime; 00601 this->dataBwCoreControlAvg = this->dataBwCoreControlTotal/this->maxTime; 00602 this->dataBwAccessControlAvg = this->dataBwAccessControlTotal/this->maxTime; 00603 this->dataBwAccessUpControlAvg = this->dataBwAccessUpControlTotal/this->maxTime; 00604 this->dataBwAccessDownControlAvg = this->dataBwAccessDownControlTotal/this->maxTime; 00605 this->dataBwServerControlAvg = this->dataBwServerControlTotal/this->maxTime; 00606 00607 // Routers 00608 for(__uint32 index = 0; index < this->topology->Nodes(); index++) 00609 { 00610 this->routers[index]->Finalize(); 00611 } 00612 00613 // Global file 00614 sprintf(fileName, "network_%s_%u.out", this->name, this->topologyNumber); 00615 out.open(fileName, ios_base::out | ios_base::app); 00616 00617 if(!out.fail()) 00618 { 00619 out << 00620 this->dataBwTotal << 00621 this->dataBwAvg << 00622 this->dataBwCoreTotal << 00623 this->dataBwCoreAvg << 00624 this->dataBwAccessTotal << 00625 this->dataBwAccessAvg << 00626 this->dataBwAccessUpTotal << 00627 this->dataBwAccessUpAvg << 00628 this->dataBwAccessDownTotal << 00629 this->dataBwAccessDownAvg << 00630 this->dataBwServerTotal << 00631 this->dataBwServerAvg << 00632 this->dataBwStreamTotal << 00633 this->dataBwStreamAvg << 00634 this->dataBwCoreStreamTotal << 00635 this->dataBwCoreStreamAvg << 00636 this->dataBwAccessStreamTotal << 00637 this->dataBwAccessStreamAvg << 00638 this->dataBwAccessUpStreamTotal << 00639 this->dataBwAccessUpStreamAvg << 00640 this->dataBwAccessDownStreamTotal << 00641 this->dataBwAccessDownStreamAvg << 00642 this->dataBwServerStreamTotal << 00643 this->dataBwServerStreamAvg << 00644 this->dataBwControlTotal << 00645 this->dataBwControlAvg << 00646 this->dataBwCoreControlTotal << 00647 this->dataBwCoreControlAvg << 00648 this->dataBwAccessControlTotal << 00649 this->dataBwAccessControlAvg << 00650 this->dataBwAccessUpControlTotal << 00651 this->dataBwAccessUpControlAvg << 00652 this->dataBwAccessDownControlTotal << 00653 this->dataBwAccessDownControlAvg << 00654 this->dataBwServerControlTotal << 00655 this->dataBwServerControlAvg << endl; 00656 out.close(); 00657 } 00658 00659 //#ifdef STAT_VERBOSE 00660 // 00661 // // Channel quality 00662 // sprintf(fileName, "qchannel_%s_%u.out", this->name, this->topologyNumber); 00663 // if(fopen_s(&out, fileName, "a")) printf("\nCannot write to file %s.", fileName); 00664 // else 00665 // { 00666 // fprintf(out, "%u ", this->numChannelsMcast); 00667 // for(__uint32 index = 0; index < this->numChannels; index++) 00668 // { 00669 // fprintf(out, "%.9lf ", this->data->QualityChannelNormal(index)); 00670 // } 00671 // for(__uint32 index = 0; index < this->numChannels; index++) 00672 // { 00673 // fprintf(out, "%.9lf ", this->data->QualityChannelWeighted(index)); 00674 // } 00675 // fprintf(out, "\n"); 00676 // 00677 // fclose(out); 00678 // } 00679 // 00680 // // Session quality 00681 // sprintf(fileName, "qsession_%s_%u.out", this->name, this->topologyNumber); 00682 // if(fopen_s(&out, fileName, "a")) printf("\nCannot write to file %s.", fileName); 00683 // else 00684 // { 00685 // fprintf(out, "%u ", this->numChannelsMcast); 00686 // for(__uint32 index = 0; index < this->maxTime; index++) 00687 // { 00688 // fprintf(out, "%.9lf ", this->data->QualitySession(index)); 00689 // } 00690 // fprintf(out, "\n"); 00691 // 00692 // fclose(out); 00693 // } 00694 // 00695 // /* 00696 // * Advanced statistics 00697 // */ 00698 // 00699 // // Statistics file in user form 00700 // 00701 // sprintf(fileName, "stat_%s_%u_%u.stat", this->name, this->topologyNumber, this->numChannelsMcast); 00702 // if(fopen_s(&out, fileName, "w")) printf("\nCannot write to file %s.", fileName); 00703 // else 00704 // { 00705 // // Save host statistics 00706 // fprintf(out, "\n\nHosts\n"); 00707 // fprintf(out, "\nHost Gw Read Write"); 00708 // fprintf(out, "\n======================================================================="); 00709 // 00710 // fprintf(out, "\nSERVER %3u %10I64u %10I64u", 00711 // this->gatewayServer, 00712 // this->server->StatPacketsRead(), 00713 // this->server->StatPacketsWrite()); 00714 // 00715 // for(__uint32 index = 0; index < this->numHosts; index++) 00716 // { 00717 // fprintf(out, "\nHOST %3u %3u %10I64u %10I64u", 00718 // index, 00719 // this->gateways[index], 00720 // this->hosts[index]->StatPacketsRead(), 00721 // this->hosts[index]->StatPacketsWrite() 00722 // ); 00723 // } 00724 // 00725 // // Save router statistics 00726 // fprintf(out, "\n\nRouters\n"); 00727 // fprintf(out, "\nRouter Read Write Entr IGMP Entr PIMSM "); 00728 // fprintf(out, "\n============================================================="); 00729 // 00730 // for(__uint32 index = 0; index < this->topology->Nodes(); index++) 00731 // { 00732 // fprintf(out, "\nROUTER %3u %10I64u %10I64u %10.5lf %10.5lf", 00733 // index, 00734 // this->routers[index]->StatPacketsRead(), 00735 // this->routers[index]->StatPacketsWrite(), 00736 // this->routers[index]->StatMcastEntries(), 00737 // this->routers[index]->StatMcastEntriesPimSm() 00738 // ); 00739 // } 00740 // 00741 // 00742 // // Save link statistics : server 00743 // fprintf(out, "\n\nServer link\n"); 00744 // fprintf(out, "\nLink Bw0 Bw1 Util00 Util01 Util10 Util11 Pack00 Disc00 Pack01 Disc01 Pack10 Disc10 Pack11 Disc11 Bits00 Bits01 Bits10 Bits11 Que00 Que01 Que10 Que11"); 00745 // fprintf(out, "\n========================================================================================================================================================================"); 00746 // 00747 // this->linkServer->Finalize(); 00748 // fprintf(out, "\n%3u %10.0lf %10.0lf : %6.4lf %6.4lf %6.4lf %6.4lf %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6.2lf %6.2lf %6.2lf %6.2lf ", 00749 // 0, 00750 // this->linkServer->Bandwidth(0), 00751 // this->linkServer->Bandwidth(1), 00752 // this->linkServer->StatUtilization(0, 0), 00753 // this->linkServer->StatUtilization(0, 1), 00754 // this->linkServer->StatUtilization(1, 0), 00755 // this->linkServer->StatUtilization(1, 1), 00756 // this->linkServer->StatPackets(0, 0), 00757 // this->linkServer->StatDiscard(0, 0), 00758 // this->linkServer->StatPackets(0, 1), 00759 // this->linkServer->StatDiscard(0, 1), 00760 // this->linkServer->StatPackets(1, 0), 00761 // this->linkServer->StatDiscard(1, 0), 00762 // this->linkServer->StatPackets(1, 1), 00763 // this->linkServer->StatDiscard(1, 1), 00764 // this->linkServer->StatBits(0, 0), 00765 // this->linkServer->StatBits(0, 1), 00766 // this->linkServer->StatBits(1, 0), 00767 // this->linkServer->StatBits(1, 1), 00768 // this->linkServer->StatQueue(0, 0), 00769 // this->linkServer->StatQueue(0, 1), 00770 // this->linkServer->StatQueue(1, 0), 00771 // this->linkServer->StatQueue(1, 1) 00772 // ); 00773 // 00774 // 00775 // // Save link statistics : access 00776 // fprintf(out, "\n\nAccess links\n"); 00777 // fprintf(out, "\nLink Bw0 Bw1 Util00 Util01 Util10 Util11 Pack00 Disc00 Pack01 Disc01 Pack10 Disc10 Pack11 Disc11 Bits00 Bits01 Bits10 Bits11 Que00 Que01 Que10 Que11"); 00778 // fprintf(out, "\n========================================================================================================================================================================"); 00779 // for(__uint32 index = 0; index < this->numHosts; index++) 00780 // { 00781 // this->linksAccess[index]->Finalize(); 00782 // fprintf(out, "\n%3u %10.0lf %10.0lf : %6.4lf %6.4lf %6.4lf %6.4lf %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6.2lf %6.2lf %6.2lf %6.2lf ", 00783 // index, 00784 // this->linksAccess[index]->Bandwidth(0), 00785 // this->linksAccess[index]->Bandwidth(1), 00786 // this->linksAccess[index]->StatUtilization(0, 0), 00787 // this->linksAccess[index]->StatUtilization(0, 1), 00788 // this->linksAccess[index]->StatUtilization(1, 0), 00789 // this->linksAccess[index]->StatUtilization(1, 1), 00790 // this->linksAccess[index]->StatPackets(0, 0), 00791 // this->linksAccess[index]->StatDiscard(0, 0), 00792 // this->linksAccess[index]->StatPackets(0, 1), 00793 // this->linksAccess[index]->StatDiscard(0, 1), 00794 // this->linksAccess[index]->StatPackets(1, 0), 00795 // this->linksAccess[index]->StatDiscard(1, 0), 00796 // this->linksAccess[index]->StatPackets(1, 1), 00797 // this->linksAccess[index]->StatDiscard(1, 1), 00798 // this->linksAccess[index]->StatBits(0, 0), 00799 // this->linksAccess[index]->StatBits(0, 1), 00800 // this->linksAccess[index]->StatBits(1, 0), 00801 // this->linksAccess[index]->StatBits(1, 1), 00802 // this->linksAccess[index]->StatQueue(0, 0), 00803 // this->linksAccess[index]->StatQueue(0, 1), 00804 // this->linksAccess[index]->StatQueue(1, 0), 00805 // this->linksAccess[index]->StatQueue(1, 1) 00806 // ); 00807 // } 00808 // 00809 // // Save link statistics : core 00810 // fprintf(out, "\n\nCore links\n"); 00811 // fprintf(out, "\nLink Bw0 Bw1 Util00 Util01 Util10 Util11 Pack00 Disc00 Pack01 Disc01 Pack10 Disc10 Pack11 Disc11 Bits00 Bits01 Bits10 Bits11 Que00 Que01 Que10 Que11"); 00812 // fprintf(out, "\n========================================================================================================================================================================"); 00813 // for(__uint32 index = 0; index < this->topology->Edges(); index++) 00814 // { 00815 // this->linksCore[index]->Finalize(); 00816 // fprintf(out, "\n%3u %10.0lf %10.0lf : %6.4lf %6.4lf %6.4lf %6.4lf %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6I64u %6.2lf %6.2lf %6.2lf %6.2lf ", 00817 // index, 00818 // this->linksCore[index]->Bandwidth(0), 00819 // this->linksCore[index]->Bandwidth(1), 00820 // this->linksCore[index]->StatUtilization(0, 0), 00821 // this->linksCore[index]->StatUtilization(0, 1), 00822 // this->linksCore[index]->StatUtilization(1, 0), 00823 // this->linksCore[index]->StatUtilization(1, 1), 00824 // this->linksCore[index]->StatPackets(0, 0), 00825 // this->linksCore[index]->StatDiscard(0, 0), 00826 // this->linksCore[index]->StatPackets(0, 1), 00827 // this->linksCore[index]->StatDiscard(0, 1), 00828 // this->linksCore[index]->StatPackets(1, 0), 00829 // this->linksCore[index]->StatDiscard(1, 0), 00830 // this->linksCore[index]->StatPackets(1, 1), 00831 // this->linksCore[index]->StatDiscard(1, 1), 00832 // this->linksCore[index]->StatBits(0, 0), 00833 // this->linksCore[index]->StatBits(0, 1), 00834 // this->linksCore[index]->StatBits(1, 0), 00835 // this->linksCore[index]->StatBits(1, 1), 00836 // this->linksCore[index]->StatQueue(0, 0), 00837 // this->linksCore[index]->StatQueue(0, 1), 00838 // this->linksCore[index]->StatQueue(1, 0), 00839 // this->linksCore[index]->StatQueue(1, 1) 00840 // ); 00841 // } 00842 // fclose(out); 00843 // } 00844 // 00845 // // Statistics file in computer form 00846 // 00847 // // Hosts 00848 // 00849 // sprintf(fileName, "hosts_%s_%u_%u.stat", this->name, this->topologyNumber, this->numChannelsMcast); 00850 // if(fopen_s(&out, fileName, "w")) printf("\nCannot write to file %s.", fileName); 00851 // else 00852 // { 00853 // // Save host statistics 00854 // fprintf(out, "0 %u %I64u %I64u\n", 00855 // this->gatewayServer, 00856 // this->server->StatPacketsRead(), 00857 // this->server->StatPacketsWrite()); 00858 // 00859 // for(__uint32 index = 0; index < this->numHosts; index++) 00860 // { 00861 // fprintf(out, "%u %u %I64u %I64u\n", 00862 // index, 00863 // this->gateways[index], 00864 // this->hosts[index]->StatPacketsRead(), 00865 // this->hosts[index]->StatPacketsWrite() 00866 // ); 00867 // } 00868 // 00869 // fclose(out); 00870 // } 00871 // // Routers 00872 // 00873 // sprintf(fileName, "routers_%s_%u_%u.stat", this->name, this->topologyNumber, this->numChannelsMcast); 00874 // if(fopen_s(&out, fileName, "w")) printf("\nCannot write to file %s.", fileName); 00875 // else 00876 // { 00877 // for(__uint32 index = 0; index < this->topology->Nodes(); index++) 00878 // { 00879 // fprintf(out, "%u %I64u %I64u %.9lf %.9lf\n", 00880 // index, 00881 // this->routers[index]->StatPacketsRead(), 00882 // this->routers[index]->StatPacketsWrite(), 00883 // this->routers[index]->StatMcastEntries(), 00884 // this->routers[index]->StatMcastEntriesPimSm() 00885 // ); 00886 // } 00887 // 00888 // fclose(out); 00889 // } 00890 // // Server link 00891 // 00892 // sprintf(fileName, "slink_%s_%u_%u.stat", this->name, this->topologyNumber, this->numChannelsMcast); 00893 // if(fopen_s(&out, fileName, "w")) printf("\nCannot write to file %s.", fileName); 00894 // else 00895 // { 00896 // fprintf(out, "%u %.0lf %.0lf %.9lf %.9lf %.9lf %.9lf %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %.9lf %.9lf %.9lf %.9lf\n", 00897 // 0, 00898 // this->linkServer->Bandwidth(0), 00899 // this->linkServer->Bandwidth(1), 00900 // this->linkServer->StatUtilization(0, 0), 00901 // this->linkServer->StatUtilization(0, 1), 00902 // this->linkServer->StatUtilization(1, 0), 00903 // this->linkServer->StatUtilization(1, 1), 00904 // this->linkServer->StatPackets(0, 0), 00905 // this->linkServer->StatDiscard(0, 0), 00906 // this->linkServer->StatPackets(0, 1), 00907 // this->linkServer->StatDiscard(0, 1), 00908 // this->linkServer->StatPackets(1, 0), 00909 // this->linkServer->StatDiscard(1, 0), 00910 // this->linkServer->StatPackets(1, 1), 00911 // this->linkServer->StatDiscard(1, 1), 00912 // this->linkServer->StatBits(0, 0), 00913 // this->linkServer->StatBits(0, 1), 00914 // this->linkServer->StatBits(1, 0), 00915 // this->linkServer->StatBits(1, 1), 00916 // this->linkServer->StatQueue(0, 0), 00917 // this->linkServer->StatQueue(0, 1), 00918 // this->linkServer->StatQueue(1, 0), 00919 // this->linkServer->StatQueue(1, 1) 00920 // ); 00921 // 00922 // fclose(out); 00923 // } 00924 // // Access links 00925 // 00926 // sprintf(fileName, "alink_%s_%u_%u.stat", this->name, this->topologyNumber, this->numChannelsMcast); 00927 // if(fopen_s(&out, fileName, "w")) printf("\nCannot write to file %s.", fileName); 00928 // else 00929 // { 00930 // for(__uint32 index = 0; index < this->numHosts; index++) 00931 // { 00932 // fprintf(out, "%u %.0lf %.0lf %.9lf %.9lf %.9lf %.9lf %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %.9lf %.9lf %.9lf %.9lf\n", 00933 // index, 00934 // this->linksAccess[index]->Bandwidth(0), 00935 // this->linksAccess[index]->Bandwidth(1), 00936 // this->linksAccess[index]->StatUtilization(0, 0), 00937 // this->linksAccess[index]->StatUtilization(0, 1), 00938 // this->linksAccess[index]->StatUtilization(1, 0), 00939 // this->linksAccess[index]->StatUtilization(1, 1), 00940 // this->linksAccess[index]->StatPackets(0, 0), 00941 // this->linksAccess[index]->StatDiscard(0, 0), 00942 // this->linksAccess[index]->StatPackets(0, 1), 00943 // this->linksAccess[index]->StatDiscard(0, 1), 00944 // this->linksAccess[index]->StatPackets(1, 0), 00945 // this->linksAccess[index]->StatDiscard(1, 0), 00946 // this->linksAccess[index]->StatPackets(1, 1), 00947 // this->linksAccess[index]->StatDiscard(1, 1), 00948 // this->linksAccess[index]->StatBits(0, 0), 00949 // this->linksAccess[index]->StatBits(0, 1), 00950 // this->linksAccess[index]->StatBits(1, 0), 00951 // this->linksAccess[index]->StatBits(1, 1), 00952 // this->linksAccess[index]->StatQueue(0, 0), 00953 // this->linksAccess[index]->StatQueue(0, 1), 00954 // this->linksAccess[index]->StatQueue(1, 0), 00955 // this->linksAccess[index]->StatQueue(1, 1) 00956 // ); 00957 // } 00958 // 00959 // fclose(out); 00960 // } 00961 // 00962 // // Core links 00963 // 00964 // sprintf(fileName, "clink_%s_%u_%u.stat", this->name, this->topologyNumber, this->numChannelsMcast); 00965 // if(fopen_s(&out, fileName, "w")) printf("\nCannot write to file %s.", fileName); 00966 // else 00967 // { 00968 // for(__uint32 index = 0; index < this->topology->Edges(); index++) 00969 // { 00970 // fprintf(out, "%u %.0lf %.0lf %.9lf %.9lf %.9lf %.9lf %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %I64u %.9lf %.9lf %.9lf %.9lf\n", 00971 // index, 00972 // this->linksCore[index]->Bandwidth(0), 00973 // this->linksCore[index]->Bandwidth(1), 00974 // this->linksCore[index]->StatUtilization(0, 0), 00975 // this->linksCore[index]->StatUtilization(0, 1), 00976 // this->linksCore[index]->StatUtilization(1, 0), 00977 // this->linksCore[index]->StatUtilization(1, 1), 00978 // this->linksCore[index]->StatPackets(0, 0), 00979 // this->linksCore[index]->StatDiscard(0, 0), 00980 // this->linksCore[index]->StatPackets(0, 1), 00981 // this->linksCore[index]->StatDiscard(0, 1), 00982 // this->linksCore[index]->StatPackets(1, 0), 00983 // this->linksCore[index]->StatDiscard(1, 0), 00984 // this->linksCore[index]->StatPackets(1, 1), 00985 // this->linksCore[index]->StatDiscard(1, 1), 00986 // this->linksCore[index]->StatBits(0, 0), 00987 // this->linksCore[index]->StatBits(0, 1), 00988 // this->linksCore[index]->StatBits(1, 0), 00989 // this->linksCore[index]->StatBits(1, 1), 00990 // this->linksCore[index]->StatQueue(0, 0), 00991 // this->linksCore[index]->StatQueue(0, 1), 00992 // this->linksCore[index]->StatQueue(1, 0), 00993 // this->linksCore[index]->StatQueue(1, 1) 00994 // ); 00995 // } 00996 // 00997 // fclose(out); 00998 // } 00999 //#endif 01000 01001 /* 01002 * Cleanup objects created during simulation (objects that cannot be deleted in the destructor because they depend on the simulator) 01003 */ 01004 01005 // Delete hosts 01006 if(this->hosts) 01007 { 01008 for(__uint32 index = 0; index < this->numHosts; index++) 01009 delete this->hosts[index]; 01010 delete[] this->hosts; 01011 } 01012 01013 // Delete routers 01014 if(this->routers) 01015 { 01016 for(__uint32 index = 0; index < this->topology->Nodes(); index++) 01017 delete this->routers[index]; 01018 delete[] this->routers; 01019 } 01020 01021 // Delete server 01022 if(this->server) delete this->server; 01023 01024 // Delete links core 01025 if(this->linksCore) 01026 { 01027 for(__uint32 index = 0; index < this->topology->Edges(); index++) 01028 delete this->linksCore[index]; 01029 delete[] this->linksCore; 01030 } 01031 01032 // Delete links access 01033 if(this->linksAccess) 01034 { 01035 for(__uint32 index = 0; index < this->numHosts; index++) 01036 delete this->linksAccess[index]; 01037 delete[] this->linksAccess; 01038 } 01039 01040 // Delete link server 01041 if(this->linkServer) delete this->linkServer; 01042 } 01043 01044 int CModelPushSelect::Forward(CAddress node, CAddress dst) 01045 { 01046 // Calculates the outgoing link when the router receives a packet with a certain destination 01047 assert(node.Address() <= this->routeNodes); 01048 assert(dst.Address() <= this->routeDst); 01049 01050 return this->route[node.Address()][dst.Address()]; 01051 } 01052 01053 CChannel* CModelPushSelect::Channel(__uint32 index) 01054 { 01055 assert(index < this->numChannels); 01056 return &this->channels[index]; 01057 }
Last updated: February 8, 2011