Showing posts with label diameter. Show all posts
Showing posts with label diameter. Show all posts

Mobicents Diameter has a new home.. powered by git!

Wednesday, July 4, 2012 em 01:12
Due to the increasingly number and complexity of sub-projects, Mobicents has been splitting it's projects under independent project homes.

We are now at a transition stage, where each project lead will migrate his project at the appropriate time. For Diameter, after our major release (1.4.0.FINAL), it seemed the best time to do this migration.

The new home of the Mobicents Diameter project is located at http://code.google.com/p/jdiameter/. Feel free to visit us!

With this change, we have also taken the chance to move to a "better" and more powerful version control system, so we have changed from SVN to Git. We hope this will ease the contributions, which have been happening more often, thanks to out thriving community!

Despite being a allegedly better VCS, Git also has it's own shortcomings, such as not being able to checkout a single folder. The lack of this feature has impacted our structure, since it makes it impossible to independently release sub-components in the same Git repository.

While digging for a solution, I've came across the "sparse checkout" feature. While this may work for checking out only some folder(s), it is not supported by maven release plugin, thus not fixing the main problem. Another possible (and probably more correct) solution would be to use the "sub-repository" approach, where we'd split the components into different sub-repositories.

We actually did this on a first phase, but after realizing the big changes it would imply and being aware that google code messes with the automatic revision links (http://code.google.com/p/support/issues/detail?id=3245) we have decided to revert back to the single repository approach and abdicate from the release independency for each component. We have barely used it, anyway. The only exception is for the Jopr RHQ Plugin, so it got it's own sub-repository.

As a reference for someone going through the same process of moving from a [googlecode] SVN repository to a [googlecode] git repository, I'll leave a summary of the commands used for the move (please keep in mind that I'm totally new to git, so these may not be the optimal way, feel free to comment):

0. (optional) Since SVN only lists the username and git uses the email as well, the migration will cause weird authors such as "brainslog <brainslog@bf0df8d0-2c1f-0410-b170-bd30377b63dc>" it may be good to sanitize the authors. For that I've used the following script in the SVN repository:
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt

And then I've fixed the outcome in authors.txt to the correct: username = Full Name .

1. Clone the new (and probably empty) repository
git clone https://@code.google.com/p/jdiameter/ git-jdiameter

2. Clone from SVN (with authors fixed) to the cloned git repository, with full history, tags and branches
git svn clone -A authors.txt -Ttrunk/servers/diameter -ttags/servers/diameter -bbranches/servers/diameter https://mobicents.googlecode.com/svn git-jdiameter

Where -A points to the authors file, -T to the trunk of the SVN repository, -t to the tags and -b to the branches. Use only what you need, I didn't needed the branches part as we don't have any.

3. Enter the local git repository
cd git-jdiameter

4. Push!
git push --all

5. Create the git tags from SVN tags (I know this can be automatized but I needed to make some customizations to existing tags, as not all were correct)
git tag "1.0.0.BETA1" "refs/remotes/tags/jdiameter-1.0.0.BETA1"
...
git tag "1.0.0.FINAL" "refs/remotes/tags/1.0.0.FINAL"

6. Push.. again!
git push --tags

These are the 7 magical steps! In case that you don't care about history, simply do a "svn export --force http://mobicents.googlecode.com/svn/trunk/servers/diameter/ git-jdiameter" and push it, nothing else. Also, as mentioned, I did not had branches but I suppose they'd make it in the #4 push.

Mobicents Diameter users working with trunk master, must now switch to this new repository as the SVN will not be updated anymore! Do a "git clone https://code.google.com/p/jdiameter/" and hack away!

Mobicents Diameter 1.4.0.FINAL Released!

Monday, June 4, 2012 em 17:47
The Mobicents Diameter 1.4.0.FINAL has been released today (announcement), and it represents the last mile in a long enhancement, refactoring and improvement journey. A lot of features have been added along the way:
  • Improved Cluster Support with fine-grained data per Diameter Application;
  • Support for more 3GPP Applications (Gq', Rx, Gx, S6a) and improved/updated existing;
  • Support for Diameter RELAY / PROXY / REDIRECT Agents;
  • Performance improvement of over 9 times (now handling up to 9000 requests/second in Dev Machine, C2D @ 3.06GHz / 4GB RAM, no special setup);
  • Added several configuration parameters to optimize for different scenarios (regular usage vs high load vs small footprint, etc);
  • 100+ miscellaneous fixes to improve overall compliance and stability of the Mobicents Diameter Stack and it's JAIN SLEE Resource Adaptors;
  • Also important, Mobicents (including Diameter) license has changed from GPL to LGPL, which is generally good news for the users!
Still, there's a lot of work and improvements to be done for the upcoming 1.4.x series. To name a few:
  • Support for TLS security in Mobicents Diameter Stack (existing in 1.4.0.FINAL as experimental);
  • Support for  SCTP transport in Mobicents Diameter Stack (initial patch already contributed);
  • Support pluggable Load Balancing algorithms for Mobicents Diameter Stack; Integrate with Mobicents Load Balancer;
  • Create integration/real-world examples, eg, integrate with Mobicents JAIN SLEE B2BUA, continue work on Mobicents HSS and integrate it with Mobicents SIP Presence;
  • Improve documentation for developers using Mobicents Diameter Stack;
As you can see, there's a lot that has been improved but there's also a lot more to improve on, with our ambition aiming higher. Feel free to help us with your feedback and contributions to a better Mobicents Diameter!

Mobicents Diameter 1.4.0.BETA2 is out!

Monday, July 11, 2011 em 13:16
It's been a while since the last Mobicents Diameter release, but it's finally here, the latest and greatest! This is a special release as it is the one with the most community contribution. Thanks to all the contributors for showing the value of open-source!

- Enhanced Stability: 30+ issues regarding stack functionality were  identified and fixed, providing a more stable and usable stack;
- Improved Compliance: Better and stricter compliance to specifications, resulting in a more compatible and strict stack;
- Gq' Application Support: Another valuable 3GPP application, Gq', is now supported both in Diameter Stack and in Mobicents JAIN SLEE, with it's Resource Adaptor. Thanks to Yulian Oifa for his contribution;
 - Better Cluster Support: Improved cluster support by updating to the latest Mobicents Cluster framework and fixed replication related issues; 
 - Experimental Agent Support: Initial support for experiments with supporting RELAY, PROXY and REDIRECT agents;
 - Extended Testsuite: Over 100 new JUnit tests were added to the testsuite in order to guarantee the best compliance and continuous regression testing.

Note: This is a BETA release as there are API and deep core changes happening, but it's been thoroughly tested, with the testsuite extended to cover more than ever, including message flows for all applications both in standalone and cluster mode!

Full release notes here.

Visit Mobicents Diameter website here.

Mobicents is now LGPL 2.1

Wednesday, March 2, 2011 em 12:16
After several discussions and shared thoughts between the Mobicents team and the community, it has been decided to align the Mobicents license with the remaining JBoss projects, changing to the LGPL 2.1 Open Source license!

Mobicents SIP Servlets was already using such license, but now it is applied to ALL Mobicents Projects (Diameter, JAIN SLEE, Media Server, SS7, etc), effective March 1, 2011.

We hope the community enjoys the change!

Developing an Offline Charging Application with Mobicents Diameter

Monday, January 24, 2011 em 15:01

Introduction
A couple of months ago, the Mobicents Diameter Team decided to start a series of educational posts regarding Diameter development using Mobicents Diameter solution.

Bartosz Baranowski has kicked-off with the "Creating a "Hello World" Application with Mobicents Diameter" article where two things were addressed:
  • Explaining some basics of the Diameter protocol such as Diameter Nodes, Realms, Applications, Messages, AVPs, Sessions and all those fundamental concepts that hopefully helps to make sense out of this;
  • A step-by-step example on how to create server and client instances for a Diameter Application (a fictitious Application was used to exemplify) using Mobicents Diameter. It includes detailed code explanation and it's a good read as a preparation for this one if you're new on the subject.
In this second post, we will learn how easy it is to create an Offline Charging Application using Mobicents Diameter. Also, for those not familiar with what is Offline Charging (and Online Charging as well) a brief introduction will be provided.

Fasten your seatbelt, the ride is about to begin!

Offline and Online Charging. What's that about?
Online Charging is the name used by 3GPP for pre-paid charging in the IMS scope. It is the charging which occurs in real-time, where the service cost is deducted from the user balance (which has been previously loaded by the user) while the service is going on. In IMS this is the Ro interface, and is defined by 3GPP TS 32.299 (and extending RFC 4006 - Diameter Credit Control Application).

On the other hand, Offline Charging is the 3GPP name for post-paid charging, where the provided services are not paid at the time of their usage but rather in a periodic manner, such as at the end of each month. However, while the service is on course, it's usage is logged as a Call Detail Record (CDR) that will be processed later by a Billing system. This corresponds to the IMS interface Rf, defined also by 3GPP TS 32.299 (inheriting from Diameter Base Accounting in RFC 3588).

The CDR generation is the responsibility of an Offline Charging Server.

Please keep in mind that while we are using the Online/Offline terminology introduced by 3GPP for IMS, this post does not intend to focus on IMS details, and so, we will only use the Diameter Base Accounting Application, allowing to simplify the exchanged messages and provide a more straightforward tutorial.

The Messages and AVPs
The messages exchanged for offline charging, as defined in RFC 3588 - Section 9.7, are only two: Accounting-Request (ACR) and Accounting-Answer (ACA), with Command-Code 271.

While only a pair of Request/Answer is defined, it can be used with different purposes, depending on the value of the Accounting-Record-Type AVP (code 480). This AVP can have the following values:
  • EVENT_RECORD (1) - Defines that this is charging for a one-time event, such as a sent SMS;
  • START_RECORD (2) - In a service with a measurable length (eg: voice call) this value defines that such service has started;
  • INTERIM_RECORD (3) - In a service with the above characteristics, this ACR type provides cumulative accounting information;
  • STOP_RECORD (4) - This is used to inform that a service with measurable length has terminated and to provide cumulative accounting information regarding it.
Another meaningful AVP is the Acct-Interim-Interval AVP (code 85) where it is specified the interval at which intermediate records should be produced, by sending ACR messages with Accounting-Record-Type set to INTERIM_RECORD. The absence of it, or a value of 0, means that no intermedite records are needed.

An important note is that Base Accounting does not define any service-specific AVPs, as it is not intended to be a usable Application but rather the base for the ones being defined. As such, we will 'abuse' from User-Name AVP, and piggyback the Subscription and Service identifiers into it, in the form ".@mobicents.org".

Putting it all together!
Assuming you already know how to configure and set up the stack in your Java project (which has been explained by Bartosz on the first post of these educational series), let's start by defining the interface for our Charging Client enabler, to be used by the applications:
package org.mobicents.diameter.simulator.client;

public interface OfflineChargingClient {

  // Accounting-Record-Type Values --------------------------------------------
  static final int ACCOUNTING_RECORD_TYPE_EVENT    = 1;
  static final int ACCOUNTING_RECORD_TYPE_START    = 2;
  static final int ACCOUNTING_RECORD_TYPE_INTERIM  = 3;
  static final int ACCOUNTING_RECORD_TYPE_STOP     = 4;

  /**
   * Sends an Accounting-Request with Accounting-Record-Type set to "2" and the 
   * corresponding Subscription-Id and Service-Id AVPs filled accordingly.
   * 
   * @param subscriptionId the String value to be used for Subscription-Id AVP
   * @param serviceId the String value to be used for Service-Id AVP
   * @throws Exception
   */
  public abstract void startOfflineCharging(String subscriptionId, String serviceId)
    throws Exception;

  /**
   * Sends an Accounting-Request with Accounting-Record-Type set to "3" and the
   * corresponding Subscription-Id and Service-Id AVPs filled accordingly.
   * 
   * @param subscriptionId the String value to be used for Subscription-Id AVP
   * @param serviceId the String value to be used for Service-Id AVP
   * @throws Exception
   */
  public abstract void updateOfflineCharging(String subscriptionId, String serviceId)
    throws Exception;

  /**
   * Sends an Accounting-Request with Accounting-Record-Type set to "4" and the
   * corresponding Subscription-Id and Service-Id AVPs filled accordingly.
   * 
   * @param subscriptionId the String value to be used for Subscription-Id AVP
   * @param serviceId the String value to be used for Service-Id AVP
   * @throws Exception
   */
  public abstract void terminateOfflineCharging(String subscriptionId, String serviceId) 
    throws Exception;

  /**
   * Sends an Accounting-Request with Accounting-Record-Type set to "1" and the
   * corresponding Subscription-Id and Service-Id AVPs filled accordingly.
   * 
   * @param subscriptionId the String value to be used for Subscription-Id AVP
   * @param serviceId the String value to be used for Service-Id AVP
   * @throws Exception
   */
  public abstract void eventOfflineCharging(String subscriptionId, String serviceId)
    throws Exception;

  /**
   * Sets the listener to receive the callbacks from this charging client. 
   * @param listener an OfflineChargingClientListener implementor to be the listener
   */
  public abstract void setListener(OfflineChargingClientListener listener);

}
Also, we will need the applications to implement the Listener interface, in order to receive the callbacks from the Offline Charging Enabler. The interface to be implemented is quite simple, with only one method for the callback:
package org.mobicents.diameter.simulator.client;

/**
 * Listener interface to be implemented by applications 
 * wanting to have Offline Accounting
 */
public interface OfflineChargingClientListener {

  /**
   * Callback method invoked by Offline Charging Client to deliver answers
   * 
   * @param subscriptionId the String value identifying the user
   * @param serviceId the String value identifying the service
   * @param sessionId a String value identifying the accounting session
   * @param accountingRecordType the type of Accounting Record the answer refers to
   * @param accountingRecordNumber the Accounting Record number the answer refers to
   * @param resultCode the Result-Code value obtained from the answer
   * @param acctInterimInterval the interval in seconds to send updates
   */
  public void offlineChargingAnswerCallback(String subscriptionId, 
      String serviceId, String sessionId, int accountingRecordType, 
      long accountingRecordNumber, long resultCode, long acctInterimInterval);
  
}
The implementation for the OfflineChargingClient (not complete, just the basics to understanding) is the following:
public class OfflineChargingClientImpl implements OfflineChargingClient, 
    NetworkReqListener, EventListener<Request, Answer>, 
    StateChangeListener<AppSession>, ClientAccSessionListener {

  // Application Id -----------------------------------------------------------
  private static final ApplicationId ACCOUNTING_APPLICATION_ID = 
    ApplicationId.createByAccAppId(0, 3);

  // Configuration Values -----------------------------------------------------
  private static final String SERVER_HOST = "127.0.0.1";

  private static String REALM_NAME = "mobicents.org";

  private SessionFactory sessionFactory;
  private AccSessionFactoryImpl accountingSessionFactory;
  private OfflineChargingClientListener listener;

  private ConcurrentHashMap<String, ClientAccSession> acctSessions = 
    new ConcurrentHashMap<String, ClientAccSession>(); 
  private ConcurrentHashMap<String, Integer> acctRecNumberMap = 
    new ConcurrentHashMap<String, Integer>(); 
  
  public OfflineChargingClientImpl() throws Exception {
    // Initalize Stack
    ...
  }
At this point we just define some constants, configuration values and variables to be used later. We define two maps to allow us to keep sessions and Accounting-Record-Number values stored in the enabler. This could be moved client-side if desired.
We will next define some auxiliary methods to assit in common operations, such as creating Accounting-Requests, retrieving the appropriate Accounting-Record-Number, etc.
// Aux Methods --------------------------------------------------------------

  /**
   * Gets an accounting record number for the specified user+service id
   * @param identifier the user+service identifier
   * @param isStart indicates if it's an initial record, which should be set to 0
   * @return the accounting record number to be used in the AVP
   */
  private int getAccountingRecordNumber(String sessionId, boolean isStart) {
    // An easy way to produce unique numbers is to set the value to 0 for
    // records of type EVENT_RECORD and START_RECORD, and set the value to 1
    // for the first INTERIM_RECORD, 2 for the second, and so on until the 
    // value for STOP_RECORD is one more than for the last INTERIM_RECORD.
    int accRecNumber = 0;
    if(!isStart) {
      accRecNumber = acctRecNumberMap.get(sessionId);
      accRecNumber = accRecNumber++;
    }

    acctRecNumberMap.put(sessionId, accRecNumber);
    
    return accRecNumber;
  }
  
  /**
   * Creates an Accounting-Request with the specified data.
   * 
   * @param session the session to be used for creating the request 
   * @param accRecordType the type of Accounting Record (Event, Start, Interim, Stop)
   * @param username the value to be used in the User-Name AVP
   * @return an AccountRequest object with the needed AVPs filled
   * @throws InternalException
   */
  private AccountRequest createAccountingRequest(ClientAccSession session, 
      int accRecordType, int accRecNumber, String username) throws InternalException {
    AccountRequest acr = new AccountRequestImpl(session, accRecordType, accRecNumber,
        REALM_NAME, SERVER_HOST);

    // Let's 'abuse' from User-Name AVP and use it for identifying user@service
    AvpSet avps = acr.getMessage().getAvps();
    avps.addAvp(Avp.USER_NAME, username, false);

    return acr;
  }
  
  /**
   * Method for creating and sending an Accounting-Request
   * 
   * @param identifier the user+service identifier to be used in the User-Name AVP
   * @param accRecType the type of Accounting Record (Event, Start, Interim, Stop)
   * @throws Exception
   */
  private void sendAccountingRequest(ClientAccSession session, String identifier,
      int accRecType, int accRecNumber) throws Exception {
    // Create Accounting-Request
    AccountRequest acr = createAccountingRequest(session, accRecType, accRecNumber, 
      identifier);
    
    // Send it
    session.sendAccountRequest(acr);
  }

  /**
   * Aux method for generating a unique identifier from subscription and service ids
   * @param subscriptionId the subscription id to be used
   * @param serviceId the service id to be used
   * @return the generated unique identifier
   */
  private String getIdentifier(String subscriptionId, String serviceId) {
    return subscriptionId + "." + serviceId + "@" + REALM_NAME;
  }
And finally we can do the real implementation for the Offline Charging Client which, hopefully, became a bit simpler.
// Offline Charging Client Implementation -----------------------------------
  
  public void setListener(OfflineChargingClientListener listener) {
    this.listener = listener;
  }

  public void startOfflineCharging(String subscriptionId, String serviceId)
      throws Exception {
    // Create new session to send start record
    ClientAccSession session = (ClientAccSession) accountingSessionFactory.
      getNewSession(null, ClientAccSession.class, ACCOUNTING_APPLICATION_ID,
      new Object[]{});

    // Store it in the map
    acctSessions.put(session.getSessionId(), session);
    
    // Get the account record number
    int accRecNumber = getAccountingRecordNumber(session.getSessionId(), true);
    
    sendAccountingRequest(session, getIdentifier(subscriptionId, serviceId), 
        ACCOUNTING_RECORD_TYPE_START, accRecNumber);
  }

  public void interimOfflineCharging(String subscriptionId, String serviceId, 
      String sessionId) throws Exception {
    // Fetch existing session to send interim record
    ClientAccSession session = this.acctSessions.get(sessionId);

    // Get the account record number
    int accRecNumber = getAccountingRecordNumber(session.getSessionId(), false);
    
    sendAccountingRequest(session, getIdentifier(subscriptionId, serviceId), 
        ACCOUNTING_RECORD_TYPE_INTERIM, accRecNumber);
  }

  public void stopOfflineCharging(String subscriptionId, String serviceId,
      String sessionId) throws Exception {
    // Fetch existing session  (and remove it from map) to send stop record
    ClientAccSession session = this.acctSessions.remove(sessionId);
    
    // Get the account record number (and remove)
    int accRecNumber = getAccountingRecordNumber(session.getSessionId(), false);
    this.acctRecNumberMap.remove(session.getSessionId());

    sendAccountingRequest(session, getIdentifier(subscriptionId, serviceId), 
        ACCOUNTING_RECORD_TYPE_STOP, accRecNumber);
  }

  public void eventOfflineCharging(String subscriptionId, String serviceId) 
      throws Exception {
    // Create new session to send event record
    ClientAccSession session = (ClientAccSession) accountingSessionFactory.
      getNewSession(null, ClientAccSession.class, ACCOUNTING_APPLICATION_ID, 
      new Object[]{});

    // No need to store Session or Accounting-Record-Number as it's a one-shot.

    sendAccountingRequest(session, getIdentifier(subscriptionId, serviceId), 
        ACCOUNTING_RECORD_TYPE_EVENT, 0);
  }

  // Client Acc Session Listener Implementation -------------------------------
  
  public void doAccAnswerEvent(ClientAccSession appSession, AccountRequest request, 
      AccountAnswer answer) throws InternalException, IllegalDiameterStateException,
      RouteException, OverloadException {

    // Extract interesting AVPs
    AvpSet acaAvps = answer.getMessage().getAvps();
    
    String subscriptionId = null;
    String serviceId = null;
    try {
      String username = acaAvps.getAvp(Avp.USER_NAME).getUTF8String();
      // It's in form subscription.service@REALM_NAME
      String[] identifiers = username.replaceFirst("@" + REALM_NAME, "").split("\\.");
      subscriptionId = identifiers[0];
      serviceId = identifiers[1];
    }
    catch (Exception e) {
      e.printStackTrace();
    }

    // Get the session-id value
    String sessionId = appSession.getSessionId();

    // We must be able to get this, it's mandatory
    int accRecType = -1;
    try {
      accRecType = answer.getAccountingRecordType();
    }
    catch (Exception e) {
      e.printStackTrace();
    }

    // We must be able to get this, it's mandatory
    long accRecNumber = -1L;
    try {
      accRecNumber = answer.getAccountingRecordNumber();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    
    // If we can't get it we'll fallback to DIAMETER_UNABLE_TO_COMPLY (5012)
    long resultCode = 5012L;
    try {
      resultCode = answer.getResultCodeAvp().getUnsigned32();
    }
    catch (AvpDataException e) {
      e.printStackTrace();
    }

    // Here we fallback to 0, it means the same as omitting 
    long acctInterimInterval = 0;
    try {
      acctInterimInterval = acaAvps.getAvp(Avp.ACCT_INTERIM_INTERVAL).getUnsigned32();
    }
    catch (AvpDataException e) {
      e.printStackTrace();
    }

    // Invoke the callback to deliver the answer
    listener.offlineChargingAnswerCallback(subscriptionId, serviceId, sessionId, 
        accRecType, accRecNumber, resultCode, acctInterimInterval);
  }

  public void doOtherEvent(AppSession appSession, AppRequestEvent request, 
      AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, 
      RouteException, OverloadException {
    // We can ignore this
  }
Given the above implementation of what can be seen as the enabler for offline charging, now our Example Application should implement the following state machine using the enabler:

So let's get our hands dirty with the example application implementation, which should implement the above specified listener interface:
package org.mobicents.diameter.simulator.client;

import static org.mobicents.diameter.simulator.client.OfflineChargingClient.*;

public class ExampleApplication implements OfflineChargingClientListener  {

  // Internal Client State Machine --------------------------------------------
  private static final int STATE_IDLE                  = 0;
  private static final int STATE_START_ACR_SENT        = 2;
  private static final int STATE_START_ACA_SUCCESS     = 4;
  private static final int STATE_INTERIM_ACR_SENT      = 6;
  private static final int STATE_INTERIM_ACA_SUCCESS   = 8;
  private static final int STATE_STOP_ACR_SENT         = 10;
  private static final int STATE_STOP_ACA_SUCCESS      = 12;
  private static final int STATE_EVENT_ACR_SENT        = 14;
  private static final int STATE_EVENT_ACA_SUCCESS     = 16;
  private static final int STATE_END                   = 18;
  private static final int STATE_ERROR                 = 99;

  private int currentState = STATE_IDLE;

  public static void main(String[] args) throws Exception {
    ExampleApplication app = new ExampleApplication(new OfflineChargingClientImpl());
    app.occ.startOfflineCharging("", "");
  }

  private OfflineChargingClient occ;

  public ExampleApplication(OfflineChargingClient occ) {
    this.occ = occ;
    occ.setListener(this);
  }

  public void offlineChargingAnswerCallback(String subscriptionId, String serviceId, 
      String sessionId, int accountingRecordType, long accountingRecordNumber, 
      long resultCode, long acctInterimInterval) {
    // Handle the EVENT situation
    if(accountingRecordType == ACCOUNTING_RECORD_TYPE_EVENT) {
      if(this.currentState == STATE_EVENT_ACR_SENT) {
        if(resultCode == 2001) {
          this.currentState = STATE_EVENT_ACA_SUCCESS;
          System.out.println("(((o))) Event Offline Charging for user '"+ subscriptionId +
              "' and service '" + serviceId + "' completed! (((o)))");
          // and now just to be correct...
          this.currentState = STATE_END;          
        }
      }
      else {
        this.currentState = STATE_ERROR;
        throw new RuntimeException("Unexpected message received.");
      }
    }
    // Handle START / INTERIM / STOP situation
    else {
      switch(this.currentState) {
      // Receiving an Answer at any of these states is an error
      case STATE_IDLE:
      case STATE_EVENT_ACA_SUCCESS:
      case STATE_START_ACA_SUCCESS:
      case STATE_INTERIM_ACA_SUCCESS:
      case STATE_STOP_ACA_SUCCESS:
        // At any of these states we don't expect to receive an ACA, move to error.
        this.currentState = STATE_ERROR;
        break;
        // We've sent ACR EVENT
      case STATE_START_ACR_SENT:
        if(accountingRecordType == ACCOUNTING_RECORD_TYPE_START) {
          if(resultCode >= 2000 && resultCode < 3000) {
            // Our event charging has completed successfully. We're done!
            System.err.println("(((o))) Offline Charging for user '" + subscriptionId +
                "' and service '" + serviceId + "' started... (((o)))");

            if(acctInterimInterval > 0) {
              try {
                // Let's sleep until next interim update...
                Thread.sleep(acctInterimInterval * 1000);

                // We send an update at the correct time
                occ.interimOfflineCharging(subscriptionId, serviceId, sessionId);
              }
              catch (Exception e) {
                this.currentState = STATE_ERROR;
                throw new RuntimeException("Unable to schedule/send interim update.", e);
              }
            }
          }
          else {
            // It failed
            System.err.println("(((x))) Offline Charging for user '" + subscriptionId + 
                "' and service '" + serviceId + "' failed with Result-Code="+ resultCode +
                "! (((x)))");
          }
        }
        else {
          this.currentState = STATE_ERROR;
          throw new RuntimeException("Unexpected message received.");
        }
        break;
        // We've sent ACR START
      case STATE_INTERIM_ACR_SENT:
        if(accountingRecordType == ACCOUNTING_RECORD_TYPE_INTERIM) {
          if(resultCode >= 2000 && resultCode < 3000) {
            // Our offline charging has started successfully...
            System.out.println("(((o))) Offline Charging for user '" + subscriptionId +
                "' and service '" + serviceId + "' updated... (((o)))");

            if(acctInterimInterval > 0) {
              try {
                // Let's sleep until next interim update...
                Thread.sleep(acctInterimInterval);

                // We send an update at the correct time
                occ.interimOfflineCharging(subscriptionId, serviceId, sessionId);
              }
              catch (Exception e) {
                this.currentState = STATE_ERROR;
                throw new RuntimeException("Unable to schedule/send interim update.", e);
              }
            }
          }
          else {
            // It failed, let's warn the application
            System.out.println("(((x))) Offline Charging for user '" + subscriptionId +
                "' and service '" + serviceId + "' failed to start with Result-Code=" +
                resultCode + "! (((x)))");
          }
        }
        else {
          this.currentState = STATE_ERROR;
          throw new RuntimeException("Unexpected message received.");
        }
        break;
      case STATE_STOP_ACR_SENT:
        if(accountingRecordType == ACCOUNTING_RECORD_TYPE_INTERIM) {
          if(resultCode >= 2000 && resultCode < 3000) {
            // Our offline charging has started successfully...
            System.out.println("(((o))) Offline Charging for user '" + subscriptionId +
                "' and service '" + serviceId + "' stopped! (((o)))");
          }
          else {
            // It failed, let's warn the application
            System.out.println("(((x))) Offline Charging for user '" + subscriptionId +
                "' and service '" + serviceId + "' failed to stop with Result-Code=" +
                resultCode + "! (((x)))");
          }
        }
        else {
          this.currentState = STATE_ERROR;
          throw new RuntimeException("Unexpected message received.");
        }
        break;
      default:
        this.currentState = STATE_ERROR;
        throw new RuntimeException("Unexpected message received.");
      }
    }
  }
}
As it can be seen it turns to be really simple to implement such Application using Offline Charging in this way. The above application also provides an enhancement, which is to automatically wait and send the interim ACR updates (lines 73-85 and 107-119). That obviously is a design choice, which can be changed if control over that behavior is intended.

Conclusion
As this article was meant to demonstrate it's simple to add Offline Accounting to your applications using Mobicents Diameter solution. Several options (and scenarios) were simplified in order to keep the example easier to understand and follow the steps, as well as to give a better understanding of the Mobicents Diameter solution, while still rendering a completely functional solution.

You can learn more about Mobicents Diameter at http://www.mobicents.org/diameter/.

Mobicents Team Meeting 2010 @ Antalya, Turkey

Saturday, October 16, 2010 em 00:28

Yes, this paradisal venue (Alva Donna Resort & SPA at Belek, Antalya, Turkey) was where the 2010 Mobicents Face-to-Face Meeting was held, 24th - 30th September. Thanks to Eduardo Martins for arranging the trip, it was the best _ever_ for several reasons: It was the first time we managed to gather all the team together, ranging from a couple of hours travelling to some doing it in a day and half! But I'm sure it worth every minute!

Also, this was the first (and certainly not the last!) time we had customers and community users joining our technical meetings and providing the most valuable feedback for our products and their roadmap. It's a whole new perspective and for that, we can only say: Thank You!


It was also the one we had more entertainment available, from the first day rafting to the resort's nightly shows, several swimming pools, sliders, jetski, bowling, etc etc. It sure was a lot of fun!


But we had to work too (a lot :-)) between all this fun. We had presentations for the main Mobicents projects, mostly regarding the past, present and future of each project, ie, what we achieved in the last year, the current status of each project in terms of stability, performance and features and the plans for the upcoming year. Also we had some project-wide presentations, such as clustering which affects most of the projects.



For my main project, Mobicents Diameter, we had a crash course to give a quick introduction to what it is all about and it's role in the telco world (something to be explored here too, promised!) presented by Bartosz Baranowski and after, I did the presentation regarding the achievements and roadmap. In sum, this was a great year for Mobicents Diameter:

  • 8 Releases, 3 of them being major ones, with important features introduced (JBoss 5 support; JAIN SLEE 1.1 Resource Adaptors; High-Availability/Fault-Tolerant Stack and Resource Adaptors)
  • Management Console based on RHQ
  • 400% Performance improvement ( > 800 requests/second )
  • Complete User Guide Documentation
  • .. and some more!
We had quite a good set of achievements, I would say! But we have a lot more to achieve in the future. We are focusing on the stability and performance of our solution, extend the testsuite and interop with other Diameter products to ensure complete compliance with the protocol and applications. We have defined two different goals:
  • Continue work on the 1.x.y series, providing it with stability and better performance;
  • Start a 2.x.y series, where we intend to change several internal components as well as redesigning the API to make it more easy and intuitive to work with, probably also providing a high-level abstraction to the Diameter protocol to provide simple charging. This is something to be discussed among the community to understand the direction to follow
You can find the Diameter presentation here.

Regarding the other project where I participate, Mobicents JAIN SLEE, we had also an excellent year of work, with great achievements. You can read more in detail on Eduardo's post.

So, this was it. It was a blast! Counting the days for the next meeting, looking forward to see even more community users joining us!

The Greatest (Vladimir and Tom are missing :-\) -- Görüşmek üzere! (See you soon, in Turkish ;-))



Installing Jopr/RHQ and Mobicents JAIN SLEE (or Diameter) Plugin

Wednesday, July 21, 2010 em 02:05
As it seems that some users don't find the task of installing and configuring Mobicents JAIN SLEE / Diameter Management consoles as plugins for Jopr/RHQ easy, I've decided to make a blog post explaining how to do it.

But if an image worths more than 1.000 words, how many words can a video worth? :) Hopefully, a lot, because I've just recorded one that I hope it helps to better understand how it should be done.

Still, I will point the main actions to be executed and the time they occur at the video, for faster reference.

Here it is, right from the Mobicents Channel @ Vimeo:

Installing Jopr/RHQ and Mobicents JAIN SLEE 2.x Plugin (click to watch in HD)

  1. [00:00] Download RHQ Server from http://www.rhq-project.org/ and Unzip rhq-server-3.0.0.zip to any directory of your choice;
  2. [00:50] In a terminal, go to "rhq-server-3.0.0/bin" inside the extracted folder and run "rhq-server.[bat|sh] console", depending on your OS;
  3. [01:30] Go to http://127.0.0.1:7080/ and install the server (don't forget to select your database);
  4. [03:15] Login with default credentials (rhqadmin/rhqadmin), go to Downloads and Download the "Agent Installer";
  5. [04:00] In a new terminal, go to the directory where the Agent Installer was downloaded and issue the command "java -jar rhq-enterprise-agent-3.0.0.jar --install" to install it;
  6. [04:35] In the same terminal go to rhq-agent/bin (where it was installed) and run "rhq-agent.[bat|sh] --clean" (use --clean to make sure you will use a fresh configuration). Default values should be fine;
  7. [05:30] In the web interface, go to Administration > System Configuration > Plugins, click "Add" and browse to the Mobicents JAIN SLEE / Diameter Plugin location and click "Upload". When done, click "Scan for Updates";
  8. [07:45] If not yet running, start yout JAIN SLEE / Diameter Server;
  9. [09:30] In the RHQ Agent terminal, issue "plugins update" to update the agent plugins (download the JAIN SLEE / Diameter plugin to the agent);
  10. [11:10] Now that the plugins are updated, and with the JAIN SLEE / Diameter Server running, in the Agent terminal issue the "discovery" command to find new resources;
  11. [11:35] In the web interface, go to Overview > Auto Discovery Queue, locate the Server, check it and click "Import"
  12. [12:45] Still at the webpage, head to Resources > Servers. Click on the server entry to manage it. Enjoy!

Simple, isn't it ? Hope it is now.. It's time to have fun, managing and monitoring Mobicents Servers via Jopr/RHQ ;-)

For details on what you can do with these plugins, please refer to the documentation found in the binaries releases of the servers.

Mobicents Diameter 1.1.2.GA: Introducing Diameter Jopr Plugin

Friday, February 26, 2010 em 11:49
We've just released a new spin for Mobicents Diameter, v1.1.2.GA.

It happened on 21st of February and along with the usual bug fixing and improvements, there's a great addition to the suite: The Mobicents Diameter Jopr Plugin.

Jopr is an enterprise management solution which provides administration, monitoring, alerting, operational control and configuration in an enterprise setting with fine-grained security and an advanced extension model.

The Mobicents Diameter Jopr Plugin provides the following functionalities:

  • Stack configuration and management
    • Provides means of changing stack parameters, such as various timeout values, duplicate protection, accept undefined peers, thread pools size, etc.;
    • Start/Stop stack, Enable/Disable validation
  • Local peer configuration and statistics
    • Allows change of local peer IP Address and URI, Realm name, supported Application-Ids, etc.;
    • Real time statistics regarding memory usage
  • Network Peers management and statistics
    • Provides ability to add and remove Network Peers;
    • Statistics regarding requests/answer sent and/or received (total and per minute), Average time for message processing, Number of messages waiting on queue, number of messages failed to send/receive, etc.
  • Realms configuration and management
    • Allow runtime realm configuration, ie, change realm name, Peers list, Application Ids, etc.;
    • Add and remove Realms

All these functionalities plus the added value by Jopr, which provides availability for each component (Stack, Local Peer, Network Peers and Realms), alert configuration, intuitive graphs and some more cool and intuitive features makes this a great companion for the Diameter suite!

Regarding installation and configuration of Jopr and the plugin, while we are working at the documentation for it, you can follow JAIN SLEE Jopr Plugin User Guide (Installing Jopr and Mobicents JAIN SLEE Plugin chapter) since it's the exact same procedure.

Here are some screenshots of the plugin in action:

 

 

 

Enjoy!

Installing Seagull on Mac OS X

Sunday, November 22, 2009 em 04:29
Ahh... Nothing like a rainy Saturday to get in the mood for some tasks that were delayed for too long!

As I was getting ready to watch the soccer match between FC Porto (my team) and Oliveirense, at Oliveirense's stadium, the referee decided that there were no conditions (really bad pitch, also due to the rain) for the game to happen... well, I had to do something... :-)

Installing Seagull (the network traffic generator, useful for my Diameter tests) in my iMac was one of those tasks that I could never find the time, and today it seemed a good day. I knew it was not going to be a simple task, as I've tried sometime ago to install (ie, build from source) under Ubuntu or some other Linux distro and never made it... but I didn't tried hard either, as there are RHEL/Fedora binaries I just setup a VM with it.

OK.. So, first step was to look for someone who had already done the job... couldn't find any, seems like Mac's are not chosen as dev machines very often. No binaries, no instructions. I'm on my own.

The INSTALL.TXT has some instructions on how to build it... the commands to run. I'll do it as I like to: run until it crashes and see what's wrong after. First instruction is:
Edit build.conf to fit your needs (default should be OK)

If it says it should be OK, it should be OK. Let's move on.
run "./build.ksh -target clean"

Just to make sure everything is clean. Not a problem, no issues here. Next!
run "./build.ksh -target all"

This is where the "fun" began. It simply failed with some  generic failure message:
[Begin Makefile generation phase]
[Creating symbolic link: /Users/ammendonca/Desktop/seagull/bin]
[Making directory: /Users/ammendonca/Desktop/seagull/work-1.8.1]
[Making directory: /Users/ammendonca/Desktop/seagull/build-1.8.1]
make: *** [/Users/ammendonca/Desktop/seagull/work-1.8.1/project.mk] Error 1
 
[Begin compilation phase]
make: *** No rule to make target `all'.  Stop.

Nice, isn't it? Not much clues of what and where it is failing. After running some pieces of the make script by itself, I got to ./work-1.8.1/compiler.mk file where it said "Compiler variable for OS DARWIN not defined".

For adding this information, it was needed to edit the ./build.conf afterall :-). So I just copied all the (...)_LINUX entries and renamed them to _DARWIN, et voilá. It worked.

Next ran, next failure:
[Compiling protocol-external/C_ProtocolExternal.cpp]
[Compiling protocol-text/C_MessageText.cpp]
cc1plus: warnings being treated as errors
protocol-text/C_MessageText.cpp: In member function 'C_ProtocolFrame::_msg_error_code C_MessageText::EncodeWithContentLength(int)':
protocol-text/C_MessageText.cpp:62: warning: format '%d' expects type 'int', but argument 4 has type 'size_t'
make[1]: *** [/Users/ammendonca/Desktop/seagull/work-1.8.1/C_MessageText.o] Error 1
make: *** [all_seagull] Error 2

This was a pretty simple and obvious one. Just learned how size_t should be printed, it's with %Zd instead of the %d that is present. Made that change at line 62 of ./protocol-text/C_MessageText.cpp and that's it!

One step closer... but not there yet:
[Compiling /Users/ammendonca/Desktop/seagull/work-1.8.1/y.tab.c]
y.tab.c: In function 'int yyparse()':
y.tab.c:1349: error: 'yylex' was not declared in this scope
y.tab.c:1587: error: 'yyerror' was not declared in this scope
y.tab.c:1733: error: 'yyerror' was not declared in this scope
make[1]: *** [/Users/ammendonca/Desktop/seagull/work-1.8.1/y.tab.o] Error 1
make: *** [all_seagull] Error 2

Checking the referred y.tab.c I've checked it declared those methods only if some vars (__linux__ OR __CYGWIN__) were declared. This should be some compiler info as my friend grep didn't found any reference on the seagull sources. Googled a little bit and just found what it was and so I checked it should be __APPLE__ for my system.

A previous message showed that this y.tab.c file was being generated and, so, with the help of grep I managed to find out that it came from ./xml-parser/xml_definition.y, at line 38. Changed
#if defined(__linux__) || defined(__CYGWIN__)
to
#if defined(__linux__) || defined(__CYGWIN__) || defined(__APPLE__)

It was almost there... got the binary seagull already linked in the ./bin folder! Good news, but still some required lib is failing to link:
[Linking /Users/ammendonca/Desktop/seagull/build-1.8.1/libtrans_ip.so]
Undefined symbols:
  "_main", referenced from:
      start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: *** [/Users/ammendonca/Desktop/seagull/build-1.8.1/libtrans_ip.so] Error 1
make: *** [all_libtrans_ip.so] Error 2

Boooring! Thought this could be it... so much work and now some weird linkage error was going to throw it all away. Well.. can't give up, tried some own ideas... then went googling, nothing much useful, every linkage error seems to have this same output.

Since it referred main, started looking for it.. no sign of it in the files being linked. Hmm.. that makes sense, it's a library, why would it need to have a main anyway? After checking the flags being used for compilation, just found out this one for compiling a library was not present: -dynamiclib

So I added it to BUILD_LIB_LD_FLAGS_DARWIN in ./build.conf which now looked like this:
BUILD_LIB_LD_FLAGS_DARWIN="-shared -fPIC -dynamiclib"

Yeah! Everything worked just fine! The install was completed successfully and all the binaries were in the bin folder. Hurray!

This was a lengthy journey but in the end it was fruitful.. as always, when it works ;-) Seagull v1.8.1 running on Mac OS X 10.5.6 (Leopard)!

Notes:
  1. Apple Dev Tools are required to be installed prior to any of this being made. They can be found in  the Install DVD;
  2. I had to run the commands with "sudo" as it required permissions for some operations;
  3. Optionally you can run "./install.ksh" to copy Seagull binaries and config files as suggested in INSTALL.TXT and perform the remaining actions, if needed.

Please let me know if this has been useful for you and/or if something is inaccurate. This has been tested against Seagull 1.7.0 and 1.8.1 on Mac OS X 10.5.6 (Leopard).

Mobicents Diameter v1.1.0.GA Released!

Sunday, October 18, 2009 em 01:25
It was on Friday, 16th October 2009 that a shiny new release of Mobicents Diameter happened.

It's v1.1.0.GA and along with the usual enhancements and bug fixes, the main new features are:
  • JBoss AS 5 support
  • Stack configuration at runtime, via JMX
  • Educative Example for Cx/Dx application
  • Preview of the Mobicents Diameter User Guide
It can be downloaded from here: Mobicents Diameter v1.1.0.GA Downloads

Please note that the JBoss 5 version zip contains only the Stack and the Multiplexer, no JAIN SLEE Resource Adaptors or Examples are included. If you want to try the new Mobicents JAIN SLEE 2.x version (which runs on JBoss 5) and it's Diameter Resource Adaptors and Examples, you'll need to build them from source, which can be found in the SVN trunk.

Summing it up, you now get a more stable Diameter in 2 flavors (JBoss 4 & JBoss 5), the ability to configure the stack in realtime (add/remove realms, add/remove peers, manage timeouts, etc...), a new example of how to play with Cx/Dx (which will be the basis for the HSS prototype) plus the user guide to help you play with all of it!

A special thanks to Jared Morgan and Tom Wells for the extra effort on the documentation!

Mobicents Meeting 2009 @ Brno

Monday, September 7, 2009 em 02:23
It was that time of the year again when the Mobicents Team meets face-2-face to discuss the achievements made through the current year, plan the roadmaps for the upcoming year and last but not the least, party a lot!

This time it happened in Brno, the second largest city in Czech Republic, but at least for this week it was the funniest! Only possible thanks to Pavel, who led us through Brno! Thank You!

It had a quite troubled start, with the Portuguese members (me included) ending up by missing the plane due to issues with the airlines company (which suspended their operations since Sept. 1st). We made it anyway, missing the first day.

Regarding Mobicents, the 2009 achievements were quite amazing:

  • Mobicents SIP Servlets, Mobicents Diameter and Mobicents Media Server became GA.
  • Mobicents JAIN SLEE 2.x had it's first version, BETA1, which was certified for JAIN SLEE 1.1 (JSR 240), being the first besides the specs leader, and still the only open source.

Although all this being accomplished, there's still much more to work on, and a lot of new projects to stabilize. One of the hottest topics was the High-Availability across all these servers, which as you can understand is not a trivial subject and had a quite intense discussion.

On my side, I made a presentation regarding Diameter (available here), the main project where I'm involved. For the achievements of 2009, we have highlighted the following:
  • Integration with Mobicents SIP Servlets;
  • Sh-Client/Server Application support (3GPP TS 29.328 & TS 29.329);
  • Credit Control Application support (RFC 4006);
  • Ro/Rf Application support (3GPP TS 32.225 & TS 32.299);
  • Cx/Dx Application support (3GPP TS 29.228 & TS 29.229)
This was a great improvement for an year! But we won't stop and will evolve it even further, with the following features being the most important ones:
  • High-Availability;
  • Management Console (cross-server);
  • NAT (STUN/TURN/ICE) support;
  • WebServices support;
  • IMS Applications prototypes (HSS/x-CSCF)
So it's still a long road ahead of us, and now it's when the fun begins! And we are counting on the Mobicents Community for helping us out improving!
Here's a picture taken at the end of my presentation:
Left to right: Pavel, Bartosz, Amit, Jean, Vladimir, me, Ivelin, Luis and Eduardo.

And the team warming up for dinner (Pavel is missing and I'm taking the picture):

Left to right: Luis, Amit, Eduardo, Bartosz, Vladimir, Ivelin and Jean.

Cheers for Mobicents team and hope for another successful year!

Welcome to a new era!

Saturday, September 5, 2009 em 03:32
That's right! It's a complete new world for me now that I've started my own blog.

First of all, let me introduce myself and the role of this blog:

I'm a Software Engineer working for JBoss R&D on the open source telco framework Mobicents. I've been using and developing services for it for almost 4 years, namely in JAIN SLEE server, and roughly 2 years ago I started to work on the core team, developing JAIN SLEE core and started from scratch along with Bartosz Baranowski the Diameter component for the project.

It's been a wonderful experience so far, I've learned a lot from all the team members, all JBoss community and from work itself!

Regarding the blog, it's been a project that I've always been delaying but I think the time has come and I hope I can keep it up! I expect to write on a regular basis, mainly with new announcements, some hints regarding my work... and whatever comes to my mind! :)

See you soon!