SanityCheck.py 24.6 KB
Newer Older
1 2 3
#!/usr/local/bin/python
#
# Copyright (c) 2007 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25
#

#########################################################
26 27
# Input:
# This script requires one command line arguments
28 29 30 31 32 33
# Argument 1 - Pointer to the 
# /proj/.../exp/project_name/ directory
#
# (The elab-*, planet-* directories should
# have tcpdump log files named SanityCheck.log)
#
34 35 36 37 38 39 40 41
# 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"
#
42 43 44
#########################################################

#########################################################
45
# Sanity check for Flexlab TCP & UDP runs
46 47 48
#
# Calculates the correlation of the traffic
# on Planetlab nodes versus the traffic on the
49
# corresponding Flexlab (Emulab) nodes.
50 51 52
#
# Requires that Tcpdump files be saved on elab-*
# and planet-* nodes during the Flexlab run.
53 54
# This can be done by passing "-t" option
# to start-experiment and stop-experiment scripts
55
#
56
# This script can also be executed in stand-alone mode 
57
# after collecting the logs
58 59
# with stop-experiment  - Just point it to the 
# directory containing the logs.
60
# 
61 62 63 64
# Cross Correlation references: 
# -----------------------------
# FFT method  - http://en.wikipedia.org/wiki/Cross-correlation
# Paul Bourke - http://local.wasp.uwa.edu.au/~pbourke/other/correlate
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
#
#########################################################

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
164
                        tmpTimeCounter = tmpTimeCounter + 10000
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189

                    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)

190 191 192 193 194 195
    del packetSizeArray
    del packetTimeArray

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

196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
#}
###############################################################
###############################################################

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*)')

222 223 224 225 226 227

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

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
    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:
            #{
244 245 246 247 248 249
                currentPacketSize = int(match.group(9))
                currentPacketTime = time - lastPacketTime

                runningByteTotal += currentPacketSize
                runningTimeTotal += currentPacketTime
                runningPacketTotal += 1
250 251 252 253

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

254
                if runningPacketTotal >= minSamples:
255
                #{
256
                    if (runningPacketTotal < maxSamples) and (runningTimeTotal < avgTimeScale):
257
                    #{
258
                        throughput = 8000000*runningByteTotal/(runningTimeTotal*1024.0)
259
                    #}
260
                    elif runningPacketTotal < maxSamples:
261
                    #{
262 263 264 265 266 267 268 269
                        while (runningPacketTotal >= minSamples) and (runningTimeTotal > avgTimeScale):
                        #{
                            runningTimeTotal -= packetTimeArray[lastIndex]
                            runningByteTotal -= packetSizeArray[lastIndex]
                            lastIndex = (lastIndex + 1)%maxSamples
                            runningPacketTotal -= 1
                        #}
                        throughput = 8000000*runningByteTotal/(runningTimeTotal*1024.0)
270
                    #}
271
                    elif runningTimeTotal < avgTimeScale:
272
                    #{
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
                        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)
289 290
                    #}

291
                    if runningTimeTotal != 0 :
292 293 294 295 296
                    #{
                        tmpFileHandle.write(str(time-initTime)+" "+str(throughput)+"\n")
                        numLines += 1
                    #}
                #}
297 298 299 300

                packetSizeArray[arrayIndex] = currentPacketSize
                packetTimeArray[arrayIndex] = currentPacketTime
                arrayIndex = (arrayIndex + 1) % maxSamples
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
            #}

            lastPacketTime = time
        #}

    #}

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

    tmpFileHandle.close()
    inputFile.close()

    os.system("cat " + tmpFile + " >> " + outputFile)
    os.remove(tmpFile)
316 317 318 319 320

    del packetSizeArray
    del packetTimeArray

    # Return the avg. transfer rate - in kbps
321 322 323
    if packetAvgTime == 0:
        return 0

324
    return (8000000*packetAvgBytes/(packetAvgTime*1024.0))
325 326 327 328
#}

###############################################################
###############################################################
329

