package frenetic

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

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.

val sexp_of_int8 : int8 -> Ppx_sexp_conv_lib.Sexp.t
val int8_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> int8
val compare_int8 : int8 -> int8 -> int
type int16 = int

int16 is the type of 16-bit integers.

val sexp_of_int16 : int16 -> Ppx_sexp_conv_lib.Sexp.t
val int16_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> int16
val compare_int16 : int16 -> int16 -> int
type int48 = int64

int48 is the type of 48-bit integers.

val sexp_of_int48 : int48 -> Ppx_sexp_conv_lib.Sexp.t
val int48_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> int48
val compare_int48 : int48 -> int48 -> int
type dlAddr = int48

dlAddr is the type of Ethernet addresses.

val sexp_of_dlAddr : dlAddr -> Ppx_sexp_conv_lib.Sexp.t
val dlAddr_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> dlAddr
val compare_dlAddr : dlAddr -> dlAddr -> int
type dlTyp = int16

dlTyp is the type of Ethernet frame types.

val sexp_of_dlTyp : dlTyp -> Ppx_sexp_conv_lib.Sexp.t
val dlTyp_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> dlTyp
val compare_dlTyp : dlTyp -> dlTyp -> int
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.

val sexp_of_dlVlan : dlVlan -> Ppx_sexp_conv_lib.Sexp.t
val dlVlan_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> dlVlan
val compare_dlVlan : dlVlan -> dlVlan -> int
type dlVlanPcp = int8

dlVlanPcp is the type of 802.1Q (VLAN) priorities.

val sexp_of_dlVlanPcp : dlVlanPcp -> Ppx_sexp_conv_lib.Sexp.t
val dlVlanPcp_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> dlVlanPcp
val compare_dlVlanPcp : dlVlanPcp -> dlVlanPcp -> int
type dlVlanDei = bool

dlVlanDei is the type of 802.1Q (VLAN) drop eligible indicator.

val sexp_of_dlVlanDei : dlVlanDei -> Ppx_sexp_conv_lib.Sexp.t
val dlVlanDei_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> dlVlanDei
val compare_dlVlanDei : dlVlanDei -> dlVlanDei -> int
type nwAddr = int32

nwAddr is the type of IPv4 addresses.

val sexp_of_nwAddr : nwAddr -> Ppx_sexp_conv_lib.Sexp.t
val nwAddr_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> nwAddr
val compare_nwAddr : nwAddr -> nwAddr -> int
type nwProto = int8

nwProto is the type of IPv4 protocol numbers.

val sexp_of_nwProto : nwProto -> Ppx_sexp_conv_lib.Sexp.t
val nwProto_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> nwProto
val compare_nwProto : nwProto -> nwProto -> int
type nwTos = int8

nwTos is the type of IPv4 types of service.

val sexp_of_nwTos : nwTos -> Ppx_sexp_conv_lib.Sexp.t
val nwTos_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> nwTos
val compare_nwTos : nwTos -> nwTos -> int
type ipv6Addr = int64 * int64

ipv6Addr is the type of IPv6 addresses.

val sexp_of_ipv6Addr : ipv6Addr -> Ppx_sexp_conv_lib.Sexp.t
val ipv6Addr_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> ipv6Addr
val compare_ipv6Addr : ipv6Addr -> ipv6Addr -> int
type tpPort = int16

tpPort is the type of transport protocol ports.

val sexp_of_tpPort : tpPort -> Ppx_sexp_conv_lib.Sexp.t
val tpPort_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> tpPort
val compare_tpPort : tpPort -> tpPort -> int
module Tcp : sig ... end

TCP frame of a packet.

module Udp : sig ... end

UDP frame of a packet.

module Icmp : sig ... end

ICMP frame of a packet.

module Dns : sig ... end

Basic DNS packet type.

module Igmp1and2 : sig ... end

IGMP v1 and v2 message type.

module Igmp3 : sig ... end

IGMP v3 message type.

module Igmp : sig ... end

IGMP frame of a packet.

module Ip : sig ... end

IPv4 frame of a packet.

module Arp : sig ... end

Address resolution protocol (ARP) packet payload.

type nw =
  1. | Ip of Ip.t
    (*

    Internet Protocol version 4 (IPv4).

    *)
  2. | Arp of Arp.t
    (*

    Address Resolution Protocol (ARP).

    *)
  3. | 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.

val sexp_of_nw : nw -> Ppx_sexp_conv_lib.Sexp.t
val nw_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> nw
type packet = {
  1. dlSrc : dlAddr;
    (*

    Ethernet source address.

    *)
  2. dlDst : dlAddr;
    (*

    Ethernet destination address.

    *)
  3. dlVlan : dlVlan;
    (*

    802.1Q VLAN identifier, if any.

    *)
  4. dlVlanDei : dlVlanDei;
    (*

    802.1Q VLAN Drop Eligible Indciator. Ignored if dlVlan is None

    *)
  5. dlVlanPcp : dlVlanPcp;
    (*

    802.1Q VLAN priority. Ignored if dlVlan is None.

    *)
  6. nw : nw;
    (*

    Network payload.

    *)
}

The type packet represents a packet at the ethernet protocol level.

val sexp_of_packet : packet -> Ppx_sexp_conv_lib.Sexp.t
val packet_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> packet
Accessors
val dlTyp : packet -> dlTyp

dlTyp pkt returns the ethernet frame type of pkt

val nwSrc : packet -> nwAddr

nwSrc pkt returns the source IP address of pkt.

  • raises

    Invalid_argument if the packet is not carrying an IP payload.

val nwDst : packet -> nwAddr

nwDst pkt returns the destination IP address of pkt.

  • raises

    Invalid_argument if the packet is not carrying an IP payload.

val nwTos : packet -> nwTos

nwTos pkt returns the IPv4 type of service of pkt.

  • raises

    Invalid_argument if the packet is not carrying an IP payload.

val nwProto : packet -> nwProto

nwProto pkt returns the IP protocol number of pkt.

  • raises

    Invalid_argument if the packet is not carrying an IP payload.

val tpSrc : packet -> tpPort

tpSrc pkt returns the transport protocol source port of pkt.

val tpDst : packet -> tpPort

tpDst pkt returns the transport protocol destination port of pkt.

val arpOperation : packet -> int

arpOperation pkt returns the ARP operation code of pkt.

Mutators
val setDlSrc : packet -> dlAddr -> packet

setDlSrc pkt addr sets the ethernet source address of pkt to addr.

val setDlDst : packet -> dlAddr -> packet

setDlDst pkt addr sets the ethernet destination address of pkt to addr.

val setDlVlan : packet -> dlVlan -> packet

setDlVlan pkt vlan sets the VLAN identifier of pkt to vlan.

val setDlVlanPcp : packet -> dlVlanPcp -> packet

setDlVlanPcp pkt pri sets the VLAN priority of pkt to pri.

val setNwSrc : packet -> nwAddr -> packet

setNwSrc pkt sets the source IP address of pkt if the packet carries an IP payload. Otherwise, it returns the packet unchanged.

val setNwDst : packet -> nwAddr -> packet

setNwDst pkt sets the destination IP address of pkt if the packet carries an IP payload. Otherwise, it returns the packet unchanged.

val setNwTos : packet -> nwTos -> packet

setNwTos pkt sets the IPv4 type of service of pkt if the packet carries an IP payload. Otherwise, it returns the packet unchanged.

val setTpSrc : packet -> tpPort -> packet

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.

val setTpDst : packet -> tpPort -> packet

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.

val string_of_ipv6 : ipv6Addr -> string

string_of_ipv6 t pretty-prints an IPv6 address. *

val ipv6_of_string : string -> ipv6Addr

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.

Serialization
val parse : Cstruct.t -> packet

parse bits parses a bit sequence into a packet.

val len : packet -> int

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.

val format_packet : Format.formatter -> packet -> unit

format_packet fmt pkt uses formatter fmt to format pkt.