现在的位置: 首页 > 综合 > 正文

Open Diameter C++ API(中文)

2013年07月15日 ⁄ 综合 ⁄ 共 28215字 ⁄ 字号 评论关闭

Open Diameter C++ API

开源DiameterC++ API

Version1.0.7-e

版本1.0.7-e

Author: (作者)

Victor I. Fajardo

维克托 I.法哈托

Translator:(译者)

                Linc

                阿佛

Date: (日期)

Jan 4, 2005

2005 1.4

                 Trans Date(翻译日期)

                             2008-07-18

 

This document is a general descripton of the Open Diameter C++ API. The C++ API in this release (1.0.7-e)

该文档是对开源Diameter C++ API的概括描述。这个C++ API版本是 1.0.7-e。

 

本翻译仅供参考学习之用,本人不保证信息的准确性以及完整性,并不承担任何直接、间接、附带、特别、衍生性或惩罚性赔偿责任。

阅读本文之前请参考AAA协议 http://blog.sina.com.cn/s/blog_45bec45b010007gq.html

 

Overview(概述)

The Open Diameter C++ API is a simple session based API with each type of diameter session being represented by a C++ class. User applications derived from these session classes to implement thier own specific AAA functionality. All events, received messages
processing and message transmissions functionality are provided by these classes. Generally, the session classes are categorized into either client or server. The client classes provided AAA client capabilities and server classes provide AAA server functions.
These two types of classes are further sub-divided into either authentication/ authorization classes and accounting classes. All of these session classes derived from a specific AAA state machine framework as defined in Sec 8 of RFC3588. Applications can pick
and choose which AAA functionality they require and derived the appropriate session classes.

       开源Diameter C++ API 是一种简单的由一个C++类表示的各种类型的diameter会话(session)。用户程序(User applications)可以继承这些类来实现他们特定的AAA(鉴权计费 AAA:Authentication鉴别,Authorization授权,Accounting计费)功能。这些类提供了所有的事件、消息接收处理和消息发送功能。通常,这些session类(session classes)以客户端或服务端加以分类。客户端类提供AAA客户端功能,而服务器端类提供AAA服务器端的功能。这两种类型的类还可细分成各自的鉴别/授权类(authentication/
authorization)和帐户管理类(accounting)。所有的这些session 类都是从一个状态机框架(state machine framework)继承(由RFC3588的第八个部分定义)。程序可以选择哪个AAA功能是它们需要的,并继承相应的类。

 

The main differences between client and server classes are on the way they are instantiated. For application classes based on client sessions, it is the responsibility of the AAA client application to create and manage the instances of these sessions. For
application classes based on server sessions, the library is responsible in creating and deleting instances of these classes. Deletion of server classes are done by an internal garbage collector when a server session has completed it's execution as defined
by it's state machine. To facilitate the instantiation of application derived server session classes, the library provides a server session factory that an application may instantiate and register. Once properly registered, these session factories will create
AAA session objects everytime a new auth/accouting request arrives. The only criteria for this action is if the local AAA applicaiton supports the application id advertized in the initial request message.

       客户端和服务器端类的主要区别在于它们的实例化方式。对基于客户端会话的应用程序类来说(以下会话将直接用session,注意这里session不是HttpSession),它的职责是为AAA客户端程序创建和管理这些session实例。对基于服务端的session应用程序类来会说,由库(library)负责创建和删除这些类创建的实例。服务器端类的删除是由内部垃圾回收器来负责的,当一个服务器session已经执行完成(这由它的状态机来定义)。为了能够更容易实现从服务器端session 类继承而来的application的实例化,库提供了一个拥有实例化和注册功能的服务器端session工厂(session
factory,Hibernate也有这个术语)。一旦注册成功,这些session factory就可以在每次有新的鉴别/授权请求时创建一个AAA  session对象。这个操作的唯一条件就是本地AAA  application是否支持在初始请求消息中得到的申请ID。

 

It is important to note that both client and server session classes only provide diameter session management. Diameter peer connectivity management is provided (contained) within another class called the application class. This class manages configuration
loading, peer connectivity and AAA message routing. Client session classes binds to this application class via it's constructor. Server classes are bounded to an application class via the server session factory class which is registered in the application
class. By binding to the application class, a session classes are able to send and receive messages from the routing platform provided by the application class. The figure below shows the basic association of the different classes provided in the Open Diameter
C++ API.

       记住下面这个是很重要的:无论是服务器端还是客户端的session都只提供了diameter session管理。Diameter 点连接管理是由另一个调用程序的类提供(包含)的。这个类管理配置的装载、点连接和AAA信息发送(类似路由用能)。客户端session类通过它的构造函数绑定到这个程序类。而服务器端类是通过由服务器端程序类注册的session factory。通过绑定到程序类,一个session类就能够通过程序类从远程平台上发送和接收消息。下面的图显示了由开源DiameterC++提供的不同类的基本关系。

 

图1 :Diameter C++类的基本关系

 

As shown in the figure, an client accounting session is also required to implement a record collector object. This class is passed in as a template parameter to the client accounting sub-session and must be derived from AAA_ClientAcctRecCollector interface.
The implementation of this class is application specific. In the same token, the server accounting session is also required to implement a record storage object to archive records sent by the client (or perhaps sent to a billing system). It is also passed
in as a template parameter to the AAA_ServerAcctSession.

       如图所示,一个客户端帐户session也需要实现一个记录收集对象(record collector object)。这个类将传入一个模板参数到客户端的帐户sub-session,并继承AAA_ClientAcctRecCollector接口。这个类的(这些)操作是程序规范规定的。同样,服务器端accounting session也需要实现一个由客户端(或者可能是发送一个账单系统)发送的记录存储对象。它也是通过模板参数传入到AAA_ServerAcctSession。

 

There are also additional utility functions provided by the API to facilitate a more object oriented approach to message handling (i.e., AAA_SessionMsgMux<SESSION>). Further details about these classes and the API set is explained
in the succeeding sections. For sending AAA messages from any session class, a built-in send function exists in all session classes. The format of this function is as follows:

virtual AAAReturnCode Send(std::auto_ptr<AAAMessage> msg);

       该API还提供一些额外的功能函数来满足面向对象的信息处理(如AAA_SessionMsgMux<SESSION>))。关于这些类和API设置的更多细节将在接下来的章节中进行介绍。要从任何session类中发送AAA消息,有一个所有session类都内置的函数、这个函数的格式如下图所示(直接看上面的图示代码)

 

Note that any message that is composed by the application must be passed in as an auto_ptr<>. This means that the session class will take over ownership of the
AAAMessage object.

       请注意:任何由application生成的消息必须通过一个auto_ptr<>传值。这意味着session类从AAAMessage对象获得所有权。

 

Usage of the API is best described in the sample code of libdiameter. There are several sample code that came with the distribution and each describes how to use different aspects of the API. However, the succeding sections show all the basic classes necessary
to implement a diameter AAA application.

       这些API用法的最好描述就是参见lib Diameter的示例代码。那有几个示例代码包含了这些API在不同场合的应用描述。尽管如此,接下来的章节将展示所有这些类所必须实现的Diameter AAA  application基础。

 

Application Class(Application类)

 

The application class provides peer connectivity management, route tables and logic and general configuration databases. All applications must have an instance of the application class (AAA_Application). An instance of AAA_Application is synonymous to having
a single AAA diameter entity. So, it is possible for a single program to have multiple instance of an AAA_Application representing different AAA diameter entities. The application class also provides registration function for server session factories that
allow all server sessions to be bounded to to the AAA_Application. The following code snipet show the basic usage of AAA_Application

       application 类提供点通信管理、路由表、逻辑和数据库常规配置。所有的程序必须是application类(AAA_Application的实例)。AAA_Application的实例和AAA diameter实体是一个意思。因此,可以在一个程序中拥有多个表示不同AAA diameter实体的AAA_Application实例。Application类也提供了给多个服务器端session factory注册的功能,并允许服务器端session绑定到AAA_Application。下面的代码将说明AAA_Application的用法:

 

// A running AAA_Task must provide execution context to the AAA_Application
// 一个运行中的AAA_TaskAAA任务)必须为AAA_Application提供运行上下文
   
   AAA_Application appCore(task);
   if (appCore.Open("my_configuration_file.xml") == AAA_ERR_SUCCESS) {
 
       diameter_unsigned32_t MyApplicationId = 10000;
       
       // wait for peer connectivity before proceeding
      //在处理之前等待 点连通
       do {
           ACE_OS::sleep(1);
       } while (appCore.NumActivePeers() == 0);
 
       // Applications can now register server session factories
       // if this AAA will have some server functionality
      //如果这个AAA需要一些服务器端的功能,Application可以注册服务器端session factory
       SampleServerAllocator allocator(task, MyApplicationId);
       appCore.RegisterServerSessionFactory(allocator);
       
       // do something here 这里进行XXX处理
       // The AAA_Application object must be persistent       
       // within the instances context of all session 
       // classes since all sessions must be bounded to
       // an AAA_Application
       //因为所有session必须绑定到AAA_Application,所以AAA_Application对象在所有的session类的实例上下文中必须是持久不变的
       // remove the factory when done
      //当完成的时候移除factory       
       appCore.RemoveServerSession(MyApplicationId);
}

Authentication/Authorization Client Session鉴别/授权 客户端session

 

Diameter client applications should create instances of classes AAA_ClientAuthSession or classes that derived from them. This class provides virtual functions that is called by the library when configuration information is being gathered or when incomming
session specific answer message is recieved. The following code snipet shows all of the available virtual functions that can be implemented by the application. AAA_SampleClient is the application specific class that derives from AAA_ClientAuthSession.

       Diameter 客户端程序必须创建AAA_ClientAuthSession类的实例或从它们继承的类的实例。这个类提供了从库调用的虚函数,当搜集到配置信息或接收的指定session应答消息时。下面的代码片段显示了可以由application操作的虚函数。AAA_SampleClient是由application从AAA_ClientAuthSession继承的类。

 

class AAA_SampleServer : public AAA_ServerAuthSession {
        // AAA serve session derived from AAA_ServerAuthSession. 
        // It provides for all the functionality of a diameter 
        // server session. Note that the server session factory
        // is responsible for instantiating this object. Also,
        // any derived class must accept AAA_Task and application
        // id type as constructor parameter and must pass this
        // along to the AAA_ServerAuthSession base class.
      
      //AAA 服务器端session是从AAA_ServerAuthSession继承而来的
        //它提供了Diameter 服务器端session的所有功能。
        //注意服务器端session fact负责实例化这个对象。
        //所有继承的类必须接收AAA_Taskapplication id 类型作为构造函数的参数,
        //并把这个单独传送给AAA_ServerAuthSession基类。
 
    public:
        AAA_SampleServer(AAA_Task &task,
                         diameter_unsigned32_t id,
                         bool endOnSuccess = false) :
           AAA_ServerAuthSession(task, id) {
        }
        virtual void SetAuthSessionState
        (AAA_ScholarAttribute<diameter_unsigned32_t> &authState)
        {
            // optional override, called by the library to set 
            // the auth state. Note that this overrides the 
            // settings in the configuration file or applications 
            // sending an auth session state AVP
            // Possible values are:
            //   1. AAA_SESSION_STATE_MAINTAINED
            //   2. AAA_SESSION_NO_STATE_MAINTAINED
          
          // override可选,被库调用来设置auth状态。
          //注意这个在配置文件中或application发送一个auth session 状态 AVPoverride设置的可能值是:
            //   1. AAA_SESSION_STATE_MAINTAINED
            //   2. AAA_SESSION_NO_STATE_MAINTAINED
            authState = AAA_SESSION_STATE_MAINTAINED;
        }
        virtual void SetSessionTimeout
        (AAA_ScholarAttribute<diameter_unsigned32_t> &timeout)
        {
            // optional override, called by the library so 
            // this server can dictate the session timeout 
            // to the client. If not overridden, the value 
            // in the config file is used
 
          // override可选,被库调用来让这个server(服务器端)指定session的到clien(客户端)的超时时间。
          // 如果没有overridden,将使用config文件中的值
            timeout = 30;
        }
        virtual void SetAuthLifetimeTimeout
        (AAA_ScholarAttribute<diameter_unsigned32_t> &timeout)
        {
            // optional override, called by the library so 
            // this server can dictate the session timeout 
            // to the client. If not overridden, the value 
            // in the config file is used
 
          // 翻译: 见上面
            timeout = 2;
        }
        virtual void SetAuthGracePeriodTimeout
        (AAA_ScholarAttribute<diameter_unsigned32_t> &timeout)
        {
            // optional override, called by the library so 
            // this server can dictate the auth grace period
            // to the client. If not overridden, the value 
            // in the config file is used
 
          //override可选,被库调用来给server指定到client auth 宽限期。
          //如果未指定的话,将采用config文件中的值 
            timeout = 2;
        }
        virtual AAAReturnCode ReAuthenticate(diameter_unsigned32_t rcode) {
            // optional override, called by the library so 
            // this server is informed that the client has
            // responded to the server initiated re-auth
            // request. The result code from the client
            // is passed as a parameter to this funciton.
 
          //通知serverclient已经开始响应serverre-auth(重新鉴别)请求。
          //client得到到结果编码将被做参数传送到这个函数
            return (AAA_ERR_SUCCESS);
        }
        virtual AAAReturnCode RequestMsg(AAAMessage &msg) {
 
            // all request messages are handled by this function. 
            // This function can retrun the following values:
            // a. AAA_ERR_SUCCESS - client is successfully authenticated
            // b. AAA_ERR_INCOMPLETE - auth not yet completed, muti-round 
            //                         message trip exchange
            // c. AAA_ERR_FAILURE - client authentication failed
 
            // Generally, a server application can send an
            // application specific answer message from here
 
          //所有的请求信息都通过该函数处理。
          //这个函数将返回以下值:
            // a. AAA_ERR_SUCCESS –client已被成功鉴别
            // b. AAA_ERR_INCOMPLETE – auth尚未完成, 尚在进行多趟报文信息交换
            // c. AAA_ERR_FAILURE - client 鉴别失败
          //一般,server application会从这儿发送一个application特定的应答信息
            return (AAA_ERR_SUCCESS);
        }
        virtual AAAReturnCode AnswerMsg(AAAMessage &msg) {
            // all answer messages are handled by this function.
            // AAA servers normally should not receive
            // answer messags. 
 
          //所有的应答信息将由这个函数处理。
          //AAA servers通常不应接收应答信息
            return (AAA_ERR_SUCCESS);
        }
        virtual AAAReturnCode ErrorMsg(AAAMessage &msg) {
            // all error messages are handled by this function.
 
          // 所有的错误信息都由这个函数处理
            return (AAA_ERR_SUCCESS);
        }
        virtual AAAReturnCode Success() {
            // notification of successful auth
          // 成功auth的通知
                // ReAuth(AAA_SESSION_AUTHORIZE_AUTHENTICATE);
            }
            return (AAA_ERR_SUCCESS);
        }
        virtual AAAReturnCode Disconnect() {
            // notification of completed STR/STA exchange
          // 完成STR/STA的通知
            return (AAA_ERR_SUCCESS);
        }
        virtual AAAReturnCode SessionTimeout() {
            // notification of session timeout
          // session超时的通知
            return (AAA_ERR_SUCCESS);
        }
        virtual AAAReturnCode AuthorizationTimeout() {
            // notification of auth lifetime timeout
          // auth 生存期超时通知
            return (AAA_ERR_SUCCESS);
        }
        virtual AAAReturnCode AbortSession() {
            // notification of completed ASR/ASA exchange
          // 完成ASR/ASA交换的通知
            return (AAA_ERR_SUCCESS);
        }
};

Optionally, the server session class also has a built-in function to send a Re-Auth-Request message. This would be valid only if the server session has initiated a stateful session and currently in it's open state. The format of the re-auth function is as
follows:

       可选的,server session 类也有一个内置的函数来发送Re-Auth-Request(重鉴别请求)消息。这只在以下情况时有效:server session 开启一个状态session并还在开启状态中。

re-auth函数的格式如下所示:

 

AAAReturnCode ReAuth(diameter_unsigned32_t type);

As noted in previous sections, the application is not responsible for creating instances of server sessions. This is left to a server session factory discussed in next sections.

       关于上面的章节有一点要注意一下,application不负责创建server session的实例。这些将在下个章节session factory中讨论。

 

Server Session Factory 服务器端会话工厂(专业术语还是用原文好)

 

The server session factory is implemented using the template class AAA_ServerSessionAllocator<SERVER_SESSION> where SERVER_SESSION is an application specific class that derives from AAA_ServerAuthSession or AAA_ServerAcctSession. This class derives from
AAA_ServerSessionFactory which has a pure virtual Create(...) function called by the library when a new auth/acct request message is received from a new diameter client.

       服务器端session factory 利用AAA_ServerSessionAllocator<SERVER_SESSION>模板类实现,而SERVER_SESSION是application的特定类,从AAA_ServerAuthSession或AAA_ServerAcctSession继承而来。这个类从AAA_ServerSessionFactory继承而来,有一个纯虚函数Create()。当有一个来自新的diameter客户端的auth/acct请求消息时,这个函数被library(库)调用。

 

An instance of the AAA_ServerSessionAllocator<SERVER_SESSION> must be regsitered with an AAA_Application object. Once an AAA_Application object receives a new request message, it can check the list of locally registered factories if the application id present
in the message is supported by the diameter application. The code snipet below shows the basic scenario.

 

       AAA_ServerSessionAllocator<SERVER_SESSION>的实例必须用AAA_Application对象注册。一旦AAA_Application对象接收到一个新的请求消息,它会检测本地注册过的factory列表是否在消息中存在diameter application 支持的application id。下面的代码片段显示了一些基础情形:

 

// Server session factory. Unlike AAA clients, server
// sessions need to be created on demand. This factory
// is responsible for creating new server sessions
// based on incomming new request.
 
//session根据需要创建。这个factory基于收到的新请求而创建新的server session
typedef AAA_ServerSessionAllocator<AAA_SampleServer> 
        SampleServerAllocator;
 
int main(int argc, char *argv[])
{
   AAA_Task task;
   task.Start(5);
 
   diameter_unsigned32_t MyApplicationId = 10000;
   
   // Application core is responsible for providing
   // peer connectivity between AAA entities
 
   //Application核心负责在AAA实体中提供点通信
   AAA_Application appCore(task, "my_server_configuration.xml");
   SampleServerAllocator allocator(task, MyApplicationId);
   appCore.RegisterServerSessionFactory(allocator);
 
   // do something here to wait as a deamondaemon
   // 这里是等待后台处理程序的代码
 
   appCore.Close();
   task.Stop();
   return(0);
}

Accounting Client Session

 

Accounting architecture on the client application is based on a parent accounting session (AAA_ClientAcctSession) and one or more sub-session (AAA_ClientAcctSubSession<REC_COLLECTOR>). As described in RFC3588, a parent session defines the same Session-Id
for all of it's sub-session. Each sub-session then defines it's own Accounting-Sub-Session-Id and implements a specific record collection method. A method maybe an event based record collection wherein record collection is a one-time event or a sequence based
collection where there is a start, interim and stop events. Each sub-session implements the accounting client state machine described in Sec. 8.2 of RFC 3588. In addition, a record collection mechanism is provided to the sub-session to allow it to collect
data from application specific sources. The record collector is passed in as a template parameter to the sub-session class to bind a specific collection scheme to a sub-session. In the similar manner, the sub-session instance requires the parent session to
be passed into it's constructor to bind it to a specific accounting session.

       Accounting构架于客户端application是基于父(parents)accounting session(AAA_ClientAcctSession)和一个或多个sub-session(子session  AAA_ClientAcctSubSession<REC_COLLECTOR>)。这个再RFC3588中有描述,一个夫session为所有它的sub-session定义了相同的Session-Id。每个sub-session定义了各自的Accounting-Sub-Session-Id并实现了特定的记录收集方法。一个方法可以是一个基于记录收集的事件,其中的记录收集是一个以前的事件或者是基于收集的序列,包含开始、进行中和结束事件。每个sub-session实现了accounting客户端状态机,这在RFC
