示例#1
0
    def TMEideal(self):
        ### populate OF switch routing entries
        swHj = self.OM.SDNSwitchRoutingEntries_multi()
        for sw in swHj:
            print "OF Switch {0} has routing entries {1}".format(
                sw, len(swHj[sw]))

        ### construct network-wide observation matrix
        D_base = self.OM.setupOM()
        print "rank of matrix, SNMP Linkloads + Routing Entries: ", np.linalg.matrix_rank(
            D_base)

        ### total number of TCAMs
        K = 0
        for sw in self.swKj:
            K += self.swKj[sw]

        t_epoch = 0
        traffic_estm = []
        for fl in range(self.N):
            traffic_estm.append([])

        while (t_epoch < self.Tc):
            ### estimate TM
            col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]

            ### ideally measure Top K flows without rule placement constraints
            index = sorted(range(len(col_epoch)),
                           key=lambda k: col_epoch[k],
                           reverse=True)
            D = D_base
            for fl in index[0:K]:
                B = np.zeros((1, self.N), dtype=np.int)
                B[0][fl] = 1
                D = np.concatenate((D, B), axis=0)
            """ Debug """
            print "rank of network-wide observation matrix in ideal case: ", np.linalg.matrix_rank(
                D)

            Y = np.mat(D) * np.mat(col_epoch)
            Y = np.array(Y.tolist())

            W = np.ones([1, self.N])
            x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
            x_epoch = [round(k) for k in x_epoch]

            for fl in range(self.N):
                traffic_estm[fl].append(x_epoch[fl])

            ### ok, we just finished one t_epoch and move to next
            t_epoch += 1
        """ Debug """
        print "number of flows in tmEstm: ", len(traffic_estm)
        print "number of time intervals in tmEstm: ", len(traffic_estm[0])
        self.tmEstm = traffic_estm

        ### evaluate performance metric
        PM = performanceMetric.perfMetric(self.tmTrue, self.tmEstm,
                                          self.IPPrefix)
        return PM.calMetrics()
示例#2
0
    def TMEwMLRF(self):
        ### populate OF switch routing entries
        swHj = self.OM.SDNSwitchRoutingEntries_multi()
        for sw in swHj:
            print "OF Switch {0} has routing entries {1}".format(
                sw, len(swHj[sw]))

        ### static aggregation: MLRF
        swHj = self.OM.MLRF_multi(self.swKj)
        for sw in swHj:
            print "OF Switch {0} has entries (RE+ME) {1}".format(
                sw, len(swHj[sw]))

        ### construct network-wide observation matrix
        D = self.OM.setupOM()
        """ Debug """
        print "rank of observation D in case {0} is {1}".format(
            self.cstr, np.linalg.matrix_rank(D))

        t_epoch = 0
        traffic_estm = []
        for fl in range(self.N):
            traffic_estm.append([])

        while (t_epoch < self.Tc):
            ### estimate TM
            col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]
            Y = np.mat(D) * np.mat(col_epoch)
            Y = np.array(Y.tolist())

            W = np.ones([1, self.N])
            x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
            x_epoch = [round(k) for k in x_epoch]

            for fl in range(self.N):
                traffic_estm[fl].append(x_epoch[fl])

            ### ok, we just finished one t_epoch and move to next
            t_epoch += 1
        """ Debug """
        print "number of flows in tmEstm: ", len(traffic_estm)
        print "number of time intervals in tmEstm: ", len(traffic_estm[0])
        self.tmEstm = traffic_estm

        ### evaluate performance metric
        PM = performanceMetric.perfMetric(self.tmTrue, self.tmEstm,
                                          self.IPPrefix)
        return PM.calMetrics()
示例#3
0
    def TMEwRS(self):
        traffic_estm = []
        for fl in range(self.N):
            traffic_estm.append([])

        t_epoch = 0
        while (t_epoch < self.Tc):
            col_epoch = [row[t_epoch] for row in self.tmTrue[0:self.N]]
            index = sorted(range(len(col_epoch)),
                           key=lambda k: col_epoch[k],
                           reverse=True)
            ### random scheme: randomly sample flows
            index = np.random.permutation(index).tolist()

            # rule placement
            if self.method == "LastHop":
                [sw_bj, D] = self.OM.LastHop(index, self.swKj, False)
            elif self.method == "Greedy":
                [sw_bj, D] = self.OM.Greedy(index, self.swKj, False)
            elif self.method == "ILP":
                [sw_bj, D] = self.OM.ILP(col_epoch, self.swKj)

