Ejemplo n.º 1
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)
Ejemplo n.º 2
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