3588的8.2章节中有描述。此外,记录收集机制被用来让sub-session从Application资源中收集指定的资源。记录收集器被作为模板参数传入到sub-session类来绑定指定的collection(收集)模式到一个sub-session。同样,sub-session实例需要一个父session来传入它的构造函数以绑定到指定的accounting session。

 

Applications are also required to implement their own specific record collection schemes and must derived from AAA_ClientAcctRecCollector class. This class is an abstract class and application must implement all of the required interfaces. The signature
of the class is as follows:

       Application 也需要实现他们各自的特定记录收集配置,必须从AAA_ClientAcctRecCollector继承。这个类是一个抽象类,所以application必须实现它的所有借口。这个类的签名是如下所示:

class DIAMETERBASEPROTOCOL_EXPORT AAA_ClientAcctRecCollector
{
    public:
        virtual void GenerateRecord(AAAAvpContainerList &avpList,
                                    int recordType,
                                    int recordNum) = 0;
 
        virtual bool IsLastRecordInStorage() = 0;
 
        virtual bool IsStorageSpaceAvailable() = 0;
 
        virtual AAAReturnCode StoreLastRecord(int recordType) = 0;
 
        virtual AAAReturnCode DeleteLastRecord(int recordType) = 0;
};

 

Client accounting applications should create instances of classes AAA_ClientAcctSubSession<REC_COLLECTOR> or classes that derived from them. Where REC_COLLECTOR is a class derived from AAA_ClientAcctRecCollector. The sub-session class provides virtual functions
that is called by the library when configuration information is being gathered. The following code snipet shows all of the available virtual functions that can be implemented by the application. AAA_SampleClientSubSession is the application specific class
that derives from AAA_ClientAcctSubSession. AAA_SampleClientAcctRecCollector is a sample record collection scheme implemented by the client.

       客户端accounting applications应创建AAA_ClientAcctSubSession<REC_COLLECTOR>类(或者从他们继承的类)的实例。REC_COLLECTOR 是从AAA_ClientAcctRecCollector继承而来。当收集信息完成时,sub-session提供了用来从library调用的虚函数。下面的代码片段显示了所有可以用到的由application实现的虚函数。AAA_SampleClientSubSession是application从AAA_ClientAcctSubSession继承而来的类。AAA_SampleClientAcctRecCollector是一个由客户端实现的样例记录收集配置。

 

class AAA_SampleClientSubSession : 
    public AAA_ClientAcctSubSession<AAA_SampleClientAcctRecCollector> {
        // AAA client session derived from AAA_ClientAcctSession.
        // It provides for all the functionality of a diameter 
        // client accounting session. The ClientAcctSubSession
        // class is a template function that requires a proper
        // version of a record collector as a paramter. Note 
        // that the application is responsible for instantiating 
        // this object
 
      // AAA客户端session AAA_ClientAcctSession继承而来。
      //它提供了diameter客户端accounting session的所有功能。
      // ClientAcctSubSession类是一个模板函数,需要适当版本的记录收集器作为参数
    public:
        AAA_SampleClientSubSession(AAA_ClientAcctSession &parent) :
            AAA_ClientAcctSubSession<AAA_SampleClientAcctRecCollector>(parent) {
        }
        virtual void SetDestinationHost
        (AAA_ScholarAttribute<diameter_identity_t> &dHost)
        {
            // optional override, called by the library to 
            // set the destination host. Note that this 
            // overrides applications sending a destination
            // host AVP
 
          //override可选,从库中调用来设置目标主机。
          //注意这个override application发送主机的AVP
            dHost = "server.isp.net";
        }
        virtual void SetDestinationRealm
        (AAA_ScholarAttribute<diameter_identity_t> &dRealm)
        {
            // optional override, called by the library 
            // to set the destination realm. Note that 
            // this overrides applications sending a 
            // destination realm AVP
 
          //override可选,发送目标域。
          //注意这个override Application 发送目标域AVP
            dRealm = "isp.net";
        }
        virtual void SetRealTimeRequired
        (AAA_ScholarAttribute<diameter_enumerated_t> &rt)
        {
        }
        virtual void SetInterimInterval
        (AAA_ScholarAttribute<diameter_unsigned32_t> &timeout)
        {
        }
        virtual void SetRadiusAcctSessionId
        (AAA_ScholarAttribute<diameter_octetstring_t> &sid)
        {
        }
        virtual void SetMultiSessionId
        (AAA_ScholarAttribute<diameter_utf8string_t> &sid)
        {
        }
        virtual AAAReturnCode Success() {
            // notification of successful ACR exchange for all record type
          // 成功进行所有记录类型的ACR交换的通知
            return (AAA_ERR_SUCCESS);
        }
        virtual AAAReturnCode Failed(int recNum) {
            // notification that recNum record was not processed properly
          // recNum条记录没有正常处理的通知
            return (AAA_ERR_SUCCESS);
        }
};

 

The sub-session class also has the following built-in function to control the beginning and termination of record collection:

       sub-session class还有用于控制记录收集开始和终止的内置函数:

 

 
        AAAReturnCode Begin(bool oneTime = false);
 
        AAAReturnCode End();
/*
/end verobse
 
Client accounting applications should create instances of classes 
AAA_ClientAcctSession. This provides the accounting parent session
functionality and is passed on to a sub-sessions constructor. The basic
usage of AAA_ClientAcctSession and how it is associated with the 
sub-sessions are show below.
 
客户端accounting applications应创建AAA_ClientAcctSession的实例。它提供父accounting session 功能,并传送给sub-sessions的构造函数。
AAA_ClientAcctSession的基本用法和如何和sub-sessions联用请看下面:
/code 
*/
       diameter_unsigned32_t MyApplicationId = 10000;
       AAA_ClientAcctSession parent(task, MyApplicationId);
       for (int x = 0; x < 10; x ++) {
           // A new sub session id is created for each new sub session
           AAA_SampleClientSubSession subSession(parent);
 
           // shows sequenced record accouting (start/interim/stop)
           subSession.Begin(false);
 
           subSession.End();
}

 

Accounting Server Session

 

Server accounting applications are similiar to auth server sessions. The server session factory is responsible for it's creation. The difference is that the server accounting session takes a record storage class as a template parameter. The template format
is AAA_ServerAcctSession<REC_STORAGE> where REC_STORAGE is an application specific implementation of AAA_ServerAcctRecStorage. AAA_ServerAcctRecStorage is an abstract class that is used by the library to tell the application to store application specific record
that has been carried an Accounting-Request message. The signature of the class is as follows:

       服务器端(server)accounting applications和auth server sessions是相似的。server session factory负责创建它。不同之处在于server accounting session把一个记录存储类作为模板参数。模板格式是

AAA_ServerAcctSession<REC_STORAGE>,其中REC_STORAGE是由AAA_ServerAcctRecStorage 实现的application。AAA_ServerAcctRecStorage是一个抽象类,被library用来通知application保存application指定的记录,该记录携带有Accounting-Request消息。类的签名如下面代码所示:

class AAA_ServerAcctRecStorage
{
    public:
        virtual bool IsSpaceAvailableOnDevice() = 0;
 
        virtual void StoreRecord(AAAAvpContainerList &avpList,
                                 int recordType,
                                 int recordNum) = 0;
};

 

The AAA_ServerAcctSession<REC_STORAGE> class also provides virtual functions that is called by the library when configuration information is being gathered. The following code snipet shows all of the available virtual functions that can be implemented by
the application. AAA_SampleServer is the application specific class that derives from AAA_ServerAcctSession<REC_STORAGE>.

       AAA_ServerAcctSession<REC_STORAGE>类也提供虚函数,被当完成收集配置信息时被library调用。下面的代码片段显示了所有由application是实现的可用的虚函数。AAA_SampleServer是由application指定的类,从AAA_ServerAcctSession<REC_STORAGE>继承。

 

class AAA_SampleServer : 
    public AAA_ServerAcctSession<AAA_SampleRecStorage>
{
        // AAA server session derived from AAA_ServerAcctSession.
        // It provides for all the functionality of a diameter 
        // accounting server session. Note that the server 
        // session factory is responsible for instantiating 
        // this object. AAA_ServerAcctSession is also a template
        // class that requires an AAA_ServerAcctRecStorage derived
        // class as a parameter.
 
      // AAA server session 是从AAA_ServerAcctSession继承的。
      //它提供diameter accounting server session的所有功能。
      //注意server session factory 负责实例化这个对象。
      // AAA_ServerAcctSession也是一个模板类,需要从AAA_ServerAcctRecStorage继承的类作为参数
    public:
        AAA_SampleServer(AAA_Task &task,
                         diameter_unsigned32_t id) :
            AAA_ServerAcctSession<AAA_SampleRecStorage>
                   (task, 
                    id, 
                    true) // dictates whether this session is stateful 指示这个session 是否是状态化
        {             
        }
        virtual void SetRealTimeRequired
        (AAA_ScholarAttribute<diameter_enumerated_t> &rt)
        {
            rt = AAA_ACCT_REALTIME_DELIVER_AND_GRANT;
        }
        virtual void SetInterimInterval
        (AAA_ScholarAttribute<diameter_unsigned32_t> &timeout)
        {
            timeout = 2; // tell client to generate record every 2 sec 通知客户端每两秒生成一条记录
        }
        virtual AAAReturnCode Success() {
            // notification of successful ACR exchange for all record type 
            return (AAA_ERR_SUCCESS);
        }
        virtual AAAReturnCode Failed(int recNum) {
            // notification that recNum record was not processed properly
            return (AAA_ERR_SUCCESS);
        }
        virtual AAAReturnCode SessionTimeout() {
            // notification of session timeout if this
            // session was stateful
          //如果这个session 是状态化,session超时时发出通知
            return (AAA_ERR_SUCCESS);
        }
};

 

Message Multiplexer Class(消息多路复用器)

The message multiplexer class is an auxiliary class that can be used with sessions that process application specific message. The main purpose of the message mux is to designate handling or processing of an application specific request or answer message
to it's own class definition. It is independent of any session classes and operates soley on the
AAAMessage object passed to it. The message mux is composed of two (2) classes. An abstract class that applications must implement.
This provides the functions where
AAAMessage
will be processed (AAA_SessionMsgMuxHandler<ARG>) on a per-session basis. The second is the actual multiplexer itself (AAA_SessionMsgMux<ARG>). Both classes are template classes and has one
template argument which can be any application specific type. The multiplexer allows applications to register a AAA_SessionMsgMuxHandler<ARG> for a message code. When a
AAAMessage is multiplexed, the AAA_SessionMsgMux<ARG> simply checks a matching handler and forwards the message to that handler.
The multiplexer can be called in RequestMsg(..) or AnswerMsg(..) functions in an appropriate session class. The signature of the handlers is as follows:

       消息multiplexer 类是一个辅助类,用来利用session处理application的特定消息。消息复用的主要目的是根据application类定义来处理一个application 的特定请求或应答消息。它和任何session类无关,由AAAMessage对象传给它单独操作。消息复用由两个类组成。一个必须执行application的抽象类。这提供在每个session上要处理(AAA_SessionMsgMuxHandler<ARG>)的AAAMessage的函数。第二个是真正的多路复用器本身(AAA_SessionMsgMux<ARG>)。这两个类都是模板类和有一个可以是任何application特定类型的模板参数。Multiplexer允许application为消息编码注册一个AAA_SessionMsgMuxHandler<ARG>。当AAAMessage是multiplexed(多路的),AAA_SessionMsgMux<ARG>只要检测一个匹配的处理程序并把消息传给那个处理程序。Multiplexer可以在appropriate
sessio类中由RequestMsg(..) 或 AnswerMsg(..)函数调用。处理程序的签名如下:

 

template<class ARG>
class AAA_SessionMsgMuxHandler
{
    public:
        virtual ~AAA_SessionMsgMuxHandler() {
        }
        virtual AAAReturnCode RequestMsg(ARG &arg, AAAMessage &msg) = 0;
 
        virtual AAAReturnCode AnswerMsg(ARG &arg, AAAMessage &msg) = 0;
 
        virtual AAAReturnCode ErrorMsg(ARG &arg, AAAMessage &msg) = 0;
 
    protected:
        AAA_SessionMsgMuxHandler() {

抱歉!评论已关闭.