hep-erlang

October 31, 2013 · View on GitHub

An Erlang implementation of HEP (Homer Encapsulation Protocol).

WARNING

This project is currently in the incubator of Pannonia Technologies, so there maybe a lot of changes in how this software works or it might not even work at all. There might be terrible inconsistencies in or a complete lack of documentation. So you are warned to use this software at your own risk!

If you'd like to contribute, don't ask, just do it. That's one reason we are here on GitHub.

Goals

HEP was designed by the developers of the Homer SIP Capture Server solution. HEP is used to transport metadata and SIP messages from a SIP proxy or SIP user agent to a capture server. HEP is not limited to transport SIP messages, but before version 3 of the protocol, the payload could not be distinguished by the metadata, so transporting anything else than SIP before Version 3 is rather impractical when conveyed through the same channel. A few major Open Source SIP-related projects, like FreeSWITCH, Kamailio and OpenSIPS integrated HEP natively, so this is why this project exists and we also wanted to be able to capture and/or send HEP messages from Erlang. HEP can use any kind of transport channel, but most of the time UDP is used.

Usage

Very basic example:


-module(naive_udp_hep_listener).

-export([start/1, stop/1]).

start(Port) ->
    ListenerPid = spawn(fun() ->
        {ok, Socket} = gen_udp:open(Port, [binary, {active, true}]),
        Loop = fun(Fun) ->
            receive
                {udp, _, _, _, Message} ->
                    {ok, Hep} = hep_multi_parser:parse(Message),
                    HepMsg = hep_transform:transform(Hep),
                    error_logger:info_msg("~p~n", [HepMsg]),
                    Fun(Fun);
                stop ->
                    gen_udp:close(Socket);
                _ ->
                    Fun(Fun)
            end
        end,
        Loop(Loop)
    end),
    {ok, ListenerPid}.

stop(ListenerPid) ->
    ListenerPid ! stop.

Protocol Version 1

All integer fields are stored in network byte order.

NameLengthDescription
Version8 bitsHEP version, always 1 for this version.
Length8 bitsLength of the HEP header, including Version and Length field and excluding payload.
Protocol Family8 bitsProtocol Family PF_INET, PF_INET6 (2 = IPv4, 10 = IPv6).
Protocol8 bitsUDP, TCP, TLS, SCTP, etc..
Source Port16 bitsSource Port of the captured packet in payload.
Destination Port16 bitsDestination Port of the captured packet in payload.
Source Address*1Source IP of the captured packet in payload.
Destination Address*1Destination IP of the captured packet in payload.
Payload*2Payload (usually SIP message)

*1) Length is 32 bits for IPv4 and 128 bits for IPv6.

*2) Variable length not defined by metadata, so this protocol is really only well suited for UDP.

Protocol Version 2

All integer fields are stored in network byte order.

NameLengthDescription
Version8 bitsHEP version, always 2 for this version.
Length8 bitsLength of the HEP header, including Version and Length field and excluding payload.
Protocol Family8 bitsProtocol Family PF_INET, PF_INET6 (2 = IPv4, 10 = IPv6).
Protocol8 bitsUDP, TCP, TLS, SCTP, etc..
Source Port16 bitsSource Port of the captured packet in payload.
Destination Port16 bitsDestination Port of the captured packet in payload.
Source Address*1Source IP of the captured packet in payload.
Destination Address*1Destination IP of the captured packet in payload.
Seconds32 bitsThe timestamp in seconds since the Epoch when the included payload was captured.
Microseconds32 bitsThe microseconds part of the timestamp.
Capture ID of node16 bitsA capture ID of the node. XXX: What does this exactly mean???
unused16 bitsunused
Payload*2Payload (usually SIP message)

*1) Length is 32 bits for IPv4 and 128 bits for IPv6.

*2) Variable length not defined by metadata, so this protocol is really only well suited for UDP.

Protocol Version 3

Each packet in HEP version 3 starts with a header:

NameLengthDescription
Protocol Identifier4 bytesAlways contains "HEP3" for this version.
Total Length2 bytesThe total length of this packet, including Protocol Identifier and Total Length.
ChunksvariableThe payload as chunks, with a length of "Total Length" minus 6.

All data is encapsulated in chunks:

NameLengthDescription
Vendor ID2 bytesVendor Namespace of this chunk.
Chunk ID2 bytesVendor specific chunk id.
Chunk Length2 bytesThe total length of this chunk, including Vendor ID and Chunk ID.
Chunk PayloadvariableThe payload of the chunk, with a length of "Chunk Length minus 6.

The following chunk data types are defined:

TypeDescription
octet-stringArbitrary octet string ("byte array").
utf8-stringUTF-8 encoded character sequence.
uint88 bit unsigned integer.
uint1616 bit unsigned integer in network byte order.
uint3232 bit unsigned integer in network byte order.
inet4-addr4 octet IPv4 address, most significant octet first.
inet6-addr16 octet IPv6 address, most significant octet first.

The following Vendor IDs are assigned:

Vendor IDAssigned Vendor
16#0000Generic chunk types, see below.
16#0001FreeSWITCH
16#0002Kamailio
16#0003OpenSIPS
16#0004Asterisk
16#0005Homer Project
16#0006SipXecs

Generic chunk types:

Chunk IDTypeDescription
16#0001uint8IP protocol family
16#0002uint8IP protocol id
16#0003inet4-addrIPv4 source address
16#0004inet4-addrIPv4 destination address
16#0005inet6-addrIPv6 source address
16#0006inet6-addrIPv6 destination address
16#0007uint16Protocol source port
16#0008uint16Protocol destination port
16#0009uint32Timestamp in seconds since the Epoch
16#000auint32Microseconds part of timestamp
16#000buint8Protocol type (see table below)
16#000cuint32Capture agent id
16#000duint16keep alive time in seconds
16#000eoctet-stringAuthenticate key
16#000foctet-stringcaptured packet payload

Protocol types:

Type IDDescription
16#00reserved
16#01SIP
16#02H.323
16#03SDP
16#04RTP
16#05RTCP
16#06MGCP
16#07MEGACO / H.248
16#08M2UA (SS7/SIGTRAN)
16#09M3UA (SS7/SIGTRAN)
16#10IAX

JSON representation

[
    {
        "type": "HEP",
        "version": 1,
        "protocolFamily": 2,
        "protocol": 17,
        "srcIp": "192.168.3.11",
        "srcPort": 5060,
        "dstIp": "192.168.3.190",
        "dstPort": 2048,
        "timestamp": "2013-10-29T15:25:53.567Z",
        "timestampUSecs": 123,
        "captureId": null,
        "vendorChunks": [],
        "payload": {
            "type": "SIP",
            "data": "INVITE sip:100@pantech.intern SIP/2.0\r\n..."
        }
    },
    {
        "type": "HEP",
        "version": 2,
        "protocolFamily": 2,
        "protocol": 17,
        "srcIp": "192.168.3.12",
        "srcPort": 5060,
        "dstIp": "192.168.3.11",
        "dstPort": 5060,
        "timestamp": "2013-10-29T15:25:53:577Z",
        "timestampUSecs": 0,
        "captureId": 241,
        "vendorChunks": [],
        "payload": {
            "type": "SIP",
            "data": "INVITE sip:100@pantech.intern SIP/2.0\r\n..."
        }
    }
]

Other Software Supporting HEP

This is third-party software also supporting HEP.

NameHEP Versions SupportedClientServer
captagent1, 2, 3yesno
FreeSWITCH1yesno
Kamailio1, 2yesyes
OpenSIPS1, 2yesyes

Contributors

License

This project is licensed under the ISC License. See LICENSE for details.


Copyright © 2013 Matthias Endler. All rights reserved.