### estimate TM
            col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]
            Y = np.mat(D) * np.mat(col_epoch)
            Y = np.array(Y.tolist())

            W = np.ones([1, self.N])
            x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
            x_epoch = [round(k) for k in x_epoch]

            for fl in range(self.N):
                traffic_estm[fl].append(x_epoch[fl])

### ok, we just finished one t_epoch and move to next
            t_epoch += 1
        """ Debug """
        print "number of flows in tmEstm: ", len(traffic_estm)
        print "number of time intervals in tmEstm: ", len(traffic_estm[0])
        self.tmEstm = traffic_estm

        ### evaluate performance metric
        PM = performanceMetric.perfMetric(self.tmTrue, self.tmEstm,
                                          self.IPPrefix)
        result = PM.calMetrics()
        return result
    def TMEwSNMPLinkLoad(self):
        ### Construct network-wide observation matrix
        D = self.OM.setupOM()
        """ Debug """
        print "rank of observation D in case {0} is {1}".format(
            self.cstr, np.linalg.matrix_rank(D))

        t_epoch = 0
        traffic_estm = []
        for fl in range(self.N):
            traffic_estm.append([])

        while (t_epoch < self.Tc):
            ### estimate TM
            col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]
            Y = np.mat(D) * np.mat(col_epoch)
            Y = np.array(Y.tolist())

            W = np.ones([1, self.N])
            x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
            x_epoch = [round(k) for k in x_epoch]

            for fl in range(self.N):
                traffic_estm[fl].append(x_epoch[fl])

            ### ok, we just finished one t_epoch and move to next
            t_epoch += 1
        """ Debug """
        print "number of flows in tmEstm: ", len(traffic_estm)
        print "number of time intervals in tmEstm: ", len(traffic_estm[0])
        self.tmEstm = traffic_estm

        ### evaluate performance metric
        PM = performanceMetric.perfMetric(self.tmTrue, self.tmEstm,
                                          self.IPPrefix)
        return PM.calMetrics()
示例#5
0
    def TMEwMUCBP(self):
        traffic_estm = []
        for fl in range(self.N):
            traffic_estm.append([])

    ### populate OF switch routing entries
        swHj = self.OM.SDNSwitchRoutingEntries_multi()
        for sw in swHj:
            print "OF Switch {0} has routing entries {1}".format(
                sw, len(swHj[sw]))

    ### static aggregation: MLRF
        swHj = self.OM.MLRF_multi(self.swKj)
        for sw in swHj:
            print "OF Switch {0} has entries (RE+ME) {1}".format(
                sw, len(swHj[sw]))

    ### construct network-wide observation matrix
        D = self.OM.setupOM()

        t_epoch = 0
        ### MLRF to boot-strap online learning algorithms
        col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]
        Y = np.mat(D) * np.mat(col_epoch)
        Y = np.array(Y.tolist())

        W = np.ones([1, self.N])
        x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
        x_epoch = [round(k) for k in x_epoch]

        for fl in range(self.N):
            traffic_estm[fl].append(x_epoch[fl])

        if (self.windowSize == 0):
            self.windowSize = self.Tc
        """ Debug """
        print "static window size is: ", self.windowSize

        ### MUCBP online learning algorithm
        alpha = 0.1
        xj = []
        tj = []
        Ij = []
        tc = 0

        # initialize xj
        t_epoch = 0
        xj = [row[t_epoch] for row in traffic_estm]
        tj = [1 for row in self.tmTrue]
        Ij = [0 for row in self.tmTrue]
        tc = self.N
        t_epoch += 1

        # update xj, even flow fl is not directly measured
        count = 1
        while (t_epoch < self.Tc):

            # MUCB Prediction
            for k in range(self.N):
                Ij[k] = alpha * xj[k] + math.sqrt(
                    2.0 * math.log(tc) / float(tj[k]))
            index = sorted(range(len(Ij)), key=lambda k: Ij[k], reverse=True)

            # rule placement
            if self.method == "LastHop":
                [sw_bj, D] = self.OM.LastHop(index, self.swKj, False)
            elif self.method == "Greedy":
                [sw_bj, D] = self.OM.Greedy(index, self.swKj, False)
            elif self.method == "ILP":
                [sw_bj, D] = self.OM.ILP(Ij, self.swKj)

### estimate TM
            col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]
            Y = np.mat(D) * np.mat(col_epoch)
            Y = np.array(Y.tolist())

            W = np.ones([1, self.N])
            x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
            x_epoch = [round(k) for k in x_epoch]

            for fl in range(self.N):
                traffic_estm[fl].append(x_epoch[fl])

            # update tj
            for sw in sw_bj:
                for fl in sw_bj[sw]:
                    tj[fl] += 1
            # update xj
            #for sw in sw_bj:
            #	for fl in sw_bj[sw]:
            #		xj[fl] = (xj[fl] * (tj[fl]-1) + x_epoch[fl]) / float(tj[fl])

            # update xj: version 2
            for fl in range(self.N):
                xj[fl] = ((xj[fl] * count) + x_epoch[fl]) / float(count + 1)

            # update tc
            tc += sum([self.swKj[sw] for sw in self.swKj])

            if (t_epoch % self.windowSize == 0):
                tj = [1 for k in tj]
                tc = self.N
                count = 1

### ok, we just finished one t_epoch and move to next
            t_epoch += 1
            count += 1
        """ Debug """
        print "number of flows in tmEstm: ", len(traffic_estm)
        print "number of time intervals in tmEstm: ", len(traffic_estm[0])
        self.tmEstm = traffic_estm

        ### evaluate performance metric
        PM = performanceMetric.perfMetric(self.tmTrue, self.tmEstm,
                                          self.IPPrefix)
        return PM.calMetrics()
示例#6
0
    def TMEwLFF(self):
        ### populate OF switch routing entries
        swHj = self.OM.SDNSwitchRoutingEntries_multi()
        for sw in swHj:
            print "OF Switch {0} has routing entries {1}".format(
                sw, len(swHj[sw]))

        ### static aggregation: MLRF
        swHj = self.OM.MLRF_multi(self.swKj)
        for sw in swHj:
            print "OF Switch {0} has entries (RE+ME) {1}".format(
                sw, len(swHj[sw]))

        ### construct network-wide observation matrix
        D = self.OM.setupOM()

        traffic_estm = []
        for fl in range(self.N):
            traffic_estm.append([])

        t_epoch = 0
        # MLRF to estimate per-flow sizes
        col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]
        Y = np.mat(D) * np.mat(col_epoch)
        Y = np.array(Y.tolist())

        W = np.ones([1, self.N])
        x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
        x_epoch = [round(k) for k in x_epoch]

        for fl in range(self.N):
            traffic_estm[fl].append(x_epoch[fl])

        # rule placement
        if self.method == "LastHop":
            [sw_bj, D] = self.OM.LastHop(index, self.swKj, False)
        elif self.method == "Greedy":
            [sw_bj, D] = self.OM.Greedy(index, self.swKj, False)
        elif self.method == "ILP":
            [sw_bj, D] = self.OM.ILP(x_epoch, self.swKj)

        t_epoch += 1
        while (t_epoch < self.Tc):
            ### estimate TM
            col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]
            Y = np.mat(D) * np.mat(col_epoch)
            Y = np.array(Y.tolist())

            W = np.ones([1, self.N])
            x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
            x_epoch = [round(k) for k in x_epoch]

            for fl in range(self.N):
                traffic_estm[fl].append(x_epoch[fl])

            ### ok, we just finished one t_epoch and move to next
            t_epoch += 1
        """ Debug """
        print "number of flows in tmEstm: ", len(traffic_estm)
        print "number of time intervals in tmEstm: ", len(traffic_estm[0])
        self.tmEstm = traffic_estm

        ### evaluate performance metric
        PM = performanceMetric.perfMetric(self.tmTrue, self.tmEstm,
                                          self.IPPrefix)
        return PM.calMetrics()
示例#7
0
    def TMEwWLP(self):
        ### populate OF switch routing entries
        swHj = self.OM.SDNSwitchRoutingEntries_multi()
        for sw in swHj:
            print "OF Switch {0} has routing entries {1}".format(
                sw, len(swHj[sw]))

        ### static aggregation: MLRF
        swHj = self.OM.MLRF_multi(self.swKj)
        for sw in swHj:
            print "OF Switch {0} has entries (RE+ME) {1}".format(
                sw, len(swHj[sw]))

        ### construct network-wide observation matrix
        D = self.OM.setupOM()

        traffic_estm = []
        for fl in range(self.N):
            traffic_estm.append([])
        scale = (1 - math.exp(-1)) / (1 - math.exp(-1 * self.recordsNum))

        t_epoch = 0
        # MLRF to boot-strap online learning algorithms
        col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]
        Y = np.mat(D) * np.mat(col_epoch)
        Y = np.array(Y.tolist())

        W = np.ones([1, self.N])
        x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
        x_epoch = [round(k) for k in x_epoch]

        for fl in range(self.N):
            traffic_estm[fl].append(x_epoch[fl])

        t_epoch += 1
        predictValue = [0 for fl in range(self.N)]
        while (t_epoch < self.Tc):

            # linear prediction with exponential decay weight
            for fl in range(self.N):
                records = traffic_estm[fl][max(t_epoch - self.recordsNum, 0
                                               ):t_epoch][::-1]
                predictValue[fl] = sum(
                    [math.exp(-1 * idx) * k for idx, k in enumerate(records)])
                predictValue[fl] *= scale

            index = sorted(range(len(predictValue)),
                           key=lambda k: predictValue[k],
                           reverse=True)

            # rule placement
            if self.method == "LastHop":
                [sw_bj, D] = self.OM.LastHop(index, self.swKj, False)
            elif self.method == "Greedy":
                [sw_bj, D] = self.OM.Greedy(index, self.swKj, False)
            elif self.method == "ILP":
                [sw_bj, D] = self.OM.ILP(predictValue, self.swKj)

