def test(alias, dest, connection, verbose) :
    connection.network.send(makeframe(alias, dest))
    reply = connection.network.receive()
    if (reply == None ) : 
        print "Expected reply to good request not received"
        return 2
    if not (reply.startswith(":X19668") and int(reply[11:15],16)==alias and int(reply[7:10],16)==dest) :
        print "Unexpected reply received ", reply
        return 1
    if verbose : 
        print "  Node supports:"
        value = canolcbutils.bodyArray(reply)
        if (value[2] & 0x80) != 0 : print "      Protocol Identification"
        if (value[2] & 0x40) != 0 : print "      Datagram Protocol"
        if (value[2] & 0x20) != 0 : print "      Stream Protocol"
        if (value[2] & 0x10) != 0 : print "      Memory Configuration Protocol"
        if (value[2] & 0x08) != 0 : print "      Reservation Protocol"
        if (value[2] & 0x04) != 0 : print "      Event Exchange (P/C) Protocol"
        if (value[2] & 0x02) != 0 : print "      Identification Protocol"
        if (value[2] & 0x01) != 0 : print "      Teaching/Learning Protocol"
        if (value[3] & 0x80) != 0 : print "      Remote Button Protocol"
        if (value[3] & 0x40) != 0 : print "      Abbreviated Default CDI Protocol"
        if (value[3] & 0x20) != 0 : print "      Display Protocol"
        if (value[3] & 0x10) != 0 : print "      Simple Node Information Protocol"
        if (value[3] & 0x08) != 0 : print "      Configuration Description Information"

    if verbose : print "  not addressed, expect no reply"
    connection.network.send(makeframe(alias, (~dest)&0xFFF))
    reply = connection.network.receive()
    if (reply != None ) : 
        print "Unexpected reply received to request to different node ", reply
        return 1

    # test expansion by sending a start-only, then an end-only frame
        
    body = [((dest>>8)&0xFF)|0x10, dest&0xFF,0,0, 0,0,0,0]
    frame = canolcbutils.makeframestring(0x19828000+alias,body)
    connection.network.send(frame)

    reply = connection.network.receive()

    body = [((dest>>8)&0xFF)|0x20, dest&0xFF,0,0, 0,0,0,0]
    frame = canolcbutils.makeframestring(0x19828000+alias,body)
    connection.network.send(frame)

    if (reply == None ) : # if no reply to 1st frame, see if reply to 2nd frame; either OK
        reply = connection.network.receive()

    if (reply == None ) : 
        print "Expected reply to double frame not received"
        return 2
    if not (reply.startswith(":X19668") and int(reply[11:15],16)==alias and int(reply[7:10],16)==dest) :
        print "Unexpected reply received ", reply
        return 1

    reply = connection.network.receive()
    if (reply != None ) : 
        print "  Suggestion: PIP should handle start-end bits in requests for future expansion"

    return 0
def test(alias, nodeID, dest, connection, verbose):
    if verbose: print "  test against verifyNodeGlobal"
    # first, send to this node
    connection.network.send(
        canolcbutils.makeframestring(0x09490000 + alias, nodeID))
    reply = connection.network.receive()
    if reply == None:
        print "Global verify with matching node ID did not receive expected reply"
        return 2
    elif not reply.startswith(":X19170"):
        print "Global verify with matching node ID received wrong reply message", reply
        return 4

    # send without node ID
    connection.network.send(
        canolcbutils.makeframestring(0x09490000 + alias, None))
    reply = connection.network.receive()
    if reply == None:
        print "Global verify without node ID did not receive expected reply"
        return 12
    elif not reply.startswith(":X19170"):
        print "Global verify without node ID received wrong reply message ", reply
        return 14

    # send with wrong node ID
    connection.network.send(
        canolcbutils.makeframestring(0x09490000 + alias, [0, 0, 0, 0, 0, 1]))
    reply = connection.network.receive()
    if reply != None:
        print "Global verify with wrong node ID should not receive reply but did: ", reply
        return 24

    if verbose: print "  test against verifyNodeAddressed"
    connection.network.send(makeAddressedFrame(alias, dest, nodeID))
    reply = connection.network.receive()
    if reply == None:
        print "Expected reply not received"
        return 2
    elif not reply.startswith(":X19170"):
        print "Unexpected reply received ", reply
        return 1

    # try with invalid alias
    connection.network.send(makeAddressedFrame(alias, ~dest, nodeID))
    reply = connection.network.receive()
    if reply != None:
        print "Unexpected reply received ", reply
        return 1

    return 0
