SimComponentsDynamic module¶
A bit more detailed set of components to use in packet switching queueing experiments. Copyright 2014 Greg M. Bernstein Released under the MIT license
Created on Thu Jun 16 14:42:05 2022
@author: abhijeetsahu
Modified the SwitchPort class to redirect traffic: basic testing done
- class SimComponentsDynamic.Firewall(env, id, rate, qlimit=None, limit_bytes=True, debug=False)¶
Bases:
SimComponentsDynamic.SwitchPort
- change_policy()¶
- class SimComponentsDynamic.FlowDemux(outs=None, default=None)¶
Bases:
object
A demultiplexing element that splits packet streams by flow_id.
Contains a list of output ports of the same length as the probability list in the constructor. Use these to connect to other network elements.
- outsList
list of probabilities for the corresponding output ports
- put(pkt)¶
- class SimComponentsDynamic.Packet(time, size, id, src='a', dst='z', flow_id=0)¶
Bases:
object
A very simple class that represents a packet. This packet will run through a queue at a switch output port. We use a float to represent the size of the packet in bytes so that we can compare to ideal M/M/1 queues.
- timefloat
the time the packet arrives at the output queue.
- sizefloat
the size of the packet in bytes
- idint
an identifier for the packet
- src, dstint
identifiers for source and destination
- flow_idint
small integer that can be used to identify a flow
- class SimComponentsDynamic.PacketGenerator(env, id, adist, sdist, initial_delay=0, finish=inf, flow_id=0)¶
Bases:
object
Generates packets with given inter-arrival time distribution. Set the “out” member variable to the entity to receive the packet.
- envsimpy.Environment
the simulation environment
- adistfunction
a no parameter function that returns the successive inter-arrival times of the packets
- sdistfunction
a no parameter function that returns the successive sizes of the packets
- initial_delaynumber
Starts generation after an initial delay. Default = 0
- finishnumber
Stops generation at the finish time. Default is infinite
- run()¶
The generator function used in simulations.
- class SimComponentsDynamic.PacketSink(env, id, rec_arrivals=False, absolute_arrivals=False, rec_waits=True, debug=False, selector=None)¶
Bases:
object
Receives packets and collects delay information into the waits list. You can then use this list to look at delay statistics.
- envsimpy.Environment
the simulation environment
- debugboolean
if true then the contents of each packet will be printed as it is received.
- rec_arrivalsboolean
if true then arrivals will be recorded
- absolute_arrivalsboolean
if true absolute arrival times will be recorded, otherwise the time between consecutive arrivals is recorded.
- rec_waitsboolean
if true waiting time experienced by each packet is recorded
- selector: a function that takes a packet and returns a boolean
used for selective statistics. Default none.
- put(pkt)¶
- class SimComponentsDynamic.PortMonitor(env, port, dist, count_bytes=False)¶
Bases:
object
A monitor for an SwitchPort. Looks at the number of items in the SwitchPort in service + in the queue and records that info in the sizes[] list. The monitor looks at the port at time intervals given by the distribution dist.
- envsimpy.Environment
the simulation environment
- portSwitchPort
the switch port object to be monitored.
- distfunction
a no parameter function that returns the successive inter-arrival times of the packets
- run()¶
- class SimComponentsDynamic.RandomBrancher(env, probs)¶
Bases:
object
A demultiplexing element that chooses the output port at random.
Contains a list of output ports of the same length as the probability list in the constructor. Use these to connect to other network elements.
- envsimpy.Environment
the simulation environment
- probsList
list of probabilities for the corresponding output ports
- put(pkt)¶
- class SimComponentsDynamic.Router(env, id, rate, qlimit=None, limit_bytes=True, debug=False)¶
Bases:
SimComponentsDynamic.SwitchPort
- event2()¶
- exec_action()¶
- run()¶
- class SimComponentsDynamic.ShaperTokenBucket(env, rate, b_size, peak=None, debug=False)¶
Bases:
object
Models an ideal token bucket shaper. Note the token bucket size should be greater than the size of the largest packet that can occur on input. If this is not the case we always accumulate enough tokens to let the current packet pass based on the average rate. This may not be the behavior you desire.
- envsimpy.Environment
the simulation environment
- ratefloat
the token arrival rate in bits
- b_sizeNumber
a token bucket size in bytes
- peakNumber or None for infinite peak
the peak sending rate of the buffer (quickest time two packets could be sent)
- put(pkt)¶
- run()¶
- class SimComponentsDynamic.SnoopSplitter¶
Bases:
object
A snoop port like splitter. Sends the original packet out port 1 and sends a copy of the packet out port 2.
You need to set the values of out1 and out2.
- put(pkt)¶
- class SimComponentsDynamic.StampedStore(env, capacity=inf)¶
Bases:
simpy.resources.base.BaseResource
Models the production and consumption of concrete Python objects.
Items put into the store can be of any type. By default, they are put and retrieved from the store in a first-in first-out order.
The env parameter is the
Environment
instance the container is bound to.The capacity defines the size of the Store and must be a positive number (> 0). By default, a Store is of unlimited size. A
ValueError
is raised if the value is negative.- property capacity¶
The maximum capacity of the store.
- event_count¶
List of the items within the store.
- get¶
Create a new
StoreGet
event.alias of
SimComponentsDynamic.StampedStoreGet
- put¶
Create a new
StorePut
event.alias of
SimComponentsDynamic.StampedStorePut
- class SimComponentsDynamic.StampedStoreGet(resource: ResourceType)¶
Bases:
simpy.resources.base.Get
Get an item from the store or wait until one is available.
- class SimComponentsDynamic.StampedStorePut(resource, item)¶
Bases:
simpy.resources.base.Put
Put item into the store if possible or wait until it is. The item must be a tuple (stamp, contents) where the stamp is used to sort the content in the StampedStore.
- item¶
The item to put into the store.
- class SimComponentsDynamic.SwitchPort(env, id, rate, qlimit=None, limit_bytes=True, debug=False)¶
Bases:
object
Models a switch output port with a given rate and buffer size limit in bytes. Set the “out” member variable to the entity to receive the packet.
- envsimpy.Environment
the simulation environment
- ratefloat
the bit rate of the port
- qlimitinteger (or None)
a buffer size limit in bytes or packets for the queue (including items in service).
- limit_bytesIf true, the queue limit will be based on bytes if false the
queue limit will be based on packets.
- change_receiver(new_receiver)¶
- put(pkt)¶
- run()¶
- class SimComponentsDynamic.TrTCM(env, pir, pbs, cir, cbs)¶
Bases:
object
A Two rate three color marker. Uses the flow_id packet field to mark the packet with green = 0, yellow = 1, red = 2.
env : the SimPy environment (so we can get the simulated time) pir : Peak Information Rate in units of bits (slighly different from RFC) pbs : Peak Burst Size in units of bytes cir : Committed Information Rate in units of bits (time part maybe scaled) cbs : Committed Burst Size in bytes
- put(pkt)¶
- class SimComponentsDynamic.VirtualClockServer(env, rate, vticks, debug=False)¶
Bases:
object
Models a virtual clock server. For theory and implementation see: L. Zhang, Virtual clock: A new traffic control algorithm for packet switching networks, in ACM SIGCOMM Computer Communication Review, 1990, vol. 20, pp. 19.
- envsimpy.Environment
the simulation environment
- ratefloat
the bit rate of the port
- vticksA list
list of the vtick parameters (for each possible packet flow_id). We assume a simple assignment of flow id to vticks, i.e., flow_id = 0 corresponds to vticks[0], etc… We assume that the vticks are the inverse of the desired rates for the flows in bits per second.
- put(pkt)¶
- run()¶
- class SimComponentsDynamic.WFQServer(env, rate, phis, debug=False)¶
Bases:
object
Models a WFQ/PGPS server. For theory and implementation see:
- envsimpy.Environment
the simulation environment
- ratefloat
the bit rate of the port
- phisA list
list of the phis parameters (for each possible packet flow_id). We assume a simple assignment of flow id to phis, i.e., flow_id = 0 corresponds to phis[0], etc…
- put(pkt)¶
- run()¶