February 25, 2011

Jain SIP introduction

IM application (IP active) implementation.

There is a good article "An Introduction to the JAIN SIP API"
which can be used as first step guide for development of "IP active" component.

SIP parser application (IP passive) implementation.

However we need to use JainSIP for parsing SIP as well.
This topic is not covered in the article. But it is enough easy.

First, we need to create and initialize SipFactory and MessageFactory instances:

sipFactory = SipFactory.getInstance();
sipFactory.setPathName("gov.nist");
messageFactory = sipFactory.createMessageFactory();

Second, we need to get instance of SIPRequest or SIPResponse and initialize them by input buffer with a real SIP message.

SIPRequest sipRequest = (SIPRequest)messageFactory.createRequest(sipMessage);

How to understand if the income message request or response:

if ( sipMessage.startsWith( SIPConstants.SIP_VERSION_STRING ) ){
processResponse( sipMessage );
}
else {
processRequest( sipMessage );
}

Now we can get any information from the SIP message.

ListIterator<String> itHeaders = sipRequest.getHeaderNames();
String requestMethod = sipRequest.getMethod();

Detailed description of JainSIP API can be found here.

February 22, 2011

Basic connections and identifiers of SIP protocol

1. Transaction

"A SIP transaction occurs between a client and a server and comprises all messages from the first request sent from the client to the server up to a final (non-1xx) response sent from the server to the client." (RFC3261)

In other words the SIP transaction includes a request and all responses on it.

The  SIP transaction is identified by a branch parameter in the top of  "Via" header field and "CSeq" header field value. These identifiers are showed in the picture below in cyan color.


2. Dialog

"A dialog is a peer-to-peer SIP relationship between two UAs that persists for some time." (RFC3261)

A dialog is identified by a call identifier in "Call-ID"header field, local tag and a remote tag in "To" and "From" header fields. The identifiers are depicted in green color.


3. Session

"A multimedia session is a set of multimedia senders and receivers and the data streams flowing from senders to receivers." (RFC2327)

The session is defined by the concatenation of the SDP user name, session id, network type, address type,  and address elements in the origin field "o=". The session identifiers are showed in yellow color.

One of the best illustrated SIP introductions - Tech-invite.

In the picture below you can see example of a SIP response message.

SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.2.102:5060;branch=z9hG4bKSEC-a01a8c0-a01a8c0-1-oW11d3T02H
From: "Test 4100" <sip:4100@192.168.2.102>;tag=snl_951dhI11AG
To: <sip:49602150014101@192.168.2.70>;tag=4138389295
Call-ID: SEC11-a01a8c0-a01a8c0-1-D9KQeE4Yc8gu
CSeq: 1235 INVITE
Allow:  INVITE,ACK,CANCEL,BYE,REFER,NOTIFY,MESSAGE,UPDATE
Allow-Events: talk, hold
Contact: 49602150014101 <sip:49602150014101@192.168.2.70:5060;transport=udp>
Server: OpenStage_20_V2 R0.30.2      SIP  100120
Supported: replaces, timer
X-Siemens-Call-Type: ST-insecure
Content-Type: application/sdp
Content-Length: 265

v=0
o=MxSIP 0 814456601 IN IP4 192.168.2.70
s=SIP Call
c=IN IP4 192.168.2.70
t=0 0
m=audio 5062 RTP/AVP 8 0 101
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=silenceSupp:off - - - -
a=fmtp:101 0-15
a=ptime:20
a=sendrecv

February 4, 2011

Simple arrays in Lua language

Arrays in Lua are based on Lua's tables.

Declaration of an array:

sample_array = {}

Addition of a new element into the sample_array:

table.insert( sample_array, some_var )

How to get array size:

array_size = #sample_array

Access to the array elements ( the first element has index 1 ):

for i=1, #sample_array do
   message( sample_array[i] )
end -- for

Lua 5.1 Reference Manual

February 3, 2011

Plugin development for Wireshark

