Exemplo n.º 1
0
def get_rules(src_switch, src_port, src_vlan, dst_switch, dst_port, dst_vlan,
              bandwidth, transit_vlan, flowid, cookie, flowpath, meter_id,
              output_action, **k):

    # TODO: Rule creation should migrate closer to path creation .. to do as part of TE / Storm refactor
    # e.g. assuming a refactor of TE into Storm, and possibly more directly attached to the right storm topology
    #       vs a separate topology, then this logic should be closer to path creation
    # TODO: We should leverage the sequence number to ensure we install / remove flows in the right order
    #       e.g. for install, go from the end to beginning; for remove, go in opposite direction.
    nodes = flowpath.get("path")
    if not nodes:
        return []

    flows = []

    flows.append(message_utils.build_ingress_flow(
        nodes, src_switch, src_port, src_vlan, bandwidth,
        transit_vlan, flowid, output_action, cookie, meter_id))

    flows.extend(message_utils.build_intermediate_flows(
        _['switch_id'], _['port_no'], __['port_no'], transit_vlan, flowid,
        cookie) for _, __ in zip(nodes[1:-1], nodes[2:]))

    flows.append(message_utils.build_egress_flow(
        nodes, dst_switch, dst_port, dst_vlan,
        transit_vlan, flowid, output_action, cookie))

    return flows
Exemplo n.º 2
0
def get_rules(src_switch, src_port, src_vlan, dst_switch, dst_port, dst_vlan,
              bandwidth, transit_vlan, flow_id, cookie, flow_path, meter_id,
              output_action):
    nodes = flow_path.get("path")
    flows = []

    if nodes:
        flows.append(
            message_utils.build_ingress_flow(nodes, src_switch, src_port,
                                             src_vlan, bandwidth, transit_vlan,
                                             flow_id, output_action, cookie,
                                             meter_id))

        transit_flow_count = (len(nodes) - 2) / 2
        i = 1
        while i <= transit_flow_count:
            flows.append(
                message_utils.build_intermediate_flows(nodes[i]['switch_id'],
                                                       nodes[i]['port_no'],
                                                       nodes[i + 1]['port_no'],
                                                       transit_vlan, flow_id,
                                                       cookie))
            i += 2

        flows.append(
            message_utils.build_egress_flow(nodes, dst_switch, dst_port,
                                            dst_vlan, transit_vlan, flow_id,
                                            output_action, cookie))

    return flows
Exemplo n.º 3
0
def get_rules(src_switch, src_port, src_vlan, dst_switch, dst_port, dst_vlan,
              bandwidth, transit_vlan, flowid, cookie, flowpath, meter_id,
              output_action, **k):
    nodes = flowpath.get("path")
    if not nodes:
        return []

    flows = []

    flows.append(
        message_utils.build_ingress_flow(nodes, src_switch, src_port, src_vlan,
                                         bandwidth, transit_vlan, flowid,
                                         output_action, cookie, meter_id))

    flows.extend(
        message_utils.build_intermediate_flows(
            _['switch_id'], _['port_no'], __['port_no'], transit_vlan, flowid,
            cookie) for _, __ in zip(nodes[1:-1], nodes[2:]))

    flows.append(
        message_utils.build_egress_flow(nodes, dst_switch, dst_port, dst_vlan,
                                        transit_vlan, flowid, output_action,
                                        cookie))

    return flows
Exemplo n.º 4
0
def get_rules(src_switch, src_port, src_vlan, dst_switch, dst_port, dst_vlan,
              bandwidth, transit_vlan, flowid, cookie, flowpath, meter_id,
              output_action, **k):

    # TODO: Rule creation should migrate closer to path creation .. to do as part of TE / Storm refactor
    # e.g. assuming a refactor of TE into Storm, and possibly more directly attached to the right storm topology
    #       vs a separate topology, then this logic should be closer to path creation
    # TODO: We should leverage the sequence number to ensure we install / remove flows in the right order
    #       e.g. for install, go from the end to beginning; for remove, go in opposite direction.
    nodes = flowpath.get("path")
    if not nodes:
        return []

    flows = []

    flows.append(
        message_utils.build_ingress_flow(nodes, src_switch, src_port, src_vlan,
                                         bandwidth, transit_vlan, flowid,
                                         output_action, cookie, meter_id))

    for i in range(1, len(nodes) - 1, 2):
        src = nodes[i]
        dst = nodes[i + 1]

        if src['switch_id'] != dst['switch_id']:
            msg = 'Found non-paired node in the flowpath: {}'.format(flowpath)
            logger.error(msg)
            raise ValueError(msg)

        segment_cookie = src.get('cookie', cookie)

        flows.append(
            message_utils.build_intermediate_flows(src['switch_id'],
                                                   src['port_no'],
                                                   dst['port_no'],
                                                   transit_vlan, flowid,
                                                   segment_cookie))

    # Egress flow has cookie of the last segment.
    egress_flow_cookie = cookie
    if nodes:
        egress_flow_cookie = nodes[-1].get('cookie', cookie)

    flows.append(
        message_utils.build_egress_flow(nodes, dst_switch, dst_port, dst_vlan,
                                        transit_vlan, flowid, output_action,
                                        egress_flow_cookie))

    return flows