faucet.valve_packet module

Utility functions for parsing and building Ethernet packet/contents.

class faucet.valve_packet.PacketMeta(data, orig_len, pkt, eth_pkt, port, valve_vlan, eth_src, eth_dst, eth_type)[source]

Bases: object

Original, and parsed Ethernet packet metadata.

ETH_TYPES_PARSERS = {2048: (4, <function ipv4_parseable at 0x7f52e337e1e0>, <class 'ryu.lib.packet.ipv4.ipv4'>), 2054: (None, None, <class 'ryu.lib.packet.arp.arp'>), 34525: (6, None, <class 'ryu.lib.packet.ipv6.ipv6'>)}
MIN_ETH_TYPE_PKT_SIZE = {2048: 38, 2054: 46, 34525: 58}
ip_ver()[source]

Return IP version number.

packet_complete()[source]

True if we have the complete packet.

reparse(max_len)[source]

Reparse packet using data up to the specified maximum length.

reparse_all()[source]

Reparse packet with all available data.

reparse_ip(payload=0)[source]

Reparse packet with specified IP header type and optionally payload.

faucet.valve_packet.arp_reply(vid, eth_src, eth_dst, src_ip, dst_ip)[source]

Return an ARP reply packet.

Parameters:
  • vid (int or None) – VLAN VID to use (or None).
  • eth_src (str) – Ethernet source address.
  • eth_dst (str) – destination Ethernet MAC address.
  • src_ip (ipaddress.IPv4Address) – source IPv4 address.
  • dst_ip (ipaddress.IPv4Address) – destination IPv4 address.
Returns:

serialized ARP reply packet.

Return type:

ryu.lib.packet.arp

faucet.valve_packet.arp_request(vid, eth_src, src_ip, dst_ip)[source]

Return an ARP request packet.

Parameters:
  • vid (int or None) – VLAN VID to use (or None).
  • eth_src (str) – Ethernet source address.
  • src_ip (ipaddress.IPv4Address) – source IPv4 address.
  • dst_ip (ipaddress.IPv4Address) – requested IPv4 address.
Returns:

serialized ARP request packet.

Return type:

ryu.lib.packet.arp

faucet.valve_packet.build_pkt_header(vid, eth_src, eth_dst, dl_type)[source]

Return an Ethernet packet header.

Parameters:
  • vid (int or None) – VLAN VID to use (or None).
  • eth_src (str) – source Ethernet MAC address.
  • eth_dst (str) – destination Ethernet MAC address.
  • dl_type (int) – EtherType.
Returns:

Ethernet packet with header.

Return type:

ryu.lib.packet.ethernet

faucet.valve_packet.echo_reply(vid, eth_src, eth_dst, src_ip, dst_ip, data)[source]

Return an ICMP echo reply packet.

Parameters:
  • vid (int or None) – VLAN VID to use (or None).
  • eth_src (str) – Ethernet source address.
  • eth_dst (str) – destination Ethernet MAC address.
  • src_ip (ipaddress.IPv4Address) – source IPv4 address.
  • dst_ip (ipaddress.IPv4Address) – destination IPv4 address.
Returns:

serialized ICMP echo reply packet.

Return type:

ryu.lib.packet.icmp

faucet.valve_packet.faucet_lldp_stack_state_tlvs(dp, port)[source]

Return a LLDP TLV for state of a stack port.

faucet.valve_packet.faucet_lldp_tlvs(dp)[source]

Return LLDP TLVs for a datapath.

faucet.valve_packet.faucet_oui(mac)[source]

Return first 3 bytes of MAC address (given as str).

faucet.valve_packet.icmpv6_echo_reply(vid, eth_src, eth_dst, src_ip, dst_ip, hop_limit, id_, seq, data)[source]

Return IPv6 ICMP echo reply packet.

Parameters:
  • vid (int or None) – VLAN VID to use (or None).
  • eth_src (str) – source Ethernet MAC address.
  • eth_dst (str) – destination Ethernet MAC address.
  • src_ip (ipaddress.IPv6Address) – source IPv6 address.
  • dst_ip (ipaddress.IPv6Address) – destination IPv6 address.
  • hop_limit (int) – IPv6 hop limit.
  • id_ (int) – identifier for echo reply.
  • seq (int) – sequence number for echo reply.
  • data (str) – payload for echo reply.
Returns:

Serialized IPv6 ICMP echo reply packet.

Return type:

ryu.lib.packet.ethernet

faucet.valve_packet.ipv4_parseable(ip_header_data)[source]

Return True if an IPv4 packet we could parse.

Return an Ethernet multicast address from an IPv6 address.

See RFC 2464 section 7.

Parameters:dst_ip (ipaddress.IPv6Address) – IPv6 address.
Returns:Ethernet multicast address.
Return type:str
faucet.valve_packet.ipv6_solicited_node_from_ucast(ucast)[source]

Return IPv6 solicited node multicast address from IPv6 unicast address.

See RFC 3513 section 2.7.1.

Parameters:ucast (ipaddress.IPv6Address) – IPv6 unicast address.
Returns:IPv6 solicited node multicast address.
Return type:ipaddress.IPv6Address
faucet.valve_packet.lacp_reqreply(eth_src, actor_system, actor_key, actor_port, partner_system, partner_key, partner_port, partner_system_priority, partner_port_priority, partner_state_defaulted, partner_state_expired, partner_state_timeout, partner_state_collecting, partner_state_distributing, partner_state_aggregation, partner_state_synchronization, partner_state_activity)[source]

