SELF CONFIGURING NETWORK MONITORING LIBRARY



 

1) Description
      The Selfconflib library contains the methods that create and send activation packets. It is composed of two files:
          * selfconflib.hpp  -  Library header
          * selfconflib.cpp  -  Library source
 

2) There are 5 entities involved in every monitoring request
        (a) the source of the activation packet  [src_act]
        (b) the monitor of the traffic  [mon_trf]
        (c) the source of the traffic to be monitored  [src_trf]
        (d) the destination of the traffic to be monitored  [dst_trf]
        (e) the destination of the measurement results [dst_msr]
 

3) The Activation Packet Structure follows
|               |               |               |               |
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Magic Number                                                  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Major Version | Minor Version | Request ID                    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number               | Traffic Flags | Nr Par Struct |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type(1)       | Size(1)       | Parameter(1)                  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ...                                                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type(2)       | Size(2)       | Parameter(2)                  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ...                                                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
....
....
....
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type(N)       | Size(N)       | Parameter(N)                  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ...                                                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 

4) The currently defined parameters are
Type Size (bytes) Parameters          Description
==================================================================================
0    x            host/port           Source of traffic [src_trf]
----------------------------------------------------------------------------------
1    x            host/port           Destination of traffic [dst_trf]
----------------------------------------------------------------------------------
2    1            traffic type        IP protocol Nr (TCP, UDP, ICMP, .)
----------------------------------------------------------------------------------
3    x            host/port           Destination of measurement results [dst_msr]
----------------------------------------------------------------------------------
4    1            traffic measurement bit 0 Bidirectional Src_trf  <--> Dst_trf
                  directions          bit 1 Unidirectional Dst_trf  <-- Src_trf
                                      bit 2 Unidirectional Dst_trf --> Src_trf
----------------------------------------------------------------------------------
 

5) Methods
NAME
Description
Parameters
 SELFCONFLib() Class constructor - creates an activation packet containing the fixed part of the packet header only none
SELFCONFLib(char *msg, int msglen) Class constructor using the fields of the activation packet passed in msg. msg  =  Buffer with the packet
msglen  =  Packet length
~SELFCONFLib() Class destructor none
int createACTPKTRequest(char *dstHost, uint16_t request_id) Create an activation packet dstHost  =  Destination of the activation packet (number-and-dot notation)
request_id  =  Request identification provided by the user.
int sendACTPKTRequest(uint16_t request_id); Send the activation packet to the traffic destination host. request_id  =  Request identification provide from the user.
 return  --> Result of sending packet, if with error or not
void setACTPKTDebugLevel(int value) Set the debug level for the class value   =  value to be set
              = 0 --> no debug information (default)
              = 1 --> print debug information
actpkt_header_t *getACTPKTHeader() Get a pointer to the fixed part of the header of the activation packet return  -->  The strucutre with all header parameters
int setACTPKTSrcTrf(char *address, char *port) Set the parameter SRC_TRF - Source of Traffic address  =  IP Address in number-and-dot notation of the source of traffic
port  =  Port of the source of traffic
return  -->  Status of this operation
int getACTPKTSrcTrf(char *address, int *port) Get the parameter SRC_TRF - Source of Traffic address  =  IP Address in number-and-dot notation of the source of traffic
port   =  Port of the source of traffic
return  --> Status of this operation
int setACTPKTDstTrf(char *address, char *port) Set the parameter DST_TRF - Destination of Traffic address  =  IP Address in number-and-dot notation of the destination of traffic
port  =  Port of the destination of traffic
return  -->  Status of this operation
int getACTPKTDstTrf(char *address, int *port) Get the parameter DST_TRF - Destination of Traffic address  =  IP Address in number-and-dot notation of the destination of traffic
port  =  Port of the destination of traffic
return  -->  Status of this operation

int setACTPKTDstMsr(char *address, char *port)
Set the parameter DST_MSR - Destination of Measurement Results address  =  IP Address in number-and-dot notation of the destination of measurement results
port  =  Port of the destination of measurement results
return  -->  Status of this operation
int getACTPKTDstMsr(char *address, int *port) Get the parameter DST_MSR - Destination of Measurements Results address  =  IP Address in number-and-dot notation of the destination of measurement results
port  =  Port of the destination of measurement results
return  -->  Status of this operation
int setACTPKTTrfType(int trfType)  Set the parameter TRF_TYPE - Traffic Type trfType  =  Traffic Type based on the IANA designations
return  --> Status of this operation
int getACTPKTTrfType(int *trfType) Get the parameter TRF_TYPE - Traffic Type trfType  =  Pointer to the Traffic Type
return  --> Status of this operation

6) Code Examples

6.1) Example 1 - Constructing and sending an activation packet

// INCLUDES
#include "selfconflib.hpp"