330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
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
346 347 348 349
# Skip the bandwidth comparison for 5 seconds, while Flexlab converges
# to the correct available bandwidth and delay estimates.
    initialThreshold = 500

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
    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
391 392 393
            if numLines > initialThreshold:
                outputFileHandle.write(str(currentTimeVal) + " " + \
                        str(valueArray[index]) + "\n")
394 395 396 397 398
            currentTimeVal += 10000
            numLines += 1
        #}
        elif currentTimeVal == timeArray[index+1]:
        #{
Pramod R Sanaga's avatar
Pramod R Sanaga committed
399 400 401
            if numLines > initialThreshold:
                outputFileHandle.write(str(currentTimeVal) + " " + \
                        str(valueArray[index+1]) + "\n")
402 403 404 405 406 407 408 409
            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
410 411 412
            if numLines > initialThreshold:
                outputFileHandle.write(str(currentTimeVal) + " " + \
                        str(intermValue) + "\n")
413 414 415 416 417 418 419 420 421 422 423 424
            currentTimeVal += 10000
            numLines += 1
        #}
        elif currentTimeVal > timeArray[index+1]:
        #{
            index += 1
            indexChanged = 1
        #}
    #}

    outputFileHandle.close()

425 426
    del timeArray
    del valueArray
427
#}
428 429
##############################################################
##############################################################
Pramod R Sanaga's avatar
Pramod R Sanaga committed
430
def CalcCorrelation(InFile1, InFile2, transportFlag, plabAvg, elabAvg):
431 432
#{

Pramod R Sanaga's avatar
Pramod R Sanaga committed
433 434 435 436 437
    delayVal = 0
    maxCorr = -2.0
    lineCount1 = 0
    lineCount2 = 0
    numLines = 0
438

Pramod R Sanaga's avatar
Pramod R Sanaga committed
439 440 441
    pipeObj = popen("wc -l " + InFile1, "r")
    lineCount1 = int(pipeObj.readline().split()[0])
    pipeObj.close()
442

Pramod R Sanaga's avatar
Pramod R Sanaga committed
443 444 445
    pipeObj = popen("wc -l " + InFile2, "r")
    lineCount2 = int(pipeObj.readline().split()[0])
    pipeObj.close()
446

Pramod R Sanaga's avatar
Pramod R Sanaga committed
447 448
    if lineCount1 < lineCount2:
        numLines = lineCount1
449
    else:
Pramod R Sanaga's avatar
Pramod R Sanaga committed
450
        numLines = lineCount2
451

Pramod R Sanaga's avatar
Pramod R Sanaga committed
452
    if numLines != 0:
453
    #{
Pramod R Sanaga's avatar
Pramod R Sanaga committed
454
        os.system("sh CorrelationR.sh " + InFile1 + " " + InFile2 + " " + "/tmp/Correlation.log" )
455

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

458 459
        for lineRead in InFileHandle1:
        #{
Pramod R Sanaga's avatar
Pramod R Sanaga committed
460 461
            shiftVal = int( lineRead.split()[0] )
            corrVal = float( lineRead.split()[1] )
462

Pramod R Sanaga's avatar
Pramod R Sanaga committed
463 464 465
            if corrVal > maxCorr:
                maxCorr = corrVal
                delayVal = shiftVal
466
        #}
467

Pramod R Sanaga's avatar
Pramod R Sanaga committed
468
        InFileHandle1.close()
469 470 471
    #}
    else:
    #{
Pramod R Sanaga's avatar
Pramod R Sanaga committed
472 473
        delayVal = 0
        maxCorr = 0.0
474 475 476 477 478 479 480 481 482
    #}

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

    diffTransferRate = elabAvg - plabAvg

483 484 485 486
    if elabAvg != 0:
        diffPercentage = 100.0*(float(diffTransferRate))/(float(elabAvg))
    else:
        diffPercentage = 0.0
487

Pramod R Sanaga's avatar
Pramod R Sanaga committed
488
    OutputFileHandle.write("Max_Correlation=" + str(maxCorr) + ":Delay=" + str(delayVal*10) + "ms:Transport=" + transport + ":N=" + str(numLines) + ":KbpsPercentDiff=" + str(diffPercentage) + "\n")
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503

#}

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


    if averagingMethod == 0: # Moving average
    #{
504
        elabAvg = CalcMovingAvgThroughput(fileNameElab, tmpFileElab1, minAvgSamples, avgTime, maxAvgSamples, transportFlag)
505 506
        sys.stdout.write("#")
        sys.stdout.flush()
507
        plabAvg = CalcMovingAvgThroughput(fileNamePlab, tmpFilePlab1, minAvgSamples, avgTime, maxAvgSamples, transportFlag)
508 509 510 511 512 513 514 515 516
        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
517
        CalcCorrelation(tmpFilePlab2, tmpFileElab2, transportFlag, plabAvg, elabAvg)
518 519 520 521 522 523 524 525 526 527
        sys.stdout.write("#")
        sys.stdout.flush()

        os.remove(tmpFileElab1)
        os.remove(tmpFileElab2)
        os.remove(tmpFilePlab1)
        os.remove(tmpFilePlab2)
    #}
    elif averagingMethod == 1: # Bucket average
    #{
528
        elabAvg = CalcBucketAvgThroughput(fileNameElab, tmpFileElab1, avgTime, transportFlag)
529 530
        sys.stdout.write("#")
        sys.stdout.flush()
531
        plabAvg = CalcBucketAvgThroughput(fileNamePlab, tmpFilePlab1, avgTime, transportFlag)
532 533
        sys.stdout.write("#")
        sys.stdout.flush()
534
        CalcCorrelationFFT(tmpFilePlab1, tmpFileElab1, transportFlag, plabAvg, elabAvg)
535 536 537 538 539 540 541 542 543 544
        sys.stdout.write("#")
        sys.stdout.flush()

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

#}
###############################################################
###############################################################
545 546 547 548 549
# 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
550 551
# b) Offset used for this value of cross-correlation <= 0
# c) Offset > -8 seconds
552 553 554 555
# d) Difference between Flexlab & Planetlab transfer rates
#    is less than 40%
# e) SanityCheck Tcpdump files exist for all pairs of nodes.
#
556 557 558 559 560
def PrintReport(correlationDataFile, numNodes, numNodesProcessed, reportFileName):
#{
    correlationFileHandle = file(correlationDataFile, "r")
    reportFileHandle = file (reportFileName, "w")

561
    correlationRegex = re.compile('Max_Correlation=([\d\.]*?):Delay=([\-\d]*?)ms:Transport=([\w]*?):N=([\d]*):KbpsPercentDiff=([\-\d\.]*?)$')
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578

    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
579
                    ( ( 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 ) ) ) :
580
            #{
581 582
                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")
583 584 585
                errorFlag = 1

            #}
586 587 588 589 590 591 592 593 594 595
# 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
            #}
596 597 598 599 600 601 602

        #}

    #}

    if numNodesProcessed != numNodes :
    #{
603 604
        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")
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625

        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 
626
    global maxAvgSamples
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
    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", \
644
            type="int",default=2000000, help="Time period for Moving/Bucket Average")
645 646

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

    cmdParser.add_option("-x", "--maxSamples", action="store", dest="maxAvgSamples", \
650
            type="int",default=500, help="Max Samples for Moving Average")
651 652 653 654 655 656 657 658 659 660 661

    (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
662
    if not(os.path.exists(logDir + "/logs")) :
663 664 665 666 667
    #{
        print "##### Error: Path given as input is invalid. Provide the path upto(not including) logs/ directory"
        sys.exit()
    #}

668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
    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
684 685 686
    else:
        transportFlag = 2
        iterator = 0
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710


    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

711 712
                if (os.stat(fileNameElab).st_size > 0 and os.stat(fileNamePlab).st_size > 0):
                #{
713

714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
                    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")
                #}
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
            #}
        #}
        else:
            break
    #}

    OutputFileHandle.close()

    PrintReport(OutputFileName, numNodes, numNodesProcessed, reportFileName)

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

Main()