Skip to main content

A library for specifying/parsing/packing binary protocols

Project description

Suitcase

Build Status Coverage Status Code Climate Latest Version License

Suitcase is a library providing a set of primitives and helpers for specifying and parsing protocols. Suitcase provides an internal DSL (Domain Specific Language) for describing protocol frames. It seeks to do for binary protocols what things like Django’s ORM and Sqlalchemy’s Declarative Syntax do for Database ORMs and adopts a similar, class-based syntax.

View the Full Documentation

The original version of suitcase was generously contributed by the Digi Wireless Design Services. The software is provided as Alpha software and has not undergone formal testing but does ship with extensive unit testing.

View the Changelog

Example

The following example shows how you would use Suitcase to describe some of the core network protocols that form the backbone of the internet:

from suitcase.fields import UBInt16, Payload, LengthField, Magic, \
    UBInt8Sequence, DispatchField, DispatchTarget, UBInt8, UBInt32, BitField, BitNum, \
    BitBool
from suitcase.structure import Structure


class TCPFrameHeader(Structure):
    source_address = UBInt16()
    destination_address = UBInt16()
    sequence_number = UBInt32()
    acknowledgement_number = UBInt32()
    options = BitField(16,
        data_offset=BitNum(4),
        reserved=BitNum(3),
        NS=BitBool(),
        CWR=BitBool(),
        ECE=BitBool(),
        URG=BitBool(),
        ACK=BitBool(),
        PSH=BitBool(),
        RST=BitBool(),
        SYN=BitBool(),
        FIN=BitBool()
    )
    window_size = UBInt16()
    checksum = UBInt16()
    urgent_pointer = UBInt16()
    # TODO: additional options if data_offset > 5


class UDPFrame(Structure):
    source_port = UBInt16()
    destination_port = UBInt16()
    length = LengthField(UBInt16())
    checksum = UBInt16()
    data = Payload(length)


class IPV4Frame(Structure):
    options = BitField(64,
        version=BitNum(4),
        internet_header_length=BitNum(4),
        differentiated_services_code_point=BitNum(6),
        explicit_congestion_notification=BitNum(2),
        total_length=BitNum(16),
        identification=BitNum(16),
        flags=BitNum(3),
        fragment_offset=BitNum(13),
    )
    time_to_live = UBInt8()
    protocol = DispatchField(UBInt8())
    header_checksum = UBInt16()
    source_ip_address = UBInt32()
    destination_ip_address = UBInt32()

From these declarative definitions, you can both create message instances and pack them or parse bytes (including stream parsing) to get objects that you can do with as you please.

For more information, including how to use the structures that you have described, please refer to the Full Documentation.

Design Goals

The library seeks to adhere to these core principles:

  • Simple Interfaces

    Interfaces to the library should be simple and there should be a logical consistency in the library API. Internally, advanced language techniques are used, but the API consumer shouldn’t need to be aware of these details.

  • Declarative Syntax

    Wherever appropriate, the library should seek to provide a syntax for specifying protocols that is as declarative as possible. These declarations should be explicit and it should be clear what is being declared.

  • Informative Error Messages

    When implementing a protocol, you usually don’t get it right the first time. The library should use all available information to provide information to the API consumer that can help them figure out what is going wrong easily.

  • Common Use Cases Should Be Easy

    There are certain data types/patterns that are common amongst protocols. The library should include code to help with these cases to make the programmer’s life easier.

  • Less Common Use Cases Should Be Possible

    When there is a protocol that is significantly different than the norm, the library should still provide some useful code that can be reused. Some parts of the library might need to be abandoned, but the hope would be that one would not need to start from scratch.

License

This software is open-source software. Copyright Digi International, 2015.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, you can obtain one at http://mozilla.org/MPL/2.0/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

suitcase-0.12.0.tar.gz (40.0 kB view details)

Uploaded Source

File details

Details for the file suitcase-0.12.0.tar.gz.

File metadata

  • Download URL: suitcase-0.12.0.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/2.7.17

File hashes

Hashes for suitcase-0.12.0.tar.gz
Algorithm Hash digest
SHA256 f7dcf1063bca62df7bfd6e5eb07760458af3981297e68f0623271055a8bccda8
MD5 77986e493ca1d1b87e8a396bbeb16060
BLAKE2b-256 bcbe86793717d388d46209d6f10947a891a4697d8c24d18a3a715924ec6122c2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page