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>, <class 'ryu.lib.packet.ipv4.ipv4'>), 34525: (6, None, <class 'ryu.lib.packet.ipv6.ipv6'>), 2054: (None, None, <class 'ryu.lib.packet.arp.arp'>)}¶
-
-
faucet.valve_packet.
arp_reply
(vid, eth_src, eth_dst, src_ip, dst_ip)[source]¶ Return an ARP reply packet.
- Args:
- 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:
- ryu.lib.packet.arp: serialized ARP reply packet.
-
faucet.valve_packet.
arp_request
(vid, eth_src, src_ip, dst_ip)[source]¶ Return an ARP request packet.
- Args:
- 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:
- ryu.lib.packet.arp: serialized ARP request packet.
-
faucet.valve_packet.
build_pkt_header
(vid, eth_src, eth_dst, dl_type)[source]¶ Return an Ethernet packet header.
- Args:
- 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:
- ryu.lib.packet.ethernet: Ethernet packet with header.
-
faucet.valve_packet.
echo_reply
(vid, eth_src, eth_dst, src_ip, dst_ip, data)[source]¶ Return an ICMP echo reply packet.
- Args:
- 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:
- ryu.lib.packet.icmp: serialized ICMP echo reply packet.
-
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.
- Args:
- 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:
- ryu.lib.packet.ethernet: Serialized IPv6 ICMP echo reply packet.
-
faucet.valve_packet.
ip_header_size
(eth_type)[source]¶ Return size of a packet header with specified ether type.
-
faucet.valve_packet.
ipv4_parseable
(ip_header_data)[source]¶ Return True if an IPv4 packet we could parse.
-
faucet.valve_packet.
ipv6_link_eth_mcast
(dst_ip)[source]¶ Return an Ethernet multicast address from an IPv6 address.
See RFC 2464 section 7.
- Args:
- dst_ip (ipaddress.IPv6Address): IPv6 address.
- Returns:
- str: Ethernet multicast address.
-
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.
- Args:
- ucast (ipaddress.IPv6Address): IPv6 unicast address.
- Returns:
- ipaddress.IPv6Address: IPv6 solicited node multicast address.
-
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.
- Args:
- 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:
- ryu.lib.packet.ethernet: Ethernet packet with header.
-
faucet.valve_packet.
mac_addr_is_unicast
(mac_addr)[source]¶ Returns True if mac_addr is a unicast Ethernet address.
- Args:
- mac_addr (str): MAC address.
- Returns:
- bool: True if a unicast Ethernet address.
-
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.
- Args:
- 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:
- ryu.lib.packet.ethernet: Serialized IPv6 neighbor discovery packet.
-
faucet.valve_packet.
nd_request
(vid, eth_src, src_ip, dst_ip)[source]¶ Return IPv6 neighbor discovery request packet.
- Args:
- 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:
- ryu.lib.packet.ethernet: Serialized IPv6 neighbor discovery packet.
-
faucet.valve_packet.
parse_eth_pkt
(pkt)[source]¶ Return parsed Ethernet packet.
- Args:
- pkt (ryu.lib.packet.packet): packet received from dataplane.
- Returns:
- ryu.lib.packet.ethernet: Ethernet packet.
-
faucet.valve_packet.
parse_lacp_pkt
(pkt)[source]¶ Return parsed LACP packet.
- Args:
- pkt (ryu.lib.packet.packet): packet received from dataplane.
- Returns:
- ryu.lib.packet.lacp: LACP packet.
-
faucet.valve_packet.
parse_packet_in_pkt
(data, max_len)[source]¶ Parse a packet received via packet in from the dataplane.
- Args:
- data (bytearray): packet data from dataplane. max_len (int): max number of packet data bytes to parse.
- Returns:
- ryu.lib.packet.ethernet: Ethernet packet. int: VLAN VID. int: Ethernet type of packet (inside VLAN)
-
faucet.valve_packet.
parse_vlan_pkt
(pkt)[source]¶ Return parsed VLAN header.
- Args:
- pkt (ryu.lib.packet.packet): packet received from dataplane.
- Returns:
- ryu.lib.packet.vlan: VLAN header.
-
faucet.valve_packet.
router_advert
(_vlan, vid, eth_src, eth_dst, src_ip, dst_ip, vips, pi_flags=6)[source]¶ Return IPv6 ICMP echo reply packet.
- Args:
- _vlan (VLAN): VLAN instance. 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:
- ryu.lib.packet.ethernet: Serialized IPv6 ICMP RA packet.