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

📄 client_test.cxx

📁 Diameter协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
  void Transmit(DiameterNasreqAuthenticationInfo &authInfo)   { session.ForwardAuthenticationInfo(authInfo); }  MyDiameterNasreqClientSession &session;};class ClientApplication : public AAA_JobData{ public:  ClientApplication(NasreqTask &task, ACE_Semaphore &sem) :     handle(MyJobHandle	   (AAA_GroupedJob::Create(task.Job(), this, "client"))),    session(boost::shared_ptr<ClientSession>(new ClientSession(handle))),    rxChannel(ClientChannel(*session)),    txChannel(0)  {    session->SetCredentials("opendiameter@research2.org", "abcdef12345678");  }  ~ClientApplication()   {}  void Start(Channel *c)  {     txChannel = c;  }  ClientChannel* RxChannel() { return &rxChannel; }  Channel& TxChannel() { return *txChannel; } private:  MyJobHandle handle;  boost::shared_ptr<ClientSession> session;  ClientChannel rxChannel;  Channel  *txChannel;};// My application session (not used in this test program).class NAS_Application : public AAA_JobData{ public:  NAS_Application(NasreqTask &task, AAAApplicationCore& appCore,		  ACE_Semaphore &sem)    : handle(MyJobHandle	     (AAA_GroupedJob::Create(appCore.GetTask().Job(), this, "NAS"))),      diameter(boost::shared_ptr<MyDiameterNasreqClientSession>	       (new MyDiameterNasreqClientSession(appCore, handle))),      semaphore(sem),      rxChannel(NAS_Channel(*diameter)),      txChannel(0)  {    semaphore.acquire();  }  ~NAS_Application() {}  /// if algorithm is 0 use PAP, otherwise use CHAP.  void Start(Channel *c, int algorithm)  {     txChannel = c;    diameter->Start();     if (algorithm == 0)      {	std::cout << "Start PAP." << std::endl;	PAP_Info papInfo;	c->Transmit(papInfo);      }    else      {	std::cout << "Start CHAP." << std::endl;	CHAP_Info chapInfo;	chapInfo.ChapAuth().ChapAlgorithm = CHAP_ALGORITHM_MD5;	chapInfo.ChapAuth().ChapIdent = std::string(1, '1'-'0');	chapInfo.ChapChallenge() = std::string("dkjf;akjkljrk;le");	c->Transmit(chapInfo);      }  }  Channel* RxChannel() { return &rxChannel; }  Channel& TxChannel() { return *txChannel; }  MyDiameterNasreqClientSession &Diameter() { return *diameter; }  ACE_Semaphore& Semaphore() { return semaphore; } private:  MyJobHandle handle;  boost::shared_ptr<MyDiameterNasreqClientSession> diameter;  ACE_Semaphore &semaphore;  NAS_Channel rxChannel;  Channel *txChannel;  std::string username;};// ----------------- Definition --------------void MyDiameterNasreqClientSession::Abort()  {    std::cout << "Diameter NASREQ client session aborted." << std::endl;    DiameterNasreqClientSession::Stop();    JobData(Type2Type<NAS_Application>()).Semaphore().release();  }void MyDiameterNasreqClientSession::SignalContinue(DiameterNasreqAuthenticationInfo& authInfo){  JobData(Type2Type<NAS_Application>()).TxChannel().Transmit(authInfo);}void MyDiameterNasreqClientSession::SignalSuccess()  {    AAA_LOG(LM_DEBUG, "Client authentication successful.\n");    TotalSuccess++;    Stop();    JobData(Type2Type<NAS_Application>()).Semaphore().release();  }void MyDiameterNasreqClientSession::SignalFailure()  {    AAA_LOG(LM_DEBUG, "Client authentication failed.\n");    Abort();  }void MyDiameterNasreqClientSession::SignalReauthentication()  {    AAA_LOG(LM_DEBUG, "Client Re-authentication triggerred (to be implemented).\n");    Abort();  }voidMyDiameterNasreqClientSession::SetDestinationRealm(AAA_ScholarAttribute<diameter_utf8string_t> &realm){  std::string& userName = AuthenticationInfo().UserName();  size_t pos = userName.find('@');  if (pos != std::string::npos) {    pos ++;    realm.Set(std::string(userName, pos, userName.length() - pos));  }  else {    realm.Set(std::string("research.org"));  }}voidClientSession::Send(DiameterNasreqAuthenticationInfo &authInfo){  handle.Job().Data(Type2Type<ClientApplication>())->TxChannel()    .Transmit(authInfo);}class MyInitializer{ public:  MyInitializer(NasreqTask &t, AAAApplicationCore &appCore)     : task(t), applicationCore(appCore)  {    Start();  }  ~MyInitializer()   {    Stop();  } private:  void Start()  {    InitTask();    InitApplicationCore();  }  void Stop()  {    task.Stop();  }  void InitTask()  {      try {         task.Start(10);      }      catch (...) {         ACE_ERROR((LM_ERROR, "(%P|%t) Server: Cannot start task\n"));         exit(1);      }  }  void InitApplicationCore()  {    ACE_DEBUG((LM_DEBUG, "[%N] Application starting\n"));    if (applicationCore.Open("config/client.local.xml",                             task) != AAA_ERR_SUCCESS)      {	ACE_ERROR((LM_ERROR, "[%N] Can't open configuraiton file."));	exit(1);      }  }  NasreqTask &task;  AAAApplicationCore &applicationCore;};intmain(int argc, char *argv[]){  NasreqTask task;  AAAApplicationCore applicationCore;  MyInitializer initializer(task, applicationCore);#if defined(WIN32)  #define num 100  char c;  std::cout << "Input any characer and return after peer connection has established: ";  std::cin >> c;#else  int num;  std::cout << "Input number of sessions and return after peer connection has established: ";  std::cin >> num;#endif  ACE_Semaphore semaphore(num);  TotalSuccess=0;  std::auto_ptr<ClientApplication> clientApp[num];  std::auto_ptr<NAS_Application> nasApp[num];  for (int i=0; i<num; i++)    {      clientApp[i] 	= std::auto_ptr<ClientApplication>	(new ClientApplication(task, semaphore));      nasApp[i] 	= std::auto_ptr<NAS_Application>	(new NAS_Application(task, applicationCore, semaphore));      clientApp[i]->Start(nasApp[i]->RxChannel());      nasApp[i]->Start(clientApp[i]->RxChannel(), i % 2);    }  // Block until the NAS conversation completes.  for (int i=0; i<num; i++)    semaphore.acquire();  task.Stop();  std::cout << "Total number of sessions : " << num << std::endl;  std::cout << "Total number of success : " << TotalSuccess.value() << std::endl;  return 0;}

⌨️ 快捷键说明

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