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.
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.
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.
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.
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.
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_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: Ethernet packet. int: VLAN VID. int: Ethernet type of packet (inside VLAN)
Return type: ryu.lib.packet.ethernet
-
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
(_vlan, vid, eth_src, eth_dst, src_ip, dst_ip, vips, pi_flags=6)[source]¶ Return IPv6 ICMP echo reply packet.
Parameters: - _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: Serialized IPv6 ICMP RA packet.
Return type: ryu.lib.packet.ethernet