Main Page | Class List | Directories | File List | Class Members

Diameter MIP v4 Application API

Version1.0.7

Author:
Miriam Tauil
Date:
Created: February 10, 2005

Introduction

The libdiametermip4 library provides a C++ API to Diameter MIP v4 (Mobile IP v4 Protocol) Application. The library implements the specification defined in draft-ietf-aaa-diameter-mobileip-20.txt. This document describes the API.

Basic Features

Client and server sessions applicable for the Diameter MIP application:

The above session classes are implemented as templates, which accepts as a parameter a "User Defined Class" providing the relevant MIP implementation or AAA Server functionality implementation.

The MIP implementation should be defined by derriving the user defined class from the interfaces defined in the following files:

The AAA Server functionality implementation should be defined by derriving the user defined class from the interface defined in the following file:

Also the FA and HA client sessions should interface with relevant Diameter-MIP sessions using the relevant interface in the following files (notification of MIP registration request arrival):

Sample Programs

Four sample programs are provided to demostrate the use of the four main Diameter-MIP sessions in two typical scenarions:

1. Mobile Node in Co-Located Mode

2. Mobile Node sending AMR through a Foreign Agent

Scenario 1: Mobile Node in Co-Located Mode

This scenario includes running the HA client program and the AAA server program.

Home Agent Client Session Sample Program:

/* BEGIN_COPYRIGHT                                                        */
/*                                                                        */
/* Open Diameter: Open-source software for the Diameter and               */
/*                Diameter related protocols                              */
/*                                                                        */
/* Copyright (C) 2002-2004 Open Diameter Project                          */
/*                                                                        */
/* This library is free software; you can redistribute it and/or modify   */
/* it under the terms of the GNU Lesser General Public License as         */
/* published by the Free Software Foundation; either version 2.1 of the   */
/* License, or (at your option) any later version.                        */
/*                                                                        */
/* This library is distributed in the hope that it will be useful,        */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
/* Lesser General Public License for more details.                        */
/*                                                                        */
/* You should have received a copy of the GNU Lesser General Public       */
/* License along with this library; if not, write to the Free Software    */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
/* USA.                                                                   */
/*                                                                        */
/* In addition, when you copy and redistribute some or the entire part of */
/* the source code of this software with or without modification, you     */
/* MUST include this copyright notice in each copy.                       */
/*                                                                        */
/* If you make any changes that are appeared to be useful, please send    */
/* sources that include the changed part to                               */
/* diameter-developers@lists.sourceforge.net so that we can reflect your  */
/* changes to one unified version of this software.                       */
/*                                                                        */
/* END_COPYRIGHT                                                          */

/* Author   : Miriam Tauil
 * Synopsis : Home Agent Client Session application test 
 */


/******************************************************************************

This sample application demostrates the use of the Diameter MIPv4 library, 
implemented as part of the Open Diameter project.

This specific application shows the use of the Diameter MIPv4 Home Agent
 Client Session. It allows the use of different MIPv4 implementations. 
The MIPv4 implementation needs to follow a specific interface specified in
 the file : diameter_mip4_ha_client_interface.hxx .

The DiameterMip4HaClientSession is a C++ template that accepts as an argument 
a MipHaClientsession object. As mentioned above, the class of this object 
needs to follow the interface in:  diameter_mip4_ha_client_interface.hxx .

The following message flow (Scenario 1) is implemented in this application:
Mobile Node in Co-Located Mode

                      AAAS
                      ^ |
                  AMR | | AMA  
                      | |
                      | V
        MIP-Reg-Req            
   MN ---------------> HA
      <--------------
        MIP-Reg-Reply


This sample application, for simplicity,demostrates only the HA CLIENT session.
(HA server session is demostrated in scenario 2, has_test. A real HA will 
include the functionality of the 2 sample applications: hac_test and has_test)
******************************************************************************/
/*
There are 2 ways to allocate the DiameterMip4HaClientSession:
=============================================================

1. Using the "new" operator. If this option is used the virtual function 
  Abort() needs to be implemented, and should contain the command:
  delete DiameterMip4HaClientSession. 
  The reason for the implementation of the Abort() function is to allow 
  memory deallocation consistently with the allocation method.

  For example:

 typedef DiameterMip4HaClientSession<XyzHaClientSession> DiameterMip4Session;

 class MyDiameterMip4Session::public DiameterMip4Session {

   public:
     MyDiameterMip4Session(AAAApplicationCore &appCore):
        DiameterMip4Session(appCore){}

     void Abort() {delete this}

 };


int main(int argc, char *argv[]) 
{
   ...
   // allocation
   DiameterMip4Session _diameterMip4Session = new MyDiameterMip4Session(appCoreRef);
   ...

   // deallocation
   _diameterMip4Session.Abort();

}

==============================================================

2. The other option will allocate the variable for the DiameterMip4Session from
the stack, which will be automatically deallocated when the main program exists.
In this case the virtual empty Abort() function in the DiameterMip4Session,
does not need to be called or implemented.

 For example:

 typedef DiameterMip4HaClientSession<XyzHaClientSession> DiameterMip4Session;

 // no need to defined an additional class inherited from DiameterMip4Session

int main(int argc, char *argv[]) 
{
   ...
   // allocation
   DiameterMip4Session _diameterMip4Session(appCoreRef);
   ...

   // automatic deallocation, 
   // or it is possible to call Abort(), implemented 
   // as calling the destructor: ~_dimeterMip4Session();

}

========================================================================
========================================================================
Additionally to the 2 option of memory allocation for the object
DiameterMip4Session, the application can allocate DiameterMip4Session objects 
  as they are required, and discarde them as the session teminates 

OR 
The DiameterMip4Session objects can be instantiated at the beginning of 
the main application and they can be used and reused as needed. This option
is illustrated in the second section in the code below:#ifdef MULTIPLE_SESSIONS.

The first option is illustrated for handling only one session in the section
#ifndef MULTIPLE_SESSIONS.

******************************************************************************/


#include "xyz_ha_client_session.hxx"
#include "../include/diameter_mip4_ha_client_session.hxx"

  typedef DiameterMip4HaClientSession<XyzHaClientSession> DiameterMip4Session;

int main(int argc, char *argv[]) 
{
 
   /*
    * The main test program is straightforward. It
    * processes all arguments passed to it then 
    * creates the appropriate number of sessions.
    * The sessions are being used as the MIP registrations are 
    * received. When the Diameter session terminates the State Machine 
    * sets the state to StInitialize, and the object is available again 
    * for a new session.
    * 
    * The number of sessions as well as the authorizing
    * host and realm is passed in as arguments. Also,
    * the configuration file is an argument.
    *
    * This application should act on triggering events: 
    * receiving MIP registration requests.  For simplicity, the content 
    * of the MIP registration requests are statically specified. 
    */

   if (argc != 5) {
      ACE_DEBUG((LM_DEBUG, "(%P|%t) Client: Usage: hac_test [AAA Server host] [AAA Server realm] [num session] [config file]\n"));
      return (1);
   }

   int howManySessions = atoi(argv[3]);
   if (howManySessions <= 0) {
      ACE_ERROR((LM_ERROR, "(%P|%t) Client: Invalid number of sessions\n"));
      return (1);
   }

  ACE_DEBUG((LM_DEBUG, "(%P|%t) HA Client: Application starting\n"));

   AAA_Task myTask;
   try {
      myTask.Start(10);
   }
   catch (...) {
      ACE_ERROR((LM_ERROR, "(%P|%t) Client: Cannot start task\n"));
      return (1);
   }

  AAAApplicationCore appCore;   
  if (appCore.Open(argv[4], myTask) != AAA_ERR_SUCCESS) {
      ACE_ERROR((LM_ERROR, "(%P|%t) Client: Application core open config file error\n"));
      return (1);
   }
  
   AAAApplicationCore &appCoreRef= appCore;

   // Primitive wait. Waiting for the client to
   // establish connection with the peers
   while (appCore.GetNumActivePeerConnections() == 0);

#define MULTIPLE_SESSIONS

#ifndef MULTIPLE_SESSIONS
   // this needs to be done for ' howManySessions'
    DiameterMip4Session _diameterMip4Session( appCoreRef);   
    _diameterMip4Session.SetDestinationHost( argv[1]);
    _diameterMip4Session.SetDestinationRealm( argv[2]);

    _diameterMip4Session.Start();

   diameter_octetstring_t _mipRegReq = "123456678788999009009-0-900-90908989809898980980978676766567564cffvtfghgfvbhbnhgjff";
   _diameterMip4Session.RxMipRegReq( _mipRegReq);

   while (1)
     {
     ACE_OS::sleep(100);
     }

#endif


#ifdef MULTIPLE_SESSIONS

   DiameterMip4Session *_diameterMip4SessionPtr[howManySessions];

   for (int i=0; i<howManySessions; i++)
   {
     (_diameterMip4SessionPtr[i]) = new DiameterMip4Session( appCoreRef);   
     (*(_diameterMip4SessionPtr[i])).SetDestinationHost( argv[1]);
     (*(_diameterMip4SessionPtr[i])).SetDestinationRealm( argv[2]);
   }

   // For each Mip registration request received assigned a free
   // DiameterMip4Session and pass it the content of the Registration Request
   int newMipRegReq = 1;
   DiameterMip4Session *nextSession = 0;

   while ( newMipRegReq )
     {
       for ( int i=0; i<howManySessions ; i++)  // loop through the array
         {
           if ( (*(_diameterMip4SessionPtr[i])).State() == 
                (*(_diameterMip4SessionPtr[i])).InitialState()  )
             {
               nextSession = _diameterMip4SessionPtr[i]; 
               break;
             }
         }

       if (nextSession == 0 )
         {
           // error handling for no session available to handle new MIP Reg Req
           // ...
         }
       else
         {
           diameter_octetstring_t _mipRegReq = "AAAAAAABBBBBBBBCCCCCCCCC";
           (* nextSession).RxMipRegReq( _mipRegReq);
         }
     }

   // should be in exit function
   for (int i=0; i<howManySessions; i++)
   {
     delete (_diameterMip4SessionPtr[i]);
   }
#endif // MULTIPLE_SESSIONS
     return (0);
}



