OpenTTCN/Knowledge base/Creating SNMP BER Codec

From OpenTTCN

Jump to: navigation, search

  OpenTTCN DocZone

  Home | Developer's corner | Knowledge base | Working documents | Documentation | OpenTTCN IDE | Tutorials | Training | How do I | Frequently asked questions | Technical support


Creating SNMP BER Codec



This article discusses creation of SNMP BER codec using BER Codec Component shipped with OpenTTCN SDK for C#.

SNMP stands for Simple Network Management Protocol and is used to manage network devices. SNMP Version 2 is defined in RFC 3416.

This article uses SNMP merely as an example protocol illustrating concrete use case scenario for BER Codec Component. This article is meant to serve as a general-purpose documentation explaining creation of custom BER codecs for specific applications.

Tools used: Technical preview of OpenTTCN Tester 2012, more specifically version 4.2.0beta4.0, with BER support, and OpenTTCN SDK for C# (shipped with OpenTTCN Tester package).

Important notice: Availability of the BER Codec Component feature may depend on the OpenTTCN Tester product version, edition, and/or particulars of the support contract in effect. If in doubt, contact sales@openttcn.fi regarding applicability of this feature to your product installation.

Contents

Acquiring ASN.1 specification

To start testing SNMP using TTCN-3, we need to at least acquire ASN.1 specification for SNMP protocol, possibly amended with an application-specific MIB. Having ASN.1 modules we can then compile them natively into OpenTTCN Repository bytecode-like format used directly for execution of test cases by OpenTTCN Virtual Machine, what enables us writing test scripts in TTCN-3 using ASN.1.

OpenTTCN ASN.1 compiler complies with the following ETSI standard: ETSI ES 201 873-7 V4.3.1 (2011-06) "Methods for Testing and Specification (MTS); The Testing and Test Control Notation version 3; Part 7: Using ASN.1 with TTCN-3".

To find out more technical details about using ASN.1 modules jointly with TTCN-3, please refer to the aforementioned ETSI standard that can be downloaded for free using the following URL: http://www.ttcn-3.org/StandardSuite.htm .

OpenTTCN ASN.1 compiler is technically a part of the importer3 command-line tool and is accessible from OpenTTCN Tester IDE as well.

Add the following core ASN.1 modules to your TTCN-3 project:

  • SNMPv2-PDU.asn1 (with modifications of the original source made by OpenTTCN marked as "OpenTTCN change")
  • Source: OpenTTCN

Add the following example MIB module (ASN.1) to your TTCN-3 project:

  • MIB-Example.asn1 (with OpenTTCN additions not found in the original RFCs marked as "OpenTTCN addition")

The above example MIB module is based on RFC 2578, RFC 3418. It represents a simplified digest of the RFC material, specifically crafted to serve as this article's example, and may not be used as an RFC-compliant normative material. OpenTTCN ASN.1 compiler supports compiling full ASN.1 MIB modules and their RFC-compliant supporting definitions as well.

Compiling ASN.1 specification

In this article we assume that the snmp testing session/project is used.

If you use OpenTTCN Tester IDE, ASN.1 modules are compiled automatically within the TTCN-3 project.

Example of compilation from the command-line (file compile.bat):

importer3 load snmp SNMPv2-PDU.asn1 SNMPv2-Message.asn1 MIB-Example.asn1

Creating coding and decoding adapter

For general-purpose information about adapter programming using OpenTTCN SDK for C#, see Creating adapter using C#.

Adapter developed in this article is limited to fulfilling SNMP-level encoding and decoding tasks only. Real-world adapters may need to handle possible encryption, authentication and transport over TCP or another bearer. These issues are discussed in greater detail in another article describing creation of adapters using Adapter Framework for C# titled Creating Adapters with Adapter Framework.

To simplify the example, we put everything into one source code file. In a real-world project it is highly recommended to refactor this functionality into several source code files.

The source code of the coding and decoding adapter is presented below.


Image:language_mapping_c_sharp.png


Observe that the developed adapter is merely a wrapper around BER Codec Component that does the main job.

BER Codec Component is identified by the http://www.openttcn.com/Codecs/2011/BER URI when it is instantiated.

Testing the coding and decoding adapter

To make sure that the developed adapter performs its coding and decoding tasks correctly, we develop a small test suite showing:

  • encoding of a TTCN-3 value into BER-codec octet stream;
  • decoding of a BER-codec octet stream to a TTCN-3 value.

As an input material for the developed test suite, we use simple request - response pair defined by GetRequest-PDU and Response-PDU, respectively, as described in chapter 4.2.1 "The GetRequest-PDU" of RFC 3416.

The source code of the codec adapter test suite is presented below:

In OpenTTCN IDE you simply add the CodecTest.ttcn file to the project. If you use command line, you need to add CodecTest.ttcn to the end of the importer3 load command in compile.bat.

After you recompile the test suite, you need to launch the codec adapter binary developed earlier in Program.cs. Consult OpenTTCN manual for questions regarding adapter compilation and startup.

When the adapter is up and running, create a Run Configuration in OpenTTCN IDE and run the CodecTest test suite. From the command line you can run the test campaign as follows:

tester run -f -l snmp @all > campaign.log

Campaign log of an example run of the test suite is presented below:

Handling BER extensions

Some BER-based protocols define protocol-specific encoding rules for portions of BER-coded data that are out of scope of the core BER specification as defined in ITU-T Rec. X.690 (07/2002) / ISO/IEC 8825-1:2003 (E) "Information technology – ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER)".

OpenTTCN BER Codec Component supports such extensions through a mechanism of encoding references defined in ITU-T Rec. X.680 (11/2008) / ISO/IEC 8824-1:2008 (E), clause 31.3, that can be attached to an ASN.1 type tag.

The list of encoding references supported by OpenTTCN BER Codec Component is presented in the table below.

Table 1: Encoding references supported by BER Codec Component
Encoding reference Effect Example type (ASN.1)

NON-SMALL-TAG-NUMBER-ENC

Instructs BER encoder to encode type tag identifier octets according to clause 8.1.2.4 of ITU-T Rec. X.690 (07/2002), i.e. as though the type tag class number had been greater than or equal to 31, even if it is less.

-- encoder constructs tag 9F01 for the type below

Type-With-Tag-9F01 ::= [NON-SMALL-TAG-NUMBER-ENC : 1] IMPLICIT OCTET STRING

Source code

You can download the full source code developed in this article by following this link.

Views
Personal tools