change. not compiling yet.
authorjihoonl <jihoonl>
Sat, 4 Jul 2009 00:16:43 +0000 (00:16 +0000)
committerjihoonl <jihoonl>
Sat, 4 Jul 2009 00:16:43 +0000 (00:16 +0000)
Robust/src/Benchmarks/SingleTM/Intruder/Decoded.java
Robust/src/Benchmarks/SingleTM/Intruder/Decoder.java
Robust/src/Benchmarks/SingleTM/Intruder/ERROR.java
Robust/src/Benchmarks/SingleTM/Intruder/List_t.java
Robust/src/Benchmarks/SingleTM/Intruder/Queue_t.java
Robust/src/Benchmarks/SingleTM/Intruder/Random.java
Robust/src/Benchmarks/SingleTM/Intruder/convertURNHex.java
Robust/src/Benchmarks/SingleTM/Intruder/toLower.java

index ec71a2f4cdb2f514b058afa399a9d1be5d13c7d0..736970ec55e2dec5ed99eb8eee574f6eada1649f 100644 (file)
@@ -5,5 +5,7 @@
 public class Decoded {
     int flowId;
     String data;
+
+    public Decoded() {}
 }
 
index 9374bcaacee3a7e7600f4b535f19e0ac8f10bb6f..4733da878e5bb967f450ff78f5fbb78706751ce2 100644 (file)
 #define MAP_T                       RBTree
 #define MAP_ALLOC(hash, cmp)        RBTree.alloc(cmp)
 #define MAP_INSERT(map, key, data)  map.insert(key, data)
-#define MAP_CONTAINS(map, key)      map.contains(key);
-#define MAP_FIND(map,key)           map.get(key);
-#define MAP_INSERT(map,key,data)    map.insert(key,data);
-#define MAP_REMOVE(map,key)         map.deleteNode(key);
+#define MAP_CONTAINS(map, key)      map.contains(key)
+#define MAP_FIND(map,key)           map.get(key)
+#define MAP_REMOVE(map,key)         map.deleteNode(key)
 
 public class Decoder {
 
@@ -93,23 +92,25 @@ public class Decoder {
         Decoder decoderPtr;
 
         decoderPtr = new Decoder();
-        if(decoderPtr) {
-            decoderPtr.fragementedMapPtr = MAP_ALLOC(0,0);
+        if(decoderPtr != null) {
+            decoderPtr.fragmentedMapPtr = MAP_ALLOC(0,0);
 
-            if(decoderPtr.fragementedMapPtr == null)
+            if(decoderPtr.fragmentedMapPtr == null)
             {
                 System.out.println("Assert in Decoder.alloc");
                 System.exit(1);
             }
             
-            decoderPtr.decodedQueuePtr = Queue_t.alloc(1024);
+            decoderPtr.decodedQueuePtr = Queue_t.queue_alloc(1024);
             if(decoderPtr.decodedQueuePtr == null)
             {
                 System.out.println("Assert in Decoder.alloc");
                 System.exit(1);
             }
 
-            return decoderPtr;            
+        }
+
+        return decoderPtr;
     }
 
 
@@ -118,28 +119,24 @@ public class Decoder {
  * =============================================================================
  void decoder_free (decoder_t* decoderPtr);
  */
-    public free(Decoder decoderPtr) {
-        fragmentedMapPtr = null;
-        decodedQueuePtr = null;
-        decoderPtr = null;
-    }
 
 
 /* =============================================================================
  * decoder_process
  * =============================================================================
- error_t decoder_process (decoder_t* decoderPtr, char* bytes, long numByte);
+ er_t decoder_process (decoder_t* decoderPtr, char* bytes, long numByte);
  */
     public int process(Packet bytes,int numByte)
     {
         boolean status;
+        ERROR er;
 
         /*
-         * Basic error checing
+         * Basic er checing
          */
 
-        if (numByte < PACKET_HEADER_LENGTH) {
-            return ERROR.SHORT;
+        if (numByte < 0) {
+            return er.SHORT;
         }
 
         /* need to look into it later */
@@ -150,16 +147,17 @@ public class Decoder {
         int length = packetPtr.length;
 
         if (flowId < 0) {
-            return ERROR.FLOWID;
+            return er.FLOWID;
         }
 
-        if ((fragmentedId < 0) || (fragmentId >= numFragment)) {
-            return ERROR.FRAGMENTID;
+        if ((fragmentId < 0) || (fragmentId >= numFragment)) {
+            return er.FRAGMENTID;
         }
 
         if (length < 0) {
-            return ERROR.LENGTH;
+            return er.LENGTH;
         }
+
     
         /*
          * Add to fragmented map for reassembling
@@ -178,16 +176,15 @@ public class Decoder {
                 }
 
                 status = MAP_INSERT(fragmentedMapPtr,flowId,fragmentListPtr);
-                if(status == null) {
+                if(status) {
                     System.out.println("Assertion in process");
                     System.exit(1);                                
                 }
             } else {
-
                 List_Iter it;
                 it.reset(fragmentListPtr);
                 
-                if(it.hasNext(fragmentListPtr) == null) {
+                if(it.hasNext(fragmentListPtr)) {
                     System.out.println("Assertion in process");
                     System.exit(1);
                 }
@@ -197,13 +194,13 @@ public class Decoder {
 
                 if (numFragment != expectedNumFragment) {
                     status = MAP_REMOVE(fragmentedMapPtr,flowId);
-                    if(status == null) {
+                    if(status) {
                         System.out.println("Assertion in process");
                         System.exit(1);
                     }
 
                     status = fragmentListPtr.insert(packetPtr);
-                    if(status == null) {
+                    if(status) {
                         System.out.println("Assertion in process");
                         System.exit(1);
                     }
@@ -214,7 +211,8 @@ public class Decoder {
 
                     if(fragmentListPtr.getSize() ==  numFragment) {
 
-                        int numByte = 0;
+
+                        int numBytes = 0;
                         int i = 0;
                         it.reset(fragmentListPtr);
 
@@ -222,37 +220,37 @@ public class Decoder {
                             Packet fragmentPtr = (Packet)it.next(fragmentListPtr);
 
                             if(fragmentPtr.fragmentId != i) {
-                                status = MAP_REMOVE(fragmentedMapPtr,(flowId);
+                                status = MAP_REMOVE(fragmentedMapPtr,flowId);
                                 
-                                if(status == null) {
+                                if(status) {
                                     System.out.println("Assertion in process");
                                     System.exit(1);
                                 }
-                                    return ERROR.INCOMPLETE; /* should be sequential */
+                               return er.INCOMPLETE; /* should be sequential */
                             }
-                                numByte += fragmentPtr.length;
+                                numBytes += fragmentPtr.length;
                                 i++;
                         }
 
-                        char[] data = new char[numByte+1];
+                        char[] data = new char[numBytes+1];
                         if(data == null) {
                              System.out.println("Assertion in process");
                              System.exit(1);
                         }
 
-                        data[numByte] = '\0';
+                        data[numBytes] = '\0';
                         int dst = 0;            // index of data
-                        int i;
                         it.reset(fragmentListPtr);
-                        while(it.hasNext(fragmentLIstPtr)) {
+                        while(it.hasNext(fragmentListPtr)) {
                             Packet fragmentPtr = (Packet)it.next(fragmentListPtr);
 
-                            for(i=0;i<fragmentPtr.length;i++)
-                                data[dst++] = fragmentPtr.data[i];
+                            for(i=0;i<fragmentPtr.length;i++) {                      
+                                data[dst++] = fragmentPtr.data.charAt(i);
+                            }
                         }
-
-                        if(dst != data + numByte) {
-                            System.out.println("Assertion in process");                           
+                        
+                        if(dst != (numBytes)) {
+                            System.out.println("Assertion in process");                         
                             System.exit(1);
                         }
 
@@ -263,31 +261,33 @@ public class Decoder {
                         }
 
                         decodedPtr.flowId = flowId;
-                        decodedPtr.data = String.copyValueOf(data);
+                        decodedPtr.data = new String(data);
 
-                        status = decodededQueuePtr.queue_push(decodedPtr);
+                        status = decodedQueuePtr.queue_push(decodedPtr);
 
-                        if(status == null) {
-                            System.out.println("Assertion in process");                           
+                        if(status) {
+                            System.out.println("Assertion in process");  
                             System.exit(1);
                         }
 
                         status = MAP_REMOVE(fragmentedMapPtr,flowId);
 
-                        if(status == null) {
-                            System.out.println("Assertion in process");                           
+                        if(status) {
+                            System.out.println("Assertion in process");                         
                             System.exit(1);
                         }
-                    }
-                }
-            } else {
+                    }                
+                } 
+            }
+
+        }else {
 
                 /*
                  * This is the only fragment, so it is ready
                  */
 
                 if (fragmentId != 0) {
-                    return ERROR.FRAGMENTID;
+                    return er.FRAGMENTID;
                 }
 
                 String data = new String();
@@ -297,8 +297,9 @@ public class Decoder {
                 }
 
                 data.concat(packetPtr.data);
-                
-                Decoded decodedPtr = new Decoded();
+
+               Decoded decodedPtr = new Decoded();
+
                 if(decodedPtr == null) {
                     System.out.println("Assertion in process");                           
                     System.exit(1);
@@ -309,22 +310,24 @@ public class Decoder {
 
                 status = decodedQueuePtr.queue_push(decodedPtr);
                 
-                if(status == null) {
+                if(status) {
                     System.out.println("Assertion in process");                           
                     System.exit(1);
                 }
-
-                return ERROR.NONE;
-
             }
 
+    
+        return er.NONE;
 
+            
+        
+    }
 
 
 /* =============================================================================
  * TMdecoder_process
  * =============================================================================
- error_t TMdecoder_process (TM_ARGDECL  decoder_t* decoderPtr, char* bytes, long numByte);
+ er_t TMdecoder_process (TM_ARGDECL  decoder_t* decoderPtr, char* bytes, long numByte);
  */
 
 
@@ -337,19 +340,19 @@ public class Decoder {
         String data;
         Decoded decodedPtr = (Decoded)decodedQueuePtr.queue_pop();
 
-        if(decodedPtr) {
+        if(decodedPtr != null) {
             decodedFlowId[0] = decodedPtr.flowId;
             data = decodedPtr.data;
             decodedPtr = null;
         } else {
-            decodedFlowId = -1;
+            decodedFlowId[0] = -1;
             data= null;
         }
 
         return data;
     }
 
-
+}
 
 /* =============================================================================
  * TMdecoder_getComplete
@@ -357,7 +360,7 @@ public class Decoder {
  * =============================================================================
  char* TMdecoder_getComplete (TM_ARGDECL  decoder_t* decoderPtr, long* decodedFlowIdPtr);
  */
-}
+
 
 /* =============================================================================
  *
index 2ff1a932a7be337d6c040b72ce8491bd5aebbe7e..2c004e6e177e1a3c30f4fb32dbadb061d598aa5e 100644 (file)
  * =============================================================================
  */
 
-public class ERROR {
-    int NONE = 0;
-    int SHORT = 1;
-    int FLOWID = 2;
-    int FRAGMENTID = 3;
-    int LENGTH = 4;
-    int NUMFRAGMENT = 5;
-    int INCOMPLETE = 6;
-    int SIGNATURE = 7;
+public static class ERROR {
+    static int NONE;
+    static int SHORT;
+    static int FLOWID;
+    static int FRAGMENTID;
+    static int LENGTH;
+    static int NUMFRAGMENT;
+    static int INCOMPLETE;
+    static int SIGNATURE;
+
+    public ERROR() {
+
+        NONE = 0;
+        SHORT = 1;
+        FLOWID = 2;
+        FRAGMENTID = 3;
+        LENGTH = 4;
+        NUMFRAGMENT = 5;
+        INCOMPLETE = 6;
+        SIGNATURE = 7;   
+    }
 }
 
 
index d32a0f454fe967ed09282b66aacefc02a5b04cf0..aa72c25be872ca4c193c0de132be5c8cc6d94b5a 100644 (file)
@@ -74,8 +74,8 @@
 
 public class List_t {
 
-    public List_Node head;
-    int flag;
+    List_Node head;
+    int chk;
     int size;
 
     public List_t() {
@@ -113,7 +113,7 @@ public class List_t {
  *
  */
 
-    public static List_t alloc(int flag
+    public static List_t alloc(int chk
     {
         List_t listPtr = new List_t();
 
@@ -125,7 +125,7 @@ public class List_t {
         listPtr.head.nextPtr = null;
         listPtr.size = 0;
         
-        listPtr.flag = flag;
+        listPtr.chk = chk;
 
         return listPtr;
     }
@@ -207,9 +207,9 @@ public class List_t {
 
     public int compare(Object obj1,Object obj2) 
     {
-        if(flag == 1)
+        if(chk == 1)
         {
-            return Packet.compareFragmentID(obj1,obj2);
+            return Packet.compareFragmentID((Packet)obj1,(Packet)obj2);
         }
         else 
             return compareObject(obj1,obj2);
@@ -294,19 +294,6 @@ public class List_t {
  * =============================================================================
  */
 
- /* Test list */
 
- public static void main(String[] argv) {
-     List_t listPtr;
-     int[] data1 = new int[5];
-     int[] data2 = new int[6];
 
-     int i;
-
-     System.out.println("Starting...");
-        }
-
-}
-
-
-     
+} 
index 0f30d35ae454df58896d5517bd33c975bec82dbb..b692dc56d543d9b3de52470c3ea9acbcaceb7667 100644 (file)
@@ -314,6 +314,27 @@ public class Queue_t {
       return dataPtr;
     }
 
+  public void queue_shuffle (Random randomPtr)
+    {
+      int numElement;
+      if (pop < push) {
+        numElement = push - (pop + 1);
+      } else {
+        numElement = capacity - (pop - push + 1);
+      }
+
+      int i;
+      int base = pop + 1;
+      for (i = 0; i < numElement; i++) {
+        int r1 = (int) (randomPtr.random_generate() % numElement);
+        int r2 = (int) (randomPtr.random_generate() % numElement);
+        int i1 = (base + r1) % capacity;
+        int i2 = (base + r2) % capacity;
+        Object tmp = elements[i1];
+        elements[i1] = elements[i2];
+        elements[i2] = tmp;
+      }
+    }
 
 }
 /* =============================================================================
index 2c601f48176362ad79ec88a09926fa924536dad2..0c1dc865ab9704e60e7c8ed7968b8cc630e743e6 100644 (file)
@@ -1,23 +1,23 @@
 public class Random {
-  long[] mt; 
+  int[] mt; 
   int mti;
-  long RANDOM_DEFAULT_SEED;
+  int RANDOM_DEFAULT_SEED;
   /* period parameter */
   int N;
   int M;
-  long MATRIX_A;
-  long UPPER_MASK;
-  long LOWER_MASK;
+  int MATRIX_A;
+  int UPPER_MASK;
+  int LOWER_MASK;
 
   public Random() {
-    RANDOM_DEFAULT_SEED = 0L;
+    RANDOM_DEFAULT_SEED = 0;
     N = 624;
     M = 397;
-    mt = new long[N];
+    mt = new int[N];
     mti = N;
-    MATRIX_A = 0x9908b0dfL;   /* constant vector a */
-    UPPER_MASK = 0x80000000L; /* most significant w-r bits */
-    LOWER_MASK = 0x7fffffffL; /* least significant r bits */
+    MATRIX_A = 0x9908b0df;   /* constant vector a */
+    UPPER_MASK = 0x80000000; /* most significant w-r bits */
+    LOWER_MASK = 0x7fffffff; /* least significant r bits */
   }
 
   public void random_alloc() {
@@ -25,34 +25,34 @@ public class Random {
   }
 
   /* initializes mt[N] with a seed */
-  public void init_genrand(long s) {
+  public void init_genrand(int s) {
     int mti;
-    mt[0]= s & 0xFFFFFFFFL;
+    mt[0]= s & 0xFFFFFFFF;
     for (mti=1; mti<N; mti++) {
-     mt[mti] = (1812433253L * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
+     mt[mti] = (1812433253 * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
       /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
       /* In the previous versions, MSBs of the seed affect   */
       /* only MSBs of the array mt[].                        */
       /* 2002/01/09 modified by Makoto Matsumoto             */
-      mt[mti] &= 0xFFFFFFFFL;
+      mt[mti] &= 0xFFFFFFFF;
       /* for >32 bit machines */
     }
     this.mti=mti;
   }
 
-  public void random_seed(long seed) {
+  public void random_seed(int seed) {
     init_genrand(seed);
   }
 
-  public long random_generate() {
+  public int random_generate() {
     return genrand_int32();
   }
 
-  //public static long genrand_int32(long[] mt, long mtiPtr) {
-  public long genrand_int32() {
-    long y;
-    long[] mag01= new long[2];
-    mag01[0] = 0x0L;
+  //public static int genrand_int32(int[] mt, int mtiPtr) {
+  public int genrand_int32() {
+    int y;
+    int[] mag01= new int[2];
+    mag01[0] = 0x0;
     mag01[1] = MATRIX_A;
     int mti = this.mti;
 
@@ -62,18 +62,18 @@ public class Random {
       int kk;
 
       if (mti == N+1)   /* if init_genrand() has not been called, */
-        init_genrand(5489L); /* a default initial seed is used */
+        init_genrand(5489); /* a default initial seed is used */
 
       for (kk=0;kk<N-M;kk++) {
         y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
-        mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[(int)(y & 0x1L)];
+        mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[(int)(y & 0x1)];
       }
       for (;kk<N-1;kk++) {
         y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
-        mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[(int)(y & 0x1L)];
+        mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[(int)(y & 0x1)];
       }
       y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
-      mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[(int)(y & 0x1L)];
+      mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[(int)(y & 0x1)];
 
       mti = 0;
     }
@@ -82,8 +82,8 @@ public class Random {
 
     /* Tempering */
     y ^= (y >> 11);
-    y ^= (y << 7) & 0x9d2c5680L;
-    y ^= (y << 15) & 0xefc60000L;
+    y ^= (y << 7) & 0x9d2c5680;
+    y ^= (y << 15) & 0xefc60000;
     y ^= (y >> 18);
 
     this.mti = mti;
index 15750b0bb09992b0512a12170b8484c531a11f33..41e839e845c2ae5299979d8a6e1ef1bd1cf431dd 100644 (file)
@@ -5,7 +5,7 @@ public class convertURNHex extends Preprocessor
     public convertURNHex() {
         super();
     }
-    public void process(String str)
+    public static void process(String str)
     {
       char[] str_char = str.toCharArray();
       int src = 0;
@@ -15,8 +15,8 @@ public class convertURNHex extends Preprocessor
       while((c = str_char[src]) != '\0') {
           if (c == '%') {
               char[] hex = new char[3];
-              hex[0] = Character.toLowerCase((str_char[src+1]));
-              hex[1] = Character.toLowerCase((str_char[src+2]));
+              hex[0] = toLowerCase((int)str_char[src+1]);
+              hex[1] = toLowerCase((int)str_char[src+2]);
               hex[2] = '\0';
                          
               String a = String.valueOf(hex);
@@ -30,6 +30,17 @@ public class convertURNHex extends Preprocessor
       }
       str_char[dst] = '\0';
       
-      str = String.valueOf(str_char);
+      str = new String(str_char);
+    }
+
+    private static char toLowerCase(int a) {
+        
+        if(a >= 65 && a <= 90)
+        {
+            return (char)(a + 32);  // difference 'a'(97) - 'A'(65) = 32
+        }
+        else return (char)a;
+
+
     }
 }
index b52cbe25baa4d87b400974256156b7169e2edb4c..69ad36b533743eca313595a101ad90f58539592f 100644 (file)
@@ -4,9 +4,9 @@ public class toLower extends Preprocessor
     public toLower() {
         super();
     }
-    public void process(String str)
+    public static void process(String str)
     {
-       return str.toLowerCase();
+       str =  str.toLowerCase();
     }
 
 }