Ejemplo n.º 1
0
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
    )
Ejemplo n.º 2
0
def mk_instructions_from_actions(actions):
    instructions_action = ofp.ofp_instruction_actions()
    instructions_action.actions.extend(actions)
    instruction = ofp.ofp_instruction(type=ofp.OFPIT_APPLY_ACTIONS,
                                      actions=instructions_action)
    return [instruction]
Ejemplo n.º 3
0
def loxi_meter_to_ofp_instruction(lo):
    return pb2.ofp_instruction(
        type=pb2.OFPIT_METER,
        meter=pb2.ofp_instruction_meter(meter_id=lo.meter_id))
Ejemplo n.º 4
0
def loxi_write_actions_to_ofp_instruction(lo):
    return pb2.ofp_instruction(type=pb2.OFPIT_WRITE_ACTIONS,
                               actions=pb2.ofp_instruction_actions(
                                   actions=[to_grpc(a) for a in lo.actions]))
Ejemplo n.º 5
0
def loxi_write_metadata_to_ofp_instruction(lo):
    return pb2.ofp_instruction(
        type=pb2.OFPIT_WRITE_METADATA,
        write_metadata=pb2.ofp_instruction_write_metadata(
            metadata=lo.metadata, metadata_mask=lo.metadata_mask))
Ejemplo n.º 6
0
def loxi_goto_table_to_ofp_instruction(lo):
    return pb2.ofp_instruction(
        type=pb2.OFPIT_GOTO_TABLE,
        goto_table=pb2.ofp_instruction_goto_table(table_id=lo.table_id))
Ejemplo n.º 7
0
def loxi_clear_actions_to_ofp_instruction(lo):
    return pb2.ofp_instruction(type=pb2.OFPIT_CLEAR_ACTIONS)
Ejemplo n.º 8
0
def loxi_apply_actions_to_ofp_instruction(lo):
    return pb2.ofp_instruction(type=pb2.OFPIT_APPLY_ACTIONS,
                               actions=pb2.ofp_instruction_actions(
                                   actions=[to_grpc(a) for a in lo.actions]))