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