Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

pana_egress.cxx

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library is distributed in the hope that it will be useful,        */
00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
00016 /* Lesser General Public License for more details.                        */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
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     // generate mac value
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     // Parse the payload
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     // Re-do the header again to set the length
00068     m_Msg.length(rawBuf->wr_ptr() - rawBuf->base());
00069     hp.parseAppToRaw();
00070 
00071     /* --- send the message --- */
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     // delete the message
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        // destination port check
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 

Generated on Fri Jun 25 19:18:29 2004 for PANA by doxygen 1.3.5