AAA Server Sample Program:

/* BEGIN_COPYRIGHT                                                        */
/*                                                                        */
/* Open Diameter: Open-source software for the Diameter and               */
/*                Diameter related protocols                              */
/*                                                                        */
/* Copyright (C) 2002-2004 Open Diameter Project                          */
/*                                                                        */
/* This library is free software; you can redistribute it and/or modify   */
/* it under the terms of the GNU Lesser General Public License as         */
/* published by the Free Software Foundation; either version 2.1 of the   */
/* License, or (at your option) any later version.                        */
/*                                                                        */
/* This library is distributed in the hope that it will be useful,        */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
/* Lesser General Public License for more details.                        */
/*                                                                        */
/* You should have received a copy of the GNU Lesser General Public       */
/* License along with this library; if not, write to the Free Software    */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
/* USA.                                                                   */
/*                                                                        */
/* In addition, when you copy and redistribute some or the entire part of */
/* the source code of this software with or without modification, you     */
/* MUST include this copyright notice in each copy.                       */
/*                                                                        */
/* If you make any changes that are appeared to be useful, please send    */
/* sources that include the changed part to                               */
/* diameter-developers@lists.sourceforge.net so that we can reflect your  */
/* changes to one unified version of this software.                       */
/*                                                                        */
/* END_COPYRIGHT                                                          */

/* Author   : Miriam Tauil
 * Synopsis : AAA Server application test 
 */

#include "diameter_specific_aaas_server_interface.hxx"


