faucet.valve_packet module

Utility functions for parsing and building Ethernet packet/contents.

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

Bases: object

Original, and parsed Ethernet packet metadata.

ETH_TYPES_PARSERS = {2048: (4, <functools._lru_cache_wrapper object>, <class 'os_ken.lib.packet.ipv4.ipv4'>), 2054: (None, None, <class 'os_ken.lib.packet.arp.arp'>), 34525: (6, None, <class 'os_ken.lib.packet.ipv6.ipv6'>)}
MAX_ETH_TYPE_PKT_SIZE = {2048: 174, 2054: 64}
MIN_ETH_TYPE_PKT_SIZE = {2048: 38, 2054: 46, 34525: 58}
data
eth_dst
eth_pkt
eth_src
eth_type
ip_ver()[source]

Return IP version number.

l3_dst
l3_offset()[source]

Return offset to where layer 3 header (IPv4/IPv6) starts

l3_pkt
l3_src
log()[source]
orig_len
packet_complete()[source]

True if we have the complete packet.

pkt
port
reason
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.

vlan
vlan_pkt
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, eth_dst, 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.

  • eth_dst (str) – Ethernet destination 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.faucet_tlvs(lldp_pkt, faucet_dp_mac)[source]

Return list of TLVs with FAUCET OUI.

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.icmpv6_time_exceeded(vid, eth_src, eth_dst, src_ip, dst_ip, data)[source]

Return IPv6 ICMP hop limit exceeded 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.

  • data (bytes) – payload for reply.

Returns:

Serialized IPv6 ICMP time-to-live exceeded packet.

Return type:

ryu.lib.packet.ethernet

faucet.valve_packet.int_from_mac(mac)[source]
faucet.valve_packet.int_in_mac(mac, to_int)[source]
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_actor_up(lacp_pkt)[source]

Return 1 if remote LACP link is up.

faucet.valve_packet.lacp_reqreply(eth_src, actor_system, actor_key, actor_port, actor_port_priority=0, actor_state_synchronization=0, actor_state_activity=0, actor_state_collecting=1, actor_state_distributing=1, partner_system='00:00:00:00:00:00', partner_key=0, partner_port=0, partner_system_priority=0, partner_port_priority=0, partner_state_defaulted=0, partner_state_expired=0, partner_state_timeout=0, partner_state_collecting=0, partner_state_distributing=0, partner_state_aggregation=0, partner_state_synchronization=0, partner_state_activity=0)[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.

  • actor_state_synchronization (int) – 1 if we will use this link.

  • actor_state_activity (int) – 1 if actively sending LACP.

  • actor_state_collecting (int) – 1 if receiving on this link.

  • actor_state_distibuting (int) – 1 if transmitting on this link.

  • 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_all_zeros(mac_addr)[source]

Returns True if mac_addr is all zeros.

Parameters:

mac_addr (str) – MAC address.

Returns:

True if all zeros.

Return type:

bool

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.mac_mask_bits(mac_mask)[source]

Return number of bits in MAC mask or 0.

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, eth_dst, 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.

  • eth_dst (str) – Ethernet destination 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_faucet_lldp(lldp_pkt, faucet_dp_mac)[source]

Parse and return FAUCET TLVs from LLDP packet.

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, eth_pkt=None, vlan_pkt=None)[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.router_advert(vid, eth_src, eth_dst, src_ip, dst_ip, vips, pi_flags=6)[source]

Return IPv6 ICMP Router Advert.

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

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

Return an ICMP time-to-live exceeded 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.

  • data (bytes) – payload for reply.

Returns:

serialized ICMP time-to-live exceeded packet.

Return type:

ryu.lib.packet.icmp

faucet.valve_packet.tlv_cast(tlvs, tlv_attr, cast_func)[source]

Return cast’d attribute of first TLV or None.

faucet.valve_packet.tlvs_by_subtype(tlvs, subtype)[source]

Return list of TLVs with matching type.

faucet.valve_packet.tlvs_by_type(tlvs, tlv_type)[source]

Return list of TLVs with matching type.