Example #3
0
def test(alias, nodeID, connection, verbose) :
    # check with node id in frame
    connection.network.send(makeframe(alias, nodeID))
    reply = connection.network.receive()
    if (reply == None ) : 
        print "Expected reply when node ID matches not received"
        return 2
    elif not reply.startswith(":X10701") :
        print "Unexpected reply received ", reply
        return 1

    # check without node id in frame 
    connection.network.send(canolcbutils.makeframestring(0x10702000+alias,None))
    reply = connection.network.receive()
    if (reply == None ) : 
        print "Expected reply when no node ID in body not received"
        return 2
    elif not reply.startswith(":X10701") :
        print "Unexpected reply received ", reply
        return 1

    # test non-matching NodeID using a reserved one
    connection.network.send(makeframe(alias, [0,0,0,0,0,1]))
    reply = connection.network.receive()
    if (reply != None ) : 
        print "Unexpected reply received when node ID didnt match ", reply
        return 2
        
    return 0
Example #4
0
def test(alias, nodeID, dest, connection, verbose):
    if verbose : print "  test against verifyNodeGlobal"
    # first, send to this node
    connection.network.send(canolcbutils.makeframestring(0x09490000+alias,nodeID))
    reply = connection.network.receive()
    if reply == None : 
        print "Global verify with matching node ID did not receive expected reply"
        return 2
    elif not reply.startswith(":X19170") :
        print "Global verify with matching node ID received wrong reply message", reply
        return 4

    # send without node ID
    connection.network.send(canolcbutils.makeframestring(0x09490000+alias, None))
    reply = connection.network.receive()
    if reply == None : 
        print "Global verify without node ID did not receive expected reply"
        return 12
    elif not reply.startswith(":X19170") :
        print "Global verify without node ID received wrong reply message ", reply
        return 14

    # send with wrong node ID
    connection.network.send(canolcbutils.makeframestring(0x09490000+alias, [0,0,0,0,0,1]))
    reply = connection.network.receive()
    if reply != None : 
        print "Global verify with wrong node ID should not receive reply but did: ", reply
        return 24

    if verbose : print "  test against verifyNodeAddressed"
    connection.network.send(makeAddressedFrame(alias, dest, nodeID))
    reply = connection.network.receive()
    if reply == None : 
        print "Expected reply not received"
        return 2
    elif not reply.startswith(":X19170") :
        print "Unexpected reply received ", reply
        return 1

    # try with invalid alias
    connection.network.send(makeAddressedFrame(alias, ~dest, nodeID))
    reply = connection.network.receive()
    if reply != None : 
        print "Unexpected reply received ", reply
        return 1
    
    return 0
def test(alias, dest, connection, verbose) :
    connection.network.send(makeframe(alias, dest))
    body = [(alias>>8)&0xFF, alias&0xFF]
    expect = canolcbutils.makeframestring(0x19668000 + dest, body)
    expect = expect[:-1]
    reply = connection.network.expect(startswith=expect)
    if (reply == None) :
        print "Expected reply to good request not received"
        return 2
    if (verbose) : 
        print "  Node supports:"
        value = canolcbutils.bodyArray(reply)
        if (value[2] & 0x80) != 0 : print "      Protocol Identification"
        if (value[2] & 0x40) != 0 : print "      Datagram Protocol"
        if (value[2] & 0x20) != 0 : print "      Stream Protocol"
        if (value[2] & 0x10) != 0 : print "      Memory Configuration Protocol"
        if (value[2] & 0x08) != 0 : print "      Reservation Protocol"
        if (value[2] & 0x04) != 0 : print "      Event Exchange (P/C) Protocol"
        if (value[2] & 0x02) != 0 : print "      Identification Protocol"
        if (value[2] & 0x01) != 0 : print "      Teaching/Learning Protocol"
        if (value[3] & 0x80) != 0 : print "      Remote Button Protocol"
        if (value[3] & 0x40) != 0 : print "      Abbreviated Default CDI Protocol"
        if (value[3] & 0x20) != 0 : print "      Display Protocol"
        if (value[3] & 0x10) != 0 : print "      Simple Node Information Protocol"
        if (value[3] & 0x08) != 0 : print "      Configuration Description Information"
        if (value[3] & 0x04) != 0 : print "      Traction Control Protocol"
        if (value[3] & 0x02) != 0 : print "      Function Description Information"
        if (value[3] & 0x01) != 0 : print "      DCC Command Station Protocol"
        if (value[4] & 0x80) != 0 : print "      SimpleTrain Node Information"
        if (value[4] & 0x40) != 0 : print "      Function Configuration"
        if (value[4] & 0x20) != 0 : print "      Firmware Upgrade Protocol"
        if (value[4] & 0x10) != 0 : print "      Firmware Upgrade Active"

    if (verbose) :
        print "  not addressed, expect no reply"
    connection.network.send(makeframe(alias, (~dest)&0xFFF))
    body = [(alias>>8)&0xFF, alias&0xFF]
    expect = canolcbutils.makeframestring(0x19668000 + dest, body)
    expect = expect[:-1]
    reply = connection.network.expect(startswith=expect)
    if (reply != None ) : 
        print "Unexpected reply received to request to different node ", reply
        return 1

    return 0