There are two types of the wireshark plugins: dissectors and taps.

The dissectors are used for specific protocol packets parsing. It is called each time when packet data should be displayed in a packet list window or in a packet details window. Documentation about dissectors development.

The tap plugins are used to collect any statistic about some protocol. It is called once for each packet. Documentation about tap plugins development.

The best guide is located on wireshark website.

Both types of the plugin can be written in C or Lua languages. All information about the Lua plugin development with examples is here.

To make and build the wireshark plugin on Windows platform it is necessary to perform some procedure. The best description is given here.

I found enough interesting article about wireshark plugin development. It gives some additional information. There is a plugin example. Although there are many good examples in wireshark/plugins directory.

I used the articles mentioned above for own plugin development. However I met some issues and I would like to describe them (Windows platform).

Tip 1. None of the sample plugins work with the official wireshark

After successful build, plugin is not loaded by wireshark. It reports about plugin loading problem. See a picture below. But it is possible to use this plugin with the wireshark built by yourself.


To solve the issue it's necessary:
  1. Open the file "config.nmake" in your developer wireshark folder, e.g. C:\wireshark\config.nmake
  2. Search for "DLL_LDFLAGS = /MANIFEST:no" and comment this line out (using "#")
  3. Compile your plugin again, a manifest file will be created in your plugin folder named "pluginName.dll.manifest"
  4. This manifest has to be included by your dll. You can either do this by typing the following command to the shell or add it somewhere in the file "makefile.nmake" (i.e. under "all:", so it is always included when "nmake... all" is called):
    mt.exe -manifest pluginName.dll.manifest -outputresource:pluginName.dll;2
Tip 2. How to debug.

Of course it is possible to use WinDbg from MS SDK. But the most convenient way is using MS Visual Studio. I just opened a source file and attached to the wireshark process. Don't forget to specify a path to debug symbol information (pdb-file). You can do this in Tools/Options/Debugging/Symbols menu.


Tip 3. Setup environment vars

I used following batch file:

@echo off
echo Adding things to the path...
set PATH=%PATH%;.
set PATH=%PATH%;d:\cygwin\bin
set HTTP_PROXY=http://proxy.yourcompany.ru:1080//

echo Setting up Visual Studio environment...
call "d:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat"

How to open and setup a run configuration for an Equinox plugin project

This note is valid for Eclipse Helios.


There is no "Open project" menu in Eclipse. To open an existing project use command File/Import.


In order to setup the Run configuration you need:
  1. Press the "Run configuration" drop down list button on a tool bar (see mark 1 in a picture below).
  2. Select the "Run configurations..." command.
  3. Deselect all items in a bundle list by pressing the "Deselect All" button (see mark 2).
  4. Select your own bundles.
  5. Press the "All Required Bundles" button to add into selection only necessary bundles (see mark 3).
  6. Finally check the "Only show selected" checkbox to filter out only selected items in the bundle list. (see mark 4)

February 2, 2011

Equinox tips and tricks

How to start Equinox from command line.

Equinox framework can be started from Windows command line by following command:

java -jar org.eclipse.osgi_3.5.2xxx.jar -console -clean

The framework file can be found in eclipse/plugins directory. A specific version will be placed instead "xxx" characters.

How to clean Equinox cache.

The Equinox framework keeps first started bundles in its cache. That is why your updates are not applied. To clean the cache you need to use a "-clean" parameter. For Windows command line please see the example in a previous clause. In a picture below you can see how to use this parameter inside Eclipse IDE. After this action you need to restart the Equinox framework.




How to get complete set of tools for plugin development

Plugin development is integrated into Eclipse JEE IDE. Don't try to use Eclipse SE.

Newest version of Eclipse


It is highly recommended to use latest version of Eclipse Helios due to enormous number of issues with OSGi.

What is a bundle URL?

The bundle URL is a path which identifies the bundle. It can look like

file:\Full_Path_To_The_Bundle

For example:

file:\C:\Java\bundle_1.0.0.jar

