faucet.valve_packet module

Utility functions for parsing and building Ethernet packet/contents.

faucet.valve_packet.ARP_PKT_SIZE = 46
faucet.valve_packet.ARP_REQ_PKT_SIZE = 28
faucet.valve_packet.BRIDGE_GROUP_ADDRESS = '01:80:c2:00:00:00'
faucet.valve_packet.BRIDGE_GROUP_MASK = 'ff:ff:ff:ff:ff:f0'
faucet.valve_packet.CISCO_CDP_VTP_UDLD_ADDRESS = '01:00:0c:cc:cc:cc'
faucet.valve_packet.CISCO_SPANNING_GROUP_ADDRESS = '01:00:0c:cc:cc:cd'
faucet.valve_packet.EAPOL_ETH_DST = '01:80:c2:00:00:03'
faucet.valve_packet.ETH_EAPOL = 34958
faucet.valve_packet.ETH_HEADER_SIZE = 14
faucet.valve_packet.ETH_VLAN_HEADER_SIZE = 18
faucet.valve_packet.EUI_BITS = 48
faucet.valve_packet.FAUCET_MAC = '0e:00:00:00:00:01'
faucet.valve_packet.ICMP_ECHO_REQ_SIZE = 72
faucet.valve_packet.IPV4_HEADER_SIZE = 20
faucet.valve_packet.IPV6_ALL_NODES = IPv6Address('ff02::1')
faucet.valve_packet.IPV6_ALL_NODES_MCAST = '33:33:00:00:00:01'
faucet.valve_packet.IPV6_ALL_ROUTERS_MCAST = '33:33:00:00:00:02'
faucet.valve_packet.IPV6_HEADER_SIZE = 40
faucet.valve_packet.IPV6_MAX_HOP_LIM = 255
faucet.valve_packet.IPV6_RA_HOP_LIM = 64
faucet.valve_packet.LACP_SIZE = 124
faucet.valve_packet.LLDP_FAUCET_DP_ID = 1
faucet.valve_packet.LLDP_FAUCET_STACK_STATE = 2
faucet.valve_packet.LLDP_MAC_NEAREST_BRIDGE = '01:80:c2:00:00:0e'
faucet.valve_packet.MAC_MASK_BITMAP = {0: 0, 140737488355328: 1, 211106232532992: 2, 246290604621824: 3, 263882790666240: 4, 272678883688448: 5, 277076930199552: 6, 279275953455104: 7, 280375465082880: 8, 280925220896768: 9, 281200098803712: 10, 281337537757184: 11, 281406257233920: 12, 281440616972288: 13, 281457796841472: 14, 281466386776064: 15, 281470681743360: 16, 281472829227008: 17, 281473902968832: 18, 281474439839744: 19, 281474708275200: 20, 281474842492928: 21, 281474909601792: 22, 281474943156224: 23, 281474959933440: 24, 281474968322048: 25, 281474972516352: 26, 281474974613504: 27, 281474975662080: 28, 281474976186368: 29, 281474976448512: 30, 281474976579584: 31, 281474976645120: 32, 281474976677888: 33, 281474976694272: 34, 281474976702464: 35, 281474976706560: 36, 281474976708608: 37, 281474976709632: 38, 281474976710144: 39, 281474976710400: 40, 281474976710528: 41, 281474976710592: 42, 281474976710624: 43, 281474976710640: 44, 281474976710648: 45, 281474976710652: 46, 281474976710654: 47, 281474976710655: 48}
class faucet.valve_packet.PacketMeta(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, <function ipv4_parseable>, <class 'ryu.lib.packet.ipv4.ipv4'>), 2054: (None, None, <class 'ryu.lib.packet.arp.arp'>), 34525: (6, None, <class 'ryu.lib.packet.ipv6.ipv6'>)}
MAX_ETH_TYPE_PKT_SIZE = {2048: 110, 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_pkt
l3_src
log()[source]
orig_len
packet_complete()[source]

True if we have the complete packet.

pkt
port
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.SLOW_PROTOCOL_MULTICAST = '01:80:c2:00:00:02'
faucet.valve_packet.VLAN_ARP_PKT_SIZE = 64
faucet.valve_packet.VLAN_ARP_REQ_PKT_SIZE = 46
faucet.valve_packet.VLAN_ICMP_ECHO_REQ_SIZE = 110
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.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_reqreply(eth_src, actor_system, actor_key, actor_port, actor_state_synchronization=0, actor_state_activity=0, 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.

  • 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.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.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.