Example #1
0
def next_hop(cur_hop, pre_hop, s, d, hash_str, 
            table, seeds, polys, flow_paths
        ):
    print('cur_hop, pre_hop', cur_hop, pre_hop)
    if cur_hop == d:
        hash_str0 = hash_str
        hash_str = hash_str0[0:14]
        marker = hash_str0[14:]
        if marker != 'None':
            append_path(hash_str, pre_hop, cur_hop, flow_paths)
        return 
    n = len(hash_str)
    
    # Header = 4+4+2+2+1 bytes
    hash_str0 = hash_str
    hash_str = hash_str0[0:13]
    marker = hash_str0[13:]
    
    if marker == cur_hop:
        append_path(hash_str, pre_hop, cur_hop, flow_paths)
        
    nhop = table[cur_hop][d][0]
    n = len(table[cur_hop][d])
    if n > 1:
        ni = crc8(seeds[cur_hop], hash_str, polys[cur_hop])%n
        nhop = table[cur_hop][d][ni]
    next_hop(nhop, cur_hop, s, d, hash_str0, table, seeds, polys, flow_paths)
Example #2
0
def spine_sw_up_0(pre_hop, cur_hop, ev, hash_str, size, seeds, polys,
                  port_list, byte_cnt, link_byte_cnt, paths):
    append_path(hash_str, cur_hop, paths)
    byte_cnt[cur_hop] += size
    link_byte_cnt[pre_hop + ' ' + cur_hop] += size
    port_num = 2
    port = crc8(seeds[cur_hop], (hash_str), polys[cur_hop]) % port_num
    next_hop = port_list[cur_hop].split()[port]
    spine_sw_up_1(cur_hop, next_hop, ev, hash_str, size, byte_cnt,
                  link_byte_cnt, paths)
Example #3
0
def next_hop_hash_set(cur_hop,
                      pre_hop,
                      s,
                      d,
                      hash_str,
                      table,
                      seeds,
                      polys,
                      flow_paths,
                      select_dict=OrderedDict({}),
                      test_hop=''):

    select_range = 1 << 28
    if cur_hop == d:
        hash_str0 = hash_str
        hash_str = hash_str0[0:13]
        marker = hash_str0[13:]
        hash_mid = crc32(hash_str)
        if hash_mid < select_range:
            append_path(hash_str, pre_hop, cur_hop, d, flow_paths)
            if cur_hop == test_hop:
                select_dict[hash_str] = 1
        return
    n = len(hash_str)

    # Header = 4+4+2+2+1 bytes
    hash_str0 = hash_str
    hash_str = hash_str0[0:13]
    marker = hash_str0[13:]

    hash_mid = crc32(hash_str)
    if hash_mid < select_range:
        append_path(hash_str, pre_hop, cur_hop, d, flow_paths)
        if cur_hop == test_hop:
            select_dict[hash_str] = 1

    nhop = table[cur_hop][d][0]
    n = len(table[cur_hop][d])
    if n > 1:
        ni = crc8(seeds[cur_hop], hash_str, polys[cur_hop]) % n
        nhop = table[cur_hop][d][ni]
    next_hop_hash_set(nhop,
                      cur_hop,
                      s,
                      d,
                      hash_str0,
                      table,
                      seeds,
                      polys,
                      flow_paths,
                      select_dict,
                      test_hop=test_hop)
Example #4
0
def next_hop(cur_hop, pre_hop, s, d, hash_str, table, seeds, polys,
             flow_paths):
    if cur_hop == d:
        append_path(hash_str, cur_hop, flow_paths)
        return

    append_path(hash_str, cur_hop, flow_paths)
    nhop = table[cur_hop][d][0]
    n = len(table[cur_hop][d])
    if n > 1:
        ni = crc8(seeds[cur_hop], hash_str, polys[cur_hop]) % n
        nhop = table[cur_hop][d][ni]
    next_hop(nhop, cur_hop, s, d, hash_str, table, seeds, polys, flow_paths)
