Esempio 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
    )
Esempio 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]
Esempio 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))
Esempio 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]))
Esempio 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))
Esempio 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))
Esempio n. 7
0
def loxi_clear_actions_to_ofp_instruction(lo):
    return pb2.ofp_instruction(type=pb2.OFPIT_CLEAR_ACTIONS)
Esempio 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]))