def test(alias, dest, nodeID, connection, verbose):
    # send correct address, correct node ID in body
    connection.network.send(makeframe(alias, dest, nodeID))
    expect = canolcbutils.makeframestring(0x19170000 + dest, nodeID)
    if (connection.network.expect(exact=expect) == None):
        print "Expected reply to correct alias & correct ID not received"
        return 2

    # send correct address, no node ID in body
    connection.network.send(makeframe(alias, dest, None))
    if (connection.network.expect(startswith=":X19170", data=nodeID) == None):
        print "Expected reply to correct alias & no ID not received"
        return 2

    # send correct address, wrong node ID in body
    tnodeID = copy.copy(nodeID)
    tnodeID[0] = tnodeID[0] ^ 1

    connection.network.send(makeframe(alias, dest, tnodeID))
    if (connection.network.expect(startswith=":X19170", data=nodeID) == None):
        print "Expected reply to correct alias & incorrect ID not received"
        return 2

    # repeat all three with invalid alias
    connection.network.send(makeframe(alias, (~dest) & 0xFFF, nodeID))
    expect = canolcbutils.makeframestring(0x19170000 + dest, nodeID)
    reply = connection.network.expect(exact=expect)
    if (reply != None):
        print "Unexpected reply received on incorrect alias, OK nodeID", reply
        return 1

    connection.network.send(makeframe(alias, (~dest) & 0xFFF, None))
    reply = connection.network.expect(startswith=":X19170", data=nodeID)
    if (reply != None):
        print "Unexpected reply received on incorrect alias, no nodeID", reply
        return 1

    connection.network.send(makeframe(alias, (~dest) & 0xFFF, tnodeID))
    reply = connection.network.expect(startswith=":X19170", data=nodeID)
    if (reply != None):
        print "Unexpected reply received on incorrect alias, wrong nodeID", reply
        return 1

    return 0
def test(alias, dest, nodeID, connection, verbose) :
    # send correct address, correct node ID in body
    connection.network.send(makeframe(alias, dest, nodeID))
    expect = canolcbutils.makeframestring(0x19170000 + dest, nodeID)
    if (connection.network.expect(exact=expect) == None) :
        print "Expected reply to correct alias & correct ID not received"
        return 2

    # send correct address, no node ID in body
    connection.network.send(makeframe(alias, dest, None))
    if (connection.network.expect(startswith=":X19170", data=nodeID) == None) :
        print "Expected reply to correct alias & no ID not received"
        return 2

    # send correct address, wrong node ID in body
    tnodeID = copy.copy(nodeID)
    tnodeID[0] = tnodeID[0]^1
    
    connection.network.send(makeframe(alias, dest, tnodeID))
    if (connection.network.expect(startswith=":X19170", data=nodeID) == None) :
        print "Expected reply to correct alias & incorrect ID not received"
        return 2

    # repeat all three with invalid alias
    connection.network.send(makeframe(alias, (~dest)&0xFFF, nodeID))
    expect = canolcbutils.makeframestring(0x19170000 + dest, nodeID)
    reply = connection.network.expect(exact=expect)
    if (reply != None) :
        print "Unexpected reply received on incorrect alias, OK nodeID", reply
        return 1
    
    connection.network.send(makeframe(alias, (~dest)&0xFFF, None))
    reply = connection.network.expect(startswith=":X19170", data=nodeID)
    if (reply != None) :
        print "Unexpected reply received on incorrect alias, no nodeID", reply
        return 1
    
    connection.network.send(makeframe(alias, (~dest)&0xFFF, tnodeID))
    reply = connection.network.expect(startswith=":X19170", data=nodeID)
    if (reply != None) :
        print "Unexpected reply received on incorrect alias, wrong nodeID", reply
        return 1
    
    return 0
