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
A 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
-
Field Summary
-
Constructor Summary
Constructors Constructor Description AbstractSwitch(CloudSim simulation, NetworkDatacenter dc)
-
Method Summary
Modifier and Type Method Description protected void
addPacketToBeSentToFirstUplinkSwitch(HostPacket netPkt)
protected void
addPacketToSendToDownlinkSwitch(Switch downlinkSwitch, HostPacket packet)
Adds a packet that will be sent to a downlinkSwitch
.protected void
addPacketToSendToHost(NetworkHost host, HostPacket packet)
Adds a packet that will be sent to aNetworkHost
.protected void
addPacketToSendToUplinkSwitch(Switch uplinkSwitch, HostPacket packet)
Adds a packet that will be sent to a uplinkSwitch
.protected double
bandwidthByPacket(double bwCapacity, int simultaneousPackets)
Considering a list of packets to be sent, gets the amount of available bandwidth for each packet, assuming that the bandwidth is shared equally among all packets.double
downlinkTransferDelay(HostPacket packet, int simultaneousPackets)
Considering a list of packets to be sent simultaneously, computes the expected time to transfer each packet through the downlink, assuming that the bandwidth is shared equally between all packets.NetworkDatacenter
getDatacenter()
Gets the Datacenter where the switch is connected to.double
getDownlinkBandwidth()
Gets the bandwidth this Switch has to communicate with Switches in the lower layer.List<Switch>
getDownlinkSwitches()
Gets the list of Switches in the lower layer that this Switch is connected to.protected List<HostPacket>
getDownlinkSwitchPacketList(Switch downlinkSwitch)
Gets the list of packets to be sent to a downlink switch.protected List<HostPacket>
getHostPacketList(NetworkHost host)
Gets the list of packets to be sent to a host.int
getPorts()
Gets the number of ports the switch has.double
getSwitchingDelay()
Gets the latency time the switch spends to process a received packet.double
getUplinkBandwidth()
Gets the bandwidth this Switch has to communicate with Switches in the upper layer.List<Switch>
getUplinkSwitches()
Gets the list of Switches in the upper layer that this Switch is connected to.protected List<HostPacket>
getUplinkSwitchPacketList(Switch uplinkSwitch)
Gets the list of packets to be sent to an uplink switch.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
packetTransferDelay(HostPacket netPkt, double bwCapacity, int simultaneousPackets)
Computes the network delay to send a packet through the network, considering that a list of packets will be sent simultaneously.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)
Sets the bandwidth this Switch has to communicate with Switches in the lower layer.void
setPorts(int ports)
Sets the number of ports the switch has.void
setSwitchingDelay(double switchingDelay)
Sets the latency time the switch spends to process a received packet.void
setUplinkBandwidth(double uplinkBandwidth)
Sets the bandwidth this Switch has to communicate with Switches in the upper layer.void
shutdown()
Shuts down the entity.protected void
startInternal()
Defines the logic to be performed by the entity when the simulation starts.double
uplinkTransferDelay(HostPacket packet, int simultaneousPackets)
Considering a list of packets to be sent simultaneously, computes the expected time to transfer each packet through the uplink, assuming that the bandwidth is shared equally between all packets.Methods inherited from class org.cloudbus.cloudsim.core.CloudSimEntity
cancelEvent, clone, compareTo, equals, getId, getName, getNextEvent, getNextEvent, getShutdownTime, getSimulation, getStartTime, getState, hashCode, isAlive, isFinished, isStarted, pause, run, run, schedule, schedule, schedule, schedule, schedule, schedule, scheduleFirst, scheduleFirst, scheduleFirstNow, scheduleFirstNow, scheduleNow, scheduleNow, selectEvent, send, send, sendNow, sendNow, setEventBuffer, setId, setName, setSimulation, 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
getShutdownTime, getSimulation, getStartTime, getState, isAlive, isFinished, isStarted, run, schedule, schedule, schedule, schedule, schedule, schedule, schedule, setName, setSimulation, setState, start
-
Constructor Details
-
AbstractSwitch
-
-
Method Details
-
startInternal
protected void startInternal()Description copied from class:CloudSimEntity
Defines the logic to be performed by the entity when the simulation starts.- Specified by:
startInternal
in classCloudSimEntity
-
processEvent
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
Process a packet sent to a host.- Parameters:
evt
- The packet sent.
-
processPacketDown
Sends a packet to Datacenter connected through a downlink port.- Parameters:
evt
- Event/packet to process
-
getVmHost
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
Sends a packet to Datacenter connected through a uplink port.- Parameters:
evt
- Event/packet to process
-
downlinkTransferDelay
Description copied from interface:Switch
Considering a list of packets to be sent simultaneously, computes the expected time to transfer each packet through the downlink, assuming that the bandwidth is shared equally between all packets.- Specified by:
downlinkTransferDelay
in interfaceSwitch
simultaneousPackets
- number of packets to be simultaneously sent- Returns:
- the expected transmission time in seconds
-
uplinkTransferDelay
Description copied from interface:Switch
Considering a list of packets to be sent simultaneously, computes the expected time to transfer each packet through the uplink, assuming that the bandwidth is shared equally between all packets.- Specified by:
uplinkTransferDelay
in interfaceSwitch
simultaneousPackets
- number of packets to be simultaneously sent- Returns:
- the expected transmission time in seconds
-
packetTransferDelay
protected double packetTransferDelay(HostPacket netPkt, double bwCapacity, int simultaneousPackets)Computes the network delay to send a packet through the network, considering that a list of packets will be sent simultaneously.- Parameters:
netPkt
- the packet to be sentbwCapacity
- the total bandwidth capacity (in Megabits/s)simultaneousPackets
- number of packets to be simultaneously sent- Returns:
- the expected time to transfer the packet through the network (in seconds)
-
bandwidthByPacket
protected double bandwidthByPacket(double bwCapacity, int simultaneousPackets)Considering a list of packets to be sent, gets the amount of available bandwidth for each packet, assuming that the bandwidth is shared equally among all packets.- Parameters:
bwCapacity
- the total bandwidth capacity to share among the packets to be sent (in Megabits/s)simultaneousPackets
- number of packets to be simultaneously sent- Returns:
- the available bandwidth for each packet in the list of packets to send (in Megabits/s) or the total bandwidth capacity if the packet list has 0 or 1 element
-
shutdown
public void shutdown()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:
shutdown
in interfaceSimEntity
- Overrides:
shutdown
in classCloudSimEntity
-
getUplinkBandwidth
public double getUplinkBandwidth()Description copied from interface:Switch
Gets the bandwidth this Switch has to communicate with Switches in the upper layer.- Specified by:
getUplinkBandwidth
in interfaceSwitch
- Returns:
- Bandwidth of uplink (in Megabits/s).
- See Also:
Switch.getUplinkSwitches()
-
setUplinkBandwidth
public final void setUplinkBandwidth(double uplinkBandwidth)Description copied from interface:Switch
Sets the bandwidth this Switch has to communicate with Switches in the upper layer.- Specified by:
setUplinkBandwidth
in interfaceSwitch
- Parameters:
uplinkBandwidth
- uplink bandwidth to set (in Megabits/s).- See Also:
Switch.getUplinkSwitches()
-
getDownlinkBandwidth
public double getDownlinkBandwidth()Description copied from interface:Switch
Gets the bandwidth this Switch has to communicate with Switches in the lower layer.- Specified by:
getDownlinkBandwidth
in interfaceSwitch
- Returns:
- Bandwidth of downlink (in Megabits/s).
- See Also:
Switch.getDownlinkSwitches()
-
setDownlinkBandwidth
public final void setDownlinkBandwidth(double downlinkBandwidth)Description copied from interface:Switch
Sets the bandwidth this Switch has to communicate with Switches in the lower layer.- Specified by:
setDownlinkBandwidth
in interfaceSwitch
- Parameters:
downlinkBandwidth
- downlink bandwidth to set (in Megabits/s).- See Also:
Switch.getDownlinkSwitches()
-
getPorts
public int getPorts()Description copied from interface:Switch
Gets the number of ports the switch has. -
setPorts
public final void setPorts(int ports)Description copied from interface:Switch
Sets the number of ports the switch has. -
getSwitchingDelay
public double getSwitchingDelay()Description copied from interface:Switch
Gets 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).- Specified by:
getSwitchingDelay
in interfaceSwitch
- Returns:
- the switching delay
-
setSwitchingDelay
public final void setSwitchingDelay(double switchingDelay)Description copied from interface:Switch
Sets 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).- Specified by:
setSwitchingDelay
in interfaceSwitch
- Parameters:
switchingDelay
- the switching delay to set
-
getUplinkSwitches
Description copied from interface:Switch
Gets the list of Switches in the upper layer that this Switch is connected to.- Specified by:
getUplinkSwitches
in interfaceSwitch
- Returns:
-
getDownlinkSwitches
Description copied from interface:Switch
Gets the list of Switches in the lower layer that this Switch is connected to.- Specified by:
getDownlinkSwitches
in interfaceSwitch
- Returns:
-
getDownlinkSwitchPacketList
Gets the list of packets to be sent to a downlink switch.- 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
Gets the list of packets to be sent to an uplink switch.- 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
Gets the list of packets to be sent to a host.- Parameters:
host
- the host to get the list of packets to send- Returns:
- the list of packets to be sent to the given host.
-
addPacketToSendToDownlinkSwitch
Adds a packet that will be sent to a downlinkSwitch
.- Parameters:
downlinkSwitch
- the target switchpacket
- the packet to be sent
-
addPacketToSendToUplinkSwitch
Adds a packet that will be sent to a uplinkSwitch
.- Parameters:
uplinkSwitch
- the target switchpacket
- the packet to be sent
-
addPacketToSendToHost
Adds a packet that will be sent to aNetworkHost
.- Parameters:
host
- the targetNetworkHost
packet
- the packet to be sent
-
getDatacenter
Description copied from interface:Switch
Gets the Datacenter where the switch is connected to.- Specified by:
getDatacenter
in interfaceSwitch
- Returns:
-
setDatacenter
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
-
getVmEdgeSwitch
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
-