faucet.valve_of module

Utility functions to parse/create OpenFlow messages.

faucet.valve_of.ECTP_ETH_TYPE = 36864
faucet.valve_of.MATCH_FIELDS = {'arp_op': <function str_to_int>, 'arp_sha': <function to_match_eth>, 'arp_spa': <function to_match_ip>, 'arp_tha': <function to_match_eth>, 'arp_tpa': <function to_match_ip>, 'eth_dst': <function to_match_eth>, 'eth_src': <function to_match_eth>, 'eth_type': <function str_to_int>, 'icmpv4_code': <function str_to_int>, 'icmpv4_type': <function str_to_int>, 'icmpv6_code': <function str_to_int>, 'icmpv6_type': <function str_to_int>, 'in_phy_port': <function str_to_int>, 'in_port': <bound method OFCtlUtil.ofp_port_from_user of <ryu.lib.ofctl_utils.OFCtlUtil object>>, 'ip_dscp': <function str_to_int>, 'ip_ecn': <function str_to_int>, 'ip_proto': <function str_to_int>, 'ipv4_dst': <function to_match_ip>, 'ipv4_src': <function to_match_ip>, 'ipv6_dst': <function to_match_ip>, 'ipv6_exthdr': <function to_match_masked_int>, 'ipv6_flabel': <function str_to_int>, 'ipv6_nd_sll': <function to_match_eth>, 'ipv6_nd_target': <function to_match_ip>, 'ipv6_nd_tll': <function to_match_eth>, 'ipv6_src': <function to_match_ip>, 'metadata': <function to_match_masked_int>, 'mpls_bos': <function str_to_int>, 'mpls_label': <function str_to_int>, 'mpls_tc': <function str_to_int>, 'pbb_isid': <function to_match_masked_int>, 'sctp_dst': <function to_match_masked_int>, 'sctp_src': <function to_match_masked_int>, 'tcp_dst': <function to_match_masked_int>, 'tcp_src': <function to_match_masked_int>, 'tunnel_id': <function to_match_masked_int>, 'udp_dst': <function to_match_masked_int>, 'udp_src': <function to_match_masked_int>, 'vlan_pcp': <function str_to_int>, 'vlan_vid': <function valve_match_vid>}
faucet.valve_of.MAX_PACKET_IN_BYTES = 128
faucet.valve_of.MAX_VID = 4095
faucet.valve_of.MIN_VID = 1
faucet.valve_of.OFERROR_TYPE_CODE = {0: ('OFPET_HELLO_FAILED', {0: 'OFPHFC_INCOMPATIBLE', 1: 'OFPHFC_EPERM'}), 1: ('OFPET_BAD_REQUEST', {0: 'OFPBRC_BAD_VERSION', 1: 'OFPBRC_BAD_TYPE', 2: 'OFPBRC_BAD_MULTIPART', 3: 'OFPBRC_BAD_EXPERIMENTER', 4: 'OFPBRC_BAD_EXP_TYPE', 5: 'OFPBRC_EPERM', 6: 'OFPBRC_BAD_LEN', 7: 'OFPBRC_BUFFER_EMPTY', 8: 'OFPBRC_BUFFER_UNKNOWN', 9: 'OFPBRC_BAD_TABLE_ID', 10: 'OFPBRC_IS_SLAVE', 11: 'OFPBRC_BAD_PORT', 12: 'OFPBRC_BAD_PACKET', 13: 'OFPBRC_MULTIPART_BUFFER_OVERFLOW'}), 2: ('OFPET_BAD_ACTION', {0: 'OFPBAC_BAD_TYPE', 1: 'OFPBAC_BAD_LEN', 2: 'OFPBAC_BAD_EXPERIMENTER', 3: 'OFPBAC_BAD_EXP_TYPE', 4: 'OFPBAC_BAD_OUT_PORT', 5: 'OFPBAC_BAD_ARGUMENT', 6: 'OFPBAC_EPERM', 7: 'OFPBAC_TOO_MANY', 8: 'OFPBAC_BAD_QUEUE', 9: 'OFPBAC_BAD_OUT_GROUP', 10: 'OFPBAC_MATCH_INCONSISTENT', 11: 'OFPBAC_UNSUPPORTED_ORDER', 12: 'OFPBAC_BAD_TAG', 13: 'OFPBAC_BAD_SET_TYPE', 14: 'OFPBAC_BAD_SET_LEN', 15: 'OFPBAC_BAD_SET_ARGUMENT'}), 3: ('OFPET_BAD_INSTRUCTION', {0: 'OFPBIC_UNKNOWN_INST', 1: 'OFPBIC_UNSUP_INST', 2: 'OFPBIC_BAD_TABLE_ID', 3: 'OFPBIC_UNSUP_METADATA', 4: 'OFPBIC_UNSUP_METADATA_MASK', 5: 'OFPBIC_BAD_EXPERIMENTER', 6: 'OFPBIC_BAD_EXP_TYPE', 7: 'OFPBIC_BAD_LEN', 8: 'OFPBIC_EPERM'}), 4: ('OFPET_BAD_MATCH', {0: 'OFPBMC_BAD_TYPE', 1: 'OFPBMC_BAD_LEN', 2: 'OFPBMC_BAD_TAG', 3: 'OFPBMC_BAD_DL_ADDR_MASK', 4: 'OFPBMC_BAD_NW_ADDR_MASK', 5: 'OFPBMC_BAD_WILDCARDS', 6: 'OFPBMC_BAD_FIELD', 7: 'OFPBMC_BAD_VALUE', 8: 'OFPBMC_BAD_MASK', 9: 'OFPBMC_BAD_PREREQ', 10: 'OFPBMC_DUP_FIELD', 11: 'OFPBMC_EPERM'}), 5: ('OFPET_FLOW_MOD_FAILED', {0: 'OFPFMFC_UNKNOWN', 1: 'OFPFMFC_TABLE_FULL', 2: 'OFPFMFC_BAD_TABLE_ID', 3: 'OFPFMFC_OVERLAP', 4: 'OFPFMFC_EPERM', 5: 'OFPFMFC_BAD_TIMEOUT', 6: 'OFPFMFC_BAD_COMMAND', 7: 'OFPFMFC_BAD_FLAGS'}), 6: ('OFPET_GROUP_MOD_FAILED', {0: 'OFPGMFC_GROUP_EXISTS', 1: 'OFPGMFC_INVALID_GROUP', 2: 'OFPGMFC_WEIGHT_UNSUPPORTED', 3: 'OFPGMFC_OUT_OF_GROUPS', 4: 'OFPGMFC_OUT_OF_BUCKETS', 5: 'OFPGMFC_CHAINING_UNSUPPORTED', 6: 'OFPGMFC_WATCH_UNSUPPORTED', 7: 'OFPGMFC_LOOP', 8: 'OFPGMFC_UNKNOWN_GROUP', 9: 'OFPGMFC_CHAINED_GROUP', 10: 'OFPGMFC_BAD_TYPE', 11: 'OFPGMFC_BAD_COMMAND', 12: 'OFPGMFC_BAD_BUCKET', 13: 'OFPGMFC_BAD_WATCH', 14: 'OFPGMFC_EPERM'}), 7: ('OFPET_PORT_MOD_FAILED', {0: 'OFPPMFC_BAD_PORT', 1: 'OFPPMFC_BAD_HW_ADDR', 2: 'OFPPMFC_BAD_CONFIG', 3: 'OFPPMFC_BAD_ADVERTISE', 4: 'OFPPMFC_EPERM'}), 8: ('OFPET_TABLE_MOD_FAILED', {0: 'OFPTMFC_BAD_TABLE', 1: 'OFPTMFC_BAD_CONFIG', 2: 'OFPTMFC_EPERM'}), 9: ('OFPET_QUEUE_OP_FAILED', {0: 'OFPQOFC_BAD_PORT', 1: 'OFPQOFC_BAD_QUEUE', 2: 'OFPQOFC_EPERM'}), 10: ('OFPET_SWITCH_CONFIG_FAILED', {0: 'OFPSCFC_BAD_FLAGS', 1: 'OFPSCFC_BAD_LEN', 2: 'OFPSCFC_EPERM'}), 11: ('OFPET_ROLE_REQUEST_FAILED', {0: 'OFPRRFC_STALE', 1: 'OFPRRFC_UNSUP', 2: 'OFPRRFC_BAD_ROLE'}), 12: ('OFPET_METER_MOD_FAILED', {0: 'OFPMMFC_UNKNOWN', 1: 'OFPMMFC_METER_EXISTS', 2: 'OFPMMFC_INVALID_METER', 3: 'OFPMMFC_UNKNOWN_METER', 4: 'OFPMMFC_BAD_COMMAND', 5: 'OFPMMFC_BAD_FLAGS', 6: 'OFPMMFC_BAD_RATE', 7: 'OFPMMFC_BAD_BURST', 8: 'OFPMMFC_BAD_BAND', 9: 'OFPMMFC_BAD_BAND_VALUE', 10: 'OFPMMFC_OUT_OF_METERS', 11: 'OFPMMFC_OUT_OF_BANDS'}), 13: ('OFPET_TABLE_FEATURES_FAILED', {0: 'OFPTFFC_BAD_TABLE', 1: 'OFPTFFC_BAD_METADATA', 2: 'OFPTFFC_BAD_TYPE', 3: 'OFPTFFC_BAD_LEN', 4: 'OFPTFFC_BAD_ARGUMENT', 5: 'OFPTFFC_EPERM'}), 65535: ('OFPET_EXPERIMENTER', {})}
faucet.valve_of.OFP_IN_PORT = 4294967288
faucet.valve_of.OFP_VERSIONS = [4]
faucet.valve_of.ROUTE_GROUP_OFFSET = 8192
faucet.valve_of.VLAN_GROUP_OFFSET = 4096
faucet.valve_of.apply_actions(actions)[source]

Return instruction that applies action list.

Parameters

actions (list) – list of OpenFlow actions.

Returns

instruction of actions.

Return type

ryu.ofproto.ofproto_v1_3_parser.OFPInstruction

faucet.valve_of.apply_meter(meter_id)[source]

Return instruction to apply a meter.

faucet.valve_of.barrier()[source]

Return OpenFlow barrier request.

Returns

barrier request.

Return type

ryu.ofproto.ofproto_v1_3_parser.OFPBarrierRequest

faucet.valve_of.bucket(weight=0, watch_port=4294967295, watch_group=4294967295, actions=None)[source]

Return a group action bucket with provided actions.

faucet.valve_of.build_group_flood_buckets(vlan_flood_acts)[source]

Return a list of group buckets to implement flooding on a VLAN.

faucet.valve_of.build_match_dict(in_port=None, vlan=None, eth_type=None, eth_src=None, eth_dst=None, eth_dst_mask=None, icmpv6_type=None, nw_proto=None, nw_dst=None, metadata=None, metadata_mask=None, vlan_pcp=None)[source]
faucet.valve_of.controller_pps_meteradd(datapath=None, pps=0)[source]

Add a PPS meter towards controller.

faucet.valve_of.controller_pps_meterdel(datapath=None)[source]

Delete a PPS meter towards controller.

faucet.valve_of.dec_ip_ttl()[source]

Return OpenFlow action to decrement IP TTL.

Returns

decrement IP TTL.

Return type

ryu.ofproto.ofproto_v1_3_parser.OFPActionDecNwTtl

faucet.valve_of.dedupe_ofmsgs(input_ofmsgs)[source]

Return deduplicated ofmsg list.

faucet.valve_of.dedupe_output_port_acts(output_port_acts)[source]

Deduplicate parser.OFPActionOutputs (because Ryu doesn’t define __eq__).

Parameters

of ryu.ofproto.ofproto_v1_3_parser.OFPActionOutput (list) – output to port actions.

Returns

output to port actions.

Return type

list of ryu.ofproto.ofproto_v1_3_parser.OFPActionOutput

faucet.valve_of.desc_stats_request(datapath=None)[source]

Query switch description.

faucet.valve_of.devid_present(vid)[source]

Return VLAN VID without VID_PRESENT flag set.

Parameters

vid (int) – VLAN VID with VID_PRESENT.

Returns

VLAN VID.

Return type

int

faucet.valve_of.faucet_async(datapath=None, notify_flow_removed=False, packet_in=True, port_status=True)[source]

Return async message config for FAUCET/Gauge

faucet.valve_of.faucet_config(datapath=None)[source]

Return switch config for FAUCET.

faucet.valve_of.flood_port_outputs(tagged_ports, untagged_ports, in_port=None, exclude_ports=None)[source]

Return actions for both tagged and untagged ports.