def test(alias, dest, nodeID, connection, verbose) :
    # check with node id in frame
    connection.network.send(makeframe(alias, nodeID))
    expect = canolcbutils.makeframestring(0x10701000 + dest, nodeID)
    if (connection.network.expect(exact=expect) == None) :
        print "Expected reply when node ID matches not received"
        return 2

    # check without node id in frame 
    connection.network.send(canolcbutils.makeframestring(0x10702000+alias,None))
    expect = canolcbutils.makeframestring(0x10701000 + dest, nodeID)
    if (connection.network.expect(exact=expect) == None) :
        print "Expected reply when node ID matches not received"
        return 2

    # test non-matching NodeID using a reserved one
    connection.network.send(makeframe(alias, [0,0,0,0,0,1]))
    reply = connection.network.receive()
    if (connection.network.expect(exact=expect) != None) :
        print "Unexpected reply received when node ID didnt match ", reply
        return 2
        
    return 0
Example #9
0
def test(alias, dest, nodeID, connection, verbose):
    # check with node id in frame
    connection.network.send(makeframe(alias, nodeID))
    expect = canolcbutils.makeframestring(0x10701000 + dest, nodeID)
    if (connection.network.expect(exact=expect) == None):
        print "Expected reply when node ID matches not received"
        return 2

    # check without node id in frame
    connection.network.send(
        canolcbutils.makeframestring(0x10702000 + alias, None))
    expect = canolcbutils.makeframestring(0x10701000 + dest, nodeID)
    if (connection.network.expect(exact=expect) == None):
        print "Expected reply when node ID matches not received"
        return 2

    # test non-matching NodeID using a reserved one
    connection.network.send(makeframe(alias, [0, 0, 0, 0, 0, 1]))
    reply = connection.network.receive()
    if (connection.network.expect(exact=expect) != None):
        print "Unexpected reply received when node ID didnt match ", reply
        return 2

    return 0
Example #10
0
def makeframe(alias, dest, nodeID):
    body = [(dest >> 8) & 0xFF, dest & 0xFF]
    if nodeID != None: body = body + nodeID
    return canolcbutils.makeframestring(0x19488000 + alias, body)
def makeframe(alias, nodeID):
    return canolcbutils.makeframestring(0x19490000 + alias, nodeID)
Example #12
0
def makeframe(alias, dest, mti) :
    return canolcbutils.makeframestring(0x19000000+alias+(mti<<12),[(dest>>8)&0xFF, dest&0xFF])
Example #13
0
def makeframe(alias, dest, nodeID) :
    body = [(dest>>8)&0xFF, dest&0xFF]
    if nodeID != None : body = body+nodeID
    return canolcbutils.makeframestring(0x19488000+alias,body)
def makeframe(alias) :
    return canolcbutils.makeframestring(0x19970000+alias, None)
def makeframe(alias, dest, mti):
    return canolcbutils.makeframestring(0x19000000 + alias + (mti << 12),
                                        [(dest >> 8) & 0xFF, dest & 0xFF])
def makeframe(alias, nodeID) :
    return canolcbutils.makeframestring(0x19490000+alias,nodeID)
def makeframe(alias) :
    return canolcbutils.makeframestring(0x19970000+alias, None)
