Class AbstractSwitch
- java.lang.Object
-
- org.cloudbus.cloudsim.core.CloudSimEntity
-
- org.cloudbus.cloudsim.network.switches.AbstractSwitch
-
- All Implemented Interfaces:
Cloneable
,Comparable<SimEntity>
,Runnable
,Identifiable
,Nameable
,SimEntity
,Switch
- Direct Known Subclasses:
AggregateSwitch
,EdgeSwitch
,RootSwitch
public abstract class AbstractSwitch extends CloudSimEntity implements Switch
An base class for implementing Network Switch.- Author:
- Saurabh Kumar Garg, Manoel Campos da Silva Filho
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.cloudbus.cloudsim.core.SimEntity
SimEntity.State
-
-
Constructor Summary
Constructors Constructor Description AbstractSwitch(CloudSim simulation, NetworkDatacenter dc)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPacketToBeSentToDownlinkSwitch(Switch downlinkSwitch, HostPacket packet)
protected void
addPacketToBeSentToFirstUplinkSwitch(HostPacket netPkt)
void
addPacketToBeSentToHost(NetworkHost host, HostPacket packet)
void
addPacketToBeSentToUplinkSwitch(Switch uplinkSwitch, HostPacket packet)
void
connectHost(NetworkHost host)
Connects aNetworkHost
to the switch, by adding it to theSwitch.getHostList()
.boolean
disconnectHost(NetworkHost host)
Disconnects aNetworkHost
from the switch, by removing it from theSwitch.getHostList()
.NetworkDatacenter
getDatacenter()
Gets the Datacenter where the switch is connected to.double
getDownlinkBandwidth()
List<Switch>
getDownlinkSwitches()
List<HostPacket>
getDownlinkSwitchPacketList(Switch downlinkSwitch)
Gets the list of packets to be sent to a downlink switch.List<NetworkHost>
getHostList()
Gets a read-only list of Hosts connected to the switch.List<HostPacket>
getHostPacketList(NetworkHost host)
Gets the list of packets to be sent to a host.List<HostPacket>
getPacketList()
Map<NetworkHost,List<HostPacket>>
getPacketToHostMap()
int
getPorts()
Gets the number of ports the switch has.double
getSwitchingDelay()
double
getUplinkBandwidth()
List<Switch>
getUplinkSwitches()
List<HostPacket>
getUplinkSwitchPacketList(Switch uplinkSwitch)
Gets the list of packets to be sent to an uplink switch.Map<Switch,List<HostPacket>>
getUplinkSwitchPacketMap()
protected EdgeSwitch
getVmEdgeSwitch(HostPacket pkt)
Gets theEdgeSwitch
that the Host where the VM receiving a packet is connected to.protected NetworkHost
getVmHost(Vm vm)
Gets the Host where a VM is placed.protected double
networkDelayForPacketTransmission(HostPacket netPkt, double bwCapacity, List<HostPacket> netPktList)
Computes the network delay to send a packet through the network.void
processEvent(SimEvent evt)
Processes events or services that are available for the entity.protected void
processHostPacket(SimEvent evt)
Process a packet sent to a host.protected void
processPacketDown(SimEvent evt)
Sends a packet to Datacenter connected through a downlink port.protected void
processPacketUp(SimEvent evt)
Sends a packet to Datacenter connected through a uplink port.void
setDatacenter(NetworkDatacenter datacenter)
Sets the Datacenter where the switch is connected to.void
setDownlinkBandwidth(double downlinkBandwidth)
void
setPorts(int ports)
void
setSwitchingDelay(double switchingDelay)
void
setUplinkBandwidth(double uplinkBandwidth)
void
shutdownEntity()
Shuts down the entity.protected void
startEntity()
Defines the logic to be performed by the entity when the simulation starts.-
Methods inherited from class org.cloudbus.cloudsim.core.CloudSimEntity
cancelEvent, clone, compareTo, equals, getId, getName, getNextEvent, getNextEvent, getSimulation, getState, hashCode, isAlive, isFinished, isStarted, numEventsWaiting, numEventsWaiting, pause, run, schedule, schedule, schedule, schedule, scheduleFirst, scheduleFirst, scheduleFirstNow, scheduleFirstNow, scheduleNow, scheduleNow, selectEvent, send, send, sendNow, sendNow, setEventBuffer, setId, setName, setSimulation, setStarted, setState, start, waitForEvent
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface org.cloudbus.cloudsim.core.Identifiable
getId
-
Methods inherited from interface org.cloudbus.cloudsim.core.SimEntity
getSimulation, getState, isAlive, isFinished, isStarted, run, schedule, schedule, schedule, schedule, setName, setSimulation, setState, start
-
-
-
-
Constructor Detail
-
AbstractSwitch
public AbstractSwitch(CloudSim simulation, NetworkDatacenter dc)
-
-
Method Detail
-
startEntity
protected void startEntity()
Description copied from class:CloudSimEntity
Defines the logic to be performed by the entity when the simulation starts.- Specified by:
startEntity
in classCloudSimEntity
-
processEvent
public void processEvent(SimEvent evt)
Description copied from interface:SimEntity
Processes events or services that are available for the entity. This method is invoked by theCloudSim
class whenever there is an event in the deferred queue, which needs to be processed by the entity.- Specified by:
processEvent
in interfaceSimEntity
- Parameters:
evt
- information about the event just happened
-
processHostPacket
protected void processHostPacket(SimEvent evt)
Process a packet sent to a host.- Parameters:
evt
- The packet sent.
-
processPacketDown
protected void processPacketDown(SimEvent evt)
Sends a packet to Datacenter connected through a downlink port.- Parameters:
evt
- Event/packet to process
-
getVmHost
protected NetworkHost getVmHost(Vm vm)
Gets the Host where a VM is placed.- Parameters:
vm
- the VM to get its Host- Returns:
- the Host where the VM is placed
-
processPacketUp
protected void processPacketUp(SimEvent evt)
Sends a packet to Datacenter connected through a uplink port.- Parameters:
evt
- Event/packet to process
-
networkDelayForPacketTransmission
protected double networkDelayForPacketTransmission(HostPacket netPkt, double bwCapacity, List<HostPacket> netPktList)
Computes the network delay to send a packet through the network.- Parameters:
netPkt
- the packet to be sentbwCapacity
- the total bandwidth capacity (in Megabits/s)netPktList
- the list of packets waiting to be sent- Returns:
- the expected time to transfer the packet through the network (in seconds)
-
shutdownEntity
public void shutdownEntity()
Description copied from interface:SimEntity
Shuts down the entity. This method is invoked by theCloudSim
before the simulation finishes. If you want to save data in log files this is the method in which the corresponding code would be placed.- Specified by:
shutdownEntity
in interfaceSimEntity
- Overrides:
shutdownEntity
in classCloudSimEntity
-
getUplinkBandwidth
public double getUplinkBandwidth()
- Specified by:
getUplinkBandwidth
in interfaceSwitch
- Returns:
- Bandwitdh of uplink (in Megabits/s).
-
setUplinkBandwidth
public final void setUplinkBandwidth(double uplinkBandwidth)
- Specified by:
setUplinkBandwidth
in interfaceSwitch
-
getDownlinkBandwidth
public double getDownlinkBandwidth()
- Specified by:
getDownlinkBandwidth
in interfaceSwitch
- Returns:
- Bandwitdh of downlink (in Megabits/s).
-
setDownlinkBandwidth
public final void setDownlinkBandwidth(double downlinkBandwidth)
- Specified by:
setDownlinkBandwidth
in interfaceSwitch
-
getPorts
public int getPorts()
Description copied from interface:Switch
Gets the number of ports the switch has.
-
getSwitchingDelay
public double getSwitchingDelay()
- Specified by:
getSwitchingDelay
in interfaceSwitch
- Returns:
- the latency time the switch spends to process a received packet. This time is considered constant no matter how many packets the switch have to process (in seconds).
-
setSwitchingDelay
public final void setSwitchingDelay(double switchingDelay)
- Specified by:
setSwitchingDelay
in interfaceSwitch
-
getUplinkSwitches
public List<Switch> getUplinkSwitches()
- Specified by:
getUplinkSwitches
in interfaceSwitch
-
getHostList
public List<NetworkHost> getHostList()
Description copied from interface:Switch
Gets a read-only list of Hosts connected to the switch.- Specified by:
getHostList
in interfaceSwitch
- Returns:
-
connectHost
public void connectHost(NetworkHost host)
Description copied from interface:Switch
Connects aNetworkHost
to the switch, by adding it to theSwitch.getHostList()
.- Specified by:
connectHost
in interfaceSwitch
- Parameters:
host
- the host to be connected to the switch
-
disconnectHost
public boolean disconnectHost(NetworkHost host)
Description copied from interface:Switch
Disconnects aNetworkHost
from the switch, by removing it from theSwitch.getHostList()
.- Specified by:
disconnectHost
in interfaceSwitch
- Parameters:
host
- the host to be disconnected from the switch- Returns:
- true if the Host was connected to the switch, false otherwise
-
getPacketToHostMap
public Map<NetworkHost,List<HostPacket>> getPacketToHostMap()
- Specified by:
getPacketToHostMap
in interfaceSwitch
- Returns:
- a read-only map of hosts and the list of packets to be sent to each one.
-
getDownlinkSwitches
public List<Switch> getDownlinkSwitches()
- Specified by:
getDownlinkSwitches
in interfaceSwitch
-
getDownlinkSwitchPacketList
public List<HostPacket> getDownlinkSwitchPacketList(Switch downlinkSwitch)
Description copied from interface:Switch
Gets the list of packets to be sent to a downlink switch.- Specified by:
getDownlinkSwitchPacketList
in interfaceSwitch
- Parameters:
downlinkSwitch
- the id of the switch to get the list of packets to send- Returns:
- the list of packets to be sent to the given switch.
-
getUplinkSwitchPacketList
public List<HostPacket> getUplinkSwitchPacketList(Switch uplinkSwitch)
Description copied from interface:Switch
Gets the list of packets to be sent to an uplink switch.- Specified by:
getUplinkSwitchPacketList
in interfaceSwitch
- Parameters:
uplinkSwitch
- the switch to get the list of packets to send- Returns:
- the list of packets to be sent to the given switch.
-
getHostPacketList
public List<HostPacket> getHostPacketList(NetworkHost host)
Description copied from interface:Switch
Gets the list of packets to be sent to a host.- Specified by:
getHostPacketList
in interfaceSwitch
- Parameters:
host
- the host to get the list of packets to send- Returns:
- the list of packets to be sent to the given host.
-
getUplinkSwitchPacketMap
public Map<Switch,List<HostPacket>> getUplinkSwitchPacketMap()
- Specified by:
getUplinkSwitchPacketMap
in interfaceSwitch
- Returns:
- a read-only map of the uplink Switches and list of packets to be sent to each one.
-
addPacketToBeSentToDownlinkSwitch
public void addPacketToBeSentToDownlinkSwitch(Switch downlinkSwitch, HostPacket packet)
- Specified by:
addPacketToBeSentToDownlinkSwitch
in interfaceSwitch
-
addPacketToBeSentToUplinkSwitch
public void addPacketToBeSentToUplinkSwitch(Switch uplinkSwitch, HostPacket packet)
- Specified by:
addPacketToBeSentToUplinkSwitch
in interfaceSwitch
-
addPacketToBeSentToHost
public void addPacketToBeSentToHost(NetworkHost host, HostPacket packet)
- Specified by:
addPacketToBeSentToHost
in interfaceSwitch
-
getDatacenter
public NetworkDatacenter getDatacenter()
Description copied from interface:Switch
Gets the Datacenter where the switch is connected to.- Specified by:
getDatacenter
in interfaceSwitch
- Returns:
-
setDatacenter
public void setDatacenter(NetworkDatacenter datacenter)
Description copied from interface:Switch
Sets the Datacenter where the switch is connected to.- Specified by:
setDatacenter
in interfaceSwitch
- Parameters:
datacenter
- the Datacenter to set
-
getPacketList
public List<HostPacket> getPacketList()
- Specified by:
getPacketList
in interfaceSwitch
-
getVmEdgeSwitch
protected EdgeSwitch getVmEdgeSwitch(HostPacket pkt)
Gets theEdgeSwitch
that the Host where the VM receiving a packet is connected to.- Parameters:
pkt
- the packet targeting some VM- Returns:
- the Edge Switch connected to the Host where the targeting VM is placed
-
addPacketToBeSentToFirstUplinkSwitch
protected void addPacketToBeSentToFirstUplinkSwitch(HostPacket netPkt)
-
-