⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client_test.cxx

📁 Diameter协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* 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                                                          *//* $Id: *//*    client_test.cxx   Client test program for Diameter NASREQ Application    Written by Yoshihiro Ohba   Created May 4, 2004.*//*  ---------------------------------------------------------  Brief explanation on what is done in this sample program.  ---------------------------------------------------------  This program includes a test for Diameter NASREQ application where  PAP or CHAP is used for authentication between a client host and a  NASREQ server via a NAS.  Half of the clients are authenticated with  PAP and the other half are authenticated with CHAP.  The client session entity will prompt you to input a username.  Once  the username is input, it is passed to the NAS.  The NAS generates a  NASREQ AA-Request and sents to the NASREQ server.  When PAP is used, it will be the following sequence:  Peer                NAS                         EAP Server                     (= NASREQ client)          (= NASREQ Server)   |    null request        |                          |   |<-----------------------|                          |   |                        |                          |(input username)            |                          |   |                        |                          |   |  Username/Password     |                          |   |----------------------->|  AA_Request/User-Name    |   |                        |    User-Password         |   |                        |------------------------->|   |                        |  AA-Answer/Result-Code=  |   |                        |    DIAMETER_SUCCESS      |   |  Success indication    |<-------------------------|   |<-----------------------|                          |   |                        |                          |  When CHAP is used, it will be the following sequence:  Peer                NAS                         EAP Server                     (= NASREQ client)          (= NASREQ Server)   |  Challenge request     |                          |   |<-----------------------|                          |   |                        |                          |(input username)            |                          |   |                        |                          |   |  Challenge response/   |                          |   |    Username            |                          |   |----------------------->|  AA_Request/User-Name    |   |                        |    CHAP-Auth,            |   |                        |    CHAP-Challenge        |   |                        |------------------------->|   |                        |  AA-Answer/Result-Code=  |   |                        |    DIAMETER_SUCCESS      |   |  Success indication    |<-------------------------|   |<-----------------------|                          |   |                        |                          | */#include <iostream>#include <ace/Log_Msg.h>#include <ace/OS.h>#include <ace/Atomic_Op_T.h>#include "diameter_api.h"#include "diameter_nasreq_client_session.hxx"ACE_Atomic_Op<ACE_Thread_Mutex, int> TotalSuccess;typedef AAA_JobHandle<AAA_GroupedJob> MyJobHandle;class ClientData;class NAS_Application;/// Task class used in this sample program.class NasreqTask : public AAA_Task{ public:  /// Constructor.  NasreqTask() : AAA_Task(AAA_SCHED_FIFO, "NASREQ")   {}  /// Destructor.  ~NasreqTask() {}};/// This class defines a transport.  When a message is sent/// to a particular entity (e.g., an entity may be a client, a NAS or/// a NASREQ server depending on the role of the sender, Transmit()/// method of the Channel object of the receiving entity is called./// Transmit() method can have sub-channels which is used for/// distinguishing different types of messages.class Channel { public:  Channel() {}  virtual ~Channel() {}  virtual void Transmit(DiameterNasreqAuthenticationInfo &authInfo)=0;};/******** Diameter NASREQ Client Session ********/class MyDiameterNasreqClientSession : public DiameterNasreqClientSession{ public:  MyDiameterNasreqClientSession(AAAApplicationCore& appCore, MyJobHandle h)     : DiameterNasreqClientSession(appCore, h)  {}  /// This virtual function is called when a NASREQ client session is  /// aborted due to enqueue failure of a job or an event inside  /// Diametger NASREQ client state machine.  void Abort();  /// This virtual function is called when a NASREQ Authentication-Info  /// is passed to the NAS.  void SignalContinue(DiameterNasreqAuthenticationInfo&);  /// Reimplemented from the parent class.  void SignalSuccess();  /// Reimplemented from the parent class.  void SignalFailure();  /// Reimplemented from the parent class.  void SignalReauthentication();  /// Reimplemented from the parent class.  void SignalDisconnect() {}  /// Reimplemented from the parent class.  void SetDestinationRealm  (AAA_ScholarAttribute<diameter_utf8string_t> &realm);  /// Reimplemented from parent class.  void SetAuthInfo(DiameterNasreqAuthenticationInfo &authInfo);};/// Class for end-host client.class ClientSession : AAA_Job{ public:  ClientSession(MyJobHandle &handle) : handle(handle) {}  int Serve() { return 0; }    int Schedule(AAA_Job*, size_t) { return 0; }  void Receive(DiameterNasreqAuthenticationInfo &authInfo)  {    if (authInfo.AuthenticationType() == 	NASREQ_AUTHENTICATION_TYPE_PAP)      // PAP      {	PAP_Info& papInfo = (PAP_Info&)authInfo;	papInfo.UserName() = username;	papInfo.UserPassword() = password;	Send(papInfo);      }    else if (authInfo.AuthenticationType() == 	     NASREQ_AUTHENTICATION_TYPE_CHAP)      // CHAP      {	CHAP_Info& chapInfo = (CHAP_Info&)authInfo;		chapInfo.UserName() = username;	// Initialize the result.	std::string md5Result(MD5_DIGEST_LENGTH, '\0');	// Do MD5.	std::string rawResponse(chapInfo.ChapAuth().ChapIdent());	rawResponse.append(password);	rawResponse.append((std::string&)chapInfo.ChapChallenge());	MD5((const unsigned char*)rawResponse.data(), 	    (unsigned)rawResponse.size(), (unsigned char*)md5Result.data());	chapInfo.ChapAuth().ChapResponse = md5Result;	Send(chapInfo);      }    else      {	AAA_LOG(LM_ERROR, "invalid authenticaiton type.\n");	Send(authInfo);      }  }  void Send(DiameterNasreqAuthenticationInfo &authInfo);  void Success();  void Failure();  void SetCredentials(std::string uname, std::string pword)  {    username = uname;    password = pword;  } private:  std::string username;  std::string password;  MyJobHandle& handle;};class ClientChannel : public Channel{ public:  ClientChannel(ClientSession &s) : session(s) {}  void Transmit(DiameterNasreqAuthenticationInfo &authInfo)   { session.Receive(authInfo); }  ClientSession &session;};class NAS_Channel : public Channel{ public:  NAS_Channel(MyDiameterNasreqClientSession& s) : session(s) {}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -