00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "pana_ingress.h"
00036 #include "pana_exceptions.h"
00037
00038 int PANA_IngressMsgDelivery::Serve()
00039 {
00040 try {
00041 (*m_MsgHandler)(m_Message);
00042 }
00043 catch (PANA_Exception &e) {
00044 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, DELIVERY] Exception, code=%d, description=%s\n",
00045 e.code(), e.description().data()));
00046 }
00047 catch (...) {
00048 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, DELIVERY] Unknown error\n"));
00049 }
00050 Release(2);
00051 return (0);
00052 }
00053
00054 int PANA_IngressMsgParser::Serve()
00055 {
00056 AAAMessageBlock *aBuffer = reinterpret_cast<AAAMessageBlock*>(&m_Message);
00057 try {
00058
00059 PANA_Message *parsedMsg;
00060 ACE_NEW_NORETURN(parsedMsg, PANA_Message);
00061
00062 if (parsedMsg == NULL) {
00063 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, ALLOC] App message\n"));
00064 throw (0);
00065 }
00066
00067 PANA_HeaderParser hp;
00068 AAADictionaryOption opt(PARSE_STRICT, PANA_DICT_PROTOCOL_ID);
00069 hp.setRawData(aBuffer);
00070 hp.setAppData(static_cast<PANA_MsgHeader*>(parsedMsg));
00071 hp.setDictData(&opt);
00072
00073 hp.parseRawToApp();
00074
00075 PANA_PayloadParser pp;
00076 pp.setRawData(aBuffer);
00077 pp.setAppData(&(parsedMsg->avpList()));
00078 pp.setDictData(parsedMsg->getDictHandle());
00079
00080 pp.parseRawToApp();
00081
00082
00083 parsedMsg->srcDevices().move(m_SrcDevices);
00084 parsedMsg->srcPort(m_SrcPort);
00085
00086 PANA_IngressMsgDelivery *delivery;
00087 ACE_NEW_NORETURN(delivery,
00088 PANA_IngressMsgDelivery(m_Group,
00089 *parsedMsg));
00090 if (delivery) {
00091 delivery->RegisterHandler(*m_MsgHandler);
00092 if (Schedule(delivery) < 0) {
00093 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, SCHEDULE] delivery job\n"));
00094 delete parsedMsg;
00095 throw (0);
00096 }
00097 }
00098 else {
00099 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, ALLOC] delivery job\n"));
00100 delete parsedMsg;
00101 throw (0);
00102 }
00103 }
00104 catch (AAAErrorStatus st) {
00105 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, PARSING] parsing error\n"));
00106 }
00107 catch (...) {
00108 }
00109
00110
00111 PANA_MESSAGE_POOL()->free(&m_Message);
00112 delete &m_SrcDevices;
00113
00114 Release(2);
00115 return (0);
00116 }
00117
00118 int PANA_IngressReceiver::Serve()
00119 {
00120 m_Signalled = true;
00121 ACE_UINT32 srcPort;
00122 PANA_MessageBuffer *msg_buffer = NULL;
00123 try {
00124 PANA_DeviceIdContainer *srcDevices;
00125 ACE_NEW_NORETURN(srcDevices, PANA_DeviceIdContainer);
00126 if (srcDevices == NULL) {
00127 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, ALLOC] device id on %s\n",
00128 m_Name.data()));
00129 throw (0);
00130 }
00131
00132 msg_buffer = PANA_MESSAGE_POOL()->malloc();
00133 ssize_t bytes = m_IO.recv(msg_buffer->wr_ptr(), msg_buffer->size(),
00134 srcPort, *srcDevices);
00135 if (bytes > 0) {
00136 if (m_MsgHandler == NULL) {
00137 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, RECV] handler absent on %s\n",
00138 m_Name.data()));
00139 throw (1);
00140 }
00141
00142 PANA_IngressMsgParser *parser;
00143 ACE_NEW_NORETURN(parser,
00144 PANA_IngressMsgParser(m_Group,
00145 *msg_buffer,
00146 srcPort,
00147 *srcDevices));
00148 if (parser) {
00149 msg_buffer->size(bytes);
00150 parser->RegisterHandler(*m_MsgHandler);
00151 if (Schedule(parser) < 0) {
00152 delete parser;
00153 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, SCHEDULE] delivery job on %s\n",
00154 m_Name.data()));
00155 throw (0);
00156 }
00157 }
00158 else {
00159 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, ALLOC] message parser job on %s\n",
00160 m_Name.data()));
00161 throw (0);
00162 }
00163 Schedule();
00164 }
00165 else if (bytes == 0) {
00166 throw (1);
00167 } else if ((errno != EAGAIN) &&
00168 (errno != ETIME) &&
00169 (errno != ECONNREFUSED)) {
00170 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, RECV] receive error on %s : %s\n",
00171 m_Name.data(), strerror(errno)));
00172 if (m_ErrHandler) {
00173 (*m_ErrHandler)(errno);
00174 }
00175 throw (0);
00176 }
00177 else {
00178
00179 throw (1);
00180 }
00181 }
00182 catch (int rc) {
00183 PANA_MESSAGE_POOL()->free(msg_buffer);
00184 if (rc) {
00185
00186 Schedule();
00187 }
00188 else {
00189 m_Signalled = false;
00190 }
00191 }
00192 return (0);
00193 }
00194