faucet.valve_of.flood_tagged_port_outputs(ports, in_port=None, exclude_ports=None)[source]

Return list of actions necessary to flood to list of tagged ports.

faucet.valve_of.flood_untagged_port_outputs(ports, in_port=None, exclude_ports=None)[source]

Return list of actions necessary to flood to list of untagged ports.

faucet.valve_of.flowmod(cookie, command, table_id, priority, out_port, out_group, match_fields, inst, hard_timeout, idle_timeout, flags=0)[source]
faucet.valve_of.goto_table(table)[source]

Return instruction to goto table.

Parameters

table (ValveTable) – table to goto.

Returns

goto instruction.

Return type

ryu.ofproto.ofproto_v1_3_parser.OFPInstruction

faucet.valve_of.group_act(group_id)[source]

Return an action to run a group.

faucet.valve_of.groupadd(datapath=None, type_=0, group_id=0, buckets=None)[source]

Add a group.

faucet.valve_of.groupadd_ff(datapath=None, group_id=0, buckets=None)[source]

Add a fast failover group.

faucet.valve_of.groupdel(datapath=None, group_id=4294967292)[source]

Delete a group (default all groups).

faucet.valve_of.groupmod(datapath=None, type_=0, group_id=0, buckets=None)[source]

Modify a group.

faucet.valve_of.groupmod_ff(datapath=None, group_id=0, buckets=None)[source]

Modify a fast failover group.

faucet.valve_of.ignore_port(port_num)[source]

Return True if FAUCET should ignore this port.

Parameters

port_num (int) – switch port.

Returns

True if FAUCET should ignore this port.

Return type

bool

faucet.valve_of.is_apply_actions(instruction)[source]

Return True if an apply action.

Parameters

instruction – OpenFlow instruction.

Returns

True if an apply action.

Return type

bool

faucet.valve_of.is_delete(ofmsg)[source]
faucet.valve_of.is_flowdel(ofmsg)[source]

Return True if flow message is a FlowMod and a delete.

Parameters

ofmsg – ryu.ofproto.ofproto_v1_3_parser message.

Returns

True if is a FlowMod delete/strict.

Return type

bool

faucet.valve_of.is_flowmod(ofmsg)[source]

Return True if flow message is a FlowMod.

Parameters

ofmsg – ryu.ofproto.ofproto_v1_3_parser message.

Returns

True if is a FlowMod

Return type

bool

faucet.valve_of.is_groupadd(ofmsg)[source]

Return True if OF message is a GroupMod and command is add.

Parameters

ofmsg – ryu.ofproto.ofproto_v1_3_parser message.

Returns

True if is a GroupMod add

Return type

bool

faucet.valve_of.is_groupdel(ofmsg)[source]

Return True if OF message is a GroupMod and command is delete.

Parameters

ofmsg – ryu.ofproto.ofproto_v1_3_parser message.

Returns

True if is a GroupMod delete

Return type

bool

faucet.valve_of.is_groupmod(ofmsg)[source]

Return True if OF message is a GroupMod.

Parameters

ofmsg – ryu.ofproto.ofproto_v1_3_parser message.

Returns

True if is a GroupMod

Return type

bool

faucet.valve_of.is_meter(instruction)[source]

Return True if a meter.

Parameters

instruction – OpenFlow instruction.

Returns

True if a meter.

Return type

bool

faucet.valve_of.is_meteradd(ofmsg)[source]

Return True if OF message is a MeterMod and command is add.

Parameters

ofmsg – ryu.ofproto.ofproto_v1_3_parser message.

Returns

True if is a MeterMod add

Return type

bool

faucet.valve_of.is_meterdel(ofmsg)[source]

Return True if OF message is a MeterMod and command is delete.

Parameters

ofmsg – ryu.ofproto.ofproto_v1_3_parser message.

Returns

True if is a MeterMod delete

Return type

bool

faucet.valve_of.is_metermod(ofmsg)[source]

Return True if OF message is a MeterMod.

Parameters

ofmsg – ryu.ofproto.ofproto_v1_3_parser message.

Returns

True if is a MeterMod

Return type

bool

faucet.valve_of.is_output(ofmsg)[source]

Return True if flow message is an action output message.

Parameters

ofmsg – ryu.ofproto.ofproto_v1_3_parser message.

