Example #1
0
def simple_test(program, debug=0):
    ''' Given a string (GP4 program) in program, compile and run it.
    '''
    p4 = compile_string( program=program )

    if not p4:
        print "Hmmm. Syntax error?"
    else:
        print p4

    return p4
Example #2
0
def parse_and_run_test(program, pkt, init_state='start', init_ctrl='', debug=0):

    p4 = compile_string( program=program )

    if not p4:
        print "Hmmm. Syntax error?"
        sys.exit(1)

    runtime = Runtime(p4)

    p4.check_self_consistent()

    err, bytes_used = runtime.parse_packet(pkt, init_state)

    if err:
        return (p4, err, bytes_used)

    if init_ctrl: run_control_function(p4, pkt, init_ctrl )

    return (p4, '', bytes_used )