Erlang -- Implementation examples

User's Guide
Reference Manual
Release Notes
PDF
Top

Megaco/H.248
User's Guide
Version 3.15.1

Expand All
Contract All

Chapters

- Introduction
  - Top of chapter
  - Scope and Purpose
  - Prerequisites
  - About This Manual
  - Where to Find More Information
- Architecture
  - Top of chapter
  - Network view
  - General
  - Single node config
  - Distributed config
  - Message round-trip call flow
- Running the stack
  - Top of chapter
  - Starting
  - MGC startup call flow
  - MG startup call flow
  - Configuring the Megaco stack
  - Initial configuration
  - Changing the configuration
  - The transaction sender
  - Segmentation of transaction replies
- Internal form and its encodings
  - Top of chapter
  - Internal form of messages
  - The different encodings
  - Configuration of Erlang distribution encoding module
  - Configuration of text encoding module(s)
  - Configuration of binary encoding module(s)
  - Handling megaco versions
  - Encoder callback functions
- Transport mechanisms
  - Top of chapter
  - Callback interface
  - Examples
- Implementation examples
  - Top of chapter
  - A simple Media Gateway Controller
  - A simple Media Gateway
- Megaco mib
  - Top of chapter
  - Intro
  - Statistics counters
  - Distribution
- Performance comparison
  - Top of chapter
  - Comparison of encoder/decoders
  - System performance characteristics
  - Description of encoders/decoders
  - Setup
  - Summary
- Testing and tools
  - Top of chapter
  - Tracing
  - Measurement and transformation

# 6 Implementation examples

### 6.1 A simple Media Gateway Controller

In megaco/examples/simple/megaco_simple_mgc.erl there is an example of a simple MGC that listens on both text and binary standard ports and is prepared to handle a Service Change Request message to arrive either via TCP/IP or UDP/IP. Messages received on the text port are decoded using a text decoder and messages received on the binary port are decoded using a binary decoder.

The Service Change Reply is encoded in the same way as the request and sent back to the MG with the same transport mechanism UDP/IP or TCP/IP.

After this initial service change message the connection between the MG and MGC is fully established and supervised.

The MGC, with its four listeners, may be started with:

          cd megaco/examples/simple
          erl -pa ../../../megaco/ebin -s megaco_filter -s megaco
          megaco_simple_mgc:start().

or simply 'gmake mgc'.

The -s megaco_filter option to erl implies, the event tracing mechanism to be enabled and an interactive sequence chart tool to be started. This may be quite useful in order to visualize how your MGC interacts with the Megaco/H.248 protocol stack.

The event traces may alternatively be directed to a file for later analyze. By default the event tracing is disabled, but it may dynamically be enabled without any need for re-compilation of the code.

### 6.2 A simple Media Gateway

In megaco/examples/simple/megaco_simple_mg.erl there is an example of a simple MG that connects to an MGC, sends a Service Change Request and waits synchronously for a reply.

After this initial service change message the connection between the MG and MGC is fully established and supervised.

Assuming that the MGC is started on the local host, four different MG's, using text over TCP/IP, binary over TCP/IP, text over UDP/IP and binary over UDP/IP may be started on the same Erlang node with:

          cd megaco/examples/simple
          erl -pa ../../../megaco/ebin -s megaco_filter -s megaco
          megaco_simple_mg:start().

or simply 'gmake mg'.

If you "only" want to start a single MG which tries to connect an MG on a host named "baidarka", you may use one of these functions (instead of the megaco_simple_mg:start/0 above):

          megaco_simple_mg:start_tcp_text("baidarka", []).
          megaco_simple_mg:start_tcp_binary("baidarka", []).
          megaco_simple_mg:start_udp_text("baidarka", []).
          megaco_simple_mg:start_udp_binary("baidarka", []).

The -s megaco_filter option to erl implies, the event tracing mechanism to be enabled and an interactive sequence chart tool to be started. This may be quite useful in order to visualize how your MG interacts with the Megaco/H.248 protocol stack.

The event traces may alternatively be directed to a file for later analyze. By default the event tracing is disabled, but it may dynamically be enabled without any need for re-compilation of the code.