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 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
00068 e.printStackTrace();
00069 } catch (IOException e) {
00070
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
00087 e.printStackTrace();
00088 } catch (IOException e) {
00089
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
00119 e.printStackTrace();
00120 LOGGER.debug("Error decoding AVP. Aborting!");
00121 System.exit(-1);
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
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
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 }
00164 }