Esempio n. 1
0
def runReplay(PcapDirectory, pacmodify, analyzerI):

    global Replaycounter

    classification = None

    cmpacNum = -1
    caction = None
    cspec = None
    smpacNum = -1
    saction = None
    sspec = None

    Side, Num, Action, Mspec = pickle.loads(pacmodify)

    if Side == 'Client':
        cmpacNum = Num
        caction = Action
        cspec = Mspec
    elif Side == 'Server':
        smpacNum = Num
        saction = Action
        sspec = Mspec

    configs = Configs()
    testID = int(configs.get('testID'))
    configs.set('testID', str(testID + 1))

    # replay_client.run(configs = configs, pcapdir = PcapDirectory, cmpacNum = cmpacNum, caction = caction, cspec = cspec,
    #                       smpacNum = smpacNum, saction = saction, sspec = sspec)
    try:
        replayResult = replay_client.run(configs = configs, pcapdir = PcapDirectory, cmpacNum = cmpacNum, caction = caction, cspec = cspec,
                          smpacNum = smpacNum, saction = saction, sspec = sspec, testID=configs.get('testID'), byExternal=True)
    except:
        print '\r\n Error when running replay'
        replayResult = None

    time.sleep(10)
    permaData = PermaData()
    try:
        PRINT_ACTION(str(analyzerI.ask4analysis(permaData.id, permaData.historyCount, configs.get('testID'))), 0 )
    except Exception as e:
        PRINT_ACTION('\n\n\n####### COULD NOT ASK FOR ANALYSIS!!!!! #######\n\n\n' + str(e),0)
    PRINT_ACTION(str(replayResult) , 0 )

    # ASK the replay analyzer for KS2 result, i.e., analyzerResult
    # replayResult is whether the replay finished, used for testing censorship
    classification = replayResult

    # Beginning of asking the replay analyzer for performance difference
    # time.sleep(15)
    # PRINT_ACTION('Fetching analysis result from the analyzer server',0)
    # res = analyzerI.getSingleResult(permaData.id, permaData.historyCount, configs.get('testID'))
    #
    # # Check whether results are successfully fetched
    #
    #
    # if res['success'] == True:
    #     # Process result here
    #     pres = processResult(res['response'])
    #     if pres == 1:
    #         PRINT_ACTION('INConclusive Result. Considered as NOT different from Original replay', 0)
    #         classification = 'Original'
    #     elif pres == 2:
    #         PRINT_ACTION('Different from Original replay', 0)
    #         classification = 'NotOriginal'
    #     else:
    #         PRINT_ACTION('NOT Different from Original replay', 0)
    #         classification = 'Original'
    # else:
    #     # Only use whether the replayResult as classification
    #     PRINT_ACTION('\r\n Failed in fetching result ' + res['error'], 0)
    #     classification = replayResult

    # TODO Supplement YOUR OWN method to get the classification result here

    # OR Manually type what this traffic is classified as
    # classification = raw_input('Is it classified the same as original replay? "YES" or "NO"?')


    return classification
Esempio n. 2
0
def runReplay(PcapDirectory, pacmodify, analyzerI, libProxy=None):

    global Replaycounter

    cmpacNum = -1
    caction = None
    cspec = None
    smpacNum = -1
    saction = None
    sspec = None

    classification = None

    Side, Num, Action, Mspec = pickle.loads(pacmodify)

    if Side == 'Client':
        cmpacNum = Num
        caction = Action
        cspec = Mspec
    elif Side == 'Server':
        smpacNum = Num
        saction = Action
        sspec = Mspec

    configs = Configs()

    try:
        replayResult = replay_client.run(configs=configs,
                                         libProxy=libProxy,
                                         pcapdir=PcapDirectory,
                                         cmpacNum=cmpacNum,
                                         caction=caction,
                                         cspec=cspec,
                                         smpacNum=smpacNum,
                                         saction=saction,
                                         sspec=sspec)
    except:
        print '\r\n Error when running replay'
        replayResult = 'Error'

    # print '\r\n Whether Finished', replayResult

    classification = replayResult

    print '\r\n CLASSIFIED AS ', classification
    # The period for extracting the classification results
    time.sleep(15)

    # ASK the replay analyzer for throughput analysis result
    permaData = PermaData()
    PRINT_ACTION('Fetching analysis result from the analyzer server', 0)
    res = analyzerI.getSingleResult(permaData.id, permaData.historyCount,
                                    configs.get('testID'))

    # Check whether results are successfully fetched

    if res['success'] == True:
        # Process result here
        pres = processResult(res['response'])
        if pres == 1:
            PRINT_ACTION(
                'INConclusive Result. Considered as NOT different from Original replay',
                0)
            classification = 'Original'
        elif pres == 2:
            PRINT_ACTION('Different from Original replay', 0)
            classification = 'NotOriginal'
        else:
            PRINT_ACTION('NOT Different from Original replay', 0)
            classification = 'Original'
    else:
        # Only use whether the replayResult as classification
        PRINT_ACTION('\r\n Failed in fetching result ' + res['error'], 0)
        classification = replayResult

    # TODO Supplement YOUR OWN method to get the classification result here

    # Use the replayResult when testing censorship

    # OR Manually type what this traffic is classified as
    # classify_result = raw_input('Is it classified the same as original replay? "YES" or "NO"?')

    return classification
Esempio n. 3
0
def runReplay(pcapDir, pacmodify, analyzerI):

    classification = None

    cmpacNum = -1
    caction = None
    cspec = None
    smpacNum = -1
    saction = None
    sspec = None

    # Check whether modification needed for this replay
    Side, Num, Action, Mspec = pickle.loads(pacmodify)

    if Side == 'Client':
        cmpacNum = Num
        caction = Action
        cspec = Mspec
    elif Side == 'Server':
        smpacNum = Num
        saction = Action
        sspec = Mspec

    configs = Configs()
    testID = int(configs.get('testID'))
    configs.set('testID', str(testID + 1))

    try:
        replayResult = replay_client.run(configs=configs,
                                         pcapdir=pcapDir,
                                         cmpacNum=cmpacNum,
                                         caction=caction,
                                         cspec=cspec,
                                         smpacNum=smpacNum,
                                         saction=saction,
                                         sspec=sspec,
                                         testID=configs.get('testID'),
                                         byExternal=True)
    except:
        print '\r\n Error when running replay'
        replayResult = None

    time.sleep(2)
    permaData = PermaData()
    try:
        PRINT_ACTION(
            str(
                analyzerI.ask4analysis(permaData.id, permaData.historyCount,
                                       configs.get('testID'))), 0)
    except Exception as e:
        PRINT_ACTION(
            '\n\n\n####### COULD NOT ASK FOR ANALYSIS!!!!! #######\n\n\n' +
            str(e), 0)

    # ASK the replay analyzer for differentiation test

    ori_avg_xputs = 0
    ran_avg_xputs = 0
    # 3 trials for getting the result, 5 * i seconds for the server to process the result each time
    for i in xrange(3):
        time.sleep(5)
        PRINT_ACTION('Fetching analysis result from the analyzer server', 0)
        res = analyzerI.getSingleResult(permaData.id, permaData.historyCount,
                                        configs.get('testID'))

        # Check whether results are successfully fetched

        if res['success'] == True:
            # Process result here
            classification = processResult(res['response'])
            ori_avg_xputs = res['response']['xput_avg_original']
            ran_avg_xputs = res['response']['xput_avg_test']
            break
        else:
            # Only use whether the replayResult as classification
            PRINT_ACTION('\r\n Failed at fetching result ' + res['error'], 0)
            classification = replayResult

    # Supplement YOUR OWN method to get the classification result here

    # OR Manually type what this traffic is classified as
    # classification = raw_input('Is it classified the same as original replay? "YES" or "NO"?')

    return classification, ori_avg_xputs, ran_avg_xputs