Returns

True if is a OFPActionOutput.

Return type

bool

faucet.valve_of.is_packetout(ofmsg)[source]

Return True if OF message is a PacketOut

Parameters

ofmsg – ryu.ofproto.ofproto_v1_3_parser message.

Returns

True if is a PacketOut

Return type

bool

faucet.valve_of.is_set_field(action)[source]
faucet.valve_of.is_table_features_req(ofmsg)[source]

Return True if flow message is a TFM req.

Parameters

ofmsg – ryu.ofproto.ofproto_v1_3_parser message.

Returns

True if is a TFM req.

Return type

bool

faucet.valve_of.match(match_fields)[source]

Return OpenFlow matches from dict.

Parameters

match_fields (dict) – match fields and values.

Returns

matches.

Return type

ryu.ofproto.ofproto_v1_3_parser.OFPMatch

faucet.valve_of.match_from_dict(match_dict)[source]
faucet.valve_of.metadata_goto_table(metadata, mask, table)[source]

Return instructions to write metadata and goto table.

Parameters
  • metadata (int) – metadata to write to packet

  • maks (int) – mask to apply to metadata

  • table (ValveTable) – table to goto.

Returns

list of OFPInstructions

faucet.valve_of.meteradd(meter_conf)[source]

Add a meter based on YAML configuration.

faucet.valve_of.meterdel(datapath=None, meter_id=4294967295)[source]

Delete a meter (default all meters).

faucet.valve_of.output_controller(max_len=128)[source]

Return OpenFlow action to packet in to the controller.

Parameters

max_len (int) – max number of bytes from packet to output.

Returns

packet in action.

Return type

ryu.ofproto.ofproto_v1_3_parser.OFPActionOutput

faucet.valve_of.output_in_port()[source]

Return OpenFlow action to output out input port.

Returns

ryu.ofproto.ofproto_v1_3_parser.OFPActionOutput.

faucet.valve_of.output_port(port_num, max_len=0)[source]

Return OpenFlow action to output to a port.

Parameters
  • port_num (int) – port to output to.

  • max_len (int) – maximum length of packet to output (default no maximum).

Returns

output to port action.

Return type

ryu.ofproto.ofproto_v1_3_parser.OFPActionOutput

faucet.valve_of.packetout(port_num, data)[source]

Return OpenFlow action to packet out to dataplane from controller.

Parameters
  • port_num (int) – port to output to.

  • data (str) – raw packet to output.

Returns

packet out action.

Return type

ryu.ofproto.ofproto_v1_3_parser.OFPActionOutput

faucet.valve_of.packetouts(port_nums, data)[source]

Return OpenFlow action to mulltiply packet out to dataplane from controller.

Parameters
  • port_num (list) – ints, ports to output to.

  • data (str) – raw packet to output.

Returns

packet out action.

Return type

ryu.ofproto.ofproto_v1_3_parser.OFPActionOutput

faucet.valve_of.pop_vlan()[source]

Return OpenFlow action to pop outermost Ethernet 802.1Q VLAN header.

Returns

Pop VLAN.

Return type

ryu.ofproto.ofproto_v1_3_parser.OFPActionPopVlan

faucet.valve_of.port_status_from_state(state)[source]

Return True if OFPPS_LINK_DOWN is not set.

faucet.valve_of.push_vlan_act(table, vlan_vid, eth_type=33024)[source]

Return OpenFlow action list to push Ethernet 802.1Q header with VLAN VID.

Parameters

vid (int) – VLAN VID

Returns

actions to push 802.1Q header with VLAN VID set.

Return type

list

faucet.valve_of.set_field(**kwds)[source]

Return action to set any field.

Parameters

kwds (dict) – exactly one field to set

Returns

set field action.

Return type

ryu.ofproto.ofproto_v1_3_parser.OFPActionSetField

faucet.valve_of.table_features(body)[source]
faucet.valve_of.valve_flowreorder(input_ofmsgs, use_barriers=True)[source]

Reorder flows for better OFA performance.

faucet.valve_of.valve_match_vid(value)[source]
faucet.valve_of.vid_present(vid)[source]

Return VLAN VID with VID_PRESENT flag set.

Parameters

vid (int) – VLAN VID

Returns

VLAN VID with VID_PRESENT.

Return type

int