### estimate TM
            col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]
            Y = np.mat(D) * np.mat(col_epoch)
            Y = np.array(Y.tolist())

            W = np.ones([1, self.N])
            x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
            x_epoch = [round(k) for k in x_epoch]

            for fl in range(self.N):
                traffic_estm[fl].append(x_epoch[fl])

### ok, we just finished one t_epoch and move to next
            t_epoch += 1
        """ Debug """
        print "number of flows in tmEstm: ", len(traffic_estm)
        print "number of time intervals in tmEstm: ", len(traffic_estm[0])
        self.tmEstm = traffic_estm

        ### evaluate performance metric
        PM = performanceMetric.perfMetric(self.tmTrue, self.tmEstm,
                                          self.IPPrefix)
        return PM.calMetrics()
示例#8
0
    def TMEwLB(self):
        ### populate OF switch routing entries
        swHj = self.OM.SDNSwitchRoutingEntries_multi()
        for sw in swHj:
            print "OF Switch {0} has routing entries {1}".format(
                sw, len(swHj[sw]))

        ### static aggregation: MLRF
        swHj = self.OM.MLRF_multi(self.swKj)
        for sw in swHj:
            print "OF Switch {0} has entries (RE+ME) {1}".format(
                sw, len(swHj[sw]))

        ### construct network-wide observation matrix
        D = self.OM.setupOM()

        traffic_estm = []
        for fl in range(self.N):
            traffic_estm.append([])

        t_epoch = 0
        # MLRF to boot-strap online learning algorithms
        col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]
        Y = np.mat(D) * np.mat(col_epoch)
        Y = np.array(Y.tolist())

        W = np.ones([1, self.N])
        x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
        x_epoch = [round(k) for k in x_epoch]

        for fl in range(self.N):
            traffic_estm[fl].append(x_epoch[fl])

        t_epoch += 1
        """ Debug """
        hitRate = 0

        while (t_epoch < self.Tc):
            col_epoch = [row[t_epoch] for row in self.tmTrue[0:self.N]]
            index = sorted(range(len(col_epoch)),
                           key=lambda k: col_epoch[k],
                           reverse=True)

            # rule placement
            if self.method == "LastHop":
                [sw_bj, D] = self.OM.LastHop(index, self.swKj, False)
            elif self.method == "Greedy":
                [sw_bj, D] = self.OM.Greedy(index, self.swKj, False)
            elif self.method == "ILP":
                [sw_bj, D] = self.OM.ILP(col_epoch, self.swKj)

            # calculate large flows hitRate
            measured = []
            for sw in sw_bj:
                for fl in sw_bj[sw]:
                    measured.append(fl)

            K = len(measured)
            match = sum([1 for fl in measured if fl in index[0:K]])
            hitRate += match / float(K)

            ### estimate TM
            col_epoch = [[row[t_epoch]] for row in self.tmTrue[0:self.N]]
            Y = np.mat(D) * np.mat(col_epoch)
            Y = np.array(Y.tolist())

            W = np.ones([1, self.N])
            x_epoch = cvxpySolver.estm_TM(Y, D, W, self.N)
            x_epoch = [round(k) for k in x_epoch]

            for fl in range(self.N):
                traffic_estm[fl].append(x_epoch[fl])

### ok, we just finished one t_epoch and move to next
            t_epoch += 1
        """ Debug """
        print "number of flows in tmEstm: ", len(traffic_estm)
        print "number of time intervals in tmEstm: ", len(traffic_estm[0])
        self.tmEstm = traffic_estm
        hitRate /= float(self.Tc - 1)

        ### evaluate performance metric
        PM = performanceMetric.perfMetric(self.tmTrue, self.tmEstm,
                                          self.IPPrefix)
        result = PM.calMetrics()
        result.append(hitRate)
        return result