예제 #1
0
        return pkt.src == "SJSU2"

    ps1 = PacketSink(env, debug=False, rec_arrivals=True, selector=selector)
    ps2 = PacketSink(env, debug=False, rec_waits=True, selector=selector2)
    pg1 = PacketGenerator(env, "SJSU1", adist1, sdist)
    pg2 = PacketGenerator(env, "SJSU2", adist2, sdist)
    pg3 = PacketGenerator(env, "SJSU3", adist3, sdist)
    branch1 = RandomBrancher(env, [0.75, 0.25])
    branch2 = RandomBrancher(env, [0.65, 0.35])
    switch_port1 = SwitchPort(env, 's1', port_rate)
    switch_port2 = SwitchPort(env, 's2', port_rate)
    switch_port3 = SwitchPort(env, 's3', port_rate)
    switch_port4 = SwitchPort(env, 's4', port_rate)

    # Wire packet generators, switch ports, and sinks together
    pg1.out = switch_port1
    switch_port1.out = branch1
    branch1.outs[0] = switch_port2
    switch_port2.out = branch2
    branch2.outs[0] = switch_port3
    branch2.outs[1] = switch_port4
    pg3.out = switch_port3
    pg2.out = switch_port4
    switch_port3.out = ps1
    switch_port4.out = ps2
    # Run it
    env.run(until=4000)
    print(ps2.waits[-10:])
    # print pm.sizes[-10:]
    # print ps.arrivals[-10:]
    print("average wait source 1 to output 3 = {}".format(
예제 #2
0
    adist = functools.partial(random.expovariate, 0.5)
    sdist = functools.partial(random.expovariate, 0.01)  # mean size 100 bytes
    samp_dist = functools.partial(random.expovariate, 1.0)
    port_rate = 1000.0

    # Create the SimPy environment
    env = simpy.Environment()
    # Create the packet generators and sink
    ps = PacketSink(env, debug=False, rec_arrivals=True)
    pg = PacketGenerator(env, "Test", adist, sdist)
    switch_port = SwitchPort(env, port_rate, qlimit=10000)
    # Using a PortMonitor to track queue sizes over time
    pm = PortMonitor(env, switch_port, samp_dist)
    # Wire packet generators, switch ports, and sinks together
    pg.out = switch_port
    switch_port.out = ps
    # Run it
    env.run(until=8000)
    print("Last 10 waits: " +
          ", ".join(["{:.3f}".format(x) for x in ps.waits[-10:]]))
    print("Last 10 queue sizes: {}".format(pm.sizes[-10:]))
    print("Last 10 sink arrival times: " +
          ", ".join(["{:.3f}".format(x) for x in ps.arrivals[-10:]]))
    print("average wait = {:.3f}".format(sum(ps.waits) / len(ps.waits)))
    print("received: {}, dropped {}, sent {}".format(switch_port.packets_rec,
                                                     switch_port.packets_drop,
                                                     pg.packets_sent))
    print("loss rate: {}".format(
        float(switch_port.packets_drop) / switch_port.packets_rec))
    print("average system occupancy: {:.3f}".format(
예제 #3
0
from random import expovariate
import simpy
from SimComponents import PacketGenerator, PacketSink


def constArrival():  # Constant arrival distribution for generator 1
    return 1.5


def constArrival2():
    return 2.0


def distSize():
    return expovariate(0.01)


env = simpy.Environment()  # Create the SimPy environment
# Create the packet generators and sink
ps = PacketSink(env, debug=True)  # debugging enable for simple output
pg = PacketGenerator(env, "EE283", constArrival, distSize)
pg2 = PacketGenerator(env, "SJSU", constArrival2, distSize)
# Wire packet generators and sink together
pg.out = ps
pg2.out = ps
env.run(until=20)
    def const_size():
        return 1500.0

    pir = 6000.0  # 6Gbps
    pbs = 3000  # bytes
    cir = 3000.0  # 3Gbps
    cbs = 4000  # bytes

    env = simpy.Environment()
    pg = PacketGenerator(env, "SJSU", const_arrival, const_size)
    ps_green = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    ps_yellow = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    ps_red = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    marker = TrTCM(env, pir, pbs, cir, cbs)
    demux = FlowDemux([ps_green, ps_yellow, ps_red])
    pg.out = marker
    marker.out = demux
    env.run(until=50)

    fig, ax1 = plt.subplots()
    ax1.vlines(ps_green.arrivals,
               0.0,
               1.0,
               colors="g",
               linewidth=2.0,
               label='green')
    ax1.vlines(ps_yellow.arrivals,
               0.0,
               0.8,
               colors="y",
               linewidth=2.0,
예제 #5
0
                          flow_id=1)
    ps = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    ps2 = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    ps_snoop1 = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    ps_snoop2 = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    # Set up the virtual clock switch port
    source_rate = 8.0 * const_size() / const_arrival(
    )  # the average source rate
    phi_base = source_rate
    switch_port = WFQServer(env, source_rate, [0.5 * phi_base, 0.5 * phi_base])
    switch_port2 = VirtualClockServer(env, source_rate,
                                      [2.0 / phi_base, 2.0 / phi_base])
    demux = FlowDemux()
    snoop1 = SnoopSplitter()
    snoop2 = SnoopSplitter()
    pg.out = snoop1
    pg2.out = snoop2
    snoop1.out2 = ps_snoop1
    snoop2.out2 = ps_snoop2
    #  Comment out the next 4 lines and uncomment the following 4 lines to compare with virtual clock.
    type = "WFQ"
    snoop1.out1 = switch_port
    snoop2.out1 = switch_port
    switch_port.out = demux
    # snoop1.out1 = switch_port2
    # snoop2.out1 = switch_port2
    # switch_port2.out = demux
    # type = "VC"

    demux.outs = [ps, ps2]
    env.run(until=10000)
                         initial_delay=7.0,
                         finish=35)
    pg2 = PacketGenerator(env,
                          "SJSU",
                          const_arrival,
                          const_size,
                          initial_delay=7.0,
                          finish=35)
    ps = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    ps2 = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    source_rate = 8.0 * const_size() / const_arrival(
    )  # the average source rate
    bucket_rate = 0.5 * source_rate
    bucket_size = 1.0 * const_size()
    shaper = ShaperTokenBucket(env, bucket_rate, bucket_size)
    pg.out = ps
    pg2.out = shaper
    shaper.out = ps2
    env.run(until=10000)
    print ps.arrivals

    fig, axis = plt.subplots()
    axis.vlines(ps.arrivals,
                0.0,
                1.0,
                colors="g",
                linewidth=2.0,
                label='input stream')
    axis.vlines(ps2.arrivals,
                0.0,
                0.7,
예제 #7
0
                          finish=35,
                          flow_id=1)
    ps = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    ps2 = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    #    ps_snoop1 = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    #    ps_snoop2 = PacketSink(env, rec_arrivals=True, absolute_arrivals=True)
    # Set up the virtual clock switch port
    source_rate = 8.0 * const_size() / const_arrival(
    )  # the average source rate
    phi_base = source_rate
    switch_port = WFQServer(env, source_rate, [0.5 * phi_base, 0.5 * phi_base])
    #switch_port2 = VirtualClockServer(env, source_rate, [2.0/phi_base, 2.0/phi_base])
    demux = FlowDemux()
    #    snoop1 = SnoopSplitter()
    #    snoop2 = SnoopSplitter()
    pg.out = switch_port  #snoop1
    pg2.out = switch_port  #snoop2
    #snoop1.out2 = ps_snoop1
    #snoop2.out2 = ps_snoop2
    #  Comment out the next 4 lines and uncomment the following 4 lines to compare with virtual clock.
    type = "WFQ"
    #snoop1.out1 = switch_port
    #snoop2.out1 = switch_port
    switch_port.out = demux
    # snoop1.out1 = switch_port2
    # snoop2.out1 = switch_port2
    # switch_port2.out = demux
    # type = "VC"

    demux.outs = [ps, ps2]
    env.run(until=10000)
예제 #8
0

def constArrival(): # Constant arrival distribution for generator 1
    return 10

def constArrival2(): # Constant arrival distribution for generator 2
    return 15

def distSize(): # Random packet size distribution
    return expovariate(0.01)


env = simpy.Environment()  # Create the SimPy environment
# Create the packet generators and sink
ps = PacketSink(env, debug=True)  # debugging enable for simple output
pg = PacketGenerator(env, "EE283", constArrival, distSize)
pg2 = PacketGenerator(env, "SJSU", constArrival2, distSize)
# Wire packet generators and sink together
q1 = ocx.queue("q1")
q2 = ocx.queue("q2")


pg.out  = q1
pg2.out = q2

p = ocx.port(env)
p.all_queues = [q1,q2]
q1.x = p
q2.x = p
# Run it
env.run(until=200)
예제 #9
0
파일: modelos.py 프로젝트: wagamezj/trafico
def MM1K(lamda, mu, ql, user, port_rate, Tsim, bins, directorio):
    try:
        plt.close('all')

        ############# DEFINICION DE LOS PARAMETROS DEL MODELO #########################
        #    Creacion de carpeta temporal para guardar graficos
        if os.path.exists(directorio + 'temp_graficos'):
            shutil.rmtree(directorio + 'temp_graficos')
        os.mkdir(directorio + 'temp_graficos')
        #Parametros del Sumidero
        debugSink = False  #o False, muestra en la salida lo que llega al servidor
        rec_arrivalsSink = True  #Si es verdadero los arribos se graban
        abs_arrivalsSink = False  # true, se graban tiempos de arribo absoluto; False, el tiempo entre arribos consecutivos

        #Parametros del Generador de Paquetes.
        mu_paq = ((mu * 8) / port_rate)

        adist = functools.partial(
            random.expovariate, lamda)  #Tiempo de inter arribo de los paquetes
        sdist = functools.partial(random.expovariate,
                                  mu_paq)  # Tamaño de los paquetes

        #Parametros del Monitor
        Smd = lamda
        samp_dist = functools.partial(random.expovariate, Smd)

        ###############################################################################

        ############# CREACION DEL ENTORNO Y SUS COMPONENTES  #########################

        # Creación del Entorno de Simpy
        env = simpy.Environment()

        # Creación del Generador de Paquetes y Servidor
        psink = PacketSink(env,
                           debug=debugSink,
                           rec_arrivals=rec_arrivalsSink,
                           absolute_arrivals=abs_arrivalsSink)

        pg = PacketGenerator(env, user, adist, sdist)

        switch_port = SwitchPort(env, rate=port_rate, qlimit=ql)

        # PortMonitor para rastrear los tamaños de cola a lo largo del tiempo
        pm = PortMonitor(env, switch_port, samp_dist, count_bytes=True)

        ###############################################################################

        ############# CONEXION DE LOS COMPONENTES DEL MODELO  #########################

        pg.out = switch_port
        switch_port.out = psink

        # Correr la simulacion del entorno. Paramatro el tiempo
        env.run(until=Tsim)

        ###############################################################################

        ############# MUESTRA DE RESULTADOS  ##########################################

        pkt_drop = switch_port.packets_drop
        pkt_recibidos_serv = psink.packets_rec
        pkt_enviados = pg.packets_sent
        ocup_sistema_L = float(sum(pm.sizes)) / len(pm.sizes)
        intensidad_trafico = lamda / mu
        if lamda != mu:
            pk = (((1 - intensidad_trafico) * intensidad_trafico**(ql)) /
                  (1 - intensidad_trafico**(ql + 1)))
        else:
            pk = 1 / (ql + 1)

        lamda_eficaz = lamda * (1 - pk)
        espera_sist_W = ocup_sistema_L / lamda_eficaz
        espera_cola_Wq = espera_sist_W - 1 / mu
        ocup_cola_Lq = espera_cola_Wq * lamda_eficaz
        tasa_perdida = lamda * pk

        ###############################################################################

        ############# GRAFICOS  #######################################################
        directorio = directorio + "temp_graficos/"
        #--------- NORMALIZADOS-----------------------------------------------------
        fig, axis = plt.subplots()
        axis.hist(psink.waits,
                  bins,
                  normed=True,
                  alpha=1,
                  edgecolor='black',
                  linewidth=1)
        axis.set_title("Tiempos de Espera - Normalizado")
        axis.set_xlabel("Tiempo")
        axis.set_ylabel("Frecuencia de ocurrencia")
        fig.savefig(directorio + "WaitHistogram_normal.png")

        fig, axis = plt.subplots()
        axis.hist(pm.sizes,
                  bins,
                  normed=True,
                  alpha=1,
                  edgecolor='black',
                  linewidth=1)
        axis.set_title("Tiempos de Ocupación del Sistema - Normalizado")
        axis.set_xlabel("Nro")
        axis.set_ylabel("Frecuencia de ocurrencia")
        fig.savefig(directorio + "QueueHistogram_normal.png")

        fig, axis = plt.subplots()
        axis.hist(psink.arrivals,
                  bins,
                  normed=True,
                  alpha=1,
                  edgecolor='black',
                  linewidth=1)
        axis.set_title("Tiempos de Inter-Arribo a la Cola - Normalizado")
        axis.set_xlabel("Tiempo")
        axis.set_ylabel("Frecuencia de ocurrencia")
        fig.savefig(directorio + "ArrivalHistogram_normal.png")

        #---------SIN NORMALIZAR-----------------------------------------------------
        fig, axis = plt.subplots()
        axis.hist(psink.waits,
                  bins,
                  normed=False,
                  alpha=1,
                  edgecolor='black',
                  linewidth=1)
        axis.set_title("Tiempos de Espera")
        axis.set_xlabel("Tiempo")
        axis.set_ylabel("Frecuencia de ocurrencia ")
        fig.savefig(directorio + "WaitHistogram.png")

        fig, axis = plt.subplots()
        axis.hist(pm.sizes,
                  bins,
                  normed=False,
                  alpha=1,
                  edgecolor='black',
                  linewidth=1)
        axis.set_title("Tiempos de Ocupación del Sistema")
        axis.set_xlabel("Nro")
        axis.set_ylabel("Frecuencia de ocurrencia")
        fig.savefig(directorio + "QueueHistogram.png")

        fig, axis = plt.subplots()
        axis.hist(psink.arrivals,
                  bins,
                  normed=False,
                  alpha=1,
                  edgecolor='black',
                  linewidth=1)
        axis.set_title("Tiempos de Inter-Arribo a la Cola")
        axis.set_xlabel("Tiempo")
        axis.set_ylabel("Frecuencia de ocurrencia")
        fig.savefig(directorio + "ArrivalHistogram.png")

        datos = psink.data
        str1 = '&'.join(datos)
        aux_str1 = str1
        str1 = aux_str1.replace('&', '\n')
        aux_str1 = str1
        str1 = (aux_str1.replace(',', '  \t  '))

        return str1, espera_sist_W, pkt_drop, pkt_enviados, tasa_perdida, ocup_sistema_L, pkt_recibidos_serv, intensidad_trafico, espera_cola_Wq, ocup_cola_Lq

    except:
        error = traceback.format_exc()
        QMessageBox.critical(
            None, 'Error de ejecucion', "Detalle del error:\n\n" + error +
            '\n\nPor favor, revise la documentacion del programa.',
            QMessageBox.Ok)
        sys.exit(0)
예제 #10
0
    # figure out the use of selector
    # ps1 = PacketSink(env, debug=False, rec_arrivals=True)
    pg1 = PacketGenerator(env, 'src1', adist1, sdist)
    pg2 = PacketGenerator(env, 'src2', adist2, sdist)
    branch1 = RandomBrancher(env, [0.50, 0.50])
    branch2 = RandomBrancher(env, [0.50, 0.50])
    #pseudoBrancher
    branch3 = RandomBrancher(env, [1.00, 0.00])
    switch_port1 = SwitchPort(env, port_rate, qlimit=qlim)
    switch_port2 = SwitchPort(env, port_rate, qlimit=qlim)
    switch_port3 = SwitchPort(env, port_rate, qlimit=qlim)
    switch_port4 = SwitchPort(env, port_rate, qlimit=qlim)
    switch_port5 = SwitchPort(env, port_rate, qlimit=qlim)

    # Wire packet generators, switch ports, and sinks together
    pg1.out = switch_port1
    switch_port1.out = branch1
    branch1.outs[0] = switch_port3
    branch1.outs[1] = switch_port4
    pg2.out = switch_port2
    switch_port2.out = branch2
    branch2.outs[0] = switch_port3
    branch2.outs[1] = switch_port4

    switch_port3.out = branch3
    branch3.outs[0] = switch_port5

    switch_port4.out = branch3
    branch3.outs[0] = switch_port5

    switch_port5.out = ps1