Return a LACP frame.

Parameters:
  • eth_src (str) – source Ethernet MAC address.
  • actor_system (str) – actor system ID (MAC address)
  • actor_key (int) – actor’s LACP key assigned to this port.
  • actor_port (int) – actor port number.
  • partner_system (str) – partner system ID (MAC address)
  • partner_key (int) – partner’s LACP key assigned to this port.
  • partner_port (int) – partner port number.
  • partner_system_priority (int) – partner’s system priority.
  • partner_port_priority (int) – partner’s port priority.
  • partner_state_defaulted (int) – 1 if partner reverted to defaults.
  • partner_state_expired (int) – 1 if partner thinks LACP expired.
  • partner_state_timeout (int) – 1 if partner has short timeout.
  • partner_state_collecting (int) – 1 if partner receiving on this link.
  • partner_state_distributing (int) – 1 if partner transmitting on this link.
  • partner_state_aggregation (int) – 1 if partner can aggregate this link.
  • partner_state_synchronization (int) – 1 if partner will use this link.
  • partner_state_activity (int) – 1 if partner actively sends LACP.
Returns:

Ethernet packet with header.

Return type:

ryu.lib.packet.ethernet

faucet.valve_packet.lldp_beacon(eth_src, chassis_id, port_id, ttl, org_tlvs=None, system_name=None, port_descr=None)[source]

Return an LLDP frame suitable for a host/access port.

Parameters:
  • eth_src (str) – source Ethernet MAC address.
  • chassis_id (str) – Chassis ID.
  • port_id (int) – port ID,
  • TTL (int) – TTL for payload.
  • org_tlvs (list) – list of tuples of (OUI, subtype, info).
Returns:

Ethernet packet with header.

Return type:

ryu.lib.packet.ethernet

faucet.valve_packet.mac_addr_is_unicast(mac_addr)[source]

Returns True if mac_addr is a unicast Ethernet address.

Parameters:mac_addr (str) – MAC address.
Returns:True if a unicast Ethernet address.
Return type:bool
faucet.valve_packet.mac_byte_mask(mask_bytes=0)[source]

Return a MAC address mask with n bytes masked out.

faucet.valve_packet.nd_advert(vid, eth_src, eth_dst, src_ip, dst_ip)[source]

Return IPv6 neighbor avertisement packet.

Parameters:
  • vid (int or None) – VLAN VID to use (or None).
  • eth_src (str) – source Ethernet MAC address.
  • eth_dst (str) – destination Ethernet MAC address.
  • src_ip (ipaddress.IPv6Address) – source IPv6 address.
  • dst_ip (ipaddress.IPv6Address) – destination IPv6 address.
Returns:

Serialized IPv6 neighbor discovery packet.

Return type:

ryu.lib.packet.ethernet

faucet.valve_packet.nd_request(vid, eth_src, src_ip, dst_ip)[source]

Return IPv6 neighbor discovery request packet.

Parameters:
  • vid (int or None) – VLAN VID to use (or None).
  • eth_src (str) – source Ethernet MAC address.
  • src_ip (ipaddress.IPv6Address) – source IPv6 address.
  • dst_ip (ipaddress.IPv6Address) – requested IPv6 address.
Returns:

Serialized IPv6 neighbor discovery packet.

Return type:

ryu.lib.packet.ethernet

faucet.valve_packet.parse_eth_pkt(pkt)[source]

Return parsed Ethernet packet.

Parameters:pkt (ryu.lib.packet.packet) – packet received from dataplane.
Returns:Ethernet packet.
Return type:ryu.lib.packet.ethernet
faucet.valve_packet.parse_lacp_pkt(pkt)[source]

Return parsed LACP packet.

Parameters:pkt (ryu.lib.packet.packet) – packet received from dataplane.
Returns:LACP packet.
Return type:ryu.lib.packet.lacp
faucet.valve_packet.parse_lldp(pkt)[source]

Return parsed LLDP packet.

Parameters:pkt (ryu.lib.packet.packet) – packet received from dataplane.
Returns:LLDP packet.
Return type:ryu.lib.packet.lldp
faucet.valve_packet.parse_packet_in_pkt(data, max_len)[source]

Parse a packet received via packet in from the dataplane.

Parameters:
  • data (bytearray) – packet data from dataplane.
  • max_len (int) – max number of packet data bytes to parse.
Returns:

raw packet ryu.lib.packet.ethernet: parsed Ethernet packet. int: Ethernet type of packet (inside VLAN) int: VLAN VID (or None if no VLAN)

Return type:

ryu.lib.packet.packet

faucet.valve_packet.parse_vlan_pkt(pkt)[source]

Return parsed VLAN header.

Parameters:pkt (ryu.lib.packet.packet) – packet received from dataplane.
Returns:VLAN header.
Return type:ryu.lib.packet.vlan
faucet.valve_packet.router_advert(vid, eth_src, eth_dst, src_ip, dst_ip, vips, pi_flags=6)[source]

Return IPv6 ICMP echo reply packet.

Parameters:
  • vid (int or None) – VLAN VID to use (or None).
  • eth_src (str) – source Ethernet MAC address.
  • eth_dst (str) – dest Ethernet MAC address.
  • src_ip (ipaddress.IPv6Address) – source IPv6 address.
  • vips (list) – prefixes (ipaddress.IPv6Address) to advertise.
  • pi_flags (int) – flags to set in prefix information field (default set A and L)
Returns:

Serialized IPv6 ICMP RA packet.

Return type:

ryu.lib.packet.ethernet