📄 output.java
字号:
destId + " = " + GridSim.getEntityName(destId) ); *********/ // create junk packets or empty NetPacket. for (i = 0; i < freq; i++) { convertIntoPacket(MTU, numPackets+1, tag, destId, type); } } // send to all resources + other entities else if (pattern == TrafficGenerator.SEND_ALL) { // send to all resources and user entities for (int k = 0; k < list_.size(); k++) { destId = ((Integer) list_.get(k)).intValue(); /********* // DEBUG info System.out.println(super.get_name() + ": Destination id = " + destId + " = " + GridSim.getEntityName(destId) ); *********/ // create junk packets or empty NetPacket. for (i = 0; i < freq; i++) { convertIntoPacket(MTU, numPackets+1, tag, destId, type); } } } // sends the next junk packets super.sim_schedule(super.get_id(), time, GridSimTags.JUNK_PKT); } /** * Initial start for the background traffic * @pre $none * @post $none */ private synchronized void startBackgroundTraffic() { // if no background traffic generator, then skip the rest if (gen_ == null) { return; } // get the next inter-arrival time long time = gen_.getNextPacketTime(); System.out.println(super.get_name() + ": background traffic will start at time " + time); // starts background traffic if the inter-arrival time is valid if (time == -1) { return; } super.sim_schedule(super.get_id(), time, GridSimTags.JUNK_PKT); } /** * This method processes outgoing data without a network extension. * @param ev a Sim_event object * @param gisID the central/default GIS entity ID * @param statID the GridStatistic entity ID * @param shutdownID the GridSimShutdown entity ID * @pre ev != null * @post $none */ private synchronized void defaultSend(Sim_event ev, int gisID, int statID, int shutdownID) { IO_data io = (IO_data) ev.get_data(); int destId = io.getDestID(); /***** // DEBUG info System.out.println(super.get_name() + ".defaultSend(): Send to " + GridSim.getEntityName(destId) + " tag = " + ev.get_tag() ); *****/ // if this entity uses a network extension if (link_ != null && destId != gisID && destId != statID && destId != shutdownID) { submitToLink(ev); return; } // Identify ID of an entity which acts as Input/Buffer // entity of destination entity int id = GridSim.getEntityId( "Input_" + Sim_system.get_entity(destId).get_name() ); // Send first and then hold super.sim_schedule(id, GridSimTags.SCHEDULE_NOW, ev.get_tag(), io); double receiverBaudRate = ( (Input) Sim_system.get_entity(id) ).getBaudRate(); // NOTE: io is in byte and baud rate is in bits. 1 byte = 8 bits // So, convert io into bits double minBaudRate = Math.min(baudRate_, receiverBaudRate); double communicationDelay = GridSimRandom.realIO( (io.getByteSize() * BITS) / minBaudRate); // NOTE: Below is a deprecated method for SimJava 2 //super.sim_hold(communicationDelay); super.sim_process(communicationDelay); } /** * This method takes data from an entity. If the size of the data is larger * than the MTU of the link, then the packet is split into mutiple size * units. After this it calls enque() to queue these packets into its * buffer. * * @param ev A Sim_event data that contains all the data for this method * to do its task. * @pre ev != null * @post $none */ private synchronized void submitToLink(Sim_event ev) { IO_data data = (IO_data) ev.get_data(); Object obj = data.getData(); long size = data.getByteSize(); int tag = ev.get_tag(); int destId = data.getDestID(); int netServiceType = data.getNetServiceLevel(); // we need to packetsize the data, all packets are sent with size MTU. // only the last packet contains the data, the receiver should // throw away all other packets int MTU = link_.getMTU(); int numPackets = (int) Math.ceil( size / (MTU * 1.0) ); // make dummy packets with null data convertIntoPacket(MTU, numPackets, tag, destId, netServiceType); // last packet contains the actual data NetPacket np = null; np = new NetPacket(obj,pktID_,size - MTU*(numPackets-1),tag,super.get_id(), destId, netServiceType, numPackets, numPackets); pktID_++; // increments packet ID enque(np, GridSimTags.SCHEDULE_NOW); } /** * Creates many dummy or null packets * @param size packet size (in bytes) * @param numPackets total number of packets to be created * @param tag packet tag * @param destId destination ID for sending the packet * @param netServiceType level type of service for the packet * @pre $none * @post $none */ private synchronized void convertIntoPacket(long size, int numPackets, int tag, int destId, int netServiceType) { NetPacket np = null; for (int i = 0; i < numPackets - 1; i++) { // change the tag name for dummy packets, apart from junk packets if (tag != GridSimTags.JUNK_PKT) { tag = GridSimTags.EMPTY_PKT; } np = new NetPacket(null, pktID_, size, tag, super.get_id(), destId, netServiceType, i+1, numPackets); pktID_++; // increments packet ID enque(np, GridSimTags.SCHEDULE_NOW); } } /** * Sends an InfoPacket for ping request * @param ev a Sim_Event object * @pre ev != null * @post $none */ private synchronized void sendInfoPacket(Sim_event ev) { IO_data data = (IO_data) ev.get_data(); // gets all the relevant info long size = data.getByteSize(); int destId = data.getDestID(); int netServiceType = data.getNetServiceLevel(); int tag = ev.get_tag(); String name = GridSim.getEntityName( outPort_.get_dest() ); // we need to packetsize the data, all packets are sent with size MTU // only the last packet contains the ping data, the receiver should // throw away all other data int MTU = link_.getMTU(); int numPackets = (int) Math.ceil( size / (MTU * 1.0) ); // break ping size into smaller pieces // Also, make sure that it is not for pinging itself if (size > MTU && outPort_.get_dest() != destId) { // make dummy packets with null data convertIntoPacket(MTU, numPackets, tag, destId, netServiceType); } // get the remaining ping size size = data.getByteSize() - MTU*(numPackets-1); // create the real InfoPacket InfoPacket pkt = new InfoPacket(name,pktID_,size,outPort_.get_dest(), destId,netServiceType); // set the required info pkt.setLast( super.get_id() ); pkt.addHop( outPort_.get_dest() ); pkt.addEntryTime( GridSim.clock() ); pkt.setOriginalPingSize( data.getByteSize() ); pktID_++; // increments packet ID enque(pkt, GridSimTags.SCHEDULE_NOW); } /** * Sends back the ping() request to the next hop or destination * @param ev a Sim_event object * @pre ev != null * @post $none */ private void returnInfoPacket(Sim_event ev) { IO_data data = (IO_data) ev.get_data(); // use the original ping size rather than IO_data or InfoPacket size // since the latter is restricted to MTU InfoPacket pkt = (InfoPacket) data.getData(); long size = pkt.getOriginalPingSize(); // get other relevant info int tag = ev.get_tag(); int destId = pkt.getSrcID(); int netServiceType = data.getNetServiceLevel(); // we need to packetsize the data, all packets are sent with size MTU. // only the last packet contains the data, the receiver should // throw away all other packets int MTU = link_.getMTU(); int numPackets = (int) Math.ceil( size / (MTU * 1.0) ); // make dummy packets with null data convertIntoPacket(MTU, numPackets, tag, destId, netServiceType); // set the original packet of last hop into this entity id pkt.setLast( super.get_id() ); enque(pkt, GridSimTags.SCHEDULE_NOW); } /** * Takes a packet, adds it into a buffer and schedules it to be sent out at * an appropriate time. * * @param pkt The packet to be buffered * @param delay The length of time this packet should be delayed (exclusive * of the transmission time) * @pre pkt != null * @pre delay > 0 * @post $none */ private synchronized void enque(Packet pkt, double delay) { packetList_.add(pkt); if (packetList_.size() == 1) { double total = delay + (pkt.getSize()*SIZE / link_.getBaudRate()); super.sim_schedule(super.get_id(), total, GridSimTags.SEND_PACKET); } } /** * Removes a single packet from the buffer and sends it down the link. * Then, schedules the next packet in the list. * @pre $none * @post $none */ private synchronized void sendPacket() { if (packetList_ == null || packetList_.isEmpty() == true) { return; } // submits the first packet in the list Packet np = (Packet) packetList_.remove(0); boolean ping = false; // a flag to determine ping packet or not int tag = -1; // event tag ID int dest = -1; // destination ID // if a packet belongs to a ping packet if (np instanceof InfoPacket) { ((InfoPacket)np).addExitTime( GridSim.clock() ); ((InfoPacket)np).addBaudRate( link_.getBaudRate() ); ping = true; } // if an entity tries to send a packet to itself if ( np.getDestID() == outPort_.get_dest() ) { // then change the destination name and id String destName = super.get_name(); destName = destName.replaceFirst("Output", "Input"); dest = Sim_system.get_entity_id(destName); // for a ping packet, change the tag if (ping == true) { // don't forget to change the packet tag tag = GridSimTags.INFOPKT_RETURN; ((InfoPacket) np).setTag(tag); } else { tag = np.getTag(); } } else // if an entity tries to send to other entity { // change or keep the event tag tag = GridSimTags.PKT_FORWARD; if (np.getTag() == GridSimTags.JUNK_PKT) { tag = GridSimTags.JUNK_PKT; } // sends the packet into the link dest = link_.get_id(); } // send the packet super.sim_schedule(dest, GridSimTags.SCHEDULE_NOW, tag, np); /***** // DEBUG info System.out.println(super.get_name() + " send to " + GridSim.getEntityName(dest) + " tag = " + tag); ****/ // if the list is not empty, then schedule the next packet in the list if (packetList_.isEmpty() != true) { double delay = np.getSize() * SIZE / link_.getBaudRate(); super.sim_schedule(super.get_id(), delay, GridSimTags.SEND_PACKET); } }} // end class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -