SanityCheck.py 23.9 KB
Newer Older
1 2 3 4 5 6 7 8
#!/usr/local/bin/python
#
# EMULAB-COPYRIGHT
# Copyright (c) 2007 University of Utah and the Flux Group.
# All rights reserved.
#

#########################################################
9 10
# Input:
# This script requires one command line arguments
11 12 13 14 15 16
# Argument 1 - Pointer to the 
# /proj/.../exp/project_name/ directory
#
# (The elab-*, planet-* directories should
# have tcpdump log files named SanityCheck.log)
#
17 18 19 20 21 22 23 24
# Output:
# The report will be a file named SanityCheckReport.txt
# in the "given_directory/logs"
# Details for each pair of machines - the exact
# cross correlation value, Percentage difference between
# Flexlab & Planetlab transfer rates etc. can be found
# in "given_directory/logs/SanityCheckDetails.txt"
#
25 26 27
#########################################################

#########################################################
28
# Sanity check for Flexlab TCP & UDP runs
29 30 31
#
# Calculates the correlation of the traffic
# on Planetlab nodes versus the traffic on the
32
# corresponding Flexlab (Emulab) nodes.
33 34 35
#
# Requires that Tcpdump files be saved on elab-*
# and planet-* nodes during the Flexlab run.
36 37
# This can be done by passing "-t" option
# to start-experiment and stop-experiment scripts
38
#
39
# This script can also be executed in stand-alone mode 
40
# after collecting the logs
41 42
# with stop-experiment  - Just point it to the 
# directory containing the logs.
43
# 
44 45 46 47
# Cross Correlation references: 
# -----------------------------
# FFT method  - http://en.wikipedia.org/wiki/Cross-correlation
# Paul Bourke - http://local.wasp.uwa.edu.au/~pbourke/other/correlate
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
#
#########################################################

import sys
import re
import os
import array
import math
from posix import *
from optparse import OptionParser

global minAvgSamples
global avgTime
global maxAvgSamples 

# Take the directory to be processed from the command line arguments
global logDir
global OutputFileHandle 


tmpFile = "/tmp/flexlab-tmp"

###############################################################
###############################################################

def CalcBucketAvgThroughput(fileName, outputFile, bucketSize, transportFlag):
#{
    initTime = 0
    lastPacketTime = 0
    arrayIndex = 0
    packetAvgBytes = 0
    packetAvgTime = 0
    numPackets = 0
    numLines = 0
    lastBucketThreshold = 0
    timePeriod = 0

    maxAvgSamples = 100000

    packetSizeArray = [0] * maxAvgSamples
    packetTimeArray = [0] * maxAvgSamples


    tmpFileHandle = file(tmpFile,"w")
    outputFileHandle = file(outputFile,"w")

    command = "tcpdump -r " + fileName + " 2> /dev/null "
    inputFile = popen(command, "r")

    if transportFlag == 0 : # TCP 
        regExp = re.compile('^(\d\d):(\d\d):(\d\d)\.(\d{6})\sIP\s([\w\d\.\-]*?)\.([\d\w\-]*)\s>\s([\w\d\.\-]*?)\.([\d\w\-]*):\s[\w\d\s\.\:]*?\(([\d]*)\)[\w\d\s]*')
    elif transportFlag == 1: # UDP
        regExp = re.compile('^(\d\d):(\d\d):(\d\d)\.(\d{6})\sIP\s([\w\d\.\-]*?)\.([\d\w\-]*)\s>\s([\w\d\.\-]*?)\.([\d\w\-]*):\sUDP,\slength\s(\d*)')

    for lineRead in inputFile:
    #{
        match = regExp.match(lineRead)


        if match:
        #{
            time = ((int(match.group(1)))*3600 + (int(match.group(2)))*60 + int(match.group(3)))*1000000 + int(match.group(4))

            if initTime == 0:
            #{
                initTime = time
                lastPacketTime = time
            #}
            else:
            #{
                packetSizeArray[arrayIndex] = int(match.group(9))
                packetTimeArray[arrayIndex] = time - lastPacketTime

                packetAvgBytes = packetAvgBytes + int(match.group(9))
                packetAvgTime = packetAvgTime + packetTimeArray[arrayIndex]

                timePeriod += packetTimeArray[arrayIndex]

                if timePeriod >= bucketSize:
                #{
                    iter = 0
                    packetSizeSum = 0

                    while iter <= arrayIndex :
                    #{
                        packetSizeSum += packetSizeArray[iter]
                        iter += 1
                    #}
                    throughput = 8000000*packetSizeSum/(timePeriod*1024.0)

                    numLinesToWrite = timePeriod / 10000;

                    iter = 0
                    tmpTimeCounter = lastBucketThreshold * 10000 + 10000

                    while iter <  numLinesToWrite:
                        tmpFileHandle.write(str(tmpTimeCounter)+" "+str(throughput)+"\n")
                        iter += 1
                        numLines += 1
147
                        tmpTimeCounter = tmpTimeCounter + 10000
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

                    lastBucketThreshold = lastBucketThreshold + timePeriod / 10000

                    arrayIndex = 0
                    timePeriod = 0
                #}
                else:
                    arrayIndex = (arrayIndex + 1) % maxAvgSamples

            #}

            lastPacketTime = time
        #}

    #}

    outputFileHandle.write(str(numLines) + "\n")
    outputFileHandle.close()

    tmpFileHandle.close()
    inputFile.close()

    os.system("cat " + tmpFile + " >> " + outputFile)
    os.remove(tmpFile)

173 174 175 176 177 178
    del packetSizeArray
    del packetTimeArray

    # Return the avg. transfer rate - in kbps
    return (8000000*packetAvgBytes/(packetAvgTime*1024.0))

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
#}
###############################################################
###############################################################

def CalcMovingAvgThroughput(fileName, outputFile, minSamples, avgTimeScale, maxSamples, transportFlag):
#{
    initTime = 0
    lastPacketTime = 0
    arrayIndex = 0
    packetAvgBytes = 0
    packetAvgTime = 0
    numLines = 0
    packetSizeArray = [0] * maxAvgSamples
    packetTimeArray = [0] * maxAvgSamples

    tmpFileHandle = file(tmpFile,"w")
    outputFileHandle = file(outputFile,"w")

    command = "tcpdump -r " + fileName + " 2> /dev/null "
    inputFile = popen(command, "r")

    if transportFlag == 0 : # TCP 
        regExp = re.compile('^(\d\d):(\d\d):(\d\d)\.(\d{6})\sIP\s([\w\d\.\-]*?)\.([\d\w\-]*)\s>\s([\w\d\.\-]*?)\.([\d\w\-]*):\s[\w\d\s\.\:]*?\(([\d]*)\)[\w\d\s]*')
    elif transportFlag == 1: # UDP
        regExp = re.compile('^(\d\d):(\d\d):(\d\d)\.(\d{6})\sIP\s([\w\d\.\-]*?)\.([\d\w\-]*)\s>\s([\w\d\.\-]*?)\.([\d\w\-]*):\sUDP,\slength\s(\d*)')

205 206 207 208 209 210

    runningByteTotal = 0
    runningTimeTotal = 0
    runningPacketTotal = 0
    lastIndex = 0

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
    for lineRead in inputFile:
    #{
        match = regExp.match(lineRead)

        if match:
        #{

            time = ((int(match.group(1)))*3600 + (int(match.group(2)))*60 + int(match.group(3)))*1000000 + int(match.group(4))

            if initTime == 0:
            #{
                initTime = time
                lastPacketTime = time
            #}
            else:
            #{
227 228 229 230 231 232
                currentPacketSize = int(match.group(9))
                currentPacketTime = time - lastPacketTime

                runningByteTotal += currentPacketSize
                runningTimeTotal += currentPacketTime
                runningPacketTotal += 1
233 234 235 236

                packetAvgBytes = packetAvgBytes + int(match.group(9))
                packetAvgTime = packetAvgTime + packetTimeArray[arrayIndex]

237
                if runningPacketTotal >= minSamples:
238
                #{
239
                    if (runningPacketTotal < maxSamples) and (runningTimeTotal < avgTimeScale):
240
                    #{
241
                        throughput = 8000000*runningByteTotal/(runningTimeTotal*1024.0)
242
                    #}
243
                    elif runningPacketTotal < maxSamples:
244
                    #{
245 246 247 248 249 250 251 252
                        while (runningPacketTotal >= minSamples) and (runningTimeTotal > avgTimeScale):
                        #{
                            runningTimeTotal -= packetTimeArray[lastIndex]
                            runningByteTotal -= packetSizeArray[lastIndex]
                            lastIndex = (lastIndex + 1)%maxSamples
                            runningPacketTotal -= 1
                        #}
                        throughput = 8000000*runningByteTotal/(runningTimeTotal*1024.0)
253
                    #}
254
                    elif runningTimeTotal < avgTimeScale:
255
                    #{
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
                        runningByteTotal -= packetSizeArray[lastIndex]
                        runningTimeTotal -= packetTimeArray[lastIndex]
                        runningPacketTotal -= 1
                        lastIndex = (lastIndex + 1)%maxSamples
                        throughput = 8000000*runningByteTotal/(runningTimeTotal*1024.0)
                    #}
                    else:
                    #{
                        while (runningPacketTotal >= minSamples) and (runningPacketTotal > maxSamples) and (runningTimeTotal > avgTimeScale):
                        #{
                            runningTimeTotal -= packetTimeArray[lastIndex]
                            runningByteTotal -= packetSizeArray[lastIndex]
                            lastIndex = (lastIndex + 1)%maxSamples
                            runningPacketTotal -= 1
                        #}
                        throughput = 8000000*runningByteTotal/(runningTimeTotal*1024.0)
272 273
                    #}

274
                    if runningTimeTotal != 0 :
275 276 277 278 279
                    #{
                        tmpFileHandle.write(str(time-initTime)+" "+str(throughput)+"\n")
                        numLines += 1
                    #}
                #}
280 281 282 283

                packetSizeArray[arrayIndex] = currentPacketSize
                packetTimeArray[arrayIndex] = currentPacketTime
                arrayIndex = (arrayIndex + 1) % maxSamples
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
            #}

            lastPacketTime = time
        #}

    #}

    outputFileHandle.write(str(numLines) + "\n")
    outputFileHandle.close()

    tmpFileHandle.close()
    inputFile.close()

    os.system("cat " + tmpFile + " >> " + outputFile)
    os.remove(tmpFile)
299 300 301 302 303

    del packetSizeArray
    del packetTimeArray

    # Return the avg. transfer rate - in kbps
304 305 306
    if packetAvgTime == 0:
        return 0

307
    return (8000000*packetAvgBytes/(packetAvgTime*1024.0))
308 309 310 311
#}

###############################################################
###############################################################
312

313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
def PreProcess(inputFile, outputFile):
#{

    i = 0
    j = 0
    rowCount = 0
    lastTimeVal = 0
    currentTimeVal = 0
    index = 0
    slope = 0.0
    intercept = 0.0
    indexChanged = 1
    intermValue = 0
    numRows = 0
    numLines = 0

Pramod R Sanaga's avatar
Pramod R Sanaga committed
329 330 331 332
# Skip the bandwidth comparison for 5 seconds, while Flexlab converges
# to the correct available bandwidth and delay estimates.
    initialThreshold = 500

333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
    inputFileHandle = file(inputFile,"r")
    outputFileHandle = file(outputFile,"w")

    numRows = int( (inputFileHandle.readline()).split()[0] )
    timeArray = [0] * (numRows + 1)
    valueArray = [0.0] * (numRows + 1)

    i = 1
    splitString = []

    for lineRead in inputFileHandle:
    #{
        splitString = lineRead.split()
        timeArray[i] = int(splitString[0])
        valueArray[i] = float(splitString[1])
        i += 1
    #}

    inputFileHandle.close()

    rowCount = numRows
    lastTimeVal = timeArray[rowCount-1]

    index = 0
    while 1:
    #{
        if index > rowCount - 1:
            break

        # Recalculate the slope and intercept
        # for the new index.
        if indexChanged:
        #{
            slope = (valueArray[index+1] - valueArray[index]) \
                    /float(timeArray[index+1] - timeArray[index])
            intercept = valueArray[index] - slope*timeArray[index]
            indexChanged = 0
        #}

        if currentTimeVal == timeArray[index]:
        #{
Pramod R Sanaga's avatar
Pramod R Sanaga committed
374 375 376
            if numLines > initialThreshold:
                outputFileHandle.write(str(currentTimeVal) + " " + \
                        str(valueArray[index]) + "\n")
377 378 379 380 381
            currentTimeVal += 10000
            numLines += 1
        #}
        elif currentTimeVal == timeArray[index+1]:
        #{
Pramod R Sanaga's avatar
Pramod R Sanaga committed
382 383 384
            if numLines > initialThreshold:
                outputFileHandle.write(str(currentTimeVal) + " " + \
                        str(valueArray[index+1]) + "\n")
385 386 387 388 389 390 391 392
            currentTimeVal += 10000
            index += 1
            indexChanged = 1
            numLines += 1
        #}
        elif currentTimeVal < timeArray[index+1]:
        #{
            intermValue = slope*timeArray[index] + intercept
Pramod R Sanaga's avatar
Pramod R Sanaga committed
393 394 395
            if numLines > initialThreshold:
                outputFileHandle.write(str(currentTimeVal) + " " + \
                        str(intermValue) + "\n")
396 397 398 399 400 401 402 403 404 405 406 407
            currentTimeVal += 10000
            numLines += 1
        #}
        elif currentTimeVal > timeArray[index+1]:
        #{
            index += 1
            indexChanged = 1
        #}
    #}

    outputFileHandle.close()

408 409
    del timeArray
    del valueArray
410
#}
411 412
##############################################################
##############################################################
Pramod R Sanaga's avatar
Pramod R Sanaga committed
413
def CalcCorrelation(InFile1, InFile2, transportFlag, plabAvg, elabAvg):
414 415
#{

Pramod R Sanaga's avatar
Pramod R Sanaga committed
416 417 418 419 420
    delayVal = 0
    maxCorr = -2.0
    lineCount1 = 0
    lineCount2 = 0
    numLines = 0
421

Pramod R Sanaga's avatar
Pramod R Sanaga committed
422 423 424
    pipeObj = popen("wc -l " + InFile1, "r")
    lineCount1 = int(pipeObj.readline().split()[0])
    pipeObj.close()
425

Pramod R Sanaga's avatar
Pramod R Sanaga committed
426 427 428
    pipeObj = popen("wc -l " + InFile2, "r")
    lineCount2 = int(pipeObj.readline().split()[0])
    pipeObj.close()
429

Pramod R Sanaga's avatar
Pramod R Sanaga committed
430 431
    if lineCount1 < lineCount2:
        numLines = lineCount1
432
    else:
Pramod R Sanaga's avatar
Pramod R Sanaga committed
433
        numLines = lineCount2
434

Pramod R Sanaga's avatar
Pramod R Sanaga committed
435
    if numLines != 0:
436
    #{
Pramod R Sanaga's avatar
Pramod R Sanaga committed
437
        os.system("sh CorrelationR.sh " + InFile1 + " " + InFile2 + " " + "/tmp/Correlation.log" )
438

Pramod R Sanaga's avatar
Pramod R Sanaga committed
439
        InFileHandle1 = file("/tmp/Correlation.log", "r")
440

441 442
        for lineRead in InFileHandle1:
        #{
Pramod R Sanaga's avatar
Pramod R Sanaga committed
443 444
            shiftVal = int( lineRead.split()[0] )
            corrVal = float( lineRead.split()[1] )
445

Pramod R Sanaga's avatar
Pramod R Sanaga committed
446 447 448
            if corrVal > maxCorr:
                maxCorr = corrVal
                delayVal = shiftVal
449
        #}
450

Pramod R Sanaga's avatar
Pramod R Sanaga committed
451
        InFileHandle1.close()
452 453 454
    #}
    else:
    #{
Pramod R Sanaga's avatar
Pramod R Sanaga committed
455 456
        delayVal = 0
        maxCorr = 0.0
457 458 459 460 461 462 463 464 465
    #}

    if transportFlag == 0:
        transport = "TCP"
    elif transportFlag == 1:
        transport = "UDP"

    diffTransferRate = elabAvg - plabAvg

466 467 468 469
    if elabAvg != 0:
        diffPercentage = 100.0*(float(diffTransferRate))/(float(elabAvg))
    else:
        diffPercentage = 0.0
470

Pramod R Sanaga's avatar
Pramod R Sanaga committed
471
    OutputFileHandle.write("Max_Correlation=" + str(maxCorr) + ":Delay=" + str(delayVal*10) + "ms:Transport=" + transport + ":N=" + str(numLines) + ":KbpsPercentDiff=" + str(diffPercentage) + "\n")
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486

#}

###############################################################
###############################################################
def processFiles(fileNameElab, fileNamePlab, averagingMethod, transportFlag):
#{
    tmpFileElab1 = "/tmp/tmpFileElab1"
    tmpFileElab2 = "/tmp/tmpFileElab2"
    tmpFilePlab1 = "/tmp/tmpFilePlab1"
    tmpFilePlab2 = "/tmp/tmpFilePlab2"


    if averagingMethod == 0: # Moving average
    #{
487
        elabAvg = CalcMovingAvgThroughput(fileNameElab, tmpFileElab1, minAvgSamples, avgTime, maxAvgSamples, transportFlag)
488 489
        sys.stdout.write("#")
        sys.stdout.flush()
490
        plabAvg = CalcMovingAvgThroughput(fileNamePlab, tmpFilePlab1, minAvgSamples, avgTime, maxAvgSamples, transportFlag)
491 492 493 494 495 496 497 498 499
        sys.stdout.write("#")
        sys.stdout.flush()

        PreProcess(tmpFileElab1, tmpFileElab2)
        sys.stdout.write("#")
        sys.stdout.flush()
        PreProcess(tmpFilePlab1, tmpFilePlab2)
        sys.stdout.write("#")
        sys.stdout.flush()
Pramod R Sanaga's avatar
Pramod R Sanaga committed
500
        CalcCorrelation(tmpFilePlab2, tmpFileElab2, transportFlag, plabAvg, elabAvg)
501 502 503 504 505 506 507 508 509 510
        sys.stdout.write("#")
        sys.stdout.flush()

        os.remove(tmpFileElab1)
        os.remove(tmpFileElab2)
        os.remove(tmpFilePlab1)
        os.remove(tmpFilePlab2)
    #}
    elif averagingMethod == 1: # Bucket average
    #{
511
        elabAvg = CalcBucketAvgThroughput(fileNameElab, tmpFileElab1, avgTime, transportFlag)
512 513
        sys.stdout.write("#")
        sys.stdout.flush()
514
        plabAvg = CalcBucketAvgThroughput(fileNamePlab, tmpFilePlab1, avgTime, transportFlag)
515 516
        sys.stdout.write("#")
        sys.stdout.flush()
517
        CalcCorrelationFFT(tmpFilePlab1, tmpFileElab1, transportFlag, plabAvg, elabAvg)
518 519 520 521 522 523 524 525 526 527
        sys.stdout.write("#")
        sys.stdout.flush()

        os.remove(tmpFileElab1)
        os.remove(tmpFilePlab1)
    #}

#}
###############################################################
###############################################################
528 529 530 531 532
# This is the current set of crieteria for declaring a run
# to be valid.
#
# For all pairs of nodes in the Flexlab experiment:
# a) Cross-correlation > 0.5
Pramod R Sanaga's avatar
Pramod R Sanaga committed
533 534
# b) Offset used for this value of cross-correlation <= 0
# c) Offset > -8 seconds
535 536 537 538
# d) Difference between Flexlab & Planetlab transfer rates
#    is less than 40%
# e) SanityCheck Tcpdump files exist for all pairs of nodes.
#
539 540 541 542 543
def PrintReport(correlationDataFile, numNodes, numNodesProcessed, reportFileName):
#{
    correlationFileHandle = file(correlationDataFile, "r")
    reportFileHandle = file (reportFileName, "w")

544
    correlationRegex = re.compile('Max_Correlation=([\d\.]*?):Delay=([\-\d]*?)ms:Transport=([\w]*?):N=([\d]*):KbpsPercentDiff=([\-\d\.]*?)$')
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561

    errorFlag = 0

    for i in range(1, numNodesProcessed+1):
    #{

        # Read the two lines with the path to the SanityCheck files.
        flexLabFile = correlationFileHandle.readline().strip()
        pLabFile = correlationFileHandle.readline().strip()

        for j in range(0,2):
        #{
            correlationLine = correlationFileHandle.readline()

            matchObj = correlationRegex.match(correlationLine)

            if  ( ( int(matchObj.group(4)) ) and  \
Pramod R Sanaga's avatar
Pramod R Sanaga committed
562
                    ( ( float(matchObj.group(1)) < 0.5 ) or ( int(matchObj.group(2)) > 0 ) or ( int(matchObj.group(2)) < -8000 )  or ( float(matchObj.group(5)) > 40.0 or float(matchObj.group(5)) < -40.0 ) ) ) :
563
            #{
564 565
                print "\n***** ERROR: This Flexlab run is possibly tainted. \nDetected " + matchObj.group(3) + " cross-correlation mismatch for files '" + flexLabFile + "' and '" + pLabFile + "'"
                reportFileHandle.write( "***** ERROR: This Flexlab run is possibly tainted. \nDetected " + matchObj.group(3) + " cross-correlation mismatch for files '" + flexLabFile + "' and '" + pLabFile + "'\n")
566 567 568
                errorFlag = 1

            #}
569 570 571 572 573 574 575 576 577 578
# Check the delay offset by comparing it against the sum
# of Emulab-to-Planetlab RTT + Planetlab internode RTT.
# Not implemented yet.
            if  ( ( int(matchObj.group(4)) ) and ( float (matchObj.group(1)) > 0.0 ) and ( int(matchObj.group(2)) == 0 ) ) :
                
            #{
                print "\n***** ERROR: This Flexlab run is possibly tainted. \nDetected " + matchObj.group(3) + " cross-correlation mismatch for files '" + flexLabFile + "' and '" + pLabFile + "'"
                reportFileHandle.write( "***** ERROR: This Flexlab run is possibly tainted. \nDetected " + matchObj.group(3) + " cross-correlation mismatch for files '" + flexLabFile + "' and '" + pLabFile + "'\n")
                errorFlag = 1
            #}
579 580 581 582 583 584 585

        #}

    #}

    if numNodesProcessed != numNodes :
    #{
586 587
        print "\n***** ERROR: " + str(numNodes - numNodesProcessed) + " files required for cross-correlation sanity check are missing.\nThis Flexlab run is possibly tainted."
        reportFileHandle.write("***** ERROR: " + str(numNodes - numNodesProcessed) + " files required for cross-correlation sanity check are missing.\nThis Flexlab run is possibly tainted.\n")
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608

        errorFlag = 1
    #}

    if errorFlag == 0:
    #{
        print "\n##### Cross-correlation checks successful. This Flexlab run is Good!"
        reportFileHandle.write("##### Cross-correlation checks successful. This Flexlab run is Good!\n")
    #}

    reportFileHandle.close()
    correlationFileHandle.close()

#}

###############################################################
###############################################################
def Main():
#{
    global minAvgSamples 
    global avgTime 
609
    global maxAvgSamples
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
    global logDir 
    global OutputFileHandle 

    # Parse the command line options
    usage = "usage: %prog [options] Input_Directory_Path"

    cmdParser = OptionParser(usage=usage)

    cmdParser.add_option("-t","--tcp",action="store_true",dest="tcp",default=False,help="Check TCP packet flows for correlation")
            
    cmdParser.add_option("-u", "--udp", action="store_true", dest="udp",\
            default=False, help="Check UDP packet flows for correlation")

    cmdParser.add_option("-b", "--bucket", action="store_true", dest="avgMethod", \
            default=False, help="Use Bucket average instead of Moving average")

    cmdParser.add_option("-a", "--avgTime", action="store", dest="avgTime", \
627
            type="int",default=2000000, help="Time period for Moving/Bucket Average")
628 629

    cmdParser.add_option("-m", "--minSamples", action="store", dest="minAvgSamples", \
630
            type="int",default=100, help="Min Samples for Moving Average")
631 632

    cmdParser.add_option("-x", "--maxSamples", action="store", dest="maxAvgSamples", \
633
            type="int",default=500, help="Max Samples for Moving Average")
634 635 636 637 638 639 640 641 642 643 644

    (cmdOptions, args) = cmdParser.parse_args()

    if len(args) != 1:
        cmdParser.print_help()
        sys.exit()

    logDir = args[0]
    OutputFileName = logDir + "/logs/SanityCheckDetails.txt"
    reportFileName = logDir + "/logs/SanityCheckReport.txt"

Pramod R Sanaga's avatar
Pramod R Sanaga committed
645
    if not(os.path.exists(logDir + "/logs")) :
646 647 648 649 650
    #{
        print "##### Error: Path given as input is invalid. Provide the path upto(not including) logs/ directory"
        sys.exit()
    #}

651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
    OutputFileHandle = file(OutputFileName, "w")

    if cmdOptions.avgMethod:
        avgMethod = 1
    else:
        avgMethod = 0

    if cmdOptions.tcp and cmdOptions.udp:
        transportFlag = 2
        iterator = 0
    elif cmdOptions.tcp:
        transportFlag = 1
        iterator = 0
    elif cmdOptions.udp:
        transportFlag = 2
        iterator = 1
667 668 669
    else:
        transportFlag = 2
        iterator = 0
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693


    minAvgSamples = cmdOptions.minAvgSamples
    avgTime = cmdOptions.avgTime
    maxAvgSamples = cmdOptions.maxAvgSamples

    numNodes = 0
    numNodesProcessed = 0

    for i in range(1,100):
    #{
        dirNameElab = logDir + "/logs/elab-" + str(i)
        dirNamePlab = logDir + "/logs/planet-" + str(i)
        if os.path.exists(dirNameElab) and os.path.exists(dirNamePlab) :
        #{
            numNodes = numNodes + 1

            fileNameElab = dirNameElab + "/local/logs/" + "SanityCheck.log"
            fileNamePlab = dirNamePlab + "/local/logs/" + "SanityCheck.log"

            if (os.path.exists(fileNameElab) and os.path.exists(fileNamePlab)) :
            #{
                numNodesProcessed = numNodesProcessed + 1

694 695
                if (os.stat(fileNameElab).st_size > 0 and os.stat(fileNamePlab).st_size > 0):
                #{
696

697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
                    OutputFileHandle.write("Flexlab_File = " + fileNameElab + " \nPlab_File = " + fileNamePlab + "\n")

                    if transportFlag == 2 and iterator == 1:
                        OutputFileHandle.write("Max_Correlation=0.000000" + ":Delay=0" + "ms:Transport=TCP" + ":N=0:KbpsPercentDiff=0.000000" + "\n")

                    for j in range(iterator, transportFlag):
                        processFiles(fileNameElab, fileNamePlab, avgMethod, j)

                    if transportFlag == 1 and iterator == 0:
                        OutputFileHandle.write("Max_Correlation=0.000000" + ":Delay=0" + "ms:Transport=UDP" + ":N=0:KbpsPercentDiff=0.000000" + "\n")

                #}
                else:
                #{
                    OutputFileHandle.write("Flexlab_File = " + fileNameElab + " \nPlab_File = " + fileNamePlab + "\n")
                    OutputFileHandle.write("Max_Correlation=0.000000" + ":Delay=0" + "ms:Transport=TCP" + ":N=0:KbpsPercentDiff=0.000000" + "\n")
                    OutputFileHandle.write("Max_Correlation=0.000000" + ":Delay=0" + "ms:Transport=UDP" + ":N=0:KbpsPercentDiff=0.000000" + "\n")
                #}
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
            #}
        #}
        else:
            break
    #}

    OutputFileHandle.close()

    PrintReport(OutputFileName, numNodes, numNodesProcessed, reportFileName)

#}
###############################################################
###############################################################

Main()