CodecTest.java

Go to the documentation of this file.
00001 /*
00002  * $Id: CodecTest.java 2 2006-11-14 22:37:20Z vingarzan $
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.io.File;
00034 import java.io.FileInputStream;
00035 import java.io.FileOutputStream;
00036 import java.io.FileNotFoundException;
00037 import java.io.IOException;
00038 import java.util.Arrays;
00039 
00040 import org.apache.log4j.Logger;
00041 
00042 
00049 public class CodecTest {
00050     
00052     private static final Logger LOGGER = Logger.getLogger(CodecTest.class);
00053 
00054     static byte[] readData(String filename)
00055     {
00056         FileInputStream fin;
00057         byte[] b = null;
00058         int count = 0;
00059         int len;
00060         try {
00061             fin = new FileInputStream(filename);
00062             len = fin.available();
00063             b = new byte[len];
00064             count = fin.read(b);
00065             if (count == -1) b = null;
00066         } catch (FileNotFoundException e) {
00067             // TODO Auto-generated catch block
00068             e.printStackTrace();
00069         } catch (IOException e) {
00070             // TODO Auto-generated catch block
00071             e.printStackTrace();
00072         } 
00073         return b;
00074     }
00075     static boolean writeData(String filename,byte[] data)
00076     {
00077         FileOutputStream fout;
00078         try {
00079             File f = new File(filename);
00080             if (!f.exists()) f.createNewFile();
00081             fout = new FileOutputStream(f);         
00082             fout.write(data);
00083             fout.close();
00084             return true;
00085         } catch (FileNotFoundException e) {
00086             // TODO Auto-generated catch block
00087             e.printStackTrace();
00088         } catch (IOException e) {
00089             // TODO Auto-generated catch block
00090             e.printStackTrace();
00091         } 
00092         return false;
00093     }
00094     
00095     public static void main(String[] args) {
00096         DiameterMessage msg = null;
00097         byte[] original={},bootstrapped={};
00098         long duration;
00099         int repeat = 1000000;
00100         if (args.length<1) {
00101             LOGGER.debug("No input file specified. Please specify it as first parameter!");
00102             System.exit(-1);
00103         }
00104         if (args.length<2) {
00105             LOGGER.debug("No output file specified. Please specify it as second parameter!");
00106             System.exit(-1);
00107         }
00108         original = readData(args[0]);
00109         if (original==null){
00110             LOGGER.debug("Error reading data from file. Aborting!");
00111             System.exit(-1);            
00112         }
00113         duration = System.currentTimeMillis();
00114         try {
00115             for(int i=0;i<repeat;i++)
00116                 msg = Codec.decodeDiameterMessage(original,0);
00117         } catch (DiameterMessageDecodeException e) {
00118             // TODO Auto-generated catch block
00119             e.printStackTrace();
00120             LOGGER.debug("Error decoding AVP. Aborting!");
00121             System.exit(-1);            
00122         }
00123 //      try {
00124 //          for(int i=0;i<repeat;i++)
00125 //              avp.ungroup();
00126 //      } catch (AVPDecodeException e1) {
00127 //          // TODO Auto-generated catch block
00128 //          e1.printStackTrace();
00129 //          LOGGER.debug("Error Ungrouping AVP. Aborting!");
00130 //          System.exit(-1);            
00131 //      }
00132         for(int i=0;i<repeat;i++)
00133             bootstrapped = Codec.encodeDiameterMessage(msg);
00134 
00135         duration = System.currentTimeMillis() - duration;
00136         
00137         LOGGER.debug("Speed: "+repeat/duration*1000+" ops/sec");
00138         LOGGER.debug(msg);
00139                 
00140         bootstrapped = Codec.encodeDiameterMessage(msg);
00141         if (!writeData(args[1],bootstrapped)){
00142             LOGGER.debug("Error writing data to file. Aborting!");
00143             System.exit(-1);                    
00144         }
00145         if (Arrays.equals(original,bootstrapped)){
00146             LOGGER.debug("Bootstrapping Succesfull...");        
00147         }
00148         else{
00149             LOGGER.debug("Bootstrapping failed!");
00150             System.exit(-1);                                
00151         }
00152 
00153         /* Test of AVP creation */
00154 //      avp = new AVP(123,false,16777216);
00155 //      avp.setData("Bubu was here");
00156 //      bootstrapped = AVP.encode(avp);
00157 //      if (!writeData(args[1],bootstrapped)){
00158 //          LOGGER.debug("Error writing data to file. Aborting!");
00159 //          System.exit(-1);                    
00160 //      }
00161         
00162         
00163     }
00164 }

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