gtp

package module
v0.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2020 License: MIT Imports: 4 Imported by: 0

README

go-gtp: GTP in Golang

Package gtp provides simple and painless handling of GTP(GPRS Tunneling Protocol), implemented in the Go Programming Language.

CircleCI GolangCI GoDoc GitHub

Features

  • Flexible enough to control everything in GTP protocol.;
    • For developing mobile core network nodes (see examples).
    • For developing testing tools like traffic simulators or fuzzers.
  • Many helpers kind to developers provided, like session, bearer, and TEID associations.
  • Easy handling of multiple connections with fixed IP and Port with UDP (or other net.PacketConn).
  • No platform-specific codes inside, so it works almost everywhere Golang works. Currently it works only on Linux and macOS since netlink support is introduced. I'll make them separated from the base to let it work even on Windows in the future.

Getting Started

Prerequisites

The following packages should be installed before starting.

go get -u github.com/pkg/errors
go get -u github.com/google/go-cmp/cmp
go get -u github.com/pascaldekloe/goe/verify

If you use Go 1.11+, you can also use Go Modules.

GO111MODULE=on go [test | build | run | etc...]
Running examples

Examples works as it is by go build and executing commands in the following way.

  1. Open four terminals on a machine and start capturing on loopback interface.

  2. Start P-GW on terminal #1 and #2

// on terminal #1
./pgw

// on terminal #2
./pgw -s5c 127.0.0.53 -s5u 127.0.0.5
  1. Start S-GW on terminal #3
// on terminal #3
./sgw
  1. Start MME on terminal #4
// on terminal #4
./mme
  1. You will see the nodes exchanging Create Session and Modify Bearer on C-Plane, and ICMP Echo on U-Plane afterwards.

If you want to see fewer number of subscribers, please comment-out the v2.Subscriber definitions in example/mme/main.go.

Developing by your own

Each version has net.PacketConn-like APIs and GTP-specific ones which is often version-specific. The basic idea behind the current implementation is;

  • Dial or ListenAndServe to create a connection(Conn) between nodes.
  • Register handlers to the Conn for specific messages with AddHandler, which allows users to handle the messages coming from the remote endpoint as flexible as possible, with less pain.
  • CreateXXX to create session or PDP context with arbitrary IEs given. Session/PDP context is structured and they also have some helpers like AddTEID to handle known TEID properly.

For the detailed usage of specific version, see README.md under each version's directory.

Version Details
GTPv0 README.md
GTPv1 README.md
GTPv2 README.md

Supported Features

Note that "supported" means that the package provides helpers which makes it easier to handle. In other words, even if a message/IE is not marked as "Yes", you can make it work with some additional effort.

Your contribution is welcome to implement helpers for all the types, of course!

Version Messages IEs Networking (state machine) Details
GTPv0 35.7% 81.8% not implemented yet Supported Features
GTPv1 26.6% 30.1% v1-U is functional,
v1-C is not implemented yet
Supported Features
GTPv2 41.0% 43.2% almost functional Supported Features
GTP'
(Prime)
N/A N/A N/A not planned

Disclaimer

This is still an experimental project. Any part of implementations(including exported APIs) may be changed before released as v1.0.0.

Author(s)

Yoshiyuki Kurauchi (Twitter / LinkedIn)

I'm always open to welcome co-authors! Please feel free to talk to me.

LICENSE

MIT

Documentation

Overview

Package gtp provides simple and painless handling of GTP(GPRS Tunneling Protocol), implemented in the Go Programming Language.

This package is the wrapper of all versions of GTP that is available. Please see the godocs of each version instead.

GTPv0: https://godoc.org/github.com/wmnsk/go-gtp/v0

GTPv1: https://godoc.org/github.com/wmnsk/go-gtp/v1

GTPv2: https://godoc.org/github.com/wmnsk/go-gtp/v2

Please also see README.md for detailed usage of the APIs provided by this package, as well as how to run the examples.

https://github.com/wmnsk/go-gtp/blob/master/README.md

https://github.com/wmnsk/go-gtp/tree/master/examples/gw-tester

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidVersion    = errors.New("got invalid version")
	ErrInvalidLength     = errors.New("length value is invalid")
	ErrTooShortToParse   = errors.New("too short to decode as GTP")
	ErrTooShortToMarshal = errors.New("too short to serialize")
)

Common error definitions.

Functions

func Marshal added in v0.4.2

func Marshal(m Message) ([]byte, error)

Marshal returns the byte sequence generated from a Message instance. Better to use (*MessageName).Marshal instead if you know the name of message to be serialized.

Types

type Message

type Message interface {
	MarshalTo([]byte) error
	UnmarshalBinary(b []byte) error
	MarshalLen() int
	Version() int
	MessageType() uint8
	MessageTypeName() string

	// deprecated
	SerializeTo([]byte) error
	DecodeFromBytes(b []byte) error
}

Message is an interface that defines all versions of GTP messages.

func Parse added in v0.4.2

func Parse(b []byte) (Message, error)

Parse decodes given bytes as Message.

Directories

Path Synopsis
examples
mme command
Command mme is a reference implementation of MME with go-gtp.
Command mme is a reference implementation of MME with go-gtp.
pgw command
Command pgw is a dead simple implementation of P-GW only with GTP-related features.
Command pgw is a dead simple implementation of P-GW only with GTP-related features.
sgw command
Command sgw is a dead simple implementation of S-GW only with GTP-related features.
Command sgw is a dead simple implementation of S-GW only with GTP-related features.
gw-tester/enb module
gw-tester/mme module
gw-tester/pgw module
gw-tester/sgw module
Package utils provides some utilities which might be useful specifically for GTP(or other telco protocols).
Package utils provides some utilities which might be useful specifically for GTP(or other telco protocols).
v0
Package v0 provides the simple and painless handling of GTPv1-C and GTPv1-U protocol in pure Golang.
Package v0 provides the simple and painless handling of GTPv1-C and GTPv1-U protocol in pure Golang.
ies
Package ies provides encoding/decoding feature of GTPv0 Information Elements.
Package ies provides encoding/decoding feature of GTPv0 Information Elements.
messages
Package messages provides encoding/decoding feature of GTPv0 protocol.
Package messages provides encoding/decoding feature of GTPv0 protocol.
testutils
Package testutils is an internal package to be used for unit tests.
Package testutils is an internal package to be used for unit tests.
v1
Package v1 provides the simple and painless handling of GTPv1-C and GTPv1-U protocol in pure Golang.
Package v1 provides the simple and painless handling of GTPv1-C and GTPv1-U protocol in pure Golang.
ies
Package ies provides encoding/decoding feature of GTPv1 Information Elements.
Package ies provides encoding/decoding feature of GTPv1 Information Elements.
messages
Package messages provides encoding/decoding feature of GTPv1 protocol.
Package messages provides encoding/decoding feature of GTPv1 protocol.
testutils
Package testutils is an internal package to be used for unit tests.
Package testutils is an internal package to be used for unit tests.
v2
Package v2 provides the simple and painless handling of GTPv2-C protocol in pure Golang.
Package v2 provides the simple and painless handling of GTPv2-C protocol in pure Golang.
ies
Package ies provides encoding/decoding feature of GTPv2 Information Elements.
Package ies provides encoding/decoding feature of GTPv2 Information Elements.
messages
Package messages provides encoding/decoding feature of GTPv2 protocol.
Package messages provides encoding/decoding feature of GTPv2 protocol.
testutils
Package testutils is an internal package to be used for unit tests.
Package testutils is an internal package to be used for unit tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL