Faculty of Engineering and Mathematical Sciences 
Not logged in (login)


This forum is provided to promote discussion amongst students enrolled in Computer Networks (CITS3002).
Before posting a question here, you may like to read the article How To Ask Questions The Smart Way.
RSS cloud
Jump to:

Pseudo Code Marking Guide

1 of 768 articles shown, currently no other people reading this forum.
Date: Mon 8th Jun, 10:39am


Hi Chris, 

Would something like this be correct for 2017 Q1b? 

def csma_one_persistent(nNode, nSlotTime, probNew):
  # set each node to true as all nodes want to transmit 
  transmit = [False] * nNode  # will produce an array of False for the num of nodes 
  # for each time slot 
  For slot in range(nSlotTime):
    nAttempting = 0 # set num attempting to transmit to zero 
    successfulNode = -1 # set -1 to indicate that no node was successful yet 
    # determine what nodes need to transmit or re-transmit during this time slot 
    For node in range(nNodes): 
      # does the node have a new transmission? 
      If not transmitting[node] and rand(0,1) < probNew:
        transmitting[n] = true # the node is attempting to transmit 
        successfulNode = n
        nAttempting = nAttempting + 1
      # does the node need to transmit (i.e. it waited for the next timeslot)? 
      Elif transmitting[n]:  
        successfulNode = n
        nAttempting = nAttempting + 1 
      If nAttempting == 1: # if I am the first node transmitting in this timeslot, then I 
have succeeded 
        nSuccess = nSuccess + 1
        transmitting[successfulNode] = false # set the node back to not needing to 
transmit (false)
        # All subsequent nodes will hear that there is already a transmission and NOT 
transmit, but wait for the next timeslot to transmit (i.e. it is one-persistent) 

nNodes = 10 # number of nodes wishing to transmit (arbitrarily assigned for this example) 
nSlotTime= 10000 # num of slots times for the simulation(arbitrarily assigned for this 
example). Each slot time represents 52 miliseconds  
probNew = 0.5 # probablility that a new message is to be sent 
csma_one_persistent(nNodes, nSlotTime, probNew)

Related articles

Pseudo Code Marking Guide (all 13) RSS
├─ original   Sun 7th Jun, 11:40pm, ANONYMOUS
├─ reply 1   Mon 8th Jun, 10:08am, ANONYMOUS
├─ THIS   Mon 8th Jun, 10:39am, ANONYMOUS
├─ reply 3   Mon 8th Jun, 10:41am, ANONYMOUS
├─ reply 4   Mon 8th Jun, 10:46am, ANONYMOUS  O.P.
├─ reply 5   Mon 8th Jun, 10:49am, ANONYMOUS
├─ reply 6   Mon 8th Jun, 4:34pm, Christopher M.
├─ reply 7   Mon 8th Jun, 4:42pm, ANONYMOUS  O.P.
├─ reply 8   Mon 8th Jun, 5:25pm, ANONYMOUS
├─ reply 9   Mon 8th Jun, 6:16pm, Christopher M.
├─ reply 10   Mon 8th Jun, 6:32pm, ANONYMOUS
├─ reply 11   Mon 8th Jun, 6:36pm, Christopher M.
└─ reply 12   Mon 8th Jun, 6:39pm, ANONYMOUS
This Page

Program written by: [email protected]
Feedback welcome
Last modified:  5:31am Aug 04 2020