📄 naivenetworkscheduler.java
字号:
/* * @(#)$Id: NaiveNetworkScheduler.java,v 1.5 2004/07/02 23:59:22 huebsch Exp $ * * Copyright (c) 2001-2004 Regents of the University of California. * All rights reserved. * * This file is distributed under the terms in the attached BERKELEY-LICENSE * file. If you do not find these files, copies can be found by writing to: * Computer Science Division, Database Group, Universite of California, * 617 Soda Hall #1776, Berkeley, CA 94720-1776. Attention: Berkeley License * * Copyright (c) 2003-2004 Intel Corporation. All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE file. * If you do not find these files, copies can be found by writing to: * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, * Berkeley, CA, 94704. Attention: Intel License Inquiry. */package simulator.schedulers.network.node.naive;import java.net.InetAddress;import simulator.core.Event;import simulator.core.NodeMap;import simulator.core.Simulator;import simulator.core.SimulatorClient;import simulator.schedulers.network.IPMessage;import simulator.schedulers.network.NetworkEvent;import simulator.schedulers.network.NetworkScheduler;import simulator.schedulers.network.NetworkStub;import simulator.schedulers.network.NetworkTopology;import util.network.serialization.SerializationManager;/** * Class NaiveNetworkScheduler * */public class NaiveNetworkScheduler implements NetworkScheduler, SimulatorClient { protected Simulator theSimulator; protected NetworkTopology theTopology; protected NodeMap theNodes; /** * Constructor NaiveNetworkScheduler * * @param theSimulator * @param theTopology * @param theNodes */ public NaiveNetworkScheduler(Simulator theSimulator, NetworkTopology theTopology, NodeMap theNodes) { this.theSimulator = theSimulator; this.theTopology = theTopology; this.theNodes = theNodes; } /** * Method getNodeNum * * @param ipAddress * @return */ public int getNodeNum(InetAddress ipAddress) { return theNodes.getNode(ipAddress).getNodeMapPosition(); } /** * Method getNetworkStub * * @param ipAddress * @return */ public NetworkStub getNetworkStub(InetAddress ipAddress) { return theNodes.getNode(ipAddress).getNetworkStub(); } /** * Method getCurrentTime * @return */ public double getCurrentTime() { return theSimulator.getCurrentTime(); } /** * Method deliverMessage * * @param theMessage */ protected void deliverMessage(IPMessage theMessage) { NaiveNetworkStub destinationStub = (NaiveNetworkStub) getNetworkStub(theMessage.getDestination()); if (destinationStub == null) { throw new RuntimeException( "Could not locate destination node to deliver message " + theMessage); } destinationStub.handleMessage(theMessage); } /** * Method processNetworkEvent * * @param theEvent */ protected void processNetworkEvent(NetworkEvent theEvent) { IPMessage theMessage = theEvent.getMessage(); InetAddress currentHop = theEvent.getImmediateDestination(); if (currentHop == theMessage.getDestination()) { deliverMessage(theMessage); } else { scheduleMessage(theMessage, currentHop); } } /** * Method handleEvent * * @param theEvent */ public void handleEvent(Event theEvent) { processNetworkEvent((NetworkEvent) theEvent); } /** * Method scheduleMessage * * @param theMessage */ public void scheduleMessage(IPMessage theMessage) { if (theMessage.getSource() != theMessage.getDestination()) { scheduleMessage(theMessage, theMessage.getSource()); } else { deliverMessage(theMessage); } } /** * Method scheduleMessage * * @param theMessage * @param currentHop */ protected void scheduleMessage(IPMessage theMessage, InetAddress currentHop) { NaiveNetworkStub sourceStub = (NaiveNetworkStub) getNetworkStub(currentHop); if (sourceStub == null) { throw new RuntimeException( "Could not locate source node to send message " + theMessage); } if (sourceStub.getStatus() != true) { return; } theTopology.computeNextHop(currentHop, theMessage.getDestination()); InetAddress nextHop = theTopology.getNextHop(); NaiveNetworkStub destinationStub = (NaiveNetworkStub) getNetworkStub(nextHop); if (destinationStub == null) { throw new RuntimeException( "Could not locate next hop node to send message " + theMessage); } double latency = theTopology.getLatency(); double sourceBandwidth = sourceStub.getNewFlowBandwidth(NaiveNetworkStub.OUTGOING); double destinationBandwidth = destinationStub.getNewFlowBandwidth(NaiveNetworkStub.INCOMING); double bandwidth = Math.min(Math.min(sourceBandwidth, destinationBandwidth), theTopology.getMaxBandwidth()); double transmissionTime = latency + (SerializationManager.getPayloadSize(theMessage) / bandwidth); double curTime = getCurrentTime(); NetworkEvent theEvent = NetworkEvent.allocate(this, curTime, curTime + transmissionTime, getNodeNum(nextHop), theMessage, nextHop); theSimulator.schedule(theEvent); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -