📄 switching.c
字号:
if(packetGenerateRandom < 0) packetGenerateRandom = -packetGenerateRandom; if(packetGenerateRandom < packetGenProb) packet[index1].stateCreated = true; else packet[index1].stateCreated = false; //printf("\npacket Generate :%f",packetGenerateRandom); packet[index1].startDelay = 0; packet[index1].endDelay = 0; packet[index1].delay = 0; packet[index1].startTime = itter+((rand())%101)*0.0001; packet[index1].slotNo = itter; packet[index1].inputPort = inputPort; packet[index1].outputPort = rand()%noOfPorts; packet[index1].discarded = false; if(packet[index1].outputPort < 0) packet[index1].outputPort = -packet[index1].outputPort; //printf("\nStart time: %f Output Port:%d Input port:%d\n",packet[index1].startTime,packet[index1].outputPort,packet[index1].inputPort); initializeInputQueue(packet[index1].inputPort); if(packet[index1].stateCreated == true) { enInputQueue(packet[index1].inputPort,index1,1); packet[index1].startDelay=nowTime(); } index1++; } for(outputPort = 0;outputPort < noOfPorts; outputPort++) initializeOutputQueue(outputPort); /*Packet select for Output port or discard*/ for(outputPort = 0;outputPort < noOfPorts; outputPort++) { if(packet[index2].stateCreated == true) { tempindex = deInputQueue(packet[index2].inputPort); if(outSend[packet[index2].outputPort] == -1) { //printf("Packet at Output port :%d",packet[index2].outputPort); outSend[packet[index2].outputPort] = packet[index2].inputPort; enOutputQueue(packet[index2].outputPort,index2,1); //bufferLength is 1 as only 1 output buffer. /*calculating the time delay between recieved and transmitted packet*/ retValue = deOutputQueue(packet[index2].outputPort); //transmit that packet for that slot.... if(retValue != -1) { linkUtilization[packet[index2].inputPort].activeLink[packet[index2].outputPort]+=1; packet[index2].endDelay = nowTime(); packet[index2].delay = packet[index2].endDelay-packet[index2].startDelay; //printf("Delay is in microsec:%d\n\n",packet[index2].delay); } } else packet[index2].discarded = true; if(packet[index2].discarded == true) { //printf("\nStart time: %f Output Port:%d Input port:ABCDEFG%d \n",packet[index2].startTime,packet[index2].outputPort,packet[index2].inputPort); } //if(packet[index2].endDelay != 0) if(packet[tempindex].delay > 0) { intermediateVal1[index++]=packet[index2].delay; tempDelay += packet[index2].delay; } } index2++; } //tempDelay = tempDelay/noOfPorts; //printf("\n-------------------------------------------------------------------------------\n"); } averageDelay = tempDelay/(noOfPorts*maxTimeSlot*1.0); for (count=0;count<index;count++) devIntermediate+=(intermediateVal1[count]-averageDelay)*(intermediateVal1[count]-averageDelay); devIntermediate=devIntermediate*1.0/(noOfPorts*maxTimeSlot); stdDevDelay=sqrt(devIntermediate); //stdDevDelay = (tempDelayStd/(noOfPorts*maxTimeSlot*1.0)-(averageDelay*averageDelay*1.0)); ///problem here how to find out std deviation............... //printf("\n\nAVERAGE DELAY FOR INQ IS: %fus STANDERED DEVIATION:%f \n",averageDelay,stdDevDelay); indexcount=0; /*Average link utilization*/ for(inputPort = 0;inputPort < noOfPorts; inputPort++) { for(outputPort = 0;outputPort < noOfPorts; outputPort++) { linkUtilization[inputPort].averageLink[outputPort] = linkUtilization[inputPort].activeLink[outputPort]*1.0/maxTimeSlot; //printf("link utilization for the link %d %d is %f\n",inputPort,outputPort,linkUtilization[inputPort].averageLink[outputPort]); intermediateVal2[indexcount++]=linkUtilization[inputPort].averageLink[outputPort]; tempLinkUtilization += linkUtilization[inputPort].averageLink[outputPort]; } } averageLinkUtilization=tempLinkUtilization/(noOfPorts*1.0); for (count=0;count<indexcount;count++) devIntermediate+=(intermediateVal2[count]-averageLinkUtilization)*(intermediateVal2[count]-averageLinkUtilization); devIntermediate=devIntermediate*1.0/(noOfPorts*maxTimeSlot); stdDevLinkUtilization=sqrt(devIntermediate); /*Printing in a standered ouput*/ printf("\nN p Q Type Avg PD Std Dev of PD Avg LU Std Dev of LU Switch Util"); printf("\n%d %f %s %fus %f %f %f %f\n",noOfPorts,packetGenProb,queue,averageDelay,stdDevDelay,tempLinkUtilization/(noOfPorts*1.0),stdDevLinkUtilization,tempLinkUtilization); /*Printing in a file*/ fprintf(of,"\n%d %f %s %fus %f %f %f\n",noOfPorts,packetGenProb,queue,averageDelay,stdDevDelay,tempLinkUtilization/(noOfPorts*1.0),stdDevLinkUtilization,tempLinkUtilization); fprintf(graphFile1,"%d %f\n",noOfPorts,averageDelay); fprintf(graphFile2,"%d %f\n",noOfPorts,tempLinkUtilization); } break;/****************************************************************************************** Logic for Input Queueing - INQ *******************************************************************************************/ case 1 : for(noOfPorts=4;noOfPorts<101;noOfPorts++) { /*Initialize the intput queue for each input port*/ for(inputPort = 0;inputPort < noOfPorts; inputPort++) initializeInputQueue(inputPort); for(N1=0;N1<noOfPorts;N1++) for(N2=0;N2<noOfPorts;N2++) { linkUtilization[N1].activeLink[N2]=0; linkUtilization[N1].averageLink[N2]=0.0; } tempDelay=0; tempLinkUtilization=0; devIntermediate=0; index1=0; index2=0; index=0; for(itter = 0;itter < maxTimeSlot;itter++) { for(i=0;i<noOfPorts;i++) outSend[i] = -1; /*Packet Generation */ for(inputPort = 0;inputPort < noOfPorts; inputPort++) { /*Every time packet is created but its state is CREATED or NOTCREATED i.e. if created then process otherwise dont and depends on the probability of the generation i.e. random value created..*/ /* IF(CREATED) packet[index1].stateCreated=true ELSE packet[index1].stateCreated=false*/ packetGenerateRandom = (rand()%100)*0.01; if(packetGenerateRandom < 0) packetGenerateRandom = -packetGenerateRandom; if(packetGenerateRandom < packetGenProb) packet[index1].stateCreated = true; else packet[index1].stateCreated = false; //printf("\npacket Generate :%f",packetGenerateRandom); packet[index1].startDelay = 0; packet[index1].endDelay = 0; //if endDelay == 0 at the end then this packet is still in the i/p queue. packet[index1].delay = 0; packet[index1].startTime = itter+((rand())%101)*0.0001; packet[index1].slotNo = itter; packet[index1].inputPort = inputPort; packet[index1].outputPort = rand()%noOfPorts; packet[index1].discarded = false; if(packet[index1].outputPort < 0) packet[index1].outputPort = -packet[index1].outputPort; //printf("\nStart time: %f Output Port:%d Input port:%d\n",packet[index1].startTime,packet[index1].outputPort,packet[index1].inputPort); if(packet[index1].stateCreated == true) { enInputQueue(packet[index1].inputPort,index1,bufferSize); packet[index1].startDelay=nowTime(); } index1++; } for(outputPort = 0;outputPort < noOfPorts; outputPort++) initializeOutputQueue(outputPort); /*Packet select for Output port or discard*/ for(outputPort = 0;outputPort < noOfPorts; outputPort++) { tempindexFrmQueue = false; if(itter == 0) tempindex = index2; else if(inputQ[outputPort].rear != inputQ[outputPort].front) { tempindex = inputQ[outputPort].packetSlot[inputQ[outputPort].front]; tempindexFrmQueue = true; } else tempindex = index2; if(packet[tempindex].stateCreated == true) { if(outSend[packet[tempindex].outputPort] == -1) { if(tempindexFrmQueue == true) deInputQueue(packet[tempindex].inputPort); outSend[packet[tempindex].outputPort] = packet[tempindex].inputPort; enOutputQueue(packet[tempindex].outputPort,index2,1); //bufferLength is 1 as only 1 output buffer. /*calculating the time delay between recieved and transmitted packet*/ if(packet[tempindex].startDelay == 0) //i.e. this packet was not queued in INPUT QUEUE. packet[tempindex].startDelay = nowTime(); retValue = deOutputQueue(packet[tempindex].outputPort); //transmit that packet for that slot.... if(retValue != -1) { linkUtilization[packet[tempindex].inputPort].activeLink[packet[tempindex].outputPort]+=1; packet[tempindex].endDelay = nowTime(); packet[tempindex].delay = packet[tempindex].endDelay-packet[tempindex].startDelay; //printf("Delay is in microsec:%d\n\n",packet[tempindex].delay); } } else if(tempindexFrmQueue == false) { packet[tempindex].startDelay = nowTime(); enInputQueue(packet[tempindex].inputPort,tempindex,bufferSize); } //if(packet[tempindex].endDelay != 0) if(packet[tempindex].delay > 0) { intermediateVal1[index++]=packet[tempindex].delay; tempDelay += packet[tempindex].delay/noOfPorts; } } index2++; } //printf("\n-------------------------------------------------------------------------------\n"); } averageDelay = tempDelay/(noOfPorts*maxTimeSlot); for (count=0;count<index;count++) devIntermediate+=(intermediateVal1[count]-averageDelay)*(intermediateVal1[count]-averageDelay); devIntermediate=devIntermediate*1.0/(noOfPorts*maxTimeSlot); stdDevDelay=sqrt(devIntermediate); //stdDevDelay = (averageDelay*averageDelay)-tempDelayStd/(noOfPorts*maxTimeSlot); //printf("\n\nAVERAGE DELAY FOR INQ IS: %fus STANDERED DEVIATION:%f \n",averageDelay,stdDevDelay); indexcount=0; /*Average link utilization*/ for(inputPort = 0;inputPort < noOfPorts; inputPort++) { for(outputPort = 0;outputPort < noOfPorts; outputPort++) { linkUtilization[inputPort].averageLink[outputPort] = linkUtilization[inputPort].activeLink[outputPort]*1.0/maxTimeSlot; //printf("link utilization for the link %d %d is %f\n",inputPort,outputPort,linkUtilization[inputPort].averageLink[outputPort]); intermediateVal2[indexcount++]=linkUtilization[inputPort].averageLink[outputPort]; tempLinkUtilization += linkUtilization[inputPort].averageLink[outputPort]; } } averageLinkUtilization=tempLinkUtilization/(noOfPorts*1.0); for (count=0;count<indexcount;count++) devIntermediate+=(intermediateVal2[count]-averageLinkUtilization)*(intermediateVal2[count]-averageLinkUtilization); devIntermediate=devIntermediate*1.0/(noOfPorts*maxTimeSlot); stdDevLinkUtilization=sqrt(devIntermediate); //printf("\n\nAVERAGE LINK UTILIZATION FOR NOQ IS: %f\nSTANDERED DEVIATION: %f \nSWITCH UTILIZATION: %f\n",tempLinkUtilization/ (noOfPorts*1.0),stdDevLinkUtilization,tempLinkUtilization); /*Printing in a standered ouput*/ printf("\nN p Q Type Avg PD Std Dev of PD Avg LU Std Dev of LU Switch Util"); printf("\n%d %f %s %fus %f %f %f %f\n",noOfPorts,packetGenProb,queue,averageDelay,stdDevDelay,tempLinkUtilization/(noOfPorts*1.0),stdDevLinkUtilization,tempLinkUtilization); /*Printing in a file*/ fprintf(of,"\n%d %f %s %fus %f %f %f %f\n",noOfPorts,packetGenProb,queue,averageDelay,stdDevDelay,tempLinkUtilization/(noOfPorts*1.0),stdDevLinkUtilization,tempLinkUtilization); fprintf(graphFile3,"%d %f\n",noOfPorts,averageDelay); fprintf(graphFile4,"%d %f\n",noOfPorts,tempLinkUtilization); } break;/****************************************************************************************** Logic for Itterative Matching Queueing - INI *******************************************************************************************/ case 2 : for(noOfPorts=4;noOfPorts<101;noOfPorts++) { for(N1=0;N1<noOfPorts;N1++) for(N2=0;N2<noOfPorts;N2++) { linkUtilization[N1].activeLink[N2]=0; linkUtilization[N1].averageLink[N2]=0; } /*Initialize the intput queue for each input port*/ for(inputPort = 0;inputPort < noOfPorts; inputPort++) initializeInputQueue(inputPort); tempDelay=0; tempLinkUtilization=0; devIntermediate=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -