//Title: Simulator for network bandwidth measurement //Version: //Copyright: Copyright (c) 1998 //Author: xhe //Company: UCCS package Simulator; //import java.awt.*; //import java.awt.event.*; import java.io.*; import java.util.*; //import java.swing.*; public class Simulator extends NetworkConfigure { /*Router [] Routers; Link [] Links; EventsQueue EQ; RouterTable [] RoadTable; */ Chart chart; /* old one double msgProcessingTime=0.0001; // 0.1 msec double msgProcessingSpeed= 1.0E+6; //1MBps double RouterBandwidth = 1.0E+9; double LinkBandwidth = 1.0E+7; // 10MBps double signalPropagationSpeed = 2.0E+8; // fiber speed double msgProcessingTime=0.0001; // 0.1 msec double msgProcessingSpeed= 1.5E+7; //15MBps make ture that the 10M bandwidth 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; // how many different router road //int TPSize; // traffic message size, unit is bits. int MaxMessNum=0; // the maximum message number int ProbingMessNum; // how many probing mess needed in one probe double PInternalTime; // Probing Message sending interval time in one probing cycle double TInternalTime; // Traffic Message sending interval time //double TBIntervalTime; // Traffic Bandwidth checking Interval Time double PBIntervalTime; // Probing Interval Time between two probing cycle double RoundTripTime=0.0; // the round trip time of a message with no congestion // the following two variable for Cprobing use // double CPIntervalTime; // Cprobing interval time between two probing cycle int CprobingNum=0; // How many message in one Cprobing cycle Link BottleneckLink; // the bottleneck link PrintWriter LogFile; // log file PrintWriter PFile; // log file for probing message PrintWriter EventFile; // log file for events int Start_MeaTime; // when the start of the probing int end_time; // when the end of the probing boolean NeedTraffic = false; // not for cprobing statistics // what kind of probing method results need to show in the chart boolean Single_probing = false; // single message probing boolean Cprobing = false; // cprobing boolean Adaptive_probing = false; // Adaptive probing public Simulator() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { Simulator simulation = new Simulator(); } private void jbInit() throws Exception { StringTokenizer t; Double DTemp; rnd = new Random(); chart = new Chart(); // warm up random number generator for (int index=0; index<50000; index++) rnd.nextInt(); EQ = new EventsQueue(); try { BufferedReader ifile = new BufferedReader(new FileReader("configure.txt")); String s; int iterate=0; // first line for four parameters of PInternalTime, PBIntervalTime // TInternalTime and TBIntervalTime s = ifile.readLine(); t = new StringTokenizer(s,"|"); DTemp = Double.valueOf(t.nextToken()); PInternalTime = DTemp.doubleValue(); DTemp = Double.valueOf(t.nextToken()); PBIntervalTime = DTemp.doubleValue(); DTemp = Double.valueOf(t.nextToken()); TInternalTime = DTemp.doubleValue(); DTemp = Double.valueOf(t.nextToken()); TBIntervalTime = DTemp.doubleValue(); // second line for five number: how many Router, Link and Road, // the fourth number is the number of the bottleneck Link // the fifth number is the number of how many probing message in one probing route s = ifile.readLine(); t = new StringTokenizer(s,"|"); numOfRouter = Integer.parseInt(t.nextToken()); numOfLink = Integer.parseInt(t.nextToken()); numOfRoad = Integer.parseInt(t.nextToken()); Routers = new Router[numOfRouter+1]; Links = new Link[numOfLink+1]; RoadTable = new RouterTable[numOfRoad]; // generate all the routers: range starts from 1 for(int i=1; i<= numOfRouter; i++) Routers[i] = new Router(this,i); // generate all the links: range starts from 1 for(int i=1; i<= numOfLink; i++) { int distance = rnd.nextInt(1000)+3; // a random link distance; Links[i] = new Link(this,distance,i,true); } BottleneckLink = Links[Integer.parseInt(t.nextToken())]; BottleneckLink.BottleneckLink = true; // set the field // retrieve how many messages needed in one probing cycle ProbingMessNum = Integer.parseInt(t.nextToken()); // retrieve how many messages needed in one Cprobing cycle CprobingNum = Integer.parseInt(t.nextToken()); // create the router table, start from 0 // each line after third line(included) is a single road table while (iterate < numOfRoad) { s = ifile.readLine(); t = new StringTokenizer(s,"|"); int RoadNodeNum = t.countTokens(); RoadTable[iterate] = new RouterTable(iterate,RoadNodeNum); int num=0; String tmp; while (num < RoadNodeNum){ tmp = t.nextToken(); if (tmp.charAt(0) == 'L') // this is a link object RoadTable[iterate].append(Links[Integer.parseInt(tmp.substring(1))],num); else RoadTable[iterate].append(Routers[Integer.parseInt(tmp.substring(1))],num); num++; } // end of one single line, inner while iterate ++; } // end of all road table, outer while ifile.close(); } catch (IOException d) { System.out.print("Error" + d); System.exit(1); } pareto = new Pareto(); weibull = new Weibull(); Start_MeaTime = 4; end_time = 10; //traffic = new Traffic(2,"Flat"); //traffic = new Traffic("Web"); traffic = new Traffic("Slope",false,9,1,Start_MeaTime,end_time,TBIntervalTime); NeedTraffic = true; // what kind of probing method you need to show Single_probing = true; // single message probing Cprobing = true; // cprobing Adaptive_probing = false; // Adaptive probing // start simulation start_simulation(); } private void start_simulation() { // open a log file for the writing of simulator 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); } // there is only one probing agent. // The first router of the first road is the probing agent. // the first router in each of the rest roads is the traffic generation agent. Message M,NewM; double Start_TrafficTime = 0.1; //double Start_TrafficTime = 6.0; // initializing the start event // for the probing agent // generate the initial probing message, size is static value 46 bytes M = new Message(0,0,"Probe-start",46*8,Start_MeaTime); // the message nubmer is useless. //M = new Message(0,0,"Probe-start",46*8,0); // the message nubmer is useless. EQ.insert(M); // Generate one "RoundTripTime-Probing" type messages // to measure the relatively accurate round trip time for a message // the probing agent sends this type message always. // This probing message is declared with traffic message constructor // because the queuing time at each object of its route is 0.0 M = new Message(0,0,"RoundTripTime-ProbingRequest",46*8,0.0); //M = new Message(0,0,"RoundTripTime-ProbingRequest",46*8,6.0); EQ.insert(M); // Generate the first "Traffic-start" type message // time 0.0 means this is the first one // always the first traffic agent is to use it to set the bottleneck M = new Message(0,1,"Traffic-start",46*8,Start_TrafficTime); EQ.insert(M); for (int j=2; j Start_MeaTime) { // update the chart double Available_BandWidth = LinkBandwidth - (BottleneckLink.Transfered_bit/TBIntervalTime); LogFile.println("Starting Time: "+ BottleneckLink.Tstarting_time + " End Time: " + output_time + " Available BandWidth: "+ Available_BandWidth+" | " + BottleneckLink.Transfered_bit); chart.Tupdate(output_time,Available_BandWidth*10/LinkBandwidth); } traffic.ArguChange(output_time > Start_MeaTime); } public void end_simulation() { System.exit(0); } }