Example #1
0
def filter(W=5):
    spineL, leafL, torL, serverL = gen_fattree()
    pathL = gen_int_path(spineL, leafL, torL, serverL)

    r = redis.StrictRedis(host='127.0.0.1', port=6379, db=1)  # 存每个交换机上包的数量
    r1 = redis.StrictRedis(host='127.0.0.1', port=6379, db=2)  # 存历史数据
    r2 = redis.StrictRedis(host='127.0.0.1', port=6379,
                           db=3)  # 存INT-filter减少的上传量

    t = []
    true = []
    pre = []
    while True:
        for path in pathL:
            for s in path:
                flag = int(r1.lindex(s, 0))
                if flag >= Update_interval:
                    # use true value
                    q = float(r.get(s))
                    r1.linsert(s, 'after', flag, q)
                    r1.rpop(s)
                    r1.lset(s, 0, 0)
                    true.append(q)
                    pre.append(q)
                    r2.incr('true')
                else:
                    temp_l = r1.lrange(s, 1, -1)
                    temp_l.reverse()
                    value_l = [float(q) for q in temp_l]
                    time_l = np.arange(0, W, 1)
                    start = time.time()
                    q = float(r.get(s))
                    pred, error, poly_order = predict(time_l, value_l, W, q)
                    # print(error)
                    if error < Threshold:
                        # use predict value
                        r1.linsert(s, 'after', flag, float(pred))
                        r1.rpop(s)
                        num = int(r1.lindex(s, 0))
                        r1.lset(s, 0, num + 1)
                        true.append(q)
                        pre.append(float(pred))
                        r2.incr('predict')
                    else:
                        # use true value
                        r1.linsert(s, 'after', flag, q)
                        r1.rpop(s)
                        r1.lset(s, 0, 0)
                        true.append(q)
                        pre.append(q)
                        r2.incr('true')
                    end = time.time()
                    t.append(end - start)
        time.sleep(0.1)
        if len(true) % 100 == 0:
            print(
                'INT-filter error:',
                np.sum(np.abs(np.array(true)[-100:] - np.array(pre)[-100:])) /
                100)
Example #2
0
def filter(W=1):
	spineL, leafL, torL, serverL = gen_fattree()
	pathL = gen_int_path(spineL, leafL, torL, serverL)

	r = redis.StrictRedis(host='127.0.0.1', port=6379, db=1)  # 存每个交换机上包的数量
	r3 = redis.StrictRedis(host='127.0.0.1', port=6379, db=4)  # 存Sel-INT历史数据
	r4 = redis.StrictRedis(host='127.0.0.1', port=6379, db=5)  # 存Sel-INT减少的上传量

	t = []
	true = []
	pre = []
	while True:
		for path in pathL:
			for s in path:
				flag = int(r3.lindex(s, 0))
				if flag >= Update_interval:
					# use true value
					q = float(r.get(s))
					r3.linsert(s, 'after', flag, q)
					r3.rpop(s)
					r3.lset(s, 0, 0)
					true.append(q)
					pre.append(q)
					r4.incr('true')
				else:
					temp_l = r3.lrange(s, 1, -1)
					data_p = float(temp_l[0])
					data = float(r.get(s))
					flag = abs(data_p - data) / min(data_p, data, -0.0000001)
					start = time.time()
					# print(error)
					if flag > Threshold:
						# use true value
						r3.linsert(s, 'after', flag, data)
						r3.rpop(s)
						r3.lset(s, 0, 0)
						true.append(data)
						pre.append(data)
						r4.incr('true')
					else:
						# use predict value
						num = int(r3.lindex(s, 0))
						r3.lset(s, 0, num + 1)
						true.append(data)
						pre.append(data_p)
						r4.incr('predict')
					end = time.time()
					t.append(end - start)
		time.sleep(0.1)
		if len(true) % 100 == 0:
			print('Sel-INT error:', np.sum(np.abs(np.array(true)[-100:] - np.array(pre)[-100:])) / 100)
Example #3
0
# -*- coding: UTF-8 -*-
import time
import redis
from clos import gen_fattree

def forward_packet(r, spineL, leafL, torL, serverL, forward_interval=0.1):
	# 核心交换机拥有更高的处理速率。
	while True:
		for spine in spineL:
			r.decr(spine)
		for leaf in leafL:
			r.decr(leaf)
		for tor in torL:
			r.decr(tor)
		time.sleep(forward_interval/3)



if __name__ == '__main__':
	k = 2
	W = 5
	r = redis.StrictRedis(host='127.0.0.1', port=6379, db=1)  # 存每个交换机上包的数量
	spineL, leafL, torL, serverL = gen_fattree()
	forward_packet(r, spineL, leafL, torL, serverL)