int main(int argc, char* argv[])
{
  int debugLevel = 0;

  // Default parameters
  char DstHostAddr[ACTPKT_MAX_BUFFER_LENGTH] = "131.243.2.65"; // louie
  unsigned short request_id = 11;

  char SrcTrfAddr[ACTPKT_MAX_BUFFER_LENGTH] = "131.243.2.65"; // louie
  char SrcTrfPort[ACTPKT_MAX_BUFFER_LENGTH] = "1010";

  char DstTrfAddr[ACTPKT_MAX_BUFFER_LENGTH] = "131.243.2.65"; // louie
  char DstTrfPort[ACTPKT_MAX_BUFFER_LENGTH] = "1010";

  char DstMsrAddr[ACTPKT_MAX_BUFFER_LENGTH] = "131.243.2.65"; // louie
  char DstMsrPort[ACTPKT_MAX_BUFFER_LENGTH] = "1010";

  int TrfType = 6;
 

  // initalize the class
  SELFCONFLib lib = SELFCONFLib();

  lib.setACTPKTDebugLevel(debugLevel);

  // fill out the parameters
  if( argc > 1 ) strcpy(DstHostAddr, argv[1]);
  if( argc > 2 ) request_id = atoi(argv[2]);

  if( argc > 3 ) strcpy(SrcTrfAddr, argv[3]);
  if( argc > 4 ) strcpy(SrcTrfPort, argv[4]);

  if( argc > 5 ) strcpy(DstTrfAddr, argv[5]);
  if( argc > 6 ) strcpy(DstTrfPort, argv[6]);

  if( argc > 7 ) strcpy(DstMsrAddr, argv[7]);
  if( argc > 8 ) strcpy(DstMsrPort, argv[8]);

  if( argc > 9 ) TrfType = atoi(argv[9]);

  // create a request
  lib.createACTPKTRequest(DstHostAddr, request_id);

  // put values in the packet
  lib.setACTPKTSrcTrf(SrcTrfAddr, SrcTrfPort);
  lib.setACTPKTDstTrf(DstTrfAddr, DstTrfPort);
  lib.setACTPKTTrfType(TrfType);
  lib.setACTPKTDstMsr(DstMsrAddr, DstMsrPort);

  // send packet
  lib.sendACTPKTRequest(request_id);
  printf("\n\n++++++++++++++++++++ SCNM-TEST - PACKET SENT ++++++++++++++++++++\n");
  printf("DstHostAddr = %s  -----  Request_ID = %i\n", DstHostAddr, request_id);
  printf("SrcTrfAddr  = %s  -----  SrcTrfPort = %s\n", SrcTrfAddr, SrcTrfPort);
  printf("DstTrfAddr  = %s  -----  DstTrfPort = %s\n", DstTrfAddr, DstTrfPort);
  printf("DstMsrAddr  = %s  -----  DstMsrPort = %s\n", DstMsrAddr, DstMsrPort);
  printf("TrfType     = %i\n\n", TrfType);

} // main


6.2) Example 2 - receiving and decoding an activation packet.

int build_filename(SELFCONFLib *packet_p,
               char *mon_ip,
               char *filebuf,
               int maxlen)
{
    int reqid;
    char src_ip[17], dst_ip[17];
    int src_port, dst_port;
    int ret;
    actpkt_header_t *pkt_hdr_p;
 
    /*
     * Check filename buffer size
     *
     *  'R'  =     1
     *  reqid=     6
     *  '_'  =     1
     *  host:port=21
     *  '_' =      1
     *  host:port=21
     *  '_' =      1
     *  host=     16
     *  '\0' =     1
     * ==============
     *           69
     */
    if ( maxlen < 69 )
    {
        nl_error("%s: Filename buffer too short",__func__);
        return 0;
    }

    pkt_hdr_p = packet_p->getACTPKTHeader();
    reqid = (int)pkt_hdr_p->request_id;
    if ( -1 == packet_p->getACTPKTSrcTrf( (char*)src_ip, &src_port ) )
    {
      if ( !g_silent && g_debug )
 fprintf(stderr,"%s: No traffic source in actpkt\n",__func__);
      strcpy(src_ip,"0.0.0.0");
      src_port = 0;
    }
    if ( -1 ==  packet_p->getACTPKTDstTrf( (char*)dst_ip, &dst_port ))
    {
      if ( !g_silent && g_debug )
 fprintf(stderr,"%s: No traffic destination in actpkt\n",__func__);
      strcpy(dst_ip,"0.0.0.0");
      dst_port = 0;
    }
 
    sprintf(filebuf,"R%u_%s:%u_%s:%u_%s",
            reqid,src_ip,src_port,dst_ip,dst_port,mon_ip);

    if ( !g_silent && g_debug > 1 )
      fprintf(stderr,"%s: Filename = '%s'\n",__func__,filebuf);

    return 1;
}



SCNM Home Page