Example #18
0
def test(alias, dest, connection, verbose) :
    # Note: This test assumes that the response will be
    # to reacquire another alias after the conflicted one is
    # dropped.  This isn't required behavior by standard, but
    # is a necessary condition for the test to continue and 
    # check another conflict condition.
    #
    # Sending a global message (that normally doesn't get a response)
    # by sending verifyNodeGlobal with a nodeID that doesn't match any valid
    if verbose : print "  check no-response global message with alias conflict"
    connection.network.send(verifyNodeGlobal.makeframe(dest, [0,0,0,0,0,1]))
    reply = connection.network.receive()
    if reply == None :
        print "no response received to conflict frame"
        return 21
    if not reply.startswith(":X10703") :
        print "Expected first AMR"
        return 22
    if int(reply[7:10],16) != dest :
        print "incorrect alias in AMR"
        return 23
    reply = connection.network.receive()
    if reply == None :
        print "no response received to conflict frame"
        return 21
    if not reply.startswith(":X17") :
        print "Expected first CID"
        return 22
    if int(reply[7:10],16) == 0 :
        print "received alias == 0"
        return 23
    dest = int(reply[7:10],16)
    # pull & drop rest of sequence
    reply = connection.network.receive()  # CID 2
    reply = connection.network.receive()  # CID 3
    reply = connection.network.receive()  # CID 4
    timeout = connection.network.timeout
    connection.network.timeout = 1.0
    reply = connection.network.receive()  # RID
    connection.network.timeout = timeout
    # dump everything until nothing heard
    while (reply != None) :
        reply = connection.network.receive()
    
    # Sending a global message (that normally does get a response)
    if verbose : print "  check response-inducing global message with alias conflict"
    connection.network.send(verifyNodeGlobal.makeframe(dest, None))
    reply = connection.network.receive()
    if reply == None :
        print "no response received to conflict frame"
        return 21
    if not reply.startswith(":X10703") :
        print "Expected second AMR"
        return 22
    if int(reply[7:10],16) != dest :
        print "incorrect alias in AMR"
        return 23
    reply = connection.network.receive()
    if reply == None :
        print "no response received to conflict frame"
        return 31
    if not reply.startswith(":X17") :
        print "Expected second CID"
        return 32
    if int(reply[7:10],16) == 0 :
        print "received alias == 0"
        return 33
    dest = int(reply[7:10],16)
    # pull & drop rest of sequence
    reply = connection.network.receive()  # CID 2
    reply = connection.network.receive()  # CID 3
    reply = connection.network.receive()  # CID 4
    timeout = connection.network.timeout
    connection.network.timeout = 1.0
    reply = connection.network.receive()  # RID
    connection.network.timeout = timeout
    # dump everything until nothing heard
    while (reply != None) :
        reply = connection.network.receive()
    
    # Sending an addressed message to some other alias (note arguments backwards, on purpose)
    if verbose : print "  check addressed message with alias conflict"
    connection.network.send(verifyNodeAddressed.makeframe(dest, alias, None))
    reply = connection.network.receive()
    if reply == None :
        print "no response received to conflict frame"
        return 21
    if not reply.startswith(":X10703") :
        print "Expected third AMR"
        return 22
    if int(reply[7:10],16) != dest :
        print "incorrect alias in AMR"
        return 23
    reply = connection.network.receive()
    if reply == None :
        if verbose : print "no response received to conflict frame"
        return 41
    if not reply.startswith(":X17") :
        if verbose : print "Expected third CID"
        return 42
    if int(reply[7:10],16) == 0 :
        print "received alias == 0"
        return 43
    dest = int(reply[7:10],16)
    # pull & drop rest of sequence
    reply = connection.network.receive()  # CID 2
    reply = connection.network.receive()  # CID 3
    reply = connection.network.receive()  # CID 4
    timeout = connection.network.timeout
    connection.network.timeout = 1.0
    reply = connection.network.receive()  # RID
    connection.network.timeout = timeout
    # dump everything until nothing heard
    while (reply != None) :
        reply = connection.network.receive()

    # send a CheckID   
    if verbose : print "  check CheckID with alias conflict"
    connection.network.send(canolcbutils.makeframestring(0x17020000+dest, None))
    reply = connection.network.receive()
    if reply == None :
        if verbose : print "no response received to CID"
        return 51
    if int(reply[7:10],16) != dest :
        if verbose : print "mismatched reply alias"
        return 52
    if not reply.startswith(":X10700") :
        if verbose : print "CID reply not correct, RID expected"
        return 53

    # send a ReserveID   
    connection.network.send(canolcbutils.makeframestring(0x10700000+dest, None))
    if verbose : print "  check ReserveID with alias conflict"
    reply = connection.network.receive()
    if reply == None :
        print "no response received to conflict frame"
        return 21
    if not reply.startswith(":X10703") :
        print "Expected fourth AMR"
        return 22
    if int(reply[7:10],16) != dest :
        print "incorrect alias in AMR"
        return 23
    reply = connection.network.receive()
    if reply == None :
        if verbose : print "no response received to conflict frame"
        return 61
    if not reply.startswith(":X17") :
        if verbose : print "Expected fourth CID"
        return 62
    if int(reply[7:10],16) == 0 :
        print "received alias == 0"
        return 63
    dest = int(reply[7:10],16)
    # pull & drop rest of sequence
    reply = connection.network.receive()  # CID 2
    reply = connection.network.receive()  # CID 3
    reply = connection.network.receive()  # CID 4
    timeout = connection.network.timeout
    connection.network.timeout = 1.0
    reply = connection.network.receive()  # RID
    connection.network.timeout = timeout
    # dump everything until nothing heard
    while (reply != None) :
        reply = connection.network.receive()

    return 0
