📄 sample_client3.cxx
字号:
diameter_grouped_t *grouped = tunneling.GetAvp("Tunneling"); AAA_EnumAvpContainerWidget ttypeAvp(*grouped); AAA_EnumAvpContainerWidget tmediumAvp(*grouped); AAA_Utf8AvpContainerWidget cepAvp(*grouped); AAA_Utf8AvpContainerWidget sepAvp(*grouped); diameter_enumerated_t *ttype = ttypeAvp.GetAvp("Tunnel-Type"); diameter_enumerated_t *tmedium = tmediumAvp.GetAvp("Tunnel-Medium-Type"); diameter_utf8string_t *cep = cepAvp.GetAvp("Tunnel-Client-Endpoint"); diameter_utf8string_t *sep = sepAvp.GetAvp("Tunnel-Server-Endpoint"); if (ttype) { AAA_LOG(LM_INFO, "(%P|%t) Tunnel-Type: %d\n", *ttype); } if (tmedium) { AAA_LOG(LM_INFO, "(%P|%t) Medium: %d\n", *tmedium); } if (sep) { AAA_LOG(LM_INFO, "(%P|%t) Server EP: %s\n", sep->data()); } if (cep) { AAA_LOG(LM_INFO, "(%P|%t) Client EP: %s\n", cep->data()); }#endif if ((-- m_HowManyMsg) > 0) { TxAuthenticationRequest(client); return (AAA_ERR_INCOMPLETE); } return (AAA_ERR_SUCCESS); } virtual AAAReturnCode RequestMsg(AAA_SampleClient &client, AAAMessage &msg) { // all request messages are handled by this function. // AAA clients normally should not receive // request messags. In this sample, this will not // be called since the mux is not called in the // RequestMsg() in the client session return (AAA_ERR_SUCCESS); } virtual AAAReturnCode ErrorMsg(AAA_SampleClient &client, AAAMessage &msg) { // same as ErrorMsg of client session return (AAA_ERR_SUCCESS); } AAAReturnCode TxAuthenticationRequest(AAA_SampleClient &client) { // sample of how to compose a message using parser widgets std::cout << "Sending request message" << std::endl; AAA_MsgWidget msg(300, true, 10000); AAA_UInt32AvpWidget authIdAvp(AAA_AVPNAME_AUTHAPPID); AAA_Utf8AvpWidget unameAvp(AAA_AVPNAME_USERNAME); AAA_EnumAvpWidget reAuthAvp(AAA_AVPNAME_REAUTHREQTYPE); AAA_GroupedAvpWidget tunneling("Tunneling"); authIdAvp.Get() = 10000; // my application id unameAvp.Get() = "username@domain.com"; reAuthAvp.Get() = 1; AAA_EnumAvpWidget ttype("Tunnel-Type"); AAA_EnumAvpWidget tmedium("Tunnel-Medium-Type"); AAA_Utf8AvpWidget cep("Tunnel-Client-Endpoint"); AAA_Utf8AvpWidget sep("Tunnel-Server-Endpoint"); ttype.Get() = 100; tmedium.Get() = 200; cep.Get() = "ClientEnd"; sep.Get() = "ServerEnd"; diameter_grouped_t &grp = tunneling.Get(); grp.add(ttype()); grp.add(tmedium()); grp.add(cep()); grp.add(sep()); msg()->acl.add(authIdAvp()); msg()->acl.add(unameAvp()); msg()->acl.add(reAuthAvp()); msg()->acl.add(tunneling()); client.Send(msg()); return (AAA_ERR_SUCCESS); } private: int m_HowManyMsg;};class Client{ public: Client(AAA_Task &task, diameter_unsigned32_t id, int msgCount, int number) : m_Client(task, id, number), m_Action(msgCount) { } void Start() { m_Client.Register(300, m_Action); m_Client.Begin("my_client"); m_Action.TxAuthenticationRequest(m_Client); } void Stop() { do { std::cout << "Waiting till user is authorized #" << m_Client.SessionNum() << std::endl; ACE_OS::sleep(1); } while (! m_Client.UserAuthorized()); m_Client.End(); do { std::cout << "Waiting till user is disconnected, #" << m_Client.SessionNum() << std::endl; ACE_OS::sleep(1); } while (! m_Client.SessionDisconnected()); } private: AAA_SampleClient m_Client; AAA_SampleClientAction m_Action;};// An example of a peer event// handler. We can register this// to a static peer entry to notify// us of peer fsm events.class PeerEventHandler : public AAA_PeerFsmUserEventInterface{ public: virtual void PeerFsmConnected() { AAA_LOG(LM_INFO, "(%P|%t) **** peer is now connected ****\n"); } virtual void PeerFsmDisconnected(int cause) { AAA_LOG(LM_INFO, "(%P|%t) **** peer is now disconnected: %d ****\n", cause); } virtual void PeerFsmError(PFSM_EV_ERR err) { AAA_LOG(LM_INFO, "(%P|%t) **** peer is now disconnected: %d ****\n", err); switch (err) { case PFSM_EV_ERR_CONN_NACK: break; case PFSM_EV_ERR_TIMEOUT_OR_NONCEA: break; } }};int main(int argc, char *argv[]){ AAA_Task task; task.Start(5); time_t start, end; start = time(0); int msgCountPerSession = 10; int sessionCount = 100; char *cfgFile = "config/nas2.local.xml"; if (argc == 2) { cfgFile = argv[1]; } else if (argc == 3) { cfgFile = argv[1]; sessionCount = (atoi(argv[2]) > 0) ? atoi(argv[2]) : sessionCount; } else if (argc > 1) { std::cout << "Usage: aaa_sample_client2 [config file] [num session]\n" << std::endl; exit(0); } // Application core is responsible for providing // peer connectivity between AAA entities AAA_Application appCore(task); if (appCore.Open(cfgFile) == AAA_ERR_SUCCESS) { /// We can get notified of events for "server.isp.net" peer PeerEventHandler handler; AAA_PeerManager peerMngr(task); std::string peerName("server.isp.net"); AAA_Peer *dyncPeer = peerMngr.Lookup(peerName); dyncPeer->RegisterUserEventHandler(handler); /// Wait for connectivity do { std::cout << "Waiting till this AAA has connectivity" << std::endl; ACE_OS::sleep(1); } while (appCore.NumActivePeers() == 0); /// start all session Client **c = new Client*[sessionCount]; for (int i=0; i < sessionCount; i++) { c[i] = new Client(task, 300, msgCountPerSession, i); c[i]->Start(); } /// wait for all sessions to stop for (int i=0; i < sessionCount; i++) { c[i]->Stop(); delete c[i]; } delete c; if (dyncPeer) { dyncPeer->RemoveUserEventHandler(); } } appCore.Close(); task.Stop(); end = time(0); printf("*********************** TOTAL [%ld] ****************\n", end - start); return (0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -