Esempio n. 1
0
def update_cycle_broadcasts():
    interval = 22
    ids = ['a', 'b', 'c', 'd', 'e', 'f']
    eqstate = EQState(map(lambda id: QCell(id), ids))
    sim = Simulator(eqstate, {0: [('a', 'Join')],
                              2: [('b', 'Join')],
                              3: [('c', 'Join')],
                              7: [('d', 'Join')],
                              8: [('e', 'Join')],
                              })
    sim.run(interval)
    trace = ''
    for t in range(0, interval):
        step = sim.step(t).to_str(0,0,0,0,1,0)
        if step.find('-.-')  == -1:
            step = sim.step(t).to_str(0,0,0,1,1,0)
        trace += '%s:\n%s' % (t, step)
    
    print ("""
Example: Messages and Broadcasts
--------------------------------""")
    print (trace)
    print ("""
This shows Cells 'a' - 'e' joining an eager queue. When 'd' and 'e' join there
is a collision "*.*" and one of the cells backs off.""")
Esempio n. 2
0
def join_join():
    """a.Join() ... b.Join()"""
    interval = 9
    ids = ['a', 'b', 'c', 'd', 'e', 'f']
    eqstate = EQState(map(lambda id: QCell(id), ids))
    sim = Simulator(eqstate, {1: [('a', 'Join')],
                              2: [('b', 'Join')],})
    sim.run(interval)
    trace = ''
    for t in range(0, interval):
        trace += '%s:\n%s' % (t, sim.step(t).to_str(0,1,1,0,1,1))
    print ("""
Example: Two QCells Setting Up an Eager Queue
---------------------------------------------""")
    print (trace + str(interval) + ':')
    print ('-' * 80 + """
 0 - 1: All 6 QCells are Idling.
 1 - 2: A Join command is issued and cell 'a' goes into the Listening state.
        There is no broadcast so the QCell increments its NoMessage count.
 2 - 3: A Join command is issued and cell 'b' goes into the Listening state.
        Cell 'a' listens to the channel and as there is no broadcast moves
        into the Joining state.
 3 - 4: Cell 'a' broadcasts a JOIN message and starts an eager queue.
 4 - 5: Cell 'b' broadcasts a JOIN message and joins the eager queue.
 5 - 6: Cell 'a' and 'b' listen to the channe
        and increment their NoMessage counts.
 6 - 7: Cell 'a' is at the back of the LKT vector so it broadcasts an UPDATE.
 7 - 8: Cell 'a' and 'b' listen to the channe
        and increment their NoMessage counts.
 8 - 9: Cell 'b' is at the back of the LKT vector so it broadcasts an UPDATE.
 """)
Esempio n. 3
0
def join_exit():
    """a.Join() ... a.Exit()"""
    interval = 8
    ids = ['a', 'b', 'c', 'd', 'e', 'f']
    eqstate = EQState(map(lambda id: QCell(id), ids))
    sim = Simulator(eqstate, {1: [('a', 'Join')],
                              6: [('a', 'Exit')],})
    sim.run(interval)
    trace = ''
    for t in range(0, interval):
        trace += '%s:\n%s' % (t, sim.step(t).to_str(0,1,1,0,1,1))
    print ("""
Example: A Single QCell Setting Up an Eager Queue and Exiting
-------------------------------------------------------------""")
    print (trace + str(interval) + ':')
    print ('-' * 80 + """
 0 - 1: All 6 QCells are Idling.
 1 - 2: A Join command is issued, the cell 'a' goes into the Listening state.
        There is no broadcast so the QCell increments its NoMessage count.
 2 - 3: Cell 'a' listens to the channel and as there is no broadcast moves
        into the Joining state.
 3 - 4: Cell 'a' broadcasts a JOIN message and starts an eager queue.
 4 - 5: Cell 'a' listens to the channel and increments its NoMessage count.
 5 - 6: As Cell 'a' is the only QCell in the queue it broadcasts an UPDATE.
 6 - 7: An Exit command is issued and Cell 'a' broadcasts an EXIT message
        immediately.
 7 - 8: All 6 QCells are Idling again.""")
Esempio n. 4
0
def join_request():
    """a.Join() ... b.Join()"""
    interval = 9
    ids = ['a', 'b', 'c', 'd', 'e', 'f']
    eqstate = EQState(map(lambda id: QCell(id), ids))
    sim = Simulator(eqstate, {1: [('a', 'Join')],
                              4: [('f', 'Request')],})
    sim.run(interval)
    trace = ''
    for t in range(0, interval):
        trace += '%s:\n%s' % (t, sim.step(t).to_str(0,1,1,0,1,1))
    print ("""
Example: One Cell sets up an Eager Queue, Another makes a Request
-----------------------------------------------------------------""")
    print (trace)
Esempio n. 5
0
def request_with_decline():   
    interval = 19
    ids = ['a', 'b', 'c', 'd', 'e', 'f']
    eqstate = EQState(map(lambda id: QCell(id), ids))
    sim = Simulator(eqstate, {0: [('e', 'Join')],
                              2: [('d', 'Join')],
                              3: [('c', 'Join')],
                              5: [('f', 'Join')],
                              10: [('a', 'Request')],
                              13: [('c', 'Exit')],
                              })
    sim.run(interval)
    trace = ''
    for t in range(9, interval):
        trace += '%s:\n%s' % (t, sim.step(t).to_str(0,1,0,0,1,0))
    print ("""
Example: Request with Decline
-----------------------------""")
    print (trace)
Esempio n. 6
0
def requests():   
    interval = 21
    ids = ['a', 'b', 'c', 'd', 'e', 'f']
    eqstate = EQState(map(lambda id: QCell(id), ids))
    sim = Simulator(eqstate, {0: [('a', 'Join')],
                              2: [('d', 'Join')],
                              3: [('c', 'Join')],
                              5: [('b', 'Join')],
                              10: [('e', 'Request')],
                              15: [('f', 'Request')],
                              })
    sim.run(interval)
    trace = ''
    for t in range(9, interval):
        trace += '%s:\n%s' % (t, sim.step(t).to_str(0,1,0,0,1,0))
    print ("""
Example: Two Requests started on Different "Phases"
--------------------------------------------------""")
    print (trace)