Class BasicSwitch
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,CommunicationAspect
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Decorator
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
CrossbarSwitch
,VariableDelaySwitch
public class BasicSwitch extends AtomicCommunicationAspect
ABasicSwitch
actor that, when itssendToken(Receiver, Receiver, Token)
method is called, delays the delivery of the specified token to the specified receiver according to the delays and contention on input buffers, output buffers, and switch fabric delays.This communication aspect implements a simple switch which has a parametrizable number of ports. Note that these ports are not visually represented as Ptolemy actor ports. The first token received by this actor is delayed for inputBufferDelay + switchFabricDelay + outputBufferDelay time units. Tokens received on the same switch input are buffered in a FIFO queue. Similarly, tokens for the same output are buffered in FIFO queues. The switch fabric in this switch acts as a FIFO queue as well. Tokens on different input and output ports are processed in parallel, tokens in the switch fabric are processed one after the other.
To use this actor, drag it into a model. Input ports get decorated with
BasicSwitch.BasicSwitchAttributes
which describe the path a token takes through the switch: the switch input port number and the switch output port number.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Patricia Derler
- Pt.AcceptedRating:
- Red (derler)
- Pt.ProposedRating:
- Yellow (derler)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BasicSwitch.BasicSwitchAttributes
The attributes configured per port which is mediated by a BasicSwitch.-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected double
_inputBufferDelay
Time it takes for a token to be put into the input queue.protected java.util.HashMap<java.lang.Integer,java.util.TreeSet<TimedEvent>>
_inputTokens
Tokens received by the switch.protected java.util.HashMap<Port,java.lang.Integer>
_ioPortToSwitchInPort
Tokens sent to ports mediated by this communication aspect are rerouted to the switch ports with the IDs specified in this map.protected java.util.HashMap<Port,java.lang.Integer>
_ioPortToSwitchOutPort
Tokens set to ports mediated by this communication aspect are processed by this communication aspect and then forwarded to the port through the switch port with ID specified here.protected Time
_nextFireTime
Next time a token is sent and the next token can be processed.protected int
_numberOfPorts
Number of switch ports.protected double
_outputBufferDelay
Time it takes for a token to be put into the output queue.protected java.util.HashMap<java.lang.Integer,java.util.TreeSet<TimedEvent>>
_outputTokens
Tokens to be sent to outputs.protected double
_switchFabricDelay
Time it takes for a token to be processed by the switch fabric.Parameter
inputBufferDelay
Time it takes for a token to be put into the input queue.Parameter
numberOfPorts
Number of ports on the switch.Parameter
outputBufferDelay
Time it takes for a token to be put into the output queue.Parameter
switchFabricDelay
Time it takes for a token to be processed by the switch fabric.-
Fields inherited from class ptolemy.actor.lib.aspect.AtomicCommunicationAspect
_parameters, _tokenCount
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.CommunicationAspect
decoratorHighlightColorName
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description BasicSwitch(CompositeEntity container, java.lang.String name)
Construct a BasicSwitch with a name and a container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Time
_getNextFireTime(Time nextFireTime, java.util.TreeSet<TimedEvent> tokens)
Get next fire time for a set of tokens which is either the minimum next fire time passed as an argument or the smallest timestamp of the tokens in the set.protected int
_getPortID(Receiver receiver, boolean input)
Return the IO of the switch port where this receiver is connected to.protected void
_scheduleRefire()
Schedule a refiring of this actor based on the tokens in the queues.void
attributeChanged(Attribute attribute)
If the attribute for the input, switch fabric or output delay is changed, then ensure that the value is non-negative.java.lang.Object
clone(Workspace workspace)
Clone this actor into the specified workspace.DecoratorAttributes
createDecoratorAttributes(NamedObj target)
Return the decorated attributes for the target NamedObj.IntermediateReceiver
createIntermediateReceiver(Receiver receiver)
Create an intermediate receiver that wraps a given receiver.void
fire()
Move tokens from the input queue to the switch fabric, move tokens from the switch fabric queue to the output queues and send tokens from the output queues to the target receivers.Receiver
getReceiver(Receiver receiver, IOPort port)
Create a receiver to mediate a communication via the specified receiver.void
initialize()
Initialize the actor variables.boolean
postfire()
If there are still tokens in the queue and a token has been produced in the fire, schedule a refiring.void
reset()
Reset the communication aspect and clear the tokens.void
sendToken(Receiver source, Receiver receiver, Token token)
Initiate a send of the specified token to the specified receiver.void
setContainer(CompositeEntity container)
Make sure that this communication aspect is only used in the DE domain.void
setPortIn(Port port, int portIn)
Set the id of the switch input that is receiving tokens from this actor port.void
setPortOut(Port port, int portOut)
Set the id of the switch output that is sending tokens to this actor port.-
Methods inherited from class ptolemy.actor.lib.aspect.AtomicCommunicationAspect
_sendToReceiver, decoratedObjects, isGlobalDecorator, registerListener, sendCommunicationEvent
-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, stop, stopFire, terminate, wrapup
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
numberOfPorts
public Parameter numberOfPorts
Number of ports on the switch. This parameter must contain an IntToken. The value defaults to 4.
-
inputBufferDelay
public Parameter inputBufferDelay
Time it takes for a token to be put into the input queue. This parameter must contain a DoubleToken. The value defaults to 0.1.
-
outputBufferDelay
public Parameter outputBufferDelay
Time it takes for a token to be put into the output queue. This parameter must contain a DoubleToken. The value defaults to 0.1.
-
switchFabricDelay
public Parameter switchFabricDelay
Time it takes for a token to be processed by the switch fabric. This parameter must contain a DoubleToken. The value defaults to 0.1.
-
_nextFireTime
protected Time _nextFireTime
Next time a token is sent and the next token can be processed.
-
_numberOfPorts
protected int _numberOfPorts
Number of switch ports.
-
_inputBufferDelay
protected double _inputBufferDelay
Time it takes for a token to be put into the input queue.
-
_inputTokens
protected java.util.HashMap<java.lang.Integer,java.util.TreeSet<TimedEvent>> _inputTokens
Tokens received by the switch.
-
_ioPortToSwitchInPort
protected java.util.HashMap<Port,java.lang.Integer> _ioPortToSwitchInPort
Tokens sent to ports mediated by this communication aspect are rerouted to the switch ports with the IDs specified in this map.
-
_ioPortToSwitchOutPort
protected java.util.HashMap<Port,java.lang.Integer> _ioPortToSwitchOutPort
Tokens set to ports mediated by this communication aspect are processed by this communication aspect and then forwarded to the port through the switch port with ID specified here.
-
_outputBufferDelay
protected double _outputBufferDelay
Time it takes for a token to be put into the output queue.
-
_outputTokens
protected java.util.HashMap<java.lang.Integer,java.util.TreeSet<TimedEvent>> _outputTokens
Tokens to be sent to outputs.
-
_switchFabricDelay
protected double _switchFabricDelay
Time it takes for a token to be processed by the switch fabric.
-
-
Constructor Detail
-
BasicSwitch
public BasicSwitch(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct a BasicSwitch with a name and a container. The container argument must not be null, or a NullPointerException will be thrown. This actor will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version of the workspace.- Parameters:
container
- The container.name
- The name of this actor.f- Throws:
IllegalActionException
- If the container is incompatible with this actor.NameDuplicationException
- If the name coincides with an actor already in the container.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
If the attribute for the input, switch fabric or output delay is changed, then ensure that the value is non-negative.- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the buffer delays are negative.
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone this actor into the specified workspace. The new actor is not added to the directory of that workspace (you must do this yourself if you want it there). The result is a new actor with the same ports as the original, but no connections and no container. A container must be set before much can be done with this actor.- Overrides:
clone
in classAtomicCommunicationAspect
- Parameters:
workspace
- The workspace for the cloned object.- Returns:
- A new Bus.
- Throws:
java.lang.CloneNotSupportedException
- If cloned ports cannot have as their container the cloned entity (this should not occur), or if one of the attributes cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
createDecoratorAttributes
public DecoratorAttributes createDecoratorAttributes(NamedObj target)
Return the decorated attributes for the target NamedObj. If the specified target is not an Actor, return null.- Specified by:
createDecoratorAttributes
in interfaceDecorator
- Overrides:
createDecoratorAttributes
in classAtomicCommunicationAspect
- Parameters:
target
- The NamedObj that will be decorated.- Returns:
- The decorated attributes for the target NamedObj, or null if the specified target is not an Actor.
-
createIntermediateReceiver
public IntermediateReceiver createIntermediateReceiver(Receiver receiver) throws IllegalActionException
Create an intermediate receiver that wraps a given receiver. For now, we only support wrapping input ports.- Specified by:
createIntermediateReceiver
in interfaceCommunicationAspect
- Overrides:
createIntermediateReceiver
in classAtomicCommunicationAspect
- Parameters:
receiver
- The receiver that is being wrapped.- Returns:
- A new intermediate receiver.
- Throws:
IllegalActionException
- If the receiver is an output port.
-
getReceiver
public Receiver getReceiver(Receiver receiver, IOPort port) throws IllegalActionException
Create a receiver to mediate a communication via the specified receiver. This receiver is linked to a specific port of the communication aspect.- Parameters:
receiver
- Receiver whose communication is to be mediated.port
- Port of the communication aspect.- Returns:
- A new receiver.
- Throws:
IllegalActionException
- If the receiver cannot be created.
-
initialize
public void initialize() throws IllegalActionException
Initialize the actor variables.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicCommunicationAspect
- Throws:
IllegalActionException
- If the superclass throws it or the switch table could not be parsed from the actor parameters.
-
fire
public void fire() throws IllegalActionException
Move tokens from the input queue to the switch fabric, move tokens from the switch fabric queue to the output queues and send tokens from the output queues to the target receivers. When moving tokens between queues the appropriate delays are considered.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the token cannot be sent to target receiver.
-
postfire
public boolean postfire() throws IllegalActionException
If there are still tokens in the queue and a token has been produced in the fire, schedule a refiring.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- Returns:
- True if execution can continue into the next iteration.
- Throws:
IllegalActionException
- If the refiring cannot be scheduled or by super class.
-
sendToken
public void sendToken(Receiver source, Receiver receiver, Token token) throws IllegalActionException
Initiate a send of the specified token to the specified receiver. This method will schedule a refiring of this actor if there is not one already scheduled.- Parameters:
source
- Sender of the token.receiver
- The sending receiver.token
- The token to send.- Throws:
IllegalActionException
- If the refiring request fails.
-
setContainer
public void setContainer(CompositeEntity container) throws IllegalActionException, NameDuplicationException
Make sure that this communication aspect is only used in the DE domain.- Overrides:
setContainer
in classAtomicCommunicationAspect
- Parameters:
container
- The container of this actor.- Throws:
IllegalActionException
- If thrown by the super class or if the director of this actor is not a DEDirector.NameDuplicationException
- If thrown by the super class.- See Also:
ComponentEntity.getContainer()
-
setPortIn
public void setPortIn(Port port, int portIn)
Set the id of the switch input that is receiving tokens from this actor port.- Parameters:
port
- The actor port.portIn
- The id of the switch port.
-
setPortOut
public void setPortOut(Port port, int portOut)
Set the id of the switch output that is sending tokens to this actor port.- Parameters:
port
- The actor port.portOut
- The id of the switch port.
-
reset
public void reset()
Reset the communication aspect and clear the tokens.
-
_getNextFireTime
protected Time _getNextFireTime(Time nextFireTime, java.util.TreeSet<TimedEvent> tokens)
Get next fire time for a set of tokens which is either the minimum next fire time passed as an argument or the smallest timestamp of the tokens in the set.- Parameters:
nextFireTime
- Minimum next fire time.tokens
- The set of tokens.- Returns:
- The next time this actor should be fired based on the tokens in the queue.
-
_getPortID
protected int _getPortID(Receiver receiver, boolean input)
Return the IO of the switch port where this receiver is connected to. The port ID's are set via parameters.- Parameters:
receiver
- The actor receiver.input
- Whether the port is an input port.- Returns:
- The port ID.
-
_scheduleRefire
protected void _scheduleRefire() throws IllegalActionException
Schedule a refiring of this actor based on the tokens in the queues.- Throws:
IllegalActionException
- If actor cannot be refired at the computed time.
-
-