device_graph.py 文件源码

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

项目:voltha 作者: opencord 项目源码 文件源码
def _build_routes(self, boundary_ports, graph, logical_ports):

        root_ports = dict((lp.ofp_port.port_no, lp.root_port)
                          for lp in logical_ports if lp.root_port == True)

        routes = {}

        for source, source_port_no in boundary_ports.iteritems():
            for target, target_port_no in boundary_ports.iteritems():

                if source is target:
                    continue

                # Ignore NNI - NNI routes
                if source_port_no in root_ports \
                        and target_port_no in root_ports:
                    continue

                # Ignore UNI - UNI routes
                if source_port_no not in root_ports \
                        and target_port_no not in root_ports:
                    continue

                path = nx.shortest_path(graph, source, target)

                # number of nodes in valid paths is always multiple of 3
                if len(path) % 3:
                    continue

                # in fact, we currently deal with single fan-out networks,
                # so the number of hops is always 6
                assert len(path) == 6

                ingress_input_port, ingress_device, ingress_output_port, \
                egress_input_port, egress_device, egress_output_port = path

                ingress_hop = RouteHop(
                    device=graph.node[ingress_device]['device'],
                    ingress_port=graph.node[ingress_input_port]['port'],
                    egress_port=graph.node[ingress_output_port]['port']
                )
                egress_hop = RouteHop(
                    device=graph.node[egress_device]['device'],
                    ingress_port=graph.node[egress_input_port]['port'],
                    egress_port=graph.node[egress_output_port]['port']
                )

                routes[(source_port_no, target_port_no)] = [
                    ingress_hop, egress_hop
                ]

        return routes
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号