From e193d4d2c2c04deccaabcc718fe8a71f7c90d24d Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 13 Oct 2009 23:44:03 +0000 Subject: [PATCH] changes to intruder --- .../Benchmarks/SingleTM/Intruder/Decoded.java | 4 - .../Benchmarks/SingleTM/Intruder/Decoder.java | 384 ++++++------------ .../SingleTM/Intruder/Detector.java | 120 ++---- .../SingleTM/Intruder/Intruder.java | 94 ++--- .../SingleTM/Intruder/List_Iter.java | 3 +- .../SingleTM/Intruder/List_Node.java | 2 - .../Benchmarks/SingleTM/Intruder/List_t.java | 33 +- .../Benchmarks/SingleTM/Intruder/Queue_t.java | 174 +++----- .../Benchmarks/SingleTM/Intruder/RBTree.java | 50 +-- .../Benchmarks/SingleTM/Intruder/Random.java | 39 +- .../Benchmarks/SingleTM/Intruder/Stream.java | 100 +---- .../SingleTM/Intruder/Vector_t.java | 19 +- 12 files changed, 295 insertions(+), 727 deletions(-) diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/Decoded.java b/Robust/src/Benchmarks/SingleTM/Intruder/Decoded.java index dcdcfe52..7774da66 100644 --- a/Robust/src/Benchmarks/SingleTM/Intruder/Decoded.java +++ b/Robust/src/Benchmarks/SingleTM/Intruder/Decoded.java @@ -1,7 +1,3 @@ - -/* structure in Deocder - */ - public class Decoded { int flowId; byte[] data; diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/Decoder.java b/Robust/src/Benchmarks/SingleTM/Intruder/Decoder.java index 1275e837..d8df63e9 100644 --- a/Robust/src/Benchmarks/SingleTM/Intruder/Decoder.java +++ b/Robust/src/Benchmarks/SingleTM/Intruder/Decoder.java @@ -68,281 +68,157 @@ * ============================================================================= */ - -#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_REMOVE(map,key) map.deleteNode(key) - public class Decoder { - - MAP_T fragmentedMapPtr; /* contains list of packet_t* */ - Queue_t decodedQueuePtr; /* contains decoded_t* */ + RBTree fragmentedMapPtr; /* contains list of packet_t* */ + Queue_t decodedQueuePtr; /* contains decoded_t* */ int cnt; - public Decoder() {} - /* ============================================================================= * decoder_alloc * ============================================================================= decoder_t* decoder_alloc (); */ - public static Decoder alloc() { - Decoder decoderPtr; - - decoderPtr = new Decoder(); - if(decoderPtr != null) { - decoderPtr.fragmentedMapPtr = MAP_ALLOC(0,0); - - if(decoderPtr.fragmentedMapPtr == null) - { - System.out.println("Assert in Decoder.alloc"); - System.exit(1); - } - - decoderPtr.decodedQueuePtr = Queue_t.queue_alloc(1024); - if(decoderPtr.decodedQueuePtr == null) - { - System.out.println("Assert in Decoder.alloc"); - System.exit(1); - } - - decoderPtr.cnt = 0; - - } - - return decoderPtr; - } - + public Decoder() { + fragmentedMapPtr = new RBTree(0); + decodedQueuePtr = new Queue_t(1024); + } /* ============================================================================= * decoder_free * ============================================================================= void decoder_free (decoder_t* decoderPtr); */ - - /* ============================================================================= * decoder_process * ============================================================================= er_t decoder_process (decoder_t* decoderPtr, char* bytes, long numByte); */ - public int process(Packet packetPtr,int numByte) - { - boolean status; - ERROR er = new ERROR(); - - /* - * Basic error checking - */ - - if (numByte < 0) { - return er.SHORT; - } - - - int flowId = packetPtr.flowId; - int fragmentId = packetPtr.fragmentId; - int numFragment = packetPtr.numFragment; - int length = packetPtr.length; - - - if (flowId < 0) { - return er.FLOWID; - } - - if ((fragmentId < 0) || (fragmentId >= numFragment)) { - return er.FRAGMENTID; - } - - if (length < 0) { - return er.LENGTH; - } - - - /* - * Add to fragmented map for reassembling - */ - - if (numFragment > 1) { - - List_t fragmentListPtr = (List_t)MAP_FIND(fragmentedMapPtr,flowId); - - if (fragmentListPtr == null) { - - fragmentListPtr = List_t.alloc(1); // packet_compareFragmentId - if(fragmentListPtr == null) { - System.out.println("Assertion in Decoder1.process"); - System.exit(1); - } - status = fragmentListPtr.insert(packetPtr); - - if(!status) { - System.out.println("Assertion Decoer.process"); - System.exit(1); - } - - status = MAP_INSERT(fragmentedMapPtr,flowId,fragmentListPtr); - if(!status) { - System.out.println("Assertion Decoder!!!!.process"); - System.exit(1); - } - - } else { - - List_Iter it = new List_Iter(); - it.reset(fragmentListPtr); - - if(!it.hasNext(fragmentListPtr)) { - System.out.println("Assertion in Decoder2.process"); - System.exit(1); - } - - System.out.print(""); - Packet firstFragmentPtr = (Packet)it.next(fragmentListPtr); - - - int expectedNumFragment = firstFragmentPtr.numFragment; - - - if (numFragment != expectedNumFragment) { - status = MAP_REMOVE(fragmentedMapPtr,flowId); - if(!status) { - System.out.println("Assertion in process1"); - System.exit(1); - } - return er.NUMFRAGMENT; - } - - status = fragmentListPtr.insert(packetPtr); - - if(!status) { - System.out.println("Assertion in process2"); - System.exit(1); - } - - - - /* - * If we have all thefragments we can reassemble them - */ - - if(fragmentListPtr.getSize() == numFragment) { - - int numBytes = 0; - int i = 0; - it.reset(fragmentListPtr); - - while (it.hasNext(fragmentListPtr)) { - Packet fragmentPtr = (Packet)it.next(fragmentListPtr); - - if(fragmentPtr.fragmentId != i) { - status = MAP_REMOVE(fragmentedMapPtr,flowId); - - if(!status) { - System.out.println("Assertion in process3"); - System.exit(1); - } - return er.INCOMPLETE; /* should be sequential */ - } - numBytes = numBytes + fragmentPtr.length; - i++; - - } - - byte[] data = new byte[numBytes]; - - it.reset(fragmentListPtr); - int index=0; - - while(it.hasNext(fragmentListPtr)) { - Packet fragmentPtr = (Packet)it.next(fragmentListPtr); - - for(i=0;i'A' && str[i] < 'Z') - { - str[i] = (byte)(str[i] + (byte)32); - } - } - - - } - else { - System.out.println("NOOOOOOOOOOOOO"); - } - } - - /* - * Check against signatures of known attacks - */ - - ERROR err = new ERROR(); -// System.out.print("str = \"" + str+ "\""); - String signature = dictionaryPtr.match(new String(str)); -// System.out.println("\tSign = \"" + signature+ "\""); - if(signature != null) { - return err.SIGNATURE; - } - - return err.NONE; + public int process(byte[] str) { + /* + * Apply preprocessors + */ + int numPreprocessor = preprocessorVectorPtr.vector_getSize(); + for(int p = 0; p < numPreprocessor; p++) { + Integer preprocessor = (Integer)preprocessorVectorPtr.vector_at(p); + if(preprocessor.intValue() == 1) { + System.out.println("NOOOOOOOOOOOOO"); + } else if(preprocessor.intValue() == 2) { + for(int i=0;i'A' && str[i] < 'Z') { + str[i] +=(byte)32; + } + } + } else { + System.out.println("NOOOOOOOOOOOOO"); + } + } + + /* + * Check against signatures of known attacks + */ + + ERROR err = new ERROR(); + String signature = dictionaryPtr.match(new String(str)); + if(signature != null) { + return err.SIGNATURE; } + + return err.NONE; + } } /* ============================================================================= diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/Intruder.java b/Robust/src/Benchmarks/SingleTM/Intruder/Intruder.java index a0c2efac..2810f6ae 100644 --- a/Robust/src/Benchmarks/SingleTM/Intruder/Intruder.java +++ b/Robust/src/Benchmarks/SingleTM/Intruder/Intruder.java @@ -102,14 +102,13 @@ public class Intruder extends Thread { threadID = myID; } - private void setDefaultParams() - { - percentAttack = PARAM_DEFAULT_ATTACK; - maxDataLength = PARAM_DEFAULT_LENGTH; - numFlow = PARAM_DEFAULT_NUM; - randomSeed = PARAM_DEFAULT_SEED; - numThread = PARAM_DEFAULT_THREAD; - } + private void setDefaultParams() { + percentAttack = PARAM_DEFAULT_ATTACK; + maxDataLength = PARAM_DEFAULT_LENGTH; + numFlow = PARAM_DEFAULT_NUM; + randomSeed = PARAM_DEFAULT_SEED; + numThread = PARAM_DEFAULT_THREAD; + } /* ============================================================================= @@ -188,70 +187,49 @@ public class Intruder extends Thread { Vector_t[] errorVectors = argPtr.errorVectors; - Detector detectorPtr = Detector.alloc(); - if(detectorPtr == null) - { - System.out.println("Assertion in processPackets"); - System.exit(1); - } - + Detector detectorPtr = new Detector(); detectorPtr.addPreprocessor(2); Vector_t errorVectorPtr = errorVectors[threadID]; while(true) { Packet packetPtr; - - System.out.println("Before atomic Brace"); - // TM_BEGIN(); + atomic { - System.out.println("In the atomic"); packetPtr = streamPtr.getPacket(); } - System.out.println("After atomic"); - // TM_END(); - // - if(packetPtr == null) { break; } int flowId = packetPtr.flowId; int error; - // TM_BEGIN(); atomic { error = decoderPtr.process(packetPtr,(packetPtr.length)); } - // TM_END(); - // - // - + if (error != 0) { /* * Currently, stream_generate() does not create these errors. */ - System.out.println("Here?"); - System.exit(1); + System.out.println("Here?"+error); } byte[] data; int[] decodedFlowId = new int[1]; - // TM_BEGIN(); atomic { data = decoderPtr.getComplete(decodedFlowId); } - // TM_END(); if(data != null) { - int err = detectorPtr.process(data); - - if(err != 0) { - boolean status = errorVectorPtr.vector_pushBack(new Integer(decodedFlowId[0])); - if(!status) { - System.out.println("Assertion in Intruder.processPacket"); - System.exit(1); - } - } + int err = detectorPtr.process(data); + + if(err != 0) { + boolean status = errorVectorPtr.vector_pushBack(new Integer(decodedFlowId[0])); + if(!status) { + System.out.println("Assertion in Intruder.processPacket"); + } + } } } @@ -291,44 +269,18 @@ public class Intruder extends Thread { System.out.println("Random seed = " + in.randomSeed); Dictionary dictionaryPtr = new Dictionary(); - - if(dictionaryPtr == null) { - System.out.println("Assertion in main"); - System.exit(1); - } - - Stream streamPtr = Stream.alloc(in.percentAttack); - - if(streamPtr == null) { - System.out.println("Assertion in main"); - System.exit(1); - } - + Stream streamPtr = new Stream(in.percentAttack); int numAttack = streamPtr.generate(dictionaryPtr,in.numFlow,in.randomSeed,in.maxDataLength); System.out.println("Num Attack = " + numAttack); - Decoder decoderPtr = Decoder.alloc(); - if(decoderPtr == null) { - System.out.println("Assertion in main"); - System.exit(1); - } - + Decoder decoderPtr = new Decoder(); Vector_t[] errorVectors = new Vector_t[in.numThread]; - if(errorVectors == null) { - System.out.println("Assertion in main"); - System.exit(1); - } - int i; for(i =0;i< in.numThread;i++) { - errorVectors[i] = Vector_t.vector_alloc(in.numFlow); - if(errorVectors[i] == null) { - System.out.println("Assertion in main"); - System.exit(1); - } + errorVectors[i] = new Vector_t(in.numFlow); } Arg arg = new Arg(); @@ -374,7 +326,7 @@ public class Intruder extends Thread { Vector_t errorVectorPtr = errorVectors[i]; int e; int numError = errorVectorPtr.vector_getSize(); - System.out.println("numError = " + numError); + //System.out.println("numError = " + numError); numFound += numError; for (e = 0; e< numError; e++) { int flowId = ((Integer)errorVectorPtr.vector_at(e)).intValue(); diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/List_Iter.java b/Robust/src/Benchmarks/SingleTM/Intruder/List_Iter.java index 351e80d0..c6b2058c 100644 --- a/Robust/src/Benchmarks/SingleTM/Intruder/List_Iter.java +++ b/Robust/src/Benchmarks/SingleTM/Intruder/List_Iter.java @@ -7,7 +7,6 @@ public class List_Iter { void list_iter_reset (list_iter_t* itPtr, list_t* listPtr); */ public List_Iter() { - itPtr = null; } public void reset(List_t listPtr) @@ -21,7 +20,7 @@ public class List_Iter { * bool_t list_iter_hasNext (list_iter_t* itPtr, list_t* listPtr); */ public boolean hasNext(List_t listPtr) { - return (itPtr.nextPtr != null)? true : false; + return itPtr.nextPtr != null; } /* ============================================================================= diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/List_Node.java b/Robust/src/Benchmarks/SingleTM/Intruder/List_Node.java index 806baa19..97f457a2 100644 --- a/Robust/src/Benchmarks/SingleTM/Intruder/List_Node.java +++ b/Robust/src/Benchmarks/SingleTM/Intruder/List_Node.java @@ -4,7 +4,5 @@ public class List_Node { List_Node nextPtr; public List_Node() { - dataPtr = null; - nextPtr = null; } } diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/List_t.java b/Robust/src/Benchmarks/SingleTM/Intruder/List_t.java index aa72c25b..619bf290 100644 --- a/Robust/src/Benchmarks/SingleTM/Intruder/List_t.java +++ b/Robust/src/Benchmarks/SingleTM/Intruder/List_t.java @@ -91,14 +91,7 @@ public class List_t { private List_Node allocNode(Object dataPtr) { List_Node nodePtr = new List_Node(); - - if(nodePtr == null) { - return null; - } - nodePtr.dataPtr = dataPtr; - nodePtr.nextPtr = null; - return nodePtr; } @@ -113,22 +106,10 @@ public class List_t { * */ - public static List_t alloc(int chk) - { - List_t listPtr = new List_t(); - - if(listPtr == null) { - return null; - } - - listPtr.head.dataPtr = null; - listPtr.head.nextPtr = null; - listPtr.size = 0; - - listPtr.chk = chk; - - return listPtr; - } + public List_t(int chk) { + this.head = new List_Node(); + this.chk=chk; + } /* ============================================================================= * list_free @@ -137,12 +118,6 @@ public class List_t { * ============================================================================= * void list_free (list_t* listPtr); */ - public static void free(List_t listPtr) - { - listPtr = null; - } - -// privae freeList /* ============================================================================= * list_isEmpty diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/Queue_t.java b/Robust/src/Benchmarks/SingleTM/Intruder/Queue_t.java index b692dc56..fbf9d5da 100644 --- a/Robust/src/Benchmarks/SingleTM/Intruder/Queue_t.java +++ b/Robust/src/Benchmarks/SingleTM/Intruder/Queue_t.java @@ -57,53 +57,18 @@ public class Queue_t { int capacity; Object[] elements; - public Queue_t() { - } - /* ============================================================================= * queue_alloc * ============================================================================= */ - public static Queue_t queue_alloc (int initCapacity) - { - Queue_t queuePtr = new Queue_t(); - + public Queue_t(int initCapacity) { int capacity = ((initCapacity < 2) ? 2 : initCapacity); - queuePtr.elements = new Object[capacity]; - if (queuePtr.elements == null) { - queuePtr = null; - return null; - } - queuePtr.pop = capacity - 1; - queuePtr.push = 0; - queuePtr.capacity = capacity; - - return queuePtr; + elements = new Object[capacity]; + pop = capacity - 1; + push = 0; + this.capacity = capacity; } - - /* ============================================================================= - * Pqueue_alloc - * ============================================================================= - */ - public Queue_t - Pqueue_alloc (int initCapacity) - { - Queue_t queuePtr = new Queue_t(); - - int capacity = ((initCapacity < 2) ? 2 : initCapacity); - queuePtr.elements = new Object[capacity]; - if (queuePtr.elements == null) { - queuePtr = null; - return null; - } - queuePtr.pop = capacity - 1; - queuePtr.push = 0; - queuePtr.capacity = capacity; - - return queuePtr; - } - /* ============================================================================= * queue_free * ============================================================================= @@ -112,21 +77,9 @@ public class Queue_t { queue_free (Queue_t queuePtr) { queuePtr.elements = null; - queuePtr = null; } - /* ============================================================================= - * Pqueue_free - * ============================================================================= - */ - public void - Pqueue_free (Queue_t queuePtr) - { - queuePtr.elements = null; - queuePtr = null; - } - /* ============================================================================= * TMqueue_free @@ -178,57 +131,51 @@ public class Queue_t { * queue_push * ============================================================================= */ - public boolean - queue_push (Object dataPtr) - { - - if(pop == push) { + public boolean queue_push (Object dataPtr) { + if(pop == push) { + System.out.println("push == pop in Queue.java"); + return false; + } - System.out.println("push == pop in Queue.java"); - return false; + /* Need to resize */ + int newPush = (push + 1) % capacity; + if (newPush == pop) { + int newCapacity = capacity * QUEUE_GROWTH_FACTOR; + Object[] newElements = new Object[newCapacity]; + if (newElements == null) { + return false; } - - - /* Need to resize */ - int newPush = (push + 1) % capacity; - if (newPush == pop) { - - int newCapacity = capacity * QUEUE_GROWTH_FACTOR; - Object[] newElements = new Object[newCapacity]; - if (newElements == null) { - return false; - } - - int dst = 0; - Object[] tmpelements = elements; - if (pop < push) { - int src; - for (src = (pop + 1); src < push; src++, dst++) { - newElements[dst] = elements[src]; - } - } else { - int src; - for (src = (pop + 1); src < capacity; src++, dst++) { - newElements[dst] = elements[src]; - } - for (src = 0; src < push; src++, dst++) { - newElements[dst] = elements[src]; - } - } - - //elements = null; - elements = newElements; - pop = newCapacity - 1; - capacity = newCapacity; - push = dst; - newPush = push + 1; /* no need modulo */ + + int dst = 0; + Object[] tmpelements = elements; + if (pop < push) { + int src; + for (src = (pop + 1); src < push; src++, dst++) { + newElements[dst] = elements[src]; + } + } else { + int src; + for (src = (pop + 1); src < capacity; src++, dst++) { + newElements[dst] = elements[src]; + } + for (src = 0; src < push; src++, dst++) { + newElements[dst] = elements[src]; + } } - - elements[push] = dataPtr; - push = newPush; - - return true; + + //elements = null; + elements = newElements; + pop = newCapacity - 1; + capacity = newCapacity; + push = dst; + newPush = push + 1; /* no need modulo */ } + + elements[push] = dataPtr; + push = newPush; + + return true; + } /* ============================================================================= @@ -293,26 +240,17 @@ public class Queue_t { * queue_pop * ============================================================================= */ - public Object - //queue_pop (Queue queuePtr) - queue_pop () - { - //int pop = queuePtr.pop; - //int push = queuePtr.push; - //int capacity = queuePtr.capacity; - - int newPop = (pop + 1) % capacity; - if (newPop == push) { - return null; - } - - //Object dataPtr = queuePtr.elements[newPop]; - //queuePtr.pop = newPop; - Object dataPtr = elements[newPop]; - pop = newPop; - - return dataPtr; + public Object queue_pop () { + int newPop = (pop + 1) % capacity; + if (newPop == push) { + return null; } + + Object dataPtr = elements[newPop]; + pop = newPop; + + return dataPtr; + } public void queue_shuffle (Random randomPtr) { diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/RBTree.java b/Robust/src/Benchmarks/SingleTM/Intruder/RBTree.java index 52d33008..6b3f4272 100644 --- a/Robust/src/Benchmarks/SingleTM/Intruder/RBTree.java +++ b/Robust/src/Benchmarks/SingleTM/Intruder/RBTree.java @@ -81,7 +81,11 @@ #define RED 0 #define BLACK 1 - +#define parentOf(n) (n!=null? n.p : null) +#define leftOf(n) (n!=null? n.l : null) +#define rightOf(n) (n!=null? n.r : null) +#define colorOf(n) (n!=null? n.c : BLACK) +#define setColor(n, col) if (n!=null) n.c=col; public class RBTree { Node root; @@ -153,37 +157,7 @@ public class RBTree { x.p = l; } - /* parentOf */ - private Node parentOf (Node n) - { - return ((n!=null) ? n.p : null); - } - - /* leftOf */ - private Node leftOf (Node n) - { - return ((n != null)? n.l : null); - } - - /* rightOf */ - private Node rightOf(Node n) - { - return ((n!= null) ? n.r : null); - } - - /* colorOf */ - private int colorOf(Node n) - { - return ((n!=null) ? n.c : BLACK); - } - /* setColor */ - private void setColor(Node n, int c) - { - if ( n != null) { - n.c = c; - } - } /* fixAfterInsertion */ private void fixAfterInsertion(Node x) @@ -586,16 +560,10 @@ public class RBTree { * ============================================================================= * rbtree_t* rbtree_alloc (long (*compare)(const void*, const void*)); */ - public static RBTree alloc(int compID) - { - RBTree n = new RBTree(); - if (n != null) { - n.compID = compID; - n.root = null; - } - - return n; - } + public RBTree(int compID) { + this.compID = compID; + this.root = null; + } diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/Random.java b/Robust/src/Benchmarks/SingleTM/Intruder/Random.java index 0c1dc865..e4f6cb87 100644 --- a/Robust/src/Benchmarks/SingleTM/Intruder/Random.java +++ b/Robust/src/Benchmarks/SingleTM/Intruder/Random.java @@ -8,6 +8,7 @@ public class Random { int MATRIX_A; int UPPER_MASK; int LOWER_MASK; + int[] mag01; public Random() { RANDOM_DEFAULT_SEED = 0; @@ -18,6 +19,10 @@ public class Random { MATRIX_A = 0x9908b0df; /* constant vector a */ UPPER_MASK = 0x80000000; /* most significant w-r bits */ LOWER_MASK = 0x7fffffff; /* least significant r bits */ + mag01 = new int[2]; + mag01[0] = 0x0; + mag01[1] = MATRIX_A; + } public void random_alloc() { @@ -26,9 +31,8 @@ public class Random { /* initializes mt[N] with a seed */ public void init_genrand(int s) { - int mti; mt[0]= s & 0xFFFFFFFF; - for (mti=1; mti> 30)) + mti); /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ /* In the previous versions, MSBs of the seed affect */ @@ -45,35 +49,36 @@ public class Random { } public int random_generate() { - return genrand_int32(); + return 0x7fffffff&genrand_int32(); + } + + public int posrandom_generate() { + return 0x7fffffff&genrand_int32(); } - //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; /* mag01[x] = x * MATRIX_A for x=0,1 */ - if (mti >= N) { /* generate N words at one time */ + if (mti >= 624) { /* generate N words at one time */ int kk; + int[] mt = this.mt; - if (mti == N+1) /* if init_genrand() has not been called, */ + if (mti == 624+1) /* if init_genrand() has not been called, */ init_genrand(5489); /* a default initial seed is used */ - for (kk=0;kk> 1) ^ mag01[(int)(y & 0x1)]; + for (kk=0;kk<(624-397);kk++) { + y = (mt[kk]&0x80000000)|(mt[kk+1]&0x7fffffff); + mt[kk] = mt[kk+397] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0:0x9908b0df); } - for (;kk> 1) ^ mag01[(int)(y & 0x1)]; + for (;kk<(624-1);kk++) { + y = (mt[kk]&0x80000000)|(mt[kk+1]&0x7fffffff); + mt[kk] = mt[kk+(397-624)] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0:0x9908b0df); } - y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK); - mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[(int)(y & 0x1)]; + y = (mt[624-1]&0x80000000)|(mt[0]&0x7fffffff); + mt[624-1] = mt[397-1] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0:0x9908b0df); mti = 0; } diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/Stream.java b/Robust/src/Benchmarks/SingleTM/Intruder/Stream.java index 1727f16c..04c2cba6 100644 --- a/Robust/src/Benchmarks/SingleTM/Intruder/Stream.java +++ b/Robust/src/Benchmarks/SingleTM/Intruder/Stream.java @@ -1,60 +1,30 @@ -#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_REMOVE(map,key) map.deleteNode(key) - public class Stream { int percentAttack; Random randomPtr; Vector_t allocVectorPtr; Queue_t packetQueuePtr; - MAP_T attackMapPtr; - - public Stream() {} - - - /* alloc */ - public static Stream alloc(int percentAttack) { - Stream streamPtr = new Stream(); + RBTree attackMapPtr; + public Stream(int percentAttack) { if (percentAttack < 0 || percentAttack > 100) { System.out.print("Error: Invalid percentAttack value\n"); System.exit(0); } - streamPtr.percentAttack = percentAttack; - - streamPtr.randomPtr = new Random(); - streamPtr.allocVectorPtr = Vector_t.vector_alloc(1); - if (streamPtr.allocVectorPtr == null) { - System.out.print("Error: Vector allocation failed\n"); - System.exit(0); - } - streamPtr.packetQueuePtr = Queue_t.queue_alloc(1); - if (streamPtr.packetQueuePtr == null) { - System.out.print("Error: Queue allocation failed\n"); - System.exit(0); - } - streamPtr.attackMapPtr = MAP_ALLOC(0,0); - if (streamPtr.attackMapPtr == null) { - System.out.print("Error: MAP_ALLOC failed\n"); - System.exit(0); - } - return streamPtr; + this.percentAttack = percentAttack; + randomPtr = new Random(); + allocVectorPtr = new Vector_t(1); + packetQueuePtr = new Queue_t(1); + attackMapPtr = new RBTree(0); } - /* splintIntoPackets * -- Packets will be equal-size chunks except for last one, which will have * all extra bytes */ private void splitIntoPackets(byte[] str,int flowId, Random randomPtr, - Vector_t allocVectorPtr, Queue_t packetQueuePtr) - { + Vector_t allocVectorPtr, Queue_t packetQueuePtr) { int numByte = str.length; int numPacket = randomPtr.random_generate() % numByte + 1; int numDataByte = numByte / numPacket; - int i; int p; boolean status; @@ -63,10 +33,6 @@ public class Stream { int z; for (p = 0; p < (numPacket - 1); p++) { Packet bytes = new Packet(numDataByte); - if (bytes == null) { - System.out.printString("Error: Packet class allocation failed\n"); - System.exit(-1); - } status = allocVectorPtr.vector_pushBack(bytes); if (status == false) { System.out.printString("Error: Vector pushBack failed\n"); @@ -77,72 +43,48 @@ public class Stream { bytes.numFragment = numPacket; bytes.length = numDataByte; endIndex = beginIndex + numDataByte; - - for(i=beginIndex,z=0;i