capsule 0.1.5

A framework for network function development. Written in Rust, inspired by NetBricks and built on Intel's Data Plane Development Kit.
Documentation
/*
* Copyright 2019 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

//! Hand-crafted packet byte-arrays for testing.

/// A VLAN Dot1q (802.1Q) packet.
#[rustfmt::skip]
pub const VLAN_DOT1Q_PACKET: [u8; 64] = [
// Ethernet header
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    // tpid
    0x81, 0x00,
    // tci
    0x00, 0x7b,
    // ether type
    0x08, 0x06,
    // payload
    0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x02, 0x00, 0x19,
    0x06, 0xea, 0xb8, 0xc1, 0xc0, 0xa8, 0x7b, 0x01, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xc0, 0xa8, 0x7b, 0x01, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00
];

/// A VLAN QinQ (802.1AD) packet.
#[rustfmt::skip]
pub const VLAN_QINQ_PACKET: [u8; 68] = [
// Ethernet header
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    // tpid
    0x88, 0xa8,
    // tci
    0x00, 0x1e,
    // tpid
    0x81, 0x00,
    // tci
    0x20, 0x65,
    // ether type
    0x08, 0x06,
    // payload
    0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x02, 0x00, 0x19,
    0x06, 0xea, 0xb8, 0xc1, 0xc0, 0xa8, 0x7b, 0x01, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xc0, 0xa8, 0x7b, 0x01, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00
];

/// An ARP packet.
#[rustfmt::skip]
pub const ARP4_PACKET: [u8; 42] = [
// Ethernet header
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x08, 0x06,
// ARP header
    // hardware type = Ethernet
    0x00, 0x01,
    // protocol type = IPv4
    0x08, 0x00,
    // hardware and protocol address lengths
    0x06, 0x04,
    // operation code
    0x00, 0x01,
    // source hardware address
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    // source protocol address = 139.133.217.110
    0x8b, 0x85, 0xd9, 0x6e,
    // target hardware address = blank
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    // target protocol address = 139.133.233.2
    0x8b, 0x85, 0xe9, 0x02
];

/// An IPv4 TCP packet.
#[rustfmt::skip]
pub const IPV4_TCP_PACKET: [u8; 58] = [
// Ethernet header
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    0x08, 0x00,
// IPv4 header
    0x45, 0x00,
    // IPv4 payload length
    0x00, 0x2c,
    // ident = 2232, flags = 4, frag_offset = 0
    0x08, 0xb8, 0x40, 0x00,
    // ttl = 255, protocol = TCP, checksum = 0x9997
    0xff, 0x06, 0x99, 0x97,
    // src = 139.133.217.110
    0x8b, 0x85, 0xd9, 0x6e,
    // dst = 139.133.233.2
    0x8b, 0x85, 0xe9, 0x02,
// TCP header
    // src_port = 36869, dst_port = 23
    0x90, 0x05, 0x00, 0x17,
    // seq_no = 1913975060
    0x72, 0x14, 0xf1, 0x14,
    // ack_no = 0
    0x00, 0x00, 0x00, 0x00,
    // data_offset = 6, flags = 0x02
    0x60, 0x02,
    // window = 8760, checksum = 0xa92c, urgent = 0
    0x22, 0x38, 0xa9, 0x2c, 0x00, 0x00,
    // options
    0x02, 0x04, 0x05, 0xb4
];

/// An IPv4 UDP packet.
#[rustfmt::skip]
pub const IPV4_UDP_PACKET: [u8; 52] = [
// Ethernet header
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    0x08, 0x00,
// IPv4 header
    0x45, 0x00,
    // IPv4 payload length
    0x00, 0x26,
    // ident = 43849, flags = 4, frag_offset = 0
    0xab, 0x49, 0x40, 0x00,
    // ttl = 255, protocol = UDP, checksum = 0xf700
    0xff, 0x11, 0xf7, 0x00,
    // src = 139.133.217.110
    0x8b, 0x85, 0xd9, 0x6e,
    // dst = 139.133.233.2
    0x8b, 0x85, 0xe9, 0x02,
// UDP header
    // src_port = 39376, dst_port = 1087
    0x99, 0xd0, 0x04, 0x3f,
    // UDP length = 18, checksum = 0x7228
    0x00, 0x12, 0x72, 0x28,
    // UDP payload
    0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x68, 0x65, 0x6c, 0x6c, 0x6f
];

/// An IPv6 TCP packet.
#[rustfmt::skip]
pub const IPV6_TCP_PACKET: [u8; 78] = [
// Ethernet header
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    0x86, 0xDD,
// IPv6 header
    // version, dscp, ecn, flow label
    0x60, 0x00, 0x00, 0x00,
    // payload length
    0x00, 0x18,
    // next Header
    0x06,
    // hop limit
    0x02,
    // src addr
    0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    // dst addr
    0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34,
// TCP header
    // src_port = 36869, dst_port = 23
    0x90, 0x05, 0x00, 0x17,
    // seq_no = 1913975060
    0x72, 0x14, 0xf1, 0x14,
    // ack_no = 0
    0x00, 0x00, 0x00, 0x00,
    // data_offset = 24, flags = 0x02
    0x60, 0x02,
    // window = 8760, checksum = 0xa92c, urgent = 0
    0x22, 0x38, 0xa9, 0x2c, 0x00, 0x00,
    // options
    0x02, 0x04, 0x05, 0xb4
];

/// An IPv6 segment routing TCP packet.
#[rustfmt::skip]
pub const SR_TCP_PACKET: [u8; 170] = [
// Ethernet header
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    0x86, 0xdd,
// IPv6 Header
    0x60, 0x00, 0x00, 0x00,
    // payload length
    0x00, 0x74,
    // next header (routing)
    0x2b,
    0x02,
    0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34,
// SR header
    // next header (tcp)
    0x06,
    // hdr ext len (3 segments, units of 8 octets)
    0x06,
    // routing type
    0x04,
    // segments left
    0x00,
    // last entry
    0x02,
    // flags
    0x00,
    // tag
    0x00, 0x00,
    // segments[0] 2001:0db8:85a3:0000:0000:8a2e:0370:7333
    0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x33,
    // segments[1] 2001:0db8:85a3:0000:0000:8a2e:0370:7334
    0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34,
    // segments[2] 2001:0db8:85a3:0000:0000:8a2e:0370:7335
    0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x35,
// TCP header
    // src port
    0x0d, 0x88,
    // dst port
    0x04, 0x00,
    // sequence number
    0x00, 0x00, 0x00, 0x00,
    // ack number
    0x00, 0x00, 0x00, 0x00,
    // flags
    0x50, 0x02,
    // window
    0x00, 0x0a,
    // checksum
    0x00, 0x00,
    // urgent pointer
    0x00, 0x00,
    // payload
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
];

/// An IPv6 UDP fragment packet.
#[rustfmt::skip]
pub const IPV6_FRAGMENT_PACKET: [u8; 72] = [
// Ethernet header
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    0x86, 0xdd,
// IPv6 header
    0x60, 0x02, 0x12, 0x89,
    // payload length
    0x00, 0x12,
    // next header (fragment)
    0x2c,
    0x40,
    0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34,
// Fragment header
    // next header (udp)
    0x11,
    0x00,
    // offset = 543, more fragment = no
    0x10, 0xf8,
    // identification
    0xf8, 0x8e, 0xb4, 0x66,
// UDP payload fragment
    0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x68, 0x65, 0x6c, 0x6c, 0x6f
];

/// An ICMPv4 packet.
#[rustfmt::skip]
pub const ICMPV4_PACKET: [u8; 74] = [
// Ethernet header
    0x00, 0x50, 0x56, 0xe0, 0x14, 0x49,
    0x00, 0x0c, 0x29, 0x34, 0x0B, 0xde,
    0x08, 0x00,
// IPv4 header
    0x45, 0x00, 0x00, 0x3c,
    0xd7, 0x43, 0x00, 0x00,
    0x80, 0x01, 0x2b, 0x73,
    0xc0, 0xa8, 0x9e, 0x8b,
    0xae, 0x89, 0x2a, 0x4d,
// ICMPv4 header
    // type
    0x08,
    // code
    0x00,
    // checksum
    0x2a, 0x5c,
    // data
    0x02, 0x00, 0x21, 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 
    0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 
    0x66, 0x67, 0x68, 0x69,
];

/// An ICMPv6 packet.
#[rustfmt::skip]
pub const ICMPV6_PACKET: [u8; 62] = [
// Ethernet header
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    0x86, 0xDD,
// IPv6 header
    0x60, 0x00, 0x00, 0x00,
    // payload length
    0x00, 0x08,
    0x3a,
    0xff,
    0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0xf0, 0x45, 0xff, 0xfe, 0x0c, 0x66, 0x4b,
    0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
// ICMPv6 header
    // unknown type
    0xFF,
    // code
    0x00,
    // checksum
    0x01, 0xf0,
    // data
    0x00, 0x00, 0x00, 0x00
];

/// A NDP router advertisement packet.
#[rustfmt::skip]
pub const ROUTER_ADVERT_PACKET: [u8; 142] = [
// Ethernet header
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    0x86, 0xDD,
// IPv6 header
    0x60, 0x00, 0x00, 0x00,
    // payload length
    0x00, 0x58,
    0x3a,
    0xff,
    0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0xf0, 0x45, 0xff, 0xfe, 0x0c, 0x66, 0x4b,
    0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
// ICMPv6 header
    // type
    0x86,
    // code
    0x00,
    // checksum
    0xf5, 0x0c,
// router advertisement message
    // current hop limit
    0x40,
    // flags
    0x40,
    // router lifetime
    0x0e, 0x10,
    // reachable time
    0x00, 0x00, 0x00, 0x00,
    // retrans timer
    0x00, 0x00, 0x00, 0x00,
    // prefix information option
    0x03, 0x04, 0x40, 0xc0, 0x00, 0x00, 0x09, 0x3e, 0x00, 0x00, 0x09, 0x3e, 0x00, 0x00, 0x00, 0x00,
    0x26, 0x07, 0xfc, 0xc8, 0xf1, 0x42, 0xb0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    // MTU option
    0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x05, 0xdc,
    // source link-layer address option
    0x01, 0x01, 0x70, 0x3a, 0xcb, 0x1b, 0xf9, 0x7a,
    // recursive DNS server option
    0x19, 0x03, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x26, 0x07, 0xfc, 0xc8, 0xf1, 0x42, 0xb0, 0xf0,
    0xd4, 0xf0, 0x45, 0xff, 0xfe, 0x0c, 0x66, 0x4b
];

/// A NDP router solicitation packet.
#[rustfmt::skip]
pub const ROUTER_SOLICIT_PACKET: [u8; 70] = [
// Ethernet header
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    0x86, 0xDD,
// IPv6 header
    0x60, 0x00, 0x00, 0x00,
    // payload length
    0x00, 0x10,
    0x3a,
    0xff,
    0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0xf0, 0x45, 0xff, 0xfe, 0x0c, 0x66, 0x4b,
    0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
// ICMPv6 header
    // type
    0x85,
    // code
    0x00,
    // checksum
    0xf5, 0x0c,
// router solicitation message
    // reserved
    0x00, 0x00, 0x00, 0x00,
    // source link-layer address option
    0x01, 0x01, 0x70, 0x3a, 0xcb, 0x1b, 0xf9, 0x7a
];