def mk_oxm_fields(match_fields): oxm_fields = [ ofp.ofp_oxm_field(oxm_class=ofp.OFPXMC_OPENFLOW_BASIC, ofb_field=field) for field in match_fields ] return oxm_fields
def set_field(field): return action( type=SET_FIELD, set_field=ofp.ofp_action_set_field( field=ofp.ofp_oxm_field( oxm_class=ofp.OFPXMC_OPENFLOW_BASIC, ofb_field=field)) )
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 )
def loxi_oxm_udp_src_to_ofp_oxm(lo): return pb2.ofp_oxm_field( oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, ofb_field=pb2.ofp_oxm_ofb_field(type=pb2.OFPXMT_OFB_UDP_SRC, udp_src=lo.value))
def loxi_oxm_metadata_to_ofp_oxm(lo): return pb2.ofp_oxm_field(oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, ofb_field=pb2.ofp_oxm_ofb_field( type=pb2.OFPXMT_OFB_METADATA, table_metadata=lo.value))
def loxi_oxm_ipv4_dst_to_ofp_oxm(lo): return pb2.ofp_oxm_field(oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, ofb_field=pb2.ofp_oxm_ofb_field( type=pb2.OFPXMT_OFB_IPV4_DST, ipv4_dst=lo.value))
def loxi_oxm_vlan_pcp_to_ofp_oxm(lo): return pb2.ofp_oxm_field(oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, ofb_field=pb2.ofp_oxm_ofb_field( type=pb2.OFPXMT_OFB_VLAN_PCP, vlan_pcp=lo.value))
def loxi_oxm_ip_proto_to_ofp_oxm(lo): return pb2.ofp_oxm_field(oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, ofb_field=pb2.ofp_oxm_ofb_field( type=pb2.OFPXMT_OFB_IP_PROTO, ip_proto=lo.value))
def loxi_oxm_in_port_to_ofp_oxm(lo): return pb2.ofp_oxm_field(oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, ofb_field=pb2.ofp_oxm_ofb_field( type=pb2.OFPXMT_OFB_IN_PORT, port=lo.value))
def loxi_oxm_eth_type_to_ofp_oxm(lo): return pb2.ofp_oxm_field(oxm_class=pb2.OFPXMC_OPENFLOW_BASIC, ofb_field=pb2.ofp_oxm_ofb_field( type=pb2.OFPXMT_OFB_ETH_TYPE, eth_type=lo.value))