示例#1
0
def mk_simple_flow_mod(match_fields,
                       actions,
                       command=ofp.OFPFC_ADD,
                       next_table_id=None,
                       meter_id=None,
                       metadata=None,
                       **kw):
    """
    Convenience function to generare ofp_flow_mod message with OXM BASIC match
    composed from the match_fields, and single APPLY_ACTIONS instruction with
    a list if ofp_action objects.
    :param match_fields: list(ofp_oxm_ofb_field)
    :param actions: list(ofp_action)
    :param command: one of OFPFC_*
    :param kw: additional keyword-based params to ofp_flow_mod
    :return: initialized ofp_flow_mod object
    """
    instructions = [
        ofp.ofp_instruction(
            type=ofp.OFPIT_APPLY_ACTIONS,
            actions=ofp.ofp_instruction_actions(actions=actions))
    ]

    if meter_id is not None:
        instructions.append(
            ofp.ofp_instruction(
                type=ofp.OFPIT_METER,
                meter=ofp.ofp_instruction_meter(meter_id=meter_id)))

    if next_table_id is not None:
        instructions.append(
            ofp.ofp_instruction(type=ofp.OFPIT_GOTO_TABLE,
                                goto_table=ofp.ofp_instruction_goto_table(
                                    table_id=next_table_id)))

    if metadata is not None:
        instructions.append(
            ofp.ofp_instruction(
                type=ofp.OFPIT_WRITE_METADATA,
                write_metadata=ofp.ofp_instruction_write_metadata(
                    metadata=metadata)))

    return ofp.ofp_flow_mod(
        command=command,
        match=ofp.ofp_match(type=ofp.OFPMT_OXM,
                            oxm_fields=[
                                ofp.ofp_oxm_field(
                                    oxm_class=ofp.OFPXMC_OPENFLOW_BASIC,
                                    ofb_field=field) for field in match_fields
                            ]),
        instructions=instructions,
        **kw)
def mk_simple_flow_mod(match_fields, actions, command=ofp.OFPFC_ADD,
                       next_table_id=None, **kw):
    """
    Convenience function to generare ofp_flow_mod message with OXM BASIC match
    composed from the match_fields, and single APPLY_ACTIONS instruction with
    a list if ofp_action objects.
    :param match_fields: list(ofp_oxm_ofb_field)
    :param actions: list(ofp_action)
    :param command: one of OFPFC_*
    :param kw: additional keyword-based params to ofp_flow_mod
    :return: initialized ofp_flow_mod object
    """
    instructions = [
        ofp.ofp_instruction(
            type=ofp.OFPIT_APPLY_ACTIONS,
            actions=ofp.ofp_instruction_actions(actions=actions)
        )
    ]
    if next_table_id is not None:
        instructions.append(ofp.ofp_instruction(
            type=ofp.OFPIT_GOTO_TABLE,
            goto_table=ofp.ofp_instruction_goto_table(table_id=next_table_id)
        ))

    return ofp.ofp_flow_mod(
        command=command,
        match=ofp.ofp_match(
            type=ofp.OFPMT_OXM,
            oxm_fields=[
                ofp.ofp_oxm_field(
                    oxm_class=ofp.OFPXMC_OPENFLOW_BASIC,
                    ofb_field=field
                ) for field in match_fields
            ]
        ),
        instructions=instructions,
        **kw
    )