DiameterMessage.java

Go to the documentation of this file.
00001 /*
00002  * $Id: DiameterMessage.java 167 2007-03-05 09:25:42Z shenny $
00003  *
00004  * Copyright (C) 2004-2006 FhG Fokus
00005  *
00006  * This file is part of Open IMS Core - an open source IMS CSCFs & HSS
00007  * implementation
00008  *
00009  * Open IMS Core is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * For a license to use the Open IMS Core software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact Fraunhofer FOKUS by e-mail at the following
00017  * addresses:
00018  *     info@open-ims.org
00019  *
00020  * Open IMS Core is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  *
00025  * You should have received a copy of the GNU General Public License
00026  * along with this program; if not, write to the Free Software
00027  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028  *
00029  */
00030 
00031 package de.fhg.fokus.diameter.DiameterPeer.data;
00032 
00033 import java.util.Vector;
00034 
00035 import org.apache.log4j.Logger;
00036 
00037 
00044 public class DiameterMessage {
00045     
00047     private static final Logger LOGGER = Logger.getLogger(DiameterMessage.class);
00048 
00050     int version=1;
00051     
00053     public int commandCode;
00054     
00056     public boolean flagRequest=true;
00057     
00059     public boolean flagProxiable=true;
00060     
00062     public boolean flagError=false;
00063     
00065     public boolean flagRetransmission=false;
00066     
00068     public int applicationID=0;
00069     
00071     public long hopByHopID=0;
00072 
00074     public long endToEndID=0;
00075     
00077     public Vector<AVP> avps;
00078     
00079     
00081     public long networkTime=0;
00082 
00083     
00087     public DiameterMessage()
00088     {
00089         avps = new Vector<AVP>();
00090     }
00091     
00101     public DiameterMessage(int Command_Code,boolean Request,boolean Proxiable,
00102             int Application_id,long HopByHop_id, long EndToEnd_id)
00103     {
00104         this.commandCode = Command_Code;
00105         this.flagRequest = Request;
00106         this.flagProxiable = Proxiable;
00107         this.applicationID = Application_id;
00108         this.hopByHopID = HopByHop_id;
00109         this.endToEndID = EndToEnd_id;
00110         avps = new Vector<AVP>();
00111     }
00112     
00119     public DiameterMessage(int Command_Code,boolean Request,int Application_id)
00120     {
00121         this.commandCode = Command_Code;
00122         this.flagRequest = Request;
00123         this.flagProxiable = false;
00124         this.applicationID = Application_id;
00125         avps = new Vector<AVP>();
00126     }
00127     
00132     public void addAVP(AVP child)
00133     {
00134         avps.add(child);
00135     }
00136     
00142     public int getAVPCount()
00143     {
00144         return avps.size();
00145     }
00146     
00152     public AVP getAVP(int index)
00153     {
00154         if (index<avps.size())
00155             return (AVP)avps.get(index);
00156         else return null;
00157     }
00158     
00163     public void deleteAVP(AVP avp)
00164     {
00165         avps.remove(avp);
00166     }
00167     
00175     public AVP findAVP(int Code,boolean Mandatory,int Vendor_id)
00176     {
00177         AVP avp;
00178         for(int i=0;i<avps.size();i++){
00179             avp = (AVP) avps.get(i);
00180             if (avp.code == Code &&
00181                 avp.flag_mandatory == Mandatory &&
00182                 avp.vendor_id == Vendor_id) 
00183                     return avp;
00184         }
00185         return null;
00186     }
00187     
00193     public AVP[] findAVPs(int Code)
00194     {
00195         AVP[] avpset;
00196         int j = 0, count = 0;
00197         AVP avp;
00198         
00199         for(int i=0;i<avps.size();i++){
00200             avp = (AVP) avps.get(i);
00201             if (avp.code == Code)
00202                 count++;
00203         }
00204         
00205         if (count == 0) return null;
00206         avpset = new AVP[count];
00207         for(int i=0;i<avps.size();i++){
00208             avp = (AVP) avps.get(i);
00209             if (avp.code == Code) {
00210                 avpset[j++] = avp;
00211                 if (j == count) break;
00212             }
00213         }
00214         
00215         return avpset;
00216     }
00217     
00223     public AVP findAVP(int Code) {
00224         AVP avp;
00225         for(int i=0;i<avps.size();i++){
00226             avp = (AVP) avps.get(i);
00227             if (avp.code == Code) {
00228                 
00229                 return avp;
00230             }
00231         }
00232         return null;    
00233         
00234     }
00235     
00240     public AVP getSessionId() {
00241         return findAVP(AVP.Session_Id);
00242     }
00243     
00247     public String toString()
00248     {
00249         StringBuffer x = new StringBuffer();
00250         x.append("Diameter: Code=");x.append(commandCode);
00251         if (flagRequest) x.append(" R");
00252         if (flagProxiable) x.append(" P");
00253         if (flagError) x.append(" E");
00254         if (flagRetransmission) x.append(" T");
00255         
00256         x.append(" AppID=");x.append(applicationID);
00257         x.append(" HbHID=");x.append(hopByHopID);
00258         x.append(" E2EID=");x.append(endToEndID);
00259         
00260         x.append("\n");
00261         for(int i=0;i<avps.size();i++){
00262             x.append("\t");
00263             x.append(avps.get(i).toString());
00264             x.append("\n");
00265         }       
00266         return x.toString();
00267     }
00268     
00270     public static final int Code_CE=257;
00271     
00273     public static final int Code_DW=280;
00274     
00276     public static final int Code_DP=282;
00277     
00281     public static final int DIAMETER_SUCCESS = 2001;
00282     
00287     public static final int DIAMETER_NO_COMMON_APPLICATION = 5010;
00288     
00293     public static final int DIAMETER_UNABLE_TO_COMPLY = 5012;
00294     
00295 }

Generated on Thu Oct 23 04:07:36 2008 for Open IMS Core JavaDiameterPeer by  doxygen 1.5.2