//package Simulator; import java.io.*; /** * Models routers in the simulator. */ public class Router extends NetComponents { // Fields private int number; // router number protected float Weight; double LocalTime; // need to be reset to zero in Cprobing Statistic // need to be set in Adaptive probe measurement private NetworkConfigure simulator; PrintWriter OFILE; // only used for web traffic pattern boolean parent = false; // simulator parent class is Simulator or CprobStatistic public Router(NetworkConfigure simulator, int i) { this.number = i; this.Weight = (float) 1.0; this.LocalTime = 0.0; this.simulator = simulator; try { this.OFILE = new PrintWriter(new FileWriter("RFile"+i+".txt")); } catch (IOException e) { } } /* // Constructor for simulator call public Router(Measurement simulator, int i) { this.number = i; this.Weight = (float) 1.0; this.LocalTime = 0.0; this.simulator = simulator; this.parent = true; try { this.OFILE = new PrintWriter(new FileWriter("RFile"+i+".txt")); } catch (IOException e) { } } // Constructor for CprobStatistic call public Router(CprobStatistic simulator, int i) { this.number = i; this.Weight = (float) 1.0; this.LocalTime = 0.0; this.simulator = simulator; try { this.OFILE = new PrintWriter(new FileWriter("RFile"+i+".txt")); } catch (IOException e) { } } */ // Commands public boolean EventHandler (Message Mess) { int index = 0; double ATime = Mess.getArrivalTime(); if (Mess.MessageType.compareTo("ICMP-request") == 0) index = Mess.NextObjectIndex; else index = 2*(simulator.RoadTable[Mess.RouterTableNum].numOfNode-1)-Mess.NextObjectIndex; //"ICMP-response" boolean responseMess_GetToDestination = Mess.setNextNode(simulator.RoadTable[Mess.RouterTableNum].numOfNode); if (!responseMess_GetToDestination) { // not get to the destination if (LocalTime < Mess.getArrivalTime()) { LocalTime = Mess.getArrivalTime(); } if (LocalTime > Mess.getArrivalTime()) { if ((Mess.MessageType.compareTo("ICMP-request") == 0) || (Mess.MessageType.compareTo("ICMP-response") == 0)) Mess.QueuingTime[index] = LocalTime - Mess.getArrivalTime(); } else { if ((Mess.MessageType.compareTo("ICMP-request") == 0) || (Mess.MessageType.compareTo("ICMP-response") == 0)) Mess.QueuingTime[index] = 0.0; } double switchingtime = Mess.getSize()/ simulator.RouterBandwidth; LocalTime += switchingtime + ((simulator.msgProcessingTime + Mess.getSize()/simulator.msgProcessingSpeed) / Weight); Mess.setTime(LocalTime); } OFILE.println(Mess.MessNum + " : "+ATime+" | "+LocalTime+" | "+Mess.MessageType); return responseMess_GetToDestination; } // Queries public double getLocalTime() { return LocalTime; } }