#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 {
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;
}
* =============================================================================
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 */
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
}
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);
}
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);
}
if(fragmentListPtr.getSize() == numFragment) {
- int numByte = 0;
+
+ int numBytes = 0;
int i = 0;
it.reset(fragmentListPtr);
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);
}
}
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();
}
data.concat(packetPtr.data);
-
- Decoded decodedPtr = new Decoded();
+
+ Decoded decodedPtr = new Decoded();
+
if(decodedPtr == null) {
System.out.println("Assertion in process");
System.exit(1);
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);
*/
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
* =============================================================================
char* TMdecoder_getComplete (TM_ARGDECL decoder_t* decoderPtr, long* decodedFlowIdPtr);
*/
-}
+
/* =============================================================================
*
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() {
}
/* 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;
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;
}
/* 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;