how to start rohc

Asked by monali on 2009-11-11

i want to implement rohc in my voip network. iive installed rohc 1.2, libnet and libpcap but not understanding how to proceed forward. Please help.

Question information

Language:
English Edit question
Status:
Answered
For:
rohc Edit question
Assignee:
No assignee Edit question
Last query:
2009-11-11
Last reply:
2011-07-25

Hi monali,

ROHC is a library not a program. You have to develop your own program that uses the ROHC library to compress/decompress VoIP packets on your network. None is available at the moment.

In the source code of the library, there is an small tunnel program to help you starting your own program. The tunnel application compresses packets captured on a computer and encapsulates them in an UDP stream to transmit them toward another computer. This not what you want to do, but it may help you doing your job. Be careful that the tunnel application is dedicated to tests, it is not recommended for production use.

Some links you might find interesting :
- See https://answers.launchpad.net/rohc/+faq/639 to learn how to test the ROHC library with the ROHC tunnel application.
- See https://answers.launchpad.net/rohc/+faq/638 to learn how to use the ROHC library in your own program.
- See this message on the mailing list (https://lists.launchpad.net/rohc/msg00035.html) for a very simple example using the ROHC library.
- See http://launchpad.net/~rohc/+join to join the ROHC mailing list, ask questions and/or report difficulties.

Regards,

Didier Barvaux
Viveris Technologies
http://www.tech.viveris.com/opensource/

sanmingshen (sanmingshen) said : #2

You can test the library with given example(pacp fomat file),and you need to set the main function's input

Khaan (pizwan80) said : #3

I have followed some of the FAQ specially "638" for a sample program to integrate RoHC. Snapshot of the code is given below, Now I want to hook into some of the variable i.e

ip_packet \\ Initial IP Packet
rohc_packet \\ Compressed Packet
ip_packet_rx \\ Received Packet after decompression.

I want to capture these packets in dump them into pcap for analysis, how and where I should change my code.

2ndly, if I replace the following IPv4 header with IPv6 header program should work, or do I have change compression/decompression libraries/functions?

With Kind Regards,
Shaan

---------------------------------------------------------------------------------------------------------------------------------
/* system includes */
#include <stdlib.h>
#include <stdio.h>

/* includes to create a fake IP packet */
#include <netinet/ip.h>
#include <string.h>

/* includes for using ROHC library */
#include <rohc.h>
#include <rohc_comp.h>
#include <rohc_decomp.h>

/** The size (in bytes) of the buffers used in the program */
#define BUFFER_SIZE 2048
#define MAX_SIZE 2048

/** The payload for the fake IP packet */
#define FAKE_PAYLOAD "hello, ROHC world!"

/**
 * @brief The main entry point for the simple ROHC program
 *
 * @param argc the number of arguments given to the program
 * on command line
 * @param argv the table of arguments given to the program
 * on command line
 * @return 0 in case of success, 1 otherwise
 */
int main(int argc, char **argv)
{
  struct rohc_comp *compressor; /* the ROHC compressor */
  struct rohc_decomp *decompressor; /* the ROHC decompressor */
  unsigned char ip_packet[BUFFER_SIZE]; /* the buffer that contains
                                             the IPv4 packet to compress */
  unsigned int ip_packet_len; /* the length (in bytes) of the
                                             IPv4 packet */
  struct iphdr *ip_header; /* the header of the IPv4 packet */
  unsigned char rohc_packet[BUFFER_SIZE]; /* the buffer that contains the
                                             resulting ROHC packet */
  int rohc_packet_len; /* the length (in bytes) of the
                                             resulting ROHC packet */
   unsigned int i;
//decomp
 //unsigned char packet[MAX_SIZE];
 // unsigned int rohc_len;
  unsigned char ip_packet_rx[MAX_SIZE];
  int ip_size;

  /* At program start-up, initialize the pre-computed tables for the 3-bit,
   * 7-bit and 8-bit CRCs that the ROHC library will use.
   *
   * Note that the crc_table_3, crc_table_7 and crc_table_8 variables are
   * declared inside the library, there is no need to declare them in your
   * source code.
   */
  crc_init_table(crc_table_3, crc_get_polynom(CRC_TYPE_3));
  crc_init_table(crc_table_7, crc_get_polynom(CRC_TYPE_7));
  crc_init_table(crc_table_8, crc_get_polynom(CRC_TYPE_8));

  /* create a ROHC compressor with small CIDs, no jamming and no adaptation
     to encapsulation frames */
  compressor = rohc_alloc_compressor(15, 0, 0, 0);
  if(compressor == NULL)
  {
      fprintf(stderr, "failed create the ROHC compressor\n");
      goto error;
  }
  /* create a ROHC compressor with small CIDs, no jamming and no adaptation
     to encapsulation frames */
  decompressor = rohc_alloc_decompressor(NULL);
  if(decompressor == NULL)
  {
      fprintf(stderr, "cannot create the ROHC decompressor\n");
      goto error;
  }

  /* enable the compression profiles you need (comment or uncomment some lines) */
  rohc_activate_profile(compressor, ROHC_PROFILE_UNCOMPRESSED);
  rohc_activate_profile(compressor, ROHC_PROFILE_UDP);
  rohc_activate_profile(compressor, ROHC_PROFILE_IP);
  //rohc_activate_profile(compressor, ROHC_PROFILE_UDPLITE);
  rohc_activate_profile(compressor, ROHC_PROFILE_RTP);

  /* create a fake IP packet for the purpose of this simple program */
  ip_header = (struct iphdr *) ip_packet;
  ip_header->version = 4; /* we create an IPv4 header */
  ip_header->ihl = 5; /* minimal IPv4 header length (in 32-bit words) */
  ip_header->tos = 0;
  ip_packet_len = ip_header->ihl * 4 + strlen(FAKE_PAYLOAD);
  ip_header->tot_len = htons(ip_packet_len);
  ip_header->id = 0;
  ip_header->frag_off = 0;
  ip_header->ttl = 1;
  ip_header->protocol = 134; /* unassigned number according to /etc/protocols */
  ip_header->check = 0; /* set to 0 for checksum computation */
  ip_header->saddr = htonl(0x01020304);
  ip_header->daddr = htonl(0x05060708);
  /* header is now built, compute the checksum */
  ip_header->check = ip_fast_csum(ip_packet, ip_header->ihl);
  /* copy the payload just after the IP header */
  memcpy(ip_packet + ip_header->ihl * 4, FAKE_PAYLOAD, strlen(FAKE_PAYLOAD));

  /* dump the IP packet on terminal */
  for(i = 0; i < ip_packet_len; i++)
  {
    printf("0x%02x ", ip_packet[i]);
    if(i != 0 && ((i + 1) % 8) == 0)
    {
      printf("\n");
    }
  }
  if(i != 0 && ((i + 1) % 8) != 0) /* be sure to go to the line */
  {
    printf("\n");
  }

  /* now, compress this fake IP packet */
  rohc_packet_len = rohc_compress(compressor,
                                  ip_packet, ip_packet_len,
                                  rohc_packet, BUFFER_SIZE);
  if(rohc_packet_len <= 0)
  {
      fprintf(stderr, "compression of fake IP packet failed\n");
      goto release_compressor;
  }

  /* dump the ROHC packet on terminal */
  for(i = 0; i < ((unsigned int) rohc_packet_len); i++)
  {
    printf("0x%02x ", rohc_packet[i]);
    if(i != 0 && ((i + 1) % 8) == 0)
    {
      printf("\n");
    }
  }
  if(i != 0 && ((i + 1) % 8) != 0) /* be sure to go to the line */
  {
    printf("\n");
  }

  /* release the ROHC compressor when you do not need it anymore */
  rohc_free_compressor(compressor);

  printf("the program ended successfully\n");
  return 0;

release_compressor:
  rohc_free_compressor(compressor);
error:
  fprintf(stderr, "an error occured during program execution, "
                  "abort program\n");

//--------------------------Decompressor----------------------------------------

/* read the ROHC packet somewhere, store it in the buffer named 'packet'
      and set its length in the 'packet_len' variable */

  ip_size = rohc_decompress(decompressor,rohc_packet, rohc_packet_len,ip_packet_rx, MAX_SIZE);
  if(ip_size <= 0)
  {
      if(ip_size == ROHC_FEEDBACK_ONLY)
      {
         // the ROHC packet contained feedback only, so there is no
         // decompressed IP data
        // manage this special case here, do not treat it as an error
      }
      else
      {
         fprintf(stderr, "decompression of packet failed\n");
       // manage the error here
      }
  }
rohc_free_decompressor(decompressor);

//------------------------------------------------------------------

  return 1;
}

> I want to capture these packets in dump them into pcap for analysis,
> how and where I should change my code.

Look at the non-regression tool in the test/non_regression/ directory for a good example.
See http://bazaar.launchpad.net/~didier-barvaux/rohc/main/view/head:/test/non_regression/test_non_regression.c

> 2ndly, if I replace the following IPv4 header with IPv6 header program
> should work, or do I have change compression/decompression libraries/functions?

It should work. There is nothing to change.

Regards,
Didier

Khaan (pizwan80) said : #5

Thank you, its a great help

On Fri, Jul 22, 2011 at 5:31 PM, Didier Barvaux <
<email address hidden>> wrote:

> Question #89639 on rohc changed:
> https://answers.launchpad.net/rohc/+question/89639
>
> Didier Barvaux proposed the following answer:
> > I want to capture these packets in dump them into pcap for analysis,
> > how and where I should change my code.
>
> Look at the non-regression tool in the test/non_regression/ directory for a
> good example.
> See
> http://bazaar.launchpad.net/~didier-barvaux/rohc/main/view/head:/test/non_regression/test_non_regression.c
>
> > 2ndly, if I replace the following IPv4 header with IPv6 header program
> > should work, or do I have change compression/decompression
> libraries/functions?
>
> It should work. There is nothing to change.
>
> Regards,
> Didier
>
> --
> You received this question notification because you are a member of ROHC
> Team, which is an answer contact for rohc.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~rohc
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~rohc
> More help : https://help.launchpad.net/ListHelp
>

Can you help with this problem?

Provide an answer of your own, or ask monali for more information if necessary.

To post a message you must log in.