Example #5
0
def next_hop(cur_hop,
             pre_hop,
             s,
             d,
             hash_str,
             size,
             table,
             seeds,
             polys,
             flow_paths,
             cflow_dict,
             app_link_dict,
             select_dict=OrderedDict({})):

    if cur_hop == d:
        hash_str0 = hash_str
        hash_str = hash_str0[0:14]
        marker = hash_str0[14:]
        if marker == cur_hop:
            append_path(hash_str, pre_hop, cur_hop, d, flow_paths)
            select_dict[hash_str] = 1
        return
    n = len(hash_str)

    # Header = 4+4+2+2+1 bytes
    hash_str0 = hash_str
    hash_str = hash_str0[0:13]
    marker = hash_str0[13:]

    collect_flows(hash_str, pre_hop, cur_hop, size, cflow_dict)
    if marker == cur_hop:
        append_path(hash_str, pre_hop, cur_hop, d, flow_paths)
        select_dict[hash_str] = 1

    nhop = table[cur_hop][d][0]
    n = len(table[cur_hop][d])
    if n > 1:
        ni = crc8(seeds[cur_hop], hash_str, polys[cur_hop]) % n
        nhop = table[cur_hop][d][ni]
    next_hop(nhop, cur_hop, s, d, hash_str0, size, table, seeds, polys,
             flow_paths, cflow_dict, app_link_dict, select_dict)
Example #6
0
def next_hop_rand_mark(cur_hop,
                       pre_hop,
                       s,
                       d,
                       hash_str,
                       size,
                       table,
                       seeds,
                       polys,
                       min_len,
                       flow_paths,
                       cflow_dict,
                       app_link_dict,
                       app_link_flow_dict,
                       select_dict=OrderedDict({}),
                       drop_id=0,
                       r_threshold=0.0,
                       black_hole='sh41',
                       test_hop='',
                       add_byte_dict=OrderedDict({}),
                       w_key=0.0):

    if cur_hop == d:
        hash_str0 = hash_str
        hash_str = hash_str0[0:13]
        marker = hash_str0[13:]
        if marker == "1":
            append_path(hash_str, pre_hop, cur_hop, d, flow_paths, size=size)
            #select_dict[hash_str] = 1

        return min_len

    # Header = 4+4+2+2+1 bytes
    hash_str0 = hash_str
    hash_str = hash_str0[0:13]
    marker = hash_str0[13:]

    next_hops = ''
    if pre_hop in table:
        next_hops = ','.join(sorted(table[pre_hop][d]))

    if black_hole != None:
        collect_flows(hash_str,
                      pre_hop,
                      cur_hop,
                      size,
                      cflow_dict,
                      app_link_dict,
                      app_link_flow_dict,
                      next_hops,
                      d=s)

    nhop = table[cur_hop][d][0]

    n = len(table[cur_hop][d])
    if n > 1:
        ni = crc8(seeds[cur_hop], hash_str, polys[cur_hop]) % n
        nhop = table[cur_hop][d][ni]

        if cur_hop in test_hop:
            if cur_hop not in select_dict:
                select_dict[cur_hop] = OrderedDict({})

            if hash_str not in select_dict[cur_hop]:
                select_dict[cur_hop][hash_str] = 1
                min_len = min([
                    len(select_dict[x]) for x in test_hop if x in select_dict
                ])
            #print min_len

    # Drop some packets from a particular link
    """if black_hole == nhop and int(int(s[3:])/129) == drop_id:
        r = random.random()
        if r < r_threshold:
            return"""
    """if test_hop not in add_byte_dict:
        add_byte_dict[test_hop] = 0.0
    add_byte_dict[test_hop] += size   """

    # Randomly choosen a flow and add extra byte to it
    if cur_hop in test_hop and cur_hop not in add_byte_dict:
        add_byte_dict[cur_hop] = OrderedDict({})
    if drop_id > 0 and n > 1 and cur_hop in test_hop and nhop == table[
            cur_hop][d][0] and len(add_byte_dict[cur_hop]) < 2:
        w_key1 = str(flow_cap) + ',' + cur_hop + ',' + topo_type
        w_key_size = w_key[w_key1]
        add_byte_dict[hash_str] = 1000 * size
        size = (w_key_size) * r_threshold / (1 - r_threshold * 2)
        #print 'haha', size

    if marker == "1":
        append_path(hash_str, pre_hop, cur_hop, d, flow_paths, size=size)

    min_len = next_hop_rand_mark(nhop,
                                 cur_hop,
                                 s,
                                 d,
                                 hash_str0,
                                 size,
                                 table,
                                 seeds,
                                 polys,
                                 min_len,
                                 flow_paths,
                                 cflow_dict,
                                 app_link_dict,
                                 app_link_flow_dict,
                                 select_dict,
                                 drop_id=drop_id,
                                 r_threshold=r_threshold,
                                 black_hole=black_hole,
                                 test_hop=test_hop,
                                 add_byte_dict=add_byte_dict,
                                 w_key=w_key)
    return min_len
Example #7
0
def spine_sw_up_1(pre_hop, cur_hop, ev, hash_str, size, byte_cnt,
                  link_byte_cnt, paths):
    append_path(hash_str, cur_hop, paths)
    byte_cnt[cur_hop] += size
    link_byte_cnt[pre_hop + ' ' + cur_hop] += size