def test(alias, dest, connection, num, verbose) :    
    # send a short read-request datagram in two segments
    if verbose : print "  test two segments"
    connection.network.send(makefirstframe(alias, dest, [0x20,0x41,0,0,0]))
    connection.network.send(makefinalframe(alias, dest, [0,8]))
    # check response to make sure it was received and interpreted OK
    retval = checkreply(alias, dest, connection, verbose)
    if type(retval) is int and retval != 0 :
        return retval+10
    
    # send a short read-request datagram in two segments with another to somebody else in between
    if verbose : print "  test two segments with extraneous one interposed" 
    connection.network.send(makefirstframe(alias, dest, [0x20,0x41,0,0,0]))
    connection.network.send(makeonlyframe(alias, (~dest)&0xFFF, [0x20,0x41,0,0,0]))
    connection.network.send(makefinalframe(alias, dest, [0,8]))
    # check response
    retval = checkreply(alias, dest, connection, verbose)
    if type(retval) is int and retval != 0 :
        return retval+20

    # send a final segment without a start segment
    if verbose : print "  test final segment without a start segment" 
    connection.network.send(makefinalframe(alias, dest, [0x20,0x41,0,0,0,0,8]))
    # check response, expect error
    frame = connection.network.receive()
    if not isNAK(frame) :
        print "Unexpected reply to final segment without a start segment", frame
        return 101

    # send a short read-request datagram in two segments with another from somebody else in between
    # interposed one could get rejected or processed; here we assume rejected
    if verbose : print "  test two segments with another datagram interposed" 
    connection.network.send(makefirstframe(alias, dest, [0x20,0x41,0,0,0]))
    newalias = (~alias)&0xFFF
    if newalias == dest:
	newalias = (newalias - 1)&0xFFF;
    connection.network.send(makeonlyframe(newalias, dest, [0x20,0x41,0,0,0,0,8]))
    # check for reject of this one
    frame = connection.network.receive()
    if frame == None :
        print "no reply to interposed datagram"
        return 81
    elif num == 1 and isAck(frame) :
        print "interposed datagram was not rejected due to buffer full:", frame
        return 82
    elif num > 1 and isNAK(frame) :
        print "Unexpected reject of interposed datagram:", frame
        return 83
    elif not (isNAK(frame) or isAck(frame)) : 
        print "Unexpected response to interposed datagram:", frame
        return 84
    # send final part of original datagram
    connection.network.send(makefinalframe(alias, dest, [0,8]))
    # check response
    retval = checkreply(alias, dest, connection, verbose)
    if type(retval) is int and retval != 0 :
        return retval+20

    # NAK the response datagram & check for retransmission
    if verbose : print "  send NAK to response"
    connection.network.send(makeonlyframe(alias, dest, [0x20,0x41,0,0,0,0,1]))
    frame = connection.network.receive()
    if frame == None : 
        print "Did not receive reply"
        return 31
    if not isAck(frame) :
        print "Unexpected message received instead of reply"
        return 32
    # read reply, should be a resend of same
    reply = connection.network.receive()
    if (reply == None ) : 
        print "No datagram segment received"
        return 34
    elif not reply.startswith(":X1A") :
        print "Unexpected message instead of datagram segment", reply
        return 33
    # send NAK asking for retransmit retransmit and see if it's right this time
    connection.network.send(canolcbutils.makeframestring(0x19A48000+alias,[(dest>>8)&0xFF, dest&0xFF,0x20,00]))
    #retval = datagram.receiveOneDatagram(alias, dest, connection, verbose)
    retval = receiveOneDatagram(alias, dest, connection, verbose)
    if type(retval) is int : 
        # pass error code up
        return retval
    if retval[0:3] != [0x20,0x51,0] :
        print "Unexpected message instead of read reply datagram ", retval
        return 37
        
    # Test recovery from failure during datagram send by sending a 1st segment, then AMR, 
    # then a complete datagram.  The reply will tell if the first part
    # was properly ignored.
    if verbose : print "  test recovery from AMR (node failure) after partial transmission of datagram" 
    # send 1st part (valid datagram part, garbage content)
    connection.network.send(makefirstframe(alias, dest, [0,0,0]))
    # send AMR for that node
    connection.network.send(canolcbutils.makeframestring(0x10703000+alias,None))
    # send correct datagram
    connection.network.send(makefinalframe(alias, dest, [0x20,0x41,0,0,0,0,8]))
    # check response
    retval = checkrejection(alias, dest, connection, verbose)
    if type(retval) is int and retval != 0 :
        return retval+20

    # Test recovery from failure during datagram send by sending a 1st segment, then AMD, 
    # then a complete datagram.  The reply will tell if the first part
    # was properly ignored.
    if verbose : print "  test recovery from AMD (node failure) after partial transmission of datagram" 
    # send 1st part (valid datagram part, garbage content)
    connection.network.send(makefirstframe(alias, dest, [0,0,0]))
    # send AMR for that node
    connection.network.send(canolcbutils.makeframestring(0x10701000+alias,None))
    # send correct datagram
    connection.network.send(makefinalframe(alias, dest, [0x20,0x41,0,0,0,0,8]))
    # check response
    retval = checkrejection(alias, dest, connection, verbose)
    if type(retval) is int and retval != 0 :
        return retval+20

    # Test that AMR and AMD from other nodes don't confuse datagram transmission
    if verbose : print "  test that AMR, AMD from other nodes doesnt interfere" 
    # send 1st part (valid datagram part)
    connection.network.send(makefirstframe(alias, dest, [0x20]))
    # send AMR,AMD for another node
    connection.network.send(canolcbutils.makeframestring(0x10703000+(alias^dest),None))
    connection.network.send(canolcbutils.makeframestring(0x10701000+(alias^dest),None))
    # send 2nd part datagram
    connection.network.send(makefinalframe(alias, dest, [0x41,0,0,0,0,8]))
    # check response
    retval = checkreply(alias, dest, connection, verbose)
    if type(retval) is int and retval != 0 :
        return retval+20

    return 0
