예제 #1
0
    def evalOnePair(g, lli, s, d,
                    lowerBoundCounts,
                    dagSize_stretchToCounts,
                    pairsWithDagSizeSmallerThanLowerBound,
                    codec2HdrLen_stretchToCounts,
                    codec4HdrLen_stretchToCounts,
                    pairsWithLargeCodec4Encodings,
                    M):
        lowerBound = None
        for stretch in stretches:
            pp, dp = getDgWithStretch(g, s, d, weighted, stretch)
            if (not pp):
                print 'no path: s,d="%s","%s"' % (s,d)
                return
            if dp == None:
                dp = {}
                pass

            dag, virtualDetourPaths = approach2.getDagWithVnodes(
                pp, dp, returnDetourPathsWithVNodes=True)
            codec2HdrLen = codec2.encode(
                dag, pp, virtualDetourPaths, lli, False, s, d,
                useLinkIdLenPrefix=False,
                roundUpToMultipleBits=8)[0]
            addValueCount(codec2HdrLen_stretchToCounts[stretch], codec2HdrLen)

            codec4HdrLen = codec4.encode(
                pp, dp, lli, s, d, roundUpToMultipleBits=8)
            addValueCount(codec4HdrLen_stretchToCounts[stretch], codec4HdrLen)

            dagSize = dag.number_of_edges()
            addValueCount(dagSize_stretchToCounts[stretch], dagSize)

            if codec4HdrLen > headerLengthThreshold:
                pairsWithLargeCodec4Encodings[stretch].append((s,d))
                pass

            if lowerBound is None:
                lowerBound = computeBounds(g, s, d, pp, M, weighted)
                addValueCount(lowerBoundCounts, lowerBound)
                pass
            if dagSize < lowerBound:
                pairsWithDagSizeSmallerThanLowerBound[stretch].append((s,d))
                pass
            pass
        return
예제 #2
0
    def evalOnePair(g, lli, localLinkLabelLens, s, d,
                    lowerBoundCounts,
                    dagSize_stretchToCounts,
                    pairsWithDagSizeSmallerThanLowerBound,
                    codec2HdrLen_stretchToCounts,
                    codec4HdrLen_stretchToCounts,
                    singlePath_encodingLen_counts,
                    pairsWithLargeCodec4Encodings,
                    M):
        lowerBound = None
        for stretch in stretches:
            pp, dp = getDgWithStretch(g, s, d, weighted, stretch)
            if (not pp):
                print 'no path: s,d="%s","%s"' % (s,d)
                return
            if dp == None:
                dp = {}
                pass

            dag, virtualDetourPaths = approach2.getDagWithVnodes(
                pp, dp, returnDetourPathsWithVNodes=True)
            try:
                # in bits
                codec2HdrLen = codec2.encode(
                    dag, pp, virtualDetourPaths, lli, False, s, d,
                    useLinkIdLenPrefix=False,
                    localLinkLabelLens=localLinkLabelLens,
                    returnActualEncoding=False,
                    roundUpToMultipleBits=1)[0]
                pass
            except Exception, e:
                print 'WARNING: pair s=%s,d=%s is problematic\n' %(s,d)
                print str(e)
                return
            # convert to bytes
            codec2HdrLen = int(math.ceil(float(codec2HdrLen)/8))
            addValueCount(codec2HdrLen_stretchToCounts[stretch], codec2HdrLen)

            # in bits
            codec4HdrLen = codec4.encode(
                pp, dp, lli, localLinkLabelLens, s, d, roundUpToMultipleBits=1,
                returnActualEncoding=False)
            # convert to bytes
            codec4HdrLen = int(math.ceil(float(codec4HdrLen)/8))
            addValueCount(codec4HdrLen_stretchToCounts[stretch], codec4HdrLen)

            # just sum up the all the link label lengths
            singlePath_encodingLen = sum(map(lambda n: localLinkLabelLens[n], pp[:-1]))
            # get number of bytes from number of bits
            singlePath_encodingLen = int(math.ceil(float(singlePath_encodingLen)/8))
            addValueCount(singlePath_encodingLen_counts, singlePath_encodingLen)

            dagSize = dag.number_of_edges()
            addValueCount(dagSize_stretchToCounts[stretch], dagSize)

            if codec4HdrLen > headerLengthThreshold:
                pairsWithLargeCodec4Encodings[stretch].append((s,d))
                pass

            if lowerBound is None:
                lowerBound = computeBounds(g, s, d, pp, M, weighted)
                addValueCount(lowerBoundCounts, lowerBound)
                pass
            if dagSize < lowerBound:
                pairsWithDagSizeSmallerThanLowerBound[stretch].append((s,d))
                pass
            pass