package Simulator; //import java.awt.*; //import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.JPanel; public class CprobStatistic extends NetworkConfigure { StatisChart chart; JPanel p; /*boolean NeedTraffic = false; // Link object use it double msgProcessingTime=0.0001; // 0.1 msec double RouterBandwidth = 1.0E+9; double LinkBandwidth = 1.0E+7; // 10MBps double signalPropagationSpeed = 2.0E+8; // fiber speed */ int numOfRouter; // how many router int numOfLink; // how many link int numOfRoad=1; // how many different router road, always 1 double LinkBandwidth = 1.0E+7; // always 10MBps // tested variant int MessNum; // message quantity int MessSize; int HopNumber; // Hop represents router nubmer int LinkLength; // link length (meters) protected Random rnd; PrintWriter LogFile; // log file PrintWriter PFile; // log file for probing message PrintWriter EventFile; // log file for events int argu1; int argu2; float argu3; int argu4; int argu5; int argu6; int argu7; public CprobStatistic(String TestType,int argu1, int argu2, float argu3, int argu4, int argu5, int argu6, int argu7, JPanel p) { this.argu1 = argu1; this.argu2 = argu2; this.argu3 = argu3; this.argu4 = argu4; this.argu5 = argu5; this.argu6 = argu6; this.argu7 = argu7; // only for Router speed test this.p = p; RoadTable = new RouterTable[numOfRoad]; EQ = new EventsQueue(RoadTable); try { LogFile = new PrintWriter(new FileWriter("log.txt")); PFile = new PrintWriter(new FileWriter("probing.txt")); //EventFile = new PrintWriter(new FileWriter("Events.txt")); } catch(IOException k) { System.out.print("Error" + k); System.exit(1); } // need an outer loop to do the cprobing if (TestType.equals("MessSize")) Size_Statistic(); if (TestType.equals("MessQuantity")) Quantity_Statistic(); if (TestType.equals("LinkLength")) LinkLen_Statistic(); if (TestType.equals("RouterSpeed")) RSpeed_Statistic(); if (TestType.equals("HopNumber")) HopNum_Statistic(); } private void HopNum_Statistic() { // router1 is the Cprobing agent. Message M,NewM; double firstReiceptTime=0; MessSize = argu4*8; LinkLength = argu5; MessNum = argu6; chart = new StatisChart(argu1,argu2,10,"Hop",0,10,10,"MBps",p); // initialization end float step = argu1; // Message Size is the variant for ( ; step<=argu2; ) { HopNumber = (int) step; // initialize the network configuration // create the router table numOfRouter = HopNumber; numOfLink = HopNumber - 1; Routers = new Router[numOfRouter+1]; Links = new Link[numOfLink+1]; // generate all the routers: range starts from 1 for(int i=1; i<= numOfRouter; i++) Routers[i] = new Router((CprobStatistic) this,i); // generate all the links: range starts from 1 for(int i=1; i<= numOfLink; i++) { Links[i] = new Link(this,LinkLength,i,LinkBandwidth); } int RoadNodeNum = 2*HopNumber - 1; RoadTable[0] = new RouterTable(0,RoadNodeNum); int num=0; for (int i=1; i< HopNumber; i++) { RoadTable[0].append(Routers[i],num++); RoadTable[0].append(Links[i],num++); } RoadTable[0].append(Routers[HopNumber],num++); // generate the initial probing message, size is static value 46 bytes M = new Message(0,0,"CProbe-start",46*8,0); // the message nubmer is useless. EQ.insert(M); double SendingTime=0.0; // the sending time of the first Cproing Message // start Cprobing while ((M = EQ.nextItem()) != null) { boolean flag = false; String MessageType = M.MessageType; if (MessageType.compareTo("CProbe-start") == 0) { SendingTime = M.getArrivalTime(); double NextSendingTime = M.getArrivalTime(); // A new Cprobing cycle starts for (int j=1; j<=MessNum;j++) { // generate the Cprobing mess NewM = new Message(j,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-request",MessSize,NextSendingTime,0,UnitripProbe); RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); EQ.insert(NewM); NextSendingTime = NewM.getArrivalTime(); } flag = true; } if (!flag && (MessageType.compareTo("CP-request") == 0)) { // wakeup the corresponding object to handle this message // set the wakeup time of the message next time. NewM = new Message(M.MessNum,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-request",MessSize,M.getArrivalTime(),M.NextObjectIndex,UnitripProbe); RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); EQ.insert(NewM); flag = true; } if (!flag && (MessageType.compareTo("CP-response") == 0)) { // wakeup the corresponding object to handle this message // set the wakeup time of the message next time. //double old_ArrivalTime = M.getArrivalTime(); NewM = new Message(M.MessNum,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-response",MessSize,M.getArrivalTime(),M.NextObjectIndex,UnitripProbe); boolean responseMess_GetToDestination = RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); if (!responseMess_GetToDestination) EQ.insert(NewM); // The response message does not back to its source else { if (NewM.MessNum == 1) firstReiceptTime = NewM.getArrivalTime(); if (NewM.MessNum == MessNum) { // the last one return //double Measued_Band = (MessSize * MessNum) / (NewM.getArrivalTime() - NewM.Pstarting_time); double Measued_Band = (MessSize * (MessNum-1)) / (NewM.getArrivalTime() - firstReiceptTime); chart.Cupdate(step,Measued_Band*10/LinkBandwidth); } } // end of if } EQ.remove(); // remove the first message from the event queue }// end of while step += argu3; } // end of for } // end of HopNum_statistic private void RSpeed_Statistic() { // router1 is the Cprobing agent. Message M,NewM; double firstReiceptTime=0; MessSize = argu4*8; LinkLength = argu5; MessNum = argu6; HopNumber = argu7; // initialize the network configuration // create the router table numOfRouter = HopNumber; numOfLink = HopNumber - 1; Routers = new Router[numOfRouter+1]; Links = new Link[numOfLink+1]; // generate all the routers: range starts from 1 for(int i=1; i<= numOfRouter; i++) Routers[i] = new Router((CprobStatistic) this,i); // generate all the links: range starts from 1 for(int i=1; i<= numOfLink; i++) { Links[i] = new Link(this,LinkLength,i,LinkBandwidth); } int RoadNodeNum = 2*HopNumber - 1; RoadTable[0] = new RouterTable(0,RoadNodeNum); int num=0; for (int i=1; i< HopNumber; i++) { RoadTable[0].append(Routers[i],num++); RoadTable[0].append(Links[i],num++); } RoadTable[0].append(Routers[HopNumber],num++); chart = new StatisChart(argu1,argu2,10,"MBps",0,10,10,"MBps",p); // initialization end float step = argu1; // Message Size is the variant for ( ; step<=argu2; ) { super.msgProcessingSpeed = (double) (step * 1e+6); // generate the initial probing message, size is static value 46 bytes M = new Message(0,0,"CProbe-start",46*8,0); // the message nubmer is useless. EQ.insert(M); double SendingTime=0.0; // the sending time of the first Cproing Message // start Cprobing while ((M = EQ.nextItem()) != null) { boolean flag = false; String MessageType = M.MessageType; if (MessageType.compareTo("CProbe-start") == 0) { SendingTime = M.getArrivalTime(); double NextSendingTime = M.getArrivalTime(); // A new Cprobing cycle starts for (int j=1; j<=MessNum;j++) { // generate the Cprobing mess NewM = new Message(j,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-request",MessSize,NextSendingTime,0,UnitripProbe); RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); EQ.insert(NewM); NextSendingTime = NewM.getArrivalTime(); } flag = true; } if (!flag && (MessageType.compareTo("CP-request") == 0)) { // wakeup the corresponding object to handle this message // set the wakeup time of the message next time. NewM = new Message(M.MessNum,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-request",MessSize,M.getArrivalTime(),M.NextObjectIndex,UnitripProbe); RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); EQ.insert(NewM); flag = true; } if (!flag && (MessageType.compareTo("CP-response") == 0)) { // wakeup the corresponding object to handle this message // set the wakeup time of the message next time. //double old_ArrivalTime = M.getArrivalTime(); NewM = new Message(M.MessNum,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-response",MessSize,M.getArrivalTime(),M.NextObjectIndex,UnitripProbe); boolean responseMess_GetToDestination = RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); if (!responseMess_GetToDestination) EQ.insert(NewM); // The response message does not back to its source else { if (NewM.MessNum == 1) firstReiceptTime=NewM.getArrivalTime(); if (NewM.MessNum == MessNum) { // the last one return //double Measued_Band = (MessSize * MessNum) / (NewM.getArrivalTime() - NewM.Pstarting_time); double Measued_Band = (MessSize * (MessNum-1)) / (NewM.getArrivalTime() - firstReiceptTime); /* LogFile.println("CProbing start Time: "+ M.Pstarting_time + " End Time: " + M.getArrivalTime() + " Measured BandWidth: "+ Measued_Band); */ chart.Cupdate(step,Measued_Band*10/LinkBandwidth); } } // end of if } EQ.remove(); // remove the first message from the event queue }// end of while LocalTime_reset(); // reset the local time of links and routers step += argu3; } // end of for } // end of RSpeed_statistic private void LinkLen_Statistic() { // router1 is the Cprobing agent. Message M,NewM; double firstReiceptTime=0; MessSize = argu4*8; MessNum = argu5; HopNumber = argu6; LinkLength = argu1; // initialize the network configuration // create the router table numOfRouter = HopNumber; numOfLink = HopNumber - 1; Routers = new Router[numOfRouter+1]; Links = new Link[numOfLink+1]; // generate all the routers: range starts from 1 for(int i=1; i<= numOfRouter; i++) Routers[i] = new Router((CprobStatistic) this,i); // generate all the links: range starts from 1 for(int i=1; i<= numOfLink; i++) { Links[i] = new Link(this,LinkLength,i,LinkBandwidth); } int RoadNodeNum = 2*HopNumber - 1; RoadTable[0] = new RouterTable(0,RoadNodeNum); int num=0; for (int i=1; i< HopNumber; i++) { RoadTable[0].append(Routers[i],num++); RoadTable[0].append(Links[i],num++); } RoadTable[0].append(Routers[HopNumber],num++); chart = new StatisChart(argu1,argu2,10,"Meters",0,10,10,"MBps",p); // initialization end float step = argu1; // Message Size is the variant for ( ; step<=argu2; ) { LinkLength = (int)step; // change the link length for(int i=1; i<= numOfLink; i++) { Links[i].Distance = LinkLength; } // generate the initial probing message, size is static value 46 bytes M = new Message(0,0,"CProbe-start",46*8,0); // the message nubmer is useless. EQ.insert(M); double SendingTime=0.0; // the sending time of the first Cproing Message // start Cprobing while ((M = EQ.nextItem()) != null) { boolean flag = false; String MessageType = M.MessageType; if (MessageType.compareTo("CProbe-start") == 0) { SendingTime = M.getArrivalTime(); double NextSendingTime = M.getArrivalTime(); // A new Cprobing cycle starts for (int j=1; j<=MessNum;j++) { // generate the Cprobing mess NewM = new Message(j,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-request",MessSize,NextSendingTime,0,UnitripProbe); RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); EQ.insert(NewM); NextSendingTime = NewM.getArrivalTime(); } flag = true; } if (!flag && (MessageType.compareTo("CP-request") == 0)) { // wakeup the corresponding object to handle this message // set the wakeup time of the message next time. NewM = new Message(M.MessNum,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-request",MessSize,M.getArrivalTime(),M.NextObjectIndex,UnitripProbe); RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); EQ.insert(NewM); flag = true; } if (!flag && (MessageType.compareTo("CP-response") == 0)) { // wakeup the corresponding object to handle this message // set the wakeup time of the message next time. //double old_ArrivalTime = M.getArrivalTime(); NewM = new Message(M.MessNum,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-response",MessSize,M.getArrivalTime(),M.NextObjectIndex,UnitripProbe); boolean responseMess_GetToDestination = RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); if (!responseMess_GetToDestination) EQ.insert(NewM); // The response message does not back to its source else { if (NewM.MessNum == 1) firstReiceptTime=NewM.getArrivalTime(); if (NewM.MessNum == MessNum) { // the last one return //double Measued_Band = (MessSize * MessNum) / (NewM.getArrivalTime() - NewM.Pstarting_time); double Measued_Band = (MessSize * (MessNum-1)) / (NewM.getArrivalTime() - firstReiceptTime); chart.Cupdate(LinkLength,Measued_Band*10/LinkBandwidth); } } // end of if } EQ.remove(); // remove the first message from the event queue }// end of while step += argu3; LocalTime_reset(); // reset the local time of links and routers } // end of for } // end of LinkLen_statistic private void Quantity_Statistic() { // router1 is the Cprobing agent. Message M,NewM; double firstReiceptTime=0; MessSize = argu4*8; LinkLength = argu5; HopNumber = argu6; // initialize the network configuration // create the router table numOfRouter = HopNumber; numOfLink = HopNumber - 1; Routers = new Router[numOfRouter+1]; Links = new Link[numOfLink+1]; // generate all the routers: range starts from 1 for(int i=1; i<= numOfRouter; i++) Routers[i] = new Router((CprobStatistic) this,i); // generate all the links: range starts from 1 for(int i=1; i<= numOfLink; i++) { Links[i] = new Link(this,LinkLength,i,LinkBandwidth); } int RoadNodeNum = 2*HopNumber - 1; RoadTable[0] = new RouterTable(0,RoadNodeNum); int num=0; for (int i=1; i< HopNumber; i++) { RoadTable[0].append(Routers[i],num++); RoadTable[0].append(Links[i],num++); } RoadTable[0].append(Routers[HopNumber],num++); chart = new StatisChart(argu1,argu2,10,"Quan",0,10,10,"MBps",p); // initialization end float step = argu1; // Message Size is the variant for ( ; step<=argu2; ) { MessNum = (int)step; // generate the initial probing message, size is static value 46 bytes M = new Message(0,0,"CProbe-start",46*8,0); // the message nubmer is useless. EQ.insert(M); double SendingTime=0.0; // the sending time of the first Cproing Message // start Cprobing while ((M = EQ.nextItem()) != null) { boolean flag = false; String MessageType = M.MessageType; if (MessageType.compareTo("CProbe-start") == 0) { SendingTime = M.getArrivalTime(); double NextSendingTime = M.getArrivalTime(); // A new Cprobing cycle starts for (int j=1; j<=MessNum;j++) { // generate the Cprobing mess NewM = new Message(j,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-request",MessSize,NextSendingTime,0,UnitripProbe); RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); EQ.insert(NewM); NextSendingTime = NewM.getArrivalTime(); } flag = true; } if (!flag && (MessageType.compareTo("CP-request") == 0)) { // wakeup the corresponding object to handle this message // set the wakeup time of the message next time. NewM = new Message(M.MessNum,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-request",MessSize,M.getArrivalTime(),M.NextObjectIndex,UnitripProbe); RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); EQ.insert(NewM); flag = true; } if (!flag && (MessageType.compareTo("CP-response") == 0)) { // wakeup the corresponding object to handle this message // set the wakeup time of the message next time. //double old_ArrivalTime = M.getArrivalTime(); NewM = new Message(M.MessNum,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-response",MessSize,M.getArrivalTime(),M.NextObjectIndex,UnitripProbe); boolean responseMess_GetToDestination = RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); if (!responseMess_GetToDestination) EQ.insert(NewM); // The response message does not back to its source else { if (NewM.MessNum == 1) firstReiceptTime=NewM.getArrivalTime(); if (NewM.MessNum == MessNum) { // the last one return //double Measued_Band = (MessSize * MessNum) / (NewM.getArrivalTime() - NewM.Pstarting_time); double Measued_Band = (MessSize * (MessNum-1)) / (NewM.getArrivalTime() - firstReiceptTime); /* LogFile.println("CProbing start Time: "+ M.Pstarting_time + " End Time: " + M.getArrivalTime() + " Measured BandWidth: "+ Measued_Band); */ chart.Cupdate(MessNum,Measued_Band*10/LinkBandwidth); } } // end of if } EQ.remove(); // remove the first message from the event queue }// end of while step += argu3; LocalTime_reset(); // reset the local time of links and routers } // end of for } // end of Quantity_statistic private void Size_Statistic() { // router1 is the Cprobing agent. Message M,NewM; double firstReiceptTime=0; MessNum = argu4; LinkLength = argu5; HopNumber = argu6; // initialize the network configuration // create the router table numOfRouter = HopNumber; numOfLink = HopNumber - 1; Routers = new Router[numOfRouter+1]; Links = new Link[numOfLink+1]; // generate all the routers: range starts from 1 for(int i=1; i<= numOfRouter; i++) Routers[i] = new Router((CprobStatistic) this,i); // generate all the links: range starts from 1 for(int i=1; i<= numOfLink; i++) { Links[i] = new Link(this,LinkLength,i,LinkBandwidth); } int RoadNodeNum = 2*HopNumber - 1; RoadTable[0] = new RouterTable(0,RoadNodeNum); int num=0; for (int i=1; i< HopNumber; i++) { RoadTable[0].append(Routers[i],num++); RoadTable[0].append(Links[i],num++); } RoadTable[0].append(Routers[HopNumber],num++); chart = new StatisChart(argu1,argu2,10,"Bytes",0,10,10,"MBps",p); // initialization end float step = argu1; // Message Size is the variant for ( ; step<=argu2; ) { MessSize = (int) (step*8); // generate the initial probing message, size is static value 46 bytes M = new Message(0,0,"CProbe-start",46*8,0); // the message nubmer is useless. EQ.insert(M); double SendingTime=0.0; // the sending time of the first Cproing Message // start Cprobing while ((M = EQ.nextItem()) != null) { boolean flag = false; String MessageType = M.MessageType; if (MessageType.compareTo("CProbe-start") == 0) { SendingTime = M.getArrivalTime(); double NextSendingTime = M.getArrivalTime(); // A new Cprobing cycle starts for (int j=1; j<=MessNum;j++) { // generate the Cprobing mess NewM = new Message(j,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-request",MessSize,NextSendingTime,0,UnitripProbe); RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); EQ.insert(NewM); NextSendingTime = NewM.getArrivalTime(); } flag = true; } if (!flag && (MessageType.compareTo("CP-request") == 0)) { // wakeup the corresponding object to handle this message // set the wakeup time of the message next time. NewM = new Message(M.MessNum,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-request",MessSize,M.getArrivalTime(),M.NextObjectIndex,UnitripProbe); RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); EQ.insert(NewM); flag = true; } if (!flag && (MessageType.compareTo("CP-response") == 0)) { // wakeup the corresponding object to handle this message // set the wakeup time of the message next time. //double old_ArrivalTime = M.getArrivalTime(); NewM = new Message(M.MessNum,M.RouterTableNum,RoadTable[M.RouterTableNum].numOfNode, SendingTime,"CP-response",MessSize,M.getArrivalTime(),M.NextObjectIndex,UnitripProbe); boolean responseMess_GetToDestination = RoadTable[NewM.RouterTableNum].Node(NewM.NextObjectIndex).EventHandler(NewM); if (!responseMess_GetToDestination) EQ.insert(NewM); // The response message does not back to its source else { if (NewM.MessNum == 1) firstReiceptTime=NewM.getArrivalTime(); if (NewM.MessNum == MessNum) { // the last one return //double Measued_Band = (MessSize * MessNum) / (NewM.getArrivalTime() - NewM.Pstarting_time); double Measued_Band = (MessSize * (MessNum-1)) / (NewM.getArrivalTime() - firstReiceptTime); /* LogFile.println("CProbing start Time: "+ M.Pstarting_time + " End Time: " + M.getArrivalTime() + " Measured BandWidth: "+ Measued_Band); */ chart.Cupdate(MessSize/8,Measued_Band*10/LinkBandwidth); } } // end of if } EQ.remove(); // remove the first message from the event queue }// end of while step += argu3; LocalTime_reset(); // reset the local time of links and routers } // end of for } // end of Size_statistic private void LocalTime_reset() { // reset the local time of links and routers for(int i=1; i<= numOfRouter; i++) Routers[i].LocalTime = 0.0; for(int i=1; i<= numOfLink; i++) { Links[i].LocalTime = 0.0; } } public void UpdateLog(double output_time) { } }