All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cloudsimplus.network.switches.AggregateSwitch Maven / Gradle / Ivy

/*
 * Title:        CloudSim Toolkit
 * Description:  CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 *
 * Copyright (c) 2009-2012, The University of Melbourne, Australia
 */
package org.cloudsimplus.network.switches;

import org.cloudsimplus.core.CloudSimPlus;
import org.cloudsimplus.core.events.SimEvent;
import org.cloudsimplus.datacenters.network.NetworkDatacenter;
import org.cloudsimplus.network.HostPacket;
import org.cloudsimplus.util.BytesConversion;

/**
 * This class represents an Aggregate Switch in a Datacenter network.
 * It interacts with other Datacenter in order to exchange packets.
 *
 * 

Please refer to following publication for more details: *

*

* * @author Saurabh Kumar Garg * @author Manoel Campos da Silva Filho * * @since CloudSim Toolkit 1.0 */ public class AggregateSwitch extends AbstractSwitch { /** * The level (layer) of the switch in the network topology. */ public static final int LEVEL = 1; /** * Default delay of {@link AggregateSwitch} in milliseconds. */ public static final double SWITCHING_DELAY = 0.00245; /** * Default downlink bandwidth of {@link AggregateSwitch} in Megabits/s. * It also represents the uplink bandwidth of connected edge Datacenter. */ public static final long DOWNLINK_BW = (long) BytesConversion.MEGA * 100 * 8; /** * Default number of aggregation switch ports that defines the number of * {@link EdgeSwitch} that can be connected to it. */ public static final int PORTS = 1; /** * Instantiates a Aggregate AbstractSwitch specifying the Datacenter that are * connected to its downlink and uplink ports and corresponding bandwidths. * * @param simulation the CloudSimPlus instance that represents the simulation the Entity belongs * @param dc The Datacenter where the switch is connected to */ public AggregateSwitch(final CloudSimPlus simulation, final NetworkDatacenter dc) { super(simulation, dc); setUplinkBandwidth(RootSwitch.DOWNLINK_BW); setDownlinkBandwidth(DOWNLINK_BW); setSwitchingDelay(SWITCHING_DELAY); setPorts(PORTS); } @Override protected void processPacketDown(final SimEvent evt) { /* packet is coming from root switch, so it needs to be sent to edge switch */ super.processPacketDown(evt); final var netPkt = (HostPacket) evt.getData(); final var downlinkSw = netPkt.getVmEdgeSwitch(); addPacketToSendToDownlinkSwitch(downlinkSw, netPkt); } @Override protected void processPacketUp(final SimEvent evt) { // packet is coming from edge router, so it needs to be sent to either root or another edge switch super.processPacketUp(evt); final var netPkt = (HostPacket) evt.getData(); final var downlinkSw = netPkt.getVmEdgeSwitch(); if (findConnectedEdgeSwitch(downlinkSw)) addPacketToSendToDownlinkSwitch(downlinkSw, netPkt); else addPacketToBeSentToFirstUplinkSwitch(netPkt); } /** * Checks if the Aggregate switch is connected to a given Edge switch. * @param edgeSwitch the id of the edge switch to check if the aggregate switch is connected to * @return true if the edge switch was found, false otherwise */ private boolean findConnectedEdgeSwitch(final Switch edgeSwitch) { return getDownlinkSwitches().stream().anyMatch(edgeSwitch::equals); } @Override public int getLevel() { return LEVEL; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy