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 #include "pana_egress.h"
00035 #include "pana_memory_manager.h"
00036
00037 int PANA_EgressSender::m_MacGenExclusionTable[] = { PANA_MTYPE_DISCOVER,
00038 PANA_MTYPE_START };
00039 int PANA_EgressMacGenerationJob::Serve()
00040 {
00041
00042 m_Session->SA().AddMacValue(m_Msg);
00043
00044 return PANA_EgressDeliveryJob::Serve();
00045 }
00046
00047 int PANA_EgressDeliveryJob::Serve()
00048 {
00049 PANA_MessageBuffer *rawBuf = PANA_MESSAGE_POOL()->malloc();
00050
00051 PANA_HeaderParser hp;
00052 AAADictionaryOption opt(PARSE_STRICT, PANA_DICT_PROTOCOL_ID);
00053 hp.setRawData(reinterpret_cast<AAAMessageBlock*>(rawBuf));
00054 hp.setAppData(static_cast<PANA_MsgHeader*>(&m_Msg));
00055 hp.setDictData(&opt);
00056
00057 hp.parseAppToRaw();
00058
00059
00060 PANA_PayloadParser pp;
00061 pp.setRawData(reinterpret_cast<AAAMessageBlock*>(rawBuf));
00062 pp.setAppData(&(m_Msg.avpList()));
00063 pp.setDictData(m_Msg.getDictHandle());
00064
00065 pp.parseAppToRaw();
00066
00067
00068 m_Msg.length(rawBuf->wr_ptr() - rawBuf->base());
00069 hp.parseAppToRaw();
00070
00071
00072 if (m_IO.send(rawBuf->base(), m_Msg.length(),
00073 m_Msg.srcPort(), m_Msg.srcDevices()) < 0) {
00074 ACE_DEBUG((LM_ERROR, "(%P|%t) [EGRESS, SEND] transmitt error on %s\n",
00075 m_Name.data()));
00076 }
00077
00078
00079 m_Msg.avpList().releaseContainers();
00080 delete &m_Msg;
00081
00082 PANA_MESSAGE_POOL()->free(rawBuf);
00083 Release(2);
00084 return (0);
00085 }
00086
00087 void PANA_EgressSender::Schedule()
00088 {
00089 try {
00090
00091 if (m_Msg.srcPort() <= 0) {
00092 throw (PANA_Exception(PANA_Exception::TRANSPORT_FAILED,
00093 "Invalid destination port bounded to message"));
00094 }
00095
00096 PANA_EgressJob *job = NULL;
00097 if (m_Session && (m_Session->SA().MSK().size() > 0)) {
00098 for (int i=0; i<sizeof(m_MacGenExclusionTable)/sizeof(int); i++) {
00099 if (m_Msg.type() == m_MacGenExclusionTable[i]) {
00100 ACE_NEW_NORETURN(job, PANA_EgressDeliveryJob(*this));
00101 break;
00102 }
00103 }
00104 if (job == NULL) {
00105 ACE_NEW_NORETURN(job, PANA_EgressMacGenerationJob(*this));
00106 }
00107 }
00108 else {
00109 ACE_NEW_NORETURN(job, PANA_EgressDeliveryJob(*this));
00110 }
00111
00112 if (job) {
00113 if (PANA_EgressJob::Schedule(job) < 0) {
00114 throw (PANA_Exception(PANA_Exception::TRANSPORT_FAILED,
00115 "Egress scheduling failed"));
00116 }
00117 }
00118 else {
00119 throw (PANA_Exception(PANA_Exception::NO_MEMORY,
00120 "Allocation error for message transmitter"));
00121 }
00122 }
00123 catch (PANA_Exception &e) {
00124 ACE_DEBUG((LM_ERROR, "(%P|%t) [EGRESS, SCHEDULE] Exception on %s, code=%d, description=%s\n",
00125 m_Name.data(), e.code(), e.description().data()));
00126 }
00127 catch (...) {
00128 ACE_DEBUG((LM_ERROR, "(%P|%t) [EGRESS, SCHEDULE] Unknown error on %s\n",
00129 m_Name.data()));
00130 }
00131 }
00132
00133
00134
00135