Up — package frenetic.kernel Module Frenetic_kernel.Packet Library for constructing, marshaling and parsing data packets. These packets are
independent of OpenFlow message information - they are mostly used for the payloads
of PacketIn and PacketOut messages.
Packet types
It is possible to navigate the structure of a packet directly
using the types defined here. However, using Accessors may be more
convenient.
type int8
= int
int8
is the type of 8-bit integers.
include sig ... end
val int8_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> int8
val sexp_of_int8 : int8 ‑> Ppx_sexp_conv_lib.Sexp.t
type int16
= int
int16
is the type of 16-bit integers.
include sig ... end
val int16_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> int16
val sexp_of_int16 : int16 ‑> Ppx_sexp_conv_lib.Sexp.t
type int48
= int64
int48
is the type of 48-bit integers.
include sig ... end
val int48_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> int48
val sexp_of_int48 : int48 ‑> Ppx_sexp_conv_lib.Sexp.t
dlAddr
is the type of Ethernet addresses.
include sig ... end
val dlAddr_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> dlAddr
val sexp_of_dlAddr : dlAddr ‑> Ppx_sexp_conv_lib.Sexp.t
dlTyp
is the type of Ethernet frame types.
include sig ... end
val dlTyp_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> dlTyp
val sexp_of_dlTyp : dlTyp ‑> Ppx_sexp_conv_lib.Sexp.t
type dlVlan
= int16 option
dlVlan
is the type of VLAN identifiers. A value of None
indicates that no 802.1Q (VLAN) header is set, which is distinct from
setting the VLAN to 0.
include sig ... end
val dlVlan_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> dlVlan
val sexp_of_dlVlan : dlVlan ‑> Ppx_sexp_conv_lib.Sexp.t
dlVlanPcp
is the type of 802.1Q (VLAN) priorities.
include sig ... end
val dlVlanPcp_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> dlVlanPcp
val sexp_of_dlVlanPcp : dlVlanPcp ‑> Ppx_sexp_conv_lib.Sexp.t
type dlVlanDei
= bool
dlVlanDei
is the type of 802.1Q (VLAN) drop eligible indicator.
include sig ... end
val dlVlanDei_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> dlVlanDei
val sexp_of_dlVlanDei : dlVlanDei ‑> Ppx_sexp_conv_lib.Sexp.t
type nwAddr
= int32
nwAddr
is the type of IPv4 addresses.
include sig ... end
val nwAddr_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> nwAddr
val sexp_of_nwAddr : nwAddr ‑> Ppx_sexp_conv_lib.Sexp.t
nwProto
is the type of IPv4 protocol numbers.
include sig ... end
val nwProto_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> nwProto
val sexp_of_nwProto : nwProto ‑> Ppx_sexp_conv_lib.Sexp.t
nwTos
is the type of IPv4 types of service.
include sig ... end
val nwTos_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> nwTos
val sexp_of_nwTos : nwTos ‑> Ppx_sexp_conv_lib.Sexp.t
type ipv6Addr
= int64 * int64
ipv6Addr
is the type of IPv6 addresses.
include sig ... end
val ipv6Addr_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> ipv6Addr
val sexp_of_ipv6Addr : ipv6Addr ‑> Ppx_sexp_conv_lib.Sexp.t
tpPort
is the type of transport protocol ports.
include sig ... end
val tpPort_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> tpPort
val sexp_of_tpPort : tpPort ‑> Ppx_sexp_conv_lib.Sexp.t
module Icmp : sig ... end
IGMP v1 and v2 message type.
module Igmp3 : sig ... end
module Igmp : sig ... end
Address resolution protocol (ARP) packet payload.
type nw
=
|
Ip of Ip.t
(** Internet Protocol version 4 (IPv4). *)
|
Arp of Arp.t
(** Address Resolution Protocol (ARP). *)
|
Unparsable of dlTyp * Cstruct.t
(** The EtherType code accompanied by the
uninterpreted ethernet payload. *)
The type nw
represents a packet at the network protocol level.
include sig ... end
val nw_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> nw
val sexp_of_nw : nw ‑> Ppx_sexp_conv_lib.Sexp.t
type packet
=
{
dlSrc : dlAddr ;
(** Ethernet source address. *)
dlDst : dlAddr ;
(** Ethernet destination address. *)
dlVlan : dlVlan ;
(** 802.1Q VLAN identifier, if any. *)
dlVlanDei : dlVlanDei ;
(** 802.1Q VLAN Drop Eligible Indciator. Ignored if
dlVlan
is None
*)
dlVlanPcp : dlVlanPcp ;
(** 802.1Q VLAN priority. Ignored if dlVlan
is
None
. *)
nw : nw ;
(** Network payload. *)
}
The type packet
represents a packet at the ethernet protocol level.
include sig ... end
val packet_of_sexp : Ppx_sexp_conv_lib.Sexp.t ‑> packet
val sexp_of_packet : packet ‑> Ppx_sexp_conv_lib.Sexp.t
dlTyp pkt
returns the ethernet frame type of pkt
nwSrc pkt
returns the source IP address of pkt
.
Raises Invalid_argument : if the packet is not carrying an IP payload.nwDst pkt
returns the destination IP address of pkt
.
Raises Invalid_argument : if the packet is not carrying an IP payload.nwTos pkt
returns the IPv4 type of service of pkt
.
Raises Invalid_argument : if the packet is not carrying an IP payload.nwProto pkt
returns the IP protocol number of pkt
.
Raises Invalid_argument : if the packet is not carrying an IP payload.tpSrc pkt
returns the transport protocol source port of pkt
.
Raises Invalid_argument : if the packet is not carrying a TCP or UDP
payload.tpDst pkt
returns the transport protocol destination port of
pkt
.
Raises Invalid_argument : if the packet is not carrying a
TCP or UDP payload.val arpOperation : packet ‑> int
arpOperation pkt
returns the ARP operation code of pkt
.
Raises Invalid_argument : if the packet is not carrying a ARP
payload.Mutators
setDlSrc pkt addr
sets the ethernet source address of pkt
to
addr
.
setDlDst pkt addr
sets the ethernet destination address of pkt
to addr
.
setDlVlan pkt vlan
sets the VLAN identifier of pkt
to
vlan
.
setDlVlanPcp pkt pri
sets the VLAN priority of pkt
to
pri
.
setNwSrc pkt
sets the source IP address of pkt
if the packet
carries an IP payload. Otherwise, it returns the packet
unchanged.
setNwDst pkt
sets the destination IP address of pkt
if the
packet carries an IP payload. Otherwise, it returns the packet
unchanged.
setNwTos pkt
sets the IPv4 type of service of pkt
if the
packet carries an IP payload. Otherwise, it returns the packet
unchanged.
setTpSrc pkt
sets the transport protocol source port of pkt
if
the packet carries a TCP or UDP payload. Otherwise, it returns
the packet unchanged.
setTpDst pkt
sets the transport protocol destination port of
pkt
if the packet carries a TCP or UDP payload. Otherwise, it
returns the packet unchanged.
Pretty Printing
val string_of_mac : dlAddr ‑> string
string_of_mac mac
pretty-prints an ethernet address.
val mac_of_string : string ‑> dlAddr
mac_of_string string
converts an colon-separated ethernet
address to a dlAddr
*
val string_of_dlAddr : dlAddr ‑> string
string_of_dlAddr addr
is identical to string_of_mac
.
val string_of_dlTyp : dlTyp ‑> string
string_of_dlTyp typ
pretty-prints an ethernet frame type.
val string_of_dlVlan : dlVlan ‑> string
string_of_dlVlan vlan
pretty-prints an 802.1Q VLAN
identifier.
val string_of_dlVlanPcp : dlVlanPcp ‑> string
string_of_dlVlanPcp p
pretty-prints an 802.1Q VLAN priority.
val string_of_ip : nwAddr ‑> string
string_of_ip ip
pretty-prints an IPv4 address.
val ip_of_string : string ‑> nwAddr
ip_of_string string
converts an dot-separated IPv4 address to a
nwAddr
*
val string_of_nwAddr : nwAddr ‑> string
string_of_nwAddr addr
is identical to string_of_ip
.
val string_of_nwProto : nwProto ‑> string
string_of_nwProto p
pretty-prints an IPv4 protocol.
val string_of_nwTos : nwTos ‑> string
string_of_nwTos t
pretty-prints an IPv4 type of service.
string_of_ipv6 t
pretty-prints an IPv6 address. *
string_of_ipv6 t
Converts a colon-separated IPv6 address to
ipv6Addr. *
val string_of_tpPort : tpPort ‑> string
string_of_tpPort p
pretty-prints a transport protocol port
number.
val bytes_of_mac : dlAddr ‑> string
bytes_of_mac mac
returns a bit-string representation of
mac
.
val mac_of_bytes : string ‑> int48
mac_of_bytes str
constructs a dlAddr
from a bit-string
representation.
Raises Invalid_argument : if the length of the
string is not six characters.val parse : Cstruct.t ‑> packet
parse bits
parses a bit sequence into a packet.
len pkt
length of packet in bytes.
val marshal : packet ‑> Cstruct.t
marshal pkt
marshals pkt
into a bit sequence.
val to_string : packet ‑> string
to_string pkt
prints pkt
as a string.