def makefinalframe(alias, dest, content) :
    return canolcbutils.makeframestring(0x1D000000+alias+(dest<<12),content)
Example #21
0
def makeframe(alias, eventID):
    return canolcbutils.makeframestring(0x19914000 + alias, eventID)
Example #22
0
def makeframe(alias, eventID) :
    return canolcbutils.makeframestring(0x198F4000+alias,eventID)
def makereply(alias, dest) :
    body = [(dest>>8)&0xFF, dest&0xFF]
    return canolcbutils.makeframestring(0x19A28000+alias,body)
Example #24
0
def test(alias, dest, connection, verbose):
    # Note: This test assumes that the response will be
    # to reacquire another alias after the conflicted one is
    # dropped.  This isn't required behavior by standard, but
    # is a necessary condition for the test to continue and
    # check another conflict condition.
    #
    # Sending a global message (that normally doesn't get a response)
    # by sending verifyNodeGlobal with a nodeID that doesn't match any valid
    if verbose: print "  check no-response global message with alias conflict"
    connection.network.send(
        verifyNodeGlobal.makeframe(dest, [0, 0, 0, 0, 0, 1]))
    reply = connection.network.receive()
    if reply == None:
        print "no response received to conflict frame"
        return 21
    if not reply.startswith(":X10703"):
        print "Expected first AMR"
        return 22
    if int(reply[7:10], 16) != dest:
        print "incorrect alias in AMR"
        return 23
    reply = connection.network.receive()
    if reply == None:
        print "no response received to conflict frame"
        return 21
    if not reply.startswith(":X17"):
        print "Expected first CID"
        return 22
    if int(reply[7:10], 16) == 0:
        print "received alias == 0"
        return 23
    dest = int(reply[7:10], 16)
    # pull & drop rest of sequence
    reply = connection.network.receive()  # CID 2
    reply = connection.network.receive()  # CID 3
    reply = connection.network.receive()  # CID 4
    timeout = connection.network.timeout
    connection.network.timeout = 1.0
    reply = connection.network.receive()  # RID
    connection.network.timeout = timeout
    # dump everything until nothing heard
    while (reply != None):
        reply = connection.network.receive()

    # Sending a global message (that normally does get a response)
    if verbose:
        print "  check response-inducing global message with alias conflict"
    connection.network.send(verifyNodeGlobal.makeframe(dest, None))
    reply = connection.network.receive()
    if reply == None:
        print "no response received to conflict frame"
        return 21
    if not reply.startswith(":X10703"):
        print "Expected second AMR"
        return 22
    if int(reply[7:10], 16) != dest:
        print "incorrect alias in AMR"
        return 23
    reply = connection.network.receive()
    if reply == None:
        print "no response received to conflict frame"
        return 31
    if not reply.startswith(":X17"):
        print "Expected second CID"
        return 32
    if int(reply[7:10], 16) == 0:
        print "received alias == 0"
        return 33
    dest = int(reply[7:10], 16)
    # pull & drop rest of sequence
    reply = connection.network.receive()  # CID 2
    reply = connection.network.receive()  # CID 3
    reply = connection.network.receive()  # CID 4
    timeout = connection.network.timeout
    connection.network.timeout = 1.0
    reply = connection.network.receive()  # RID
    connection.network.timeout = timeout
    # dump everything until nothing heard
    while (reply != None):
        reply = connection.network.receive()

    # Sending an addressed message to some other alias (note arguments backwards, on purpose)
    if verbose: print "  check addressed message with alias conflict"
    connection.network.send(verifyNodeAddressed.makeframe(dest, alias, None))
    reply = connection.network.receive()
    if reply == None:
        print "no response received to conflict frame"
        return 21
    if not reply.startswith(":X10703"):
        print "Expected third AMR"
        return 22
    if int(reply[7:10], 16) != dest:
        print "incorrect alias in AMR"
        return 23
    reply = connection.network.receive()
    if reply == None:
        if verbose: print "no response received to conflict frame"
        return 41
    if not reply.startswith(":X17"):
        if verbose: print "Expected third CID"
        return 42
    if int(reply[7:10], 16) == 0:
        print "received alias == 0"
        return 43
    dest = int(reply[7:10], 16)
    # pull & drop rest of sequence
    reply = connection.network.receive()  # CID 2
    reply = connection.network.receive()  # CID 3
    reply = connection.network.receive()  # CID 4
    timeout = connection.network.timeout
    connection.network.timeout = 1.0
    reply = connection.network.receive()  # RID
    connection.network.timeout = timeout
    # dump everything until nothing heard
    while (reply != None):
        reply = connection.network.receive()

    # send a CheckID
    if verbose: print "  check CheckID with alias conflict"
    connection.network.send(
        canolcbutils.makeframestring(0x17020000 + dest, None))
    reply = connection.network.receive()
    if reply == None:
        if verbose: print "no response received to CID"
        return 51
    if int(reply[7:10], 16) != dest:
        if verbose: print "mismatched reply alias"
        return 52
    if not reply.startswith(":X10700"):
        if verbose: print "CID reply not correct, RID expected"
        return 53

    # send a ReserveID
    connection.network.send(
        canolcbutils.makeframestring(0x10700000 + dest, None))
    if verbose: print "  check ReserveID with alias conflict"
    reply = connection.network.receive()
    if reply == None:
        print "no response received to conflict frame"
        return 21
    if not reply.startswith(":X10703"):
        print "Expected fourth AMR"
        return 22
    if int(reply[7:10], 16) != dest:
        print "incorrect alias in AMR"
        return 23
    reply = connection.network.receive()
    if reply == None:
        if verbose: print "no response received to conflict frame"
        return 61
    if not reply.startswith(":X17"):
        if verbose: print "Expected fourth CID"
        return 62
    if int(reply[7:10], 16) == 0:
        print "received alias == 0"
        return 63
    dest = int(reply[7:10], 16)
    # pull & drop rest of sequence
    reply = connection.network.receive()  # CID 2
    reply = connection.network.receive()  # CID 3
    reply = connection.network.receive()  # CID 4
    timeout = connection.network.timeout
    connection.network.timeout = 1.0
    reply = connection.network.receive()  # RID
    connection.network.timeout = timeout
    # dump everything until nothing heard
    while (reply != None):
        reply = connection.network.receive()

    return 0