int main(int argc, char *argv[])
{
   /*
    * This sample server test program is straight forward.
    * After creating an instance of the application core
    * and passing it the configuration file, it registers
    * a class factory for handling requests with application
    * id Mip4ApplicationId. The the configuration filename is passed in as
    * an argument.
    *
    * The functionality that is specific to the AAA server is 
    * specified in "diameter_specific_aaas_server_interface.hxx". 
    * This file includes a very thin implementation, mainly providing fixed 
    * values to different paramenters. The implementor can use this example to
    * create an interface to a real AAA server.

    * This program will create the AAA Server server session (accepting an AMR)
    * if the Mobile Node is NOT in co-located mode, it will create a client 
    * session (sending and HAR to the Home Agent).
    
    * Providing the AAA Server functionality with the interface specified in 
    * "diameter_specific_aaas_server_interface.hxx" or 
    * "diameter_mip4_aaas_server_interface.hxx" 
    * this sample application can act as a AAA server Diameter-MIP application.
    * 
    * With the following implementation, every time the a message with
      Mip4applicationId arrives, 
       if it belongs to an existing session => the msg is passed to the session
       if its SessionId is new to the server => it will create a new session 
          obj, and the message will be passed to the session message handler.

     The HandleDisconnect method of the session object needs to deallocate 
     itself, since the openDiameter library only removes the session from its
     internal database,but it is the responsability of the application creating
     the session to deallocate it.

    * Another option to implement the server is to create the maximum number
    of sessions that this server will handle simultanously , and when a session
    terminates the session will be flaged as an unused session, which will 
    be reused when the server receives a msg related to a new session.

    This can be implemented by overwriting the "create" method in the 
    AAAServerSessionClassFactory. The create method is going to create a new 
    server session object only if there is no unused session object and 
    number of session objects did not exceed the maximum limit.

    In this case the HandleDisconnect method of the session object needs 
    flag the session object as unused, so the "create" function can make use 
    of it when needed. 
    The exit routine will need to deallocate all the session objects
    previously allocated.
    
    * On exit, the factory should be removed
    * from the application core and the application cores
    * destructor will perform internal cleanup.
    *
    */

   if (argc != 2) {
      ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Usage: aaas_server_test [config file]\n"));
      return (1);
   }

   ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Application starting\n"));
   AAA_Task myTask;
   try {
      myTask.Start(10);
   }
   catch (...) {
      ACE_ERROR((LM_ERROR, "(%P|%t) Server: Cannot start task\n"));
      return (1);
   }
   AAAApplicationCore myCore;
   if (myCore.Open(argv[1], myTask) != AAA_ERR_SUCCESS) {
      ACE_ERROR((LM_ERROR, "(%P|%t) Server: Application core open error\n"));
      return (1);
   }


   /* 
    * application id is for this sample
    */

   typedef DiameterMip4AaaSServerSession<SpecificMip4AaaSServer>  DiameterMip4SpecificServer;

    AAAServerSessionClassFactory<DiameterMip4SpecificServer> authFactory( myCore, Mip4ApplicationId );

   /*
    * Register the factory to our application core.
    * All request with application id Mip4ApplicationId will be
    * handled here.
    */
   myCore.RegisterServerSessionFactory(&authFactory);

   /*
    * This will block indefinetly.
    * It should be improved providing an exit routine.
    */

   while (1)
     {
       ACE_OS::sleep (10);
     }

   // removing the session factory will go in the exit routine. 
   myCore.RemoveServerSessionFactory(&authFactory);

   ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Exiting\n"));
   
   return (0);
}






Scenario 2: Mobile Node sending AMR through a Foreign Agent

This scenario includes running the FA client program, HA server program and the same AAA Server program run for the first scenario.

Foreign Agent Client Session Sample Program:

/* BEGIN_COPYRIGHT                                                        */
/*                                                                        */
/* Open Diameter: Open-source software for the Diameter and               */
/*                Diameter related protocols                              */
/*                                                                        */
/* Copyright (C) 2002-2004 Open Diameter Project                          */
/*                                                                        */
/* This library is free software; you can redistribute it and/or modify   */
/* it under the terms of the GNU Lesser General Public License as         */
/* published by the Free Software Foundation; either version 2.1 of the   */
/* License, or (at your option) any later version.                        */
/*                                                                        */
/* This library is distributed in the hope that it will be useful,        */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
/* Lesser General Public License for more details.                        */
/*                                                                        */
/* You should have received a copy of the GNU Lesser General Public       */
/* License along with this library; if not, write to the Free Software    */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
/* USA.                                                                   */
/*                                                                        */
/* In addition, when you copy and redistribute some or the entire part of */
/* the source code of this software with or without modification, you     */
/* MUST include this copyright notice in each copy.                       */
/*                                                                        */
/* If you make any changes that are appeared to be useful, please send    */
/* sources that include the changed part to                               */
/* diameter-developers@lists.sourceforge.net so that we can reflect your  */
/* changes to one unified version of this software.                       */
/*                                                                        */
/* END_COPYRIGHT                                                          */

/* Author   : Miriam Tauil
 * Synopsis : Foreign Agent Client Session application test 
 */


/******************************************************************************

This sample application demostrates the use of the Diameter MIPv4 library, 
implemented as part of the Open Diameter project.

This specific application shows the use of the Diameter MIPv4 Foreign Agent
 Client Session. It allows the use of different MIPv4 implementations. 
The MIPv4 implementation needs to follow a specific interface specified in
 the file : diameter_mip4_fa_client_interface.hxx .

The DiameterMip4FaClientSession is a C++ template that accepts as an argument 
a MipFaClientsession object. As mentioned above, the class of this object 
needs to follow the interface in:  diameter_mip4_fa_client_interface.hxx .

The following message flow (Scenario 2) is implemented in this application:
Mobile Node sending AMR through a Foreign Agent

                              AAAH 
                             ^ /  \ ^
                            / /    \ \
                           / /   HAR\ \HAA  
                     AMR  / /AMA     \ \          
                         / /          \ \         
        MIP-Reg-Req     / V            V \
   MN ---------------> FA               HA
      <--------------
        MIP-Reg-Reply


******************************************************************************/
/*

There are 2 ways to allocate the DiameterMip4FaClientSession:
=============================================================

1. Using the "new" operator. If this option is used the virtual function 
  Abort() needs to be implemented, and should contain the command:
  delete DimeterMip4FaClientSession. 
  The reason for the implementation of the Abort() function is to allow 
  memory deallocation consistently with the allocation method.

  For example:

 typedef DiameterMip4FaClientSession<XyzFaClientSession> DiameterMip4Session;

 class MyDiameterMip4Session::public DiameterMip4Session {

   public:
     MyDiameterMip4Session(AAAApplicationCore &appCore):
        DiameterMip4Session(appCore){}

     void Abort() {delete this}

 };


int main(int argc, char *argv[]) 
{
   ...
   // allocation
   DiameterMip4Session _diameterMip4Session = new MyDiameterMip4Session(appCoreRef);
   ...

   // deallocation
   _diameterMip4Session.Abort();

}

==============================================================

2. The other option will allocate the variable for the DiameterMip4Session from
the stack, which will be automatically deallocated when the main program exists.
In this case the virtual empty Abort() function in the DiameterMip4Session,
does not need to be called or implemented.

 For example:

 typedef DiameterMip4FaClientSession<XyzFaClientSession> DiameterMip4Session;

 // no need to defined an additional class inherited from DiameterMip4Session

int main(int argc, char *argv[]) 
{
   ...
   // allocation
   DiameterMip4Session _diameterMip4Session(appCoreRef);
   ...

   // automatic deallocation, 
   // or it is possible to call Abort(), implemented 
   // as calling the destructor: ~_dimeterMip4Session();

}

========================================================================
========================================================================
Additionally to the 2 option of memory allocation for the object
DiameterMip4Session, the application can allocate DiameterMip4Session objects 
  as they are required, and discarde them as the session teminates 

OR 
The DiameterMip4Session objects can be instantiated at the beginning of 
the main application and they can be used as reused as needed. This option 
is illustrated in the second section in the code below:#ifdef MULTIPLE_SESSIONS

The first option is illustrated for handling only one session in the section
#ifndef MULTIPLE_SESSIONS.


******************************************************************************/


#include "xyz_fa_client_session.hxx"
#include "../include/diameter_mip4_fa_client_session.hxx"

  typedef DiameterMip4FaClientSession<XyzFaClientSession> DiameterMip4Session;

int main(int argc, char *argv[]) 
{
 
   /*
    * The main test program is straightforward. It
    * processes all arguments passed to it then 
    * creates the appropriate number of sessions.
    * The sessions are being used as the MIP registrations are 
    * received. When the Diameter session terminates the State Machine 
    * sets the state to StInitialize, and the object is available again 
    * for a new session.
    * 
    * The number of sessions as well as the authorizing
    * host and realm is passed in as arguments. Also,
    * the configuration file is an argument.
    *
    * This application should act on triggering events: 
    * receiving MIP registration requests.  For simplicity, the content 
    * of the MIP registration requests are statically specified. 
    */

   if (argc != 5) {
      ACE_DEBUG((LM_DEBUG, "(%P|%t) Client: Usage: fac_test [AAA Server host] [AAA Server realm] [num session] [config file]\n"));
      return (1);
   }

   int howManySessions = atoi(argv[3]);
   if (howManySessions <= 0) {
      ACE_ERROR((LM_ERROR, "(%P|%t) Client: Invalid number of sessions\n"));
      return (1);
   }

  ACE_DEBUG((LM_DEBUG, "(%P|%t) FA Client: Application starting\n"));

   AAA_Task myTask;
   try {
      myTask.Start(10);
   }
   catch (...) {
      ACE_ERROR((LM_ERROR, "(%P|%t) Client: Cannot start task\n"));
      return (1);
   }

  AAAApplicationCore appCore;   
  if (appCore.Open(argv[4], myTask) != AAA_ERR_SUCCESS) {
      ACE_ERROR((LM_ERROR, "(%P|%t) Client: Application core open config file error\n"));
      return (1);
   }
  
   AAAApplicationCore &appCoreRef= appCore;

   // Primitive wait. Waiting for the client to
   // establish connection with the peers
   while (appCore.GetNumActivePeerConnections() == 0);

#define MULTIPLE_SESSIONS
#ifndef MULTIPLE_SESSIONS
   // this needs to be done for ' howManySessions'
    DiameterMip4Session _diameterMip4Session( appCoreRef);   

    // Destination will be set to the user Home AAA, by MIP implementation,
    // based on the content of MIP req.

    _diameterMip4Session.Start();

   diameter_octetstring_t _mipRegReq = "123456678788999009009-0-900-90908989809898980980978676766567564cffvtfghgfvbhbnhgjff";
   _diameterMip4Session.RxMipRegReq( _mipRegReq);

   while (1)
     {
     ACE_OS::sleep(100);
     }
#endif
#ifdef MULTIPLE_SESSIONS
   // For each Mip registration request received assigned a free
   // DiameterMip4Session and pass it the content of the Registration Request
   int newMipRegReq = 1;
   DiameterMip4Session *nextSession = 0;

   DiameterMip4Session *_diameterMip4SessionPtr[howManySessions];


   for (int i=0; i<howManySessions; i++)
   {
     (_diameterMip4SessionPtr[i]) = new DiameterMip4Session( appCoreRef);   
     (*(_diameterMip4SessionPtr[i])).Start();
   }

   while ( newMipRegReq )
     {
       for ( int i=0; i<howManySessions ; i++)  // loop through the array
         {
           if ( (*(_diameterMip4SessionPtr[i])).State() == 
                DiameterMip4Session::InitialState()  )
             {
               nextSession = _diameterMip4SessionPtr[i]; 
               break;
             }
         }

       if (nextSession == 0 )
         {
           // error handling for no session available to handle new MIP Reg Req
           printf("ERR: FA client is handling the maximum number of sessions\n");
         }
       else
         {
           diameter_octetstring_t _mipRegReq = "MIP REGISTRATION CONTENT: XXXYYYYZZZZ";
           (* nextSession).RxMipRegReq( _mipRegReq);
         }

       newMipRegReq = 0;
     }


   // should be in exit function
   for (int i=0; i<howManySessions; i++)
   {
     delete (_diameterMip4SessionPtr[i]);
   }
#endif // MULTIPLE_SESSIONS
     return (0);
}



Home Agent Server Session Sample Program:

/* BEGIN_COPYRIGHT                                                        */
/*                                                                        */
/* Open Diameter: Open-source software for the Diameter and               */
/*                Diameter related protocols                              */
/*                                                                        */
/* Copyright (C) 2002-2004 Open Diameter Project                          */
/*                                                                        */
/* This library is free software; you can redistribute it and/or modify   */
/* it under the terms of the GNU Lesser General Public License as         */
/* published by the Free Software Foundation; either version 2.1 of the   */
/* License, or (at your option) any later version.                        */
/*                                                                        */
/* This library is distributed in the hope that it will be useful,        */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
/* Lesser General Public License for more details.                        */
/*                                                                        */
/* You should have received a copy of the GNU Lesser General Public       */
/* License along with this library; if not, write to the Free Software    */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
/* USA.                                                                   */
/*                                                                         */
/* In addition, when you copy and redistribute some or the entire part of */
/* the source code of this software with or without modification, you     */
/* MUST include this copyright notice in each copy.                       */
/*                                                                        */
/* If you make any changes that are appeared to be useful, please send    */
/* sources that include the changed part to                               */
/* diameter-developers@lists.sourceforge.net so that we can reflect your  */
/* changes to one unified version of this software.                       */
/*                                                                        */
/* END_COPYRIGHT                                                          */

/* Author   : Miriam Tauil
 * Date     : January 4, 2005
 * Synopsis : MIP4 Home Agent Server application test (accepts HAR)
 */
#include "diameter_api.h"
#include "diameter_mip4_parser.hxx"
#include "xyz_ha_server_session.hxx"
#include "diameter_mip4_ha_server_session.hxx"


int main(int argc, char *argv[])
{
   /*
    * This sample server test program is straight forward.
    * After creating an instance of the application core
    * and passing it the configuration file, it registers
    * a class factory for handling requests with application
    * id Mip4ApplicationId. The the configuration filename is passed in as
    * an argument.
    * 
    * With the following implementation, every time the a message with
      Mip4applicationId arrives, 
       if it belongs to an existing session => the msg is passed to the session
       if its SessionId is new to the server => it will create a new session 
          obj, and the message will be passed to the session message handler.

     The HandleDisconnect method of the session object needs to deallocate 
     itself, since the openDiameter library only removes the session from its
     internal database,but it is the responsability of the application creating
     the session to deallocate it.

    * Another option to implement the server is to create the maximum number
    of sessions that this server will handle simultanously , and when a session
    terminates the session will be flaged as an unused session, which will 
    be reused when the server receives a msg related to a new session.

    This can be implemented by overwriting the "create" method in the 
    AAAServerSessionClassFactory. The create method is going to create a new 
    server session object only if there is no unused session object and 
    number of session objects did not exceed the maximum limit.

    In this case the HandleDisconnect method of the session object needs 
    flag the session object as unused, so the "create" function can make use 
    of it when needed. 
    The exit routine will need to deallocate all the session objects
    previously allocated.
    
    * On exit, the factory should be removed
    * from the application core and the application cores
    * destructor will perform internal cleanup.
    *
    */

   if (argc != 2) {
      ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Usage: has_test [config file]\n"));
      return (1);
   }

   ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Application starting\n"));
   AAA_Task myTask;
   try {
      myTask.Start(10);
   }
   catch (...) {
      ACE_ERROR((LM_ERROR, "(%P|%t) Server: Cannot start task\n"));
      return (1);
   }
   AAAApplicationCore myCore;
   if (myCore.Open(argv[1], myTask) != AAA_ERR_SUCCESS) {
      ACE_ERROR((LM_ERROR, "(%P|%t) Server: Application core open error\n"));
      return (1);
   }

   typedef DiameterMip4HaServerSession<XyzHaServerSession>  DiameterMip4XyzHaServer;

    AAAServerSessionClassFactory<DiameterMip4XyzHaServer> authFactory( myCore, Mip4ApplicationId );


   /*
    * Register the factory to our application core.
    * All request with application id Mip4ApplicationId will be
    * handled here.
    */
   myCore.RegisterServerSessionFactory(&authFactory);

   /*
    * This will block indefinetly.
    * It should be improved providing an exit routine.
    */

   while (1)
     {
       ACE_OS::sleep (10);
     }

   // removing the session factory will go in the exit routine. 
   myCore.RemoveServerSessionFactory(&authFactory);

   ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Exiting\n"));
   
   return (0);
}







Generated on Thu Apr 7 09:08:51 2005 for Diameter Mobile IP v4 C++ API by  doxygen 1.4.2