send.py 文件源码

python
阅读 43 收藏 0 点赞 0 评论 0

项目:P4-network-slices-A 作者: Emil-501 项目源码 文件源码
def main():
    if len(sys.argv) != 3:
        print "Usage: send.py [this_host] [target_host]"
        print "For example: send.py h1 h2"
        sys.exit(1)

    src, dst = sys.argv[1:]

    nb_hosts, nb_switches, links = read_topo()

    port_map = {}

    for a, b in links:
        if a not in port_map:
            port_map[a] = {}
        if b not in port_map:
            port_map[b] = {}

        assert(b not in port_map[a])
        assert(a not in port_map[b])
        port_map[a][b] = len(port_map[a]) + 1
        port_map[b][a] = len(port_map[b]) + 1


    G = nx.Graph()
    for a, b in links:
        G.add_edge(a, b)

    shortest_paths = nx.shortest_path(G)
    shortest_path = shortest_paths[src][dst]

    print "path is:", shortest_path

    port_list = []
    first = shortest_path[1]
    for h in shortest_path[2:]:
        port_list.append(port_map[first][h])
        first = h

    print "port list is:", port_list

    port_str = ""
    for p in port_list:
        port_str += chr(p)

    while(1):
        msg = raw_input("What do you want to send: ")

        # finding the route
        first = None

        p = SrcRoute(num_valid = len(port_list)) / port_str / msg
        print p.show()
        sendp(p, iface = "eth0")
        # print msg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号