How to resolve a native library call in bundles?

All used native libraries should be listed in a manifest file. See the example below.

Bundle-NativeCode: lib/jnetpcap.dll;
osname = WindowsXP;
osversion = 5.1;
processor = x86

Please read the OSGi core specification (chapter 3.9) for more information.

OSGi reference framework comparision


Brief information


Felix:
Developer:                         Apache Software Foundation
License:                             Apache license 2 (FLOSS)
OSGi version:                    R4
IDE integration:                  Eclipse, NetBeans
Framework jar-file size:     400Kb

Knopflerfish / KnopflerfishPro:
Developer:                         Makewave
License:                             BSD style license (version Pro is commercial)
OSGi version:                    R4
IDE integration:                  Eclipse
Framework jar-file size:     400Kb

Eqiunox:
Developer:                         Eclipse
License:                             Eclipse Public License
OSGi version:                    R4
IDE integration:                  Eclipse
Framework jar-file size:     1200Kb

FUSE ESB 4:
It is built on Felix.
Developer:                         Progress Software Corporation
License:                             Apache license 2 (FLOSS)
OSGi version:                    R4
IDE integration:                  Eclipse
Framework jar-file size:    

It is based on Apache ServiceMix4 which uses Apache Felix.

"Enterprise IT organizations have stringent requirements for infrastructure software, and the FuseSource team addresses these needs to bridge the gap between open source projects and enterprise-class, production-ready software" 


Karaf:
It uses Felix or Equinox.
Developer:                         Apache Software Foundation
License:                             Apache license 2 (FLOSS)
OSGi version:                    R4
IDE integration:                 ?
Framework jar-file size:

Karaf can use either Apache Felix Framework or Eclipse Equinox.

OSGi services support



Service Specification
Felix     
Knopflerfish/pro   
Equinox

Core Specification




Framework Specification (all layers)
ok
ok
ok
Framework Launching
ok
ok
ok
7 Package Admin Service
ok
ok
ok
8 Start Level Service
ok
ok
ok
9 Conditional Permission Admin
ok
ok
ok
10 Permission Admin Service
ok
ok
ok
11 URL Handlers Service
ok
ok
ok
12 Service Hooks
ok
ok
ok

Compendium Specification




101 Log Service
ok
ok
ok
102 Http Service
ok
ok
ok
103 Device Access
no
ok
ok
104 Configuration Admin Service
ok
ok
ok
105 Metatype Service
ok
ok
ok
106 Preferences Service
ok
ok
ok
107 User Admin Service
no
ok
ok
108 Wire Admin Service
no
ok
ok
109 IO Connector Service
no
ok
ok
110 Initial Provisioning
no
ok
ok
111 UPnP™ Device Service
ok
ok
no
112 Declarative Services
ok
ok
ok
113 Event Admin Service
ok
ok
ok
114 Deployment Admin
no
no/ ok
no
115 Auto Configuration
no
no/ ok
no
116 Application Admin
no
no/ ok
no
117 DMT Admin Service
no
no/ ok
no
119 Monitor Admin Service
no
no/ ok
no
120 Foreign Application Access
no
no/ ok
no
121 Blueprint Container
no
no
no
701 Tracker Specification
no
ok
no
702 XML Parser Service Specification
no
ok
no
703 Position Specification
no
ok
no
704 Measurement and State
no
ok
no
999 Execution Environment



Enterprise Specification




13 Remote Services
no
no
no
122 Remote Service Admin Service
no
no
no
123 JTA Transaction Services
no
no
no
124 JMX™ Management Model
no
no
no
125 JDBC™ Service
no
no
no
126 JNDI Services
no
no
no
127 JPA Service
no
no
no
128 Web Applications
no
no
no
129 SCA Configuration Type
no
no
no


I couldn't find application benchmark tests for the OSGi frameworks. The OSGi Alliance publishes test cases to test compliance, not performance. The Knopflerfish has a regression test suite. It is located here