[Udt-java-commits] SF.net SVN: udt-java:[48] udt-java/trunk/src
Status: Alpha
Brought to you by:
bschuller
|
From: <bsc...@us...> - 2010-09-13 18:55:14
|
Revision: 48
http://udt-java.svn.sourceforge.net/udt-java/?rev=48&view=rev
Author: bschuller
Date: 2010-09-13 18:55:07 +0000 (Mon, 13 Sep 2010)
Log Message:
-----------
some refactoring
Modified Paths:
--------------
udt-java/trunk/src/main/java/udt/UDTPacket.java
udt-java/trunk/src/main/java/udt/UDTReceiver.java
udt-java/trunk/src/main/java/udt/packets/ControlPacket.java
udt-java/trunk/src/main/java/udt/packets/DataPacket.java
Added Paths:
-----------
udt-java/trunk/src/test/java/udt/packets/
udt-java/trunk/src/test/java/udt/packets/DummyControlPacket.java
udt-java/trunk/src/test/java/udt/packets/TestControlPacketType.java
udt-java/trunk/src/test/java/udt/packets/TestDataPacket.java
udt-java/trunk/src/test/java/udt/packets/TestPacketFactory.java
Removed Paths:
-------------
udt-java/trunk/src/test/java/udt/DummyControlPacket.java
udt-java/trunk/src/test/java/udt/TestControlPacketType.java
udt-java/trunk/src/test/java/udt/TestDataPacket.java
udt-java/trunk/src/test/java/udt/TestPacketFactory.java
Modified: udt-java/trunk/src/main/java/udt/UDTPacket.java
===================================================================
--- udt-java/trunk/src/main/java/udt/UDTPacket.java 2010-09-01 13:58:45 UTC (rev 47)
+++ udt-java/trunk/src/main/java/udt/UDTPacket.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -36,27 +36,21 @@
public long getMessageNumber();
+
public void setMessageNumber(long messageNumber) ;
-
public void setTimeStamp(long timeStamp);
+
public long getTimeStamp();
-
public void setDestinationID(long destinationID);
+
public long getDestinationID();
public boolean isControlPacket();
public int getControlPacketType();
-
- /**
- * header
- * @return
- */
- public byte[] getHeader();
-
public byte[] getEncoded();
/**
Modified: udt-java/trunk/src/main/java/udt/UDTReceiver.java
===================================================================
--- udt-java/trunk/src/main/java/udt/UDTReceiver.java 2010-09-01 13:58:45 UTC (rev 47)
+++ udt-java/trunk/src/main/java/udt/UDTReceiver.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -387,12 +387,12 @@
long currentSequenceNumber = dp.getPacketSequenceNumber();
//check whether to drop this packet
- n++;
+// n++;
//if(dropRate>0 && n % dropRate == 0){
- //if(n==668){
- // logger.info("**** TESTING:::: DROPPING PACKET "+currentSequenceNumber+" FOR TESTING");
- // return;
- //}
+// if(n==666){
+// logger.info("**** TESTING:::: DROPPING PACKET "+currentSequenceNumber+" FOR TESTING");
+// return;
+// }
long currentDataPacketArrivalTime = Util.getCurrentTime();
Modified: udt-java/trunk/src/main/java/udt/packets/ControlPacket.java
===================================================================
--- udt-java/trunk/src/main/java/udt/packets/ControlPacket.java 2010-09-01 13:58:45 UTC (rev 47)
+++ udt-java/trunk/src/main/java/udt/packets/ControlPacket.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -32,9 +32,6 @@
package udt.packets;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
import udt.UDTPacket;
import udt.UDTSession;
@@ -89,19 +86,13 @@
* return the header according to specification p.5
* @return
*/
- //TODO order?!?!?
- public byte[] getHeader(){
-// //sequence number with highest bit set to "0"
- try{
- ByteArrayOutputStream bos=new ByteArrayOutputStream(16);
- bos.write(PacketUtil.encodeControlPacketType(controlPacketType));
- bos.write(PacketUtil.encode(getAdditionalInfo()));
- bos.write(PacketUtil.encode(timeStamp));
- bos.write(PacketUtil.encode(destinationID));
- return bos.toByteArray();
- }catch(IOException ioe){/*can't happen*/
- return null;
- }
+ byte[] getHeader(){
+ byte[]res=new byte[16];
+ System.arraycopy(PacketUtil.encodeControlPacketType(controlPacketType), 0, res, 0, 4);
+ System.arraycopy(PacketUtil.encode(getAdditionalInfo()), 0, res, 4, 4);
+ System.arraycopy(PacketUtil.encode(timeStamp), 0, res, 8, 4);
+ System.arraycopy(PacketUtil.encode(destinationID), 0, res, 12, 4);
+ return res;
}
/**
Modified: udt-java/trunk/src/main/java/udt/packets/DataPacket.java
===================================================================
--- udt-java/trunk/src/main/java/udt/packets/DataPacket.java 2010-09-01 13:58:45 UTC (rev 47)
+++ udt-java/trunk/src/main/java/udt/packets/DataPacket.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -32,9 +32,6 @@
package udt.packets;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
import udt.UDTPacket;
import udt.UDTSession;
@@ -115,8 +112,6 @@
return this.timeStamp;
}
-
-
public void setDestinationID(long destinationID) {
this.destinationID=destinationID;
}
@@ -125,36 +120,16 @@
this.timeStamp=timeStamp;
}
-
-
/**
- * return the header according to specification p.5
- * @return
- */
- //TODO order?
- public byte[] getHeader(){
- //sequence number with highest bit set to "0"
- try{
- ByteArrayOutputStream bos=new ByteArrayOutputStream(16);
- bos.write(PacketUtil.encode(packetSequenceNumber));
- bos.write(PacketUtil.encode(messageNumber));
- bos.write(PacketUtil.encode(timeStamp));
- bos.write(PacketUtil.encode(destinationID));
- return bos.toByteArray();
-
- }catch(IOException ioe){/*can't happen*/
- return null;
- }
- }
-
- /**
* complete header+data packet for transmission
*/
public byte[] getEncoded(){
- byte[] header=getHeader();
//header.length is 16
byte[] result=new byte[16+data.length];
- System.arraycopy(header, 0, result, 0, 16);
+ System.arraycopy(PacketUtil.encode(packetSequenceNumber), 0, result, 0, 4);
+ System.arraycopy(PacketUtil.encode(messageNumber), 0, result, 4, 4);
+ System.arraycopy(PacketUtil.encode(timeStamp), 0, result, 8, 4);
+ System.arraycopy(PacketUtil.encode(destinationID), 0, result, 12, 4);
System.arraycopy(data, 0, result, 16, data.length);
return result;
}
Deleted: udt-java/trunk/src/test/java/udt/DummyControlPacket.java
===================================================================
--- udt-java/trunk/src/test/java/udt/DummyControlPacket.java 2010-09-01 13:58:45 UTC (rev 47)
+++ udt-java/trunk/src/test/java/udt/DummyControlPacket.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -1,16 +0,0 @@
-package udt;
-
-import udt.packets.ControlPacket;
-
-public class DummyControlPacket extends ControlPacket{
-
- public DummyControlPacket(){
-
- }
-
- @Override
- public byte[]encodeControlInformation(){
- //TODO Auto-generate method sub
- return null;
- }
-}
\ No newline at end of file
Deleted: udt-java/trunk/src/test/java/udt/TestControlPacketType.java
===================================================================
--- udt-java/trunk/src/test/java/udt/TestControlPacketType.java 2010-09-01 13:58:45 UTC (rev 47)
+++ udt-java/trunk/src/test/java/udt/TestControlPacketType.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -1,34 +0,0 @@
-package udt;
-
-import udt.packets.ControlPacket;
-import udt.packets.ControlPacket.ControlPacketType;
-import junit.framework.TestCase;
-
-public class TestControlPacketType extends TestCase {
-
- public void testSequenceNumber1(){
- ControlPacket p=new DummyControlPacket();
- byte[]x=p.getHeader();
- byte highest=x[0];
- assertEquals(128, highest & 0x80);
- }
-
- public void testControlPacketTypes(){
- ControlPacketType t=ControlPacketType.CONNECTION_HANDSHAKE;
- assertEquals(0,t.ordinal());
- t=ControlPacketType.KEEP_ALIVE;
- assertEquals(1,t.ordinal());
- t=ControlPacketType.ACK;
- assertEquals(2,t.ordinal());
- t=ControlPacketType.NAK;
- assertEquals(3,t.ordinal());
- t=ControlPacketType.SHUTDOWN;
- assertEquals(5,t.ordinal());
- t=ControlPacketType.ACK2;
- assertEquals(6,t.ordinal());
- t=ControlPacketType.MESSAGE_DROP_REQUEST;
- assertEquals(7,t.ordinal());
- t=ControlPacketType.USER_DEFINED;
- assertEquals(15,t.ordinal());
- }
-}
Deleted: udt-java/trunk/src/test/java/udt/TestDataPacket.java
===================================================================
--- udt-java/trunk/src/test/java/udt/TestDataPacket.java 2010-09-01 13:58:45 UTC (rev 47)
+++ udt-java/trunk/src/test/java/udt/TestDataPacket.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -1,97 +0,0 @@
-package udt;
-
-import junit.framework.TestCase;
-import udt.packets.DataPacket;
-
-public class TestDataPacket extends TestCase {
-
- public void testSequenceNumber1(){
- DataPacket p=new DataPacket();
- p.setPacketSequenceNumber(1);
- byte[]x=p.getHeader();
- byte highest=x[0];
- //check highest bit is "0" for DataPacket
- assertEquals(0, highest & 128);
- byte lowest=x[3];
- assertEquals(1, lowest);
- }
-
- public void testEncoded(){
- DataPacket p=new DataPacket();
- p.setPacketSequenceNumber(1);
- byte[] data="test".getBytes();
- p.setData(data);
- byte[]encoded=p.getEncoded();
- int headerLength=p.getHeader().length;
- assertEquals(data.length+headerLength,encoded.length);
- byte[]encData=new byte[data.length];
- System.arraycopy(encoded, headerLength, encData, 0, data.length);
- String s=new String(encData);
- assertEquals("test", s);
- System.out.println("String s = " + s);
- }
-
-
- public void testDecode1(){
-
- DataPacket testPacket1=new DataPacket();
- testPacket1.setPacketSequenceNumber(127);
- testPacket1.setDestinationID(1);
- byte[] data1="Hallo".getBytes();
- testPacket1.setData(data1);
-
- //get the encoded data
- byte[]encodedData=testPacket1.getEncoded();
-
- int headerLength=testPacket1.getHeader().length;
- assertEquals(data1.length+headerLength,encodedData.length);
-
- byte[]payload=new byte[data1.length];
- System.arraycopy(encodedData, headerLength, payload, 0, data1.length);
- String s1=new String(payload);
- assertEquals("Hallo", s1);
-
- System.out.println("String s1 = " + s1);
- System.out.println("tesPacket1Length = "+ testPacket1.getLength());
- System.out.println("sequenceNumber1 = " + testPacket1.getPacketSequenceNumber());
- System.out.println("messageNumber 1= " + testPacket1.getMessageNumber());
- System.out.println("timeStamp1 = " + testPacket1.getTimeStamp());
- System.out.println("destinationID1 = " + testPacket1.getDestinationID());
- System.out.println("data1 = " + new String(testPacket1.getData()));
-
-
- //create a new DataPacket from the encoded data
- DataPacket testPacket2=new DataPacket(encodedData);
- // and test
- System.out.println("tesPacket2Length = "+ testPacket2.getLength());
- System.out.println("sequenceNumber2 = " + testPacket2.getPacketSequenceNumber());
- System.out.println("messageNumber2 = " + testPacket2.getMessageNumber());
- System.out.println("timeStamp2 = " + testPacket2.getTimeStamp());
- System.out.println("destinationID1 = " + testPacket1.getDestinationID());
- System.out.println("data2 = " + new String(testPacket2.getData()));
-
- assertEquals(127,testPacket2.getPacketSequenceNumber());
-
-
- }
-
- public void testEncodeDecode1(){
- DataPacket dp=new DataPacket();
- dp.setPacketSequenceNumber(127);
- dp.setMessageNumber(268435457);
- dp.setTimeStamp(128);
- dp.setDestinationID(255);
- dp.setData("test".getBytes());
-
- byte[]encodedData1=dp.getEncoded();
-
- DataPacket dp2=new DataPacket(encodedData1);
- assertEquals(127,dp2.getPacketSequenceNumber());
- assertEquals(268435457,dp2.getMessageNumber());
- assertEquals(128,dp2.getTimeStamp());
- assertEquals(255,dp2.getDestinationID());
- assertEquals("test", new String(dp2.getData()));
- }
-
-
-}
Deleted: udt-java/trunk/src/test/java/udt/TestPacketFactory.java
===================================================================
--- udt-java/trunk/src/test/java/udt/TestPacketFactory.java 2010-09-01 13:58:45 UTC (rev 47)
+++ udt-java/trunk/src/test/java/udt/TestPacketFactory.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -1,181 +0,0 @@
-package udt;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-import udt.packets.Acknowledgement;
-import udt.packets.Acknowledgment2;
-import udt.packets.ConnectionHandshake;
-import udt.packets.DataPacket;
-import udt.packets.MessageDropRequest;
-import udt.packets.NegativeAcknowledgement;
-import udt.packets.PacketFactory;
-import udt.packets.Shutdown;
-
-public class TestPacketFactory extends TestCase {
-
- public void testData(){
- String test="sdjfsdjfldskjflds";
-
- byte[]data=test.getBytes();
- data[0]=(byte)(data[0] & 0x7f);
- UDTPacket p=PacketFactory.createPacket(data);
- DataPacket recv=(DataPacket)p;
- String t=new String(recv.getEncoded());
- assertTrue(p instanceof DataPacket);
- assertEquals(test,t);
- }
-
-
- public void testConnectionHandshake(){
- ConnectionHandshake p1 = new ConnectionHandshake();
- p1.setMessageNumber(9876);
- p1.setTimeStamp(3456);
- p1.setDestinationID(1);
-
- p1.setConnectionType(1);
- p1.setSocketType(1);
- p1.setInitialSeqNo(321);
- p1.setPacketSize(128);
- p1.setMaxFlowWndSize(128);
- p1.setSocketID(1);
- p1.setUdtVersion(4);
-
-
- byte[]p1_data=p1.getEncoded();
-
- UDTPacket p=PacketFactory.createPacket(p1_data);
- ConnectionHandshake p2=(ConnectionHandshake)p;
- assertEquals(p1,p2);
-
- }
-
- public void testAcknowledgement(){
- Acknowledgement p1 = new Acknowledgement();
- p1.setAckSequenceNumber(1234);
- p1.setMessageNumber(9876);
- p1.setTimeStamp(3456);
- p1.setDestinationID(1);
- p1.setBufferSize(128);
- p1.setEstimatedLinkCapacity(16);
- p1.setAckNumber(9870);
- p1.setPacketReceiveRate(1000);
- p1.setRoundTripTime(1000);
- p1.setRoundTripTimeVar(500);
-
- byte[]p1_data=p1.getEncoded();
- UDTPacket p=PacketFactory.createPacket(p1_data);
- Acknowledgement p2=(Acknowledgement)p;
- assertEquals(p1,p2);
- }
-
- public void testAcknowledgementOfAcknowledgement(){
- Acknowledgment2 p1 = new Acknowledgment2();
- p1.setAckSequenceNumber(1230);
- p1.setMessageNumber(9871);
- p1.setTimeStamp(3451);
- p1.setDestinationID(1);
-
- byte[]p1_data=p1.getEncoded();
- UDTPacket p=PacketFactory.createPacket(p1_data);
- Acknowledgment2 p2=(Acknowledgment2)p;
- assertEquals(p1,p2);
-
-
- }
-
- public void testNegativeAcknowledgement(){
- NegativeAcknowledgement p1 = new NegativeAcknowledgement();
- p1.setMessageNumber(9872);
- p1.setTimeStamp(3452);
- p1.setDestinationID(2);
- p1.addLossInfo(5);
- p1.addLossInfo(6);
- p1.addLossInfo(7, 10);
- byte[]p1_data=p1.getEncoded();
-
- UDTPacket p=PacketFactory.createPacket(p1_data);
- NegativeAcknowledgement p2=(NegativeAcknowledgement)p;
- assertEquals(p1,p2);
-
- assertEquals((Integer)5, (Integer)p2.getDecodedLossInfo().get(0));
- assertEquals(6, p2.getDecodedLossInfo().size());
- }
-
- public void testNegativeAcknowledgement2(){
- NegativeAcknowledgement p1 = new NegativeAcknowledgement();
- p1.setMessageNumber(9872);
- p1.setTimeStamp(3452);
- p1.setDestinationID(2);
- List<Long>loss=new ArrayList<Long>();
- loss.add(5l);
- loss.add(6l);
- loss.add(7l);
- loss.add(8l);
- loss.add(9l);
- loss.add(11l);
-
- p1.addLossInfo(loss);
- byte[]p1_data=p1.getEncoded();
-
- UDTPacket p=PacketFactory.createPacket(p1_data);
- NegativeAcknowledgement p2=(NegativeAcknowledgement)p;
- assertEquals(p1,p2);
-
- assertEquals((Integer)5, (Integer)p2.getDecodedLossInfo().get(0));
- assertEquals(6, p2.getDecodedLossInfo().size());
- }
-
- public void testNegativeAcknowledgement3(){
- NegativeAcknowledgement p1 = new NegativeAcknowledgement();
- p1.setMessageNumber(9872);
- p1.setTimeStamp(3452);
- p1.setDestinationID(2);
- p1.addLossInfo(5);
- p1.addLossInfo(6);
- p1.addLossInfo(147, 226);
- byte[]p1_data=p1.getEncoded();
-
- UDTPacket p=PacketFactory.createPacket(p1_data);
- NegativeAcknowledgement p2=(NegativeAcknowledgement)p;
- assertEquals(p1,p2);
-
-
- }
-
- public void testShutdown(){
- Shutdown p1 = new Shutdown();
- p1.setMessageNumber(9874);
- p1.setTimeStamp(3453);
- p1.setDestinationID(3);
-
-
- byte[]p1_data=p1.getEncoded();
-
- UDTPacket p=PacketFactory.createPacket(p1_data);
- Shutdown p2=(Shutdown)p;
- assertEquals(p1,p2);
- }
-
-
-
- public void testMessageDropRequest(){
- MessageDropRequest p1=new MessageDropRequest();
- p1.setMessageNumber(9876);
- p1.setTimeStamp(3456);
- p1.setDestinationID(4);
-
- p1.setMsgFirstSeqNo(2);
- p1.setMsgLastSeqNo(3);
-
-
- byte[]p1_data=p1.getEncoded();
-
- UDTPacket p=PacketFactory.createPacket(p1_data);
- assertTrue(p instanceof MessageDropRequest);
- MessageDropRequest p2=(MessageDropRequest)p;
- assertEquals(p1,p2);
- }
-
-}
Copied: udt-java/trunk/src/test/java/udt/packets/DummyControlPacket.java (from rev 41, udt-java/trunk/src/test/java/udt/DummyControlPacket.java)
===================================================================
--- udt-java/trunk/src/test/java/udt/packets/DummyControlPacket.java (rev 0)
+++ udt-java/trunk/src/test/java/udt/packets/DummyControlPacket.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -0,0 +1,16 @@
+package udt.packets;
+
+import udt.packets.ControlPacket;
+
+public class DummyControlPacket extends ControlPacket{
+
+ public DummyControlPacket(){
+
+ }
+
+ @Override
+ public byte[]encodeControlInformation(){
+ //TODO Auto-generate method sub
+ return null;
+ }
+}
\ No newline at end of file
Copied: udt-java/trunk/src/test/java/udt/packets/TestControlPacketType.java (from rev 46, udt-java/trunk/src/test/java/udt/TestControlPacketType.java)
===================================================================
--- udt-java/trunk/src/test/java/udt/packets/TestControlPacketType.java (rev 0)
+++ udt-java/trunk/src/test/java/udt/packets/TestControlPacketType.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -0,0 +1,34 @@
+package udt.packets;
+
+import udt.packets.ControlPacket;
+import udt.packets.ControlPacket.ControlPacketType;
+import junit.framework.TestCase;
+
+public class TestControlPacketType extends TestCase {
+
+ public void testSequenceNumber1(){
+ ControlPacket p=new DummyControlPacket();
+ byte[]x=p.getHeader();
+ byte highest=x[0];
+ assertEquals(128, highest & 0x80);
+ }
+
+ public void testControlPacketTypes(){
+ ControlPacketType t=ControlPacketType.CONNECTION_HANDSHAKE;
+ assertEquals(0,t.ordinal());
+ t=ControlPacketType.KEEP_ALIVE;
+ assertEquals(1,t.ordinal());
+ t=ControlPacketType.ACK;
+ assertEquals(2,t.ordinal());
+ t=ControlPacketType.NAK;
+ assertEquals(3,t.ordinal());
+ t=ControlPacketType.SHUTDOWN;
+ assertEquals(5,t.ordinal());
+ t=ControlPacketType.ACK2;
+ assertEquals(6,t.ordinal());
+ t=ControlPacketType.MESSAGE_DROP_REQUEST;
+ assertEquals(7,t.ordinal());
+ t=ControlPacketType.USER_DEFINED;
+ assertEquals(15,t.ordinal());
+ }
+}
Copied: udt-java/trunk/src/test/java/udt/packets/TestDataPacket.java (from rev 41, udt-java/trunk/src/test/java/udt/TestDataPacket.java)
===================================================================
--- udt-java/trunk/src/test/java/udt/packets/TestDataPacket.java (rev 0)
+++ udt-java/trunk/src/test/java/udt/packets/TestDataPacket.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -0,0 +1,96 @@
+package udt.packets;
+
+import junit.framework.TestCase;
+import udt.packets.DataPacket;
+
+public class TestDataPacket extends TestCase {
+
+ public void testSequenceNumber1(){
+ DataPacket p=new DataPacket();
+ p.setPacketSequenceNumber(1);
+ p.setData(new byte[0]);
+ byte[]x=p.getEncoded();
+ byte highest=x[0];
+ //check highest bit is "0" for DataPacket
+ assertEquals(0, highest & 128);
+ byte lowest=x[3];
+ assertEquals(1, lowest);
+ }
+
+ public void testEncoded(){
+ DataPacket p=new DataPacket();
+ p.setPacketSequenceNumber(1);
+ byte[] data="test".getBytes();
+ p.setData(data);
+ byte[]encoded=p.getEncoded();
+ byte[]encData=new byte[data.length];
+ System.arraycopy(encoded, 16, encData, 0, data.length);
+ String s=new String(encData);
+ assertEquals("test", s);
+ System.out.println("String s = " + s);
+ }
+
+
+ public void testDecode1(){
+
+ DataPacket testPacket1=new DataPacket();
+ testPacket1.setPacketSequenceNumber(127);
+ testPacket1.setDestinationID(1);
+ byte[] data1="Hallo".getBytes();
+ testPacket1.setData(data1);
+
+ //get the encoded data
+ byte[]encodedData=testPacket1.getEncoded();
+
+ int headerLength=16;
+ assertEquals(data1.length+headerLength,encodedData.length);
+
+ byte[]payload=new byte[data1.length];
+ System.arraycopy(encodedData, headerLength, payload, 0, data1.length);
+ String s1=new String(payload);
+ assertEquals("Hallo", s1);
+
+ System.out.println("String s1 = " + s1);
+ System.out.println("tesPacket1Length = "+ testPacket1.getLength());
+ System.out.println("sequenceNumber1 = " + testPacket1.getPacketSequenceNumber());
+ System.out.println("messageNumber 1= " + testPacket1.getMessageNumber());
+ System.out.println("timeStamp1 = " + testPacket1.getTimeStamp());
+ System.out.println("destinationID1 = " + testPacket1.getDestinationID());
+ System.out.println("data1 = " + new String(testPacket1.getData()));
+
+
+ //create a new DataPacket from the encoded data
+ DataPacket testPacket2=new DataPacket(encodedData);
+ // and test
+ System.out.println("tesPacket2Length = "+ testPacket2.getLength());
+ System.out.println("sequenceNumber2 = " + testPacket2.getPacketSequenceNumber());
+ System.out.println("messageNumber2 = " + testPacket2.getMessageNumber());
+ System.out.println("timeStamp2 = " + testPacket2.getTimeStamp());
+ System.out.println("destinationID1 = " + testPacket1.getDestinationID());
+ System.out.println("data2 = " + new String(testPacket2.getData()));
+
+ assertEquals(127,testPacket2.getPacketSequenceNumber());
+
+
+ }
+
+ public void testEncodeDecode1(){
+ DataPacket dp=new DataPacket();
+ dp.setPacketSequenceNumber(127);
+ dp.setMessageNumber(268435457);
+ dp.setTimeStamp(128);
+ dp.setDestinationID(255);
+ dp.setData("test".getBytes());
+
+ byte[]encodedData1=dp.getEncoded();
+
+ DataPacket dp2=new DataPacket(encodedData1);
+ assertEquals(127,dp2.getPacketSequenceNumber());
+ assertEquals(268435457,dp2.getMessageNumber());
+ assertEquals(128,dp2.getTimeStamp());
+ assertEquals(255,dp2.getDestinationID());
+ assertEquals("test", new String(dp2.getData()));
+ }
+
+
+}
Copied: udt-java/trunk/src/test/java/udt/packets/TestPacketFactory.java (from rev 43, udt-java/trunk/src/test/java/udt/TestPacketFactory.java)
===================================================================
--- udt-java/trunk/src/test/java/udt/packets/TestPacketFactory.java (rev 0)
+++ udt-java/trunk/src/test/java/udt/packets/TestPacketFactory.java 2010-09-13 18:55:07 UTC (rev 48)
@@ -0,0 +1,182 @@
+package udt.packets;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+import udt.UDTPacket;
+import udt.packets.Acknowledgement;
+import udt.packets.Acknowledgment2;
+import udt.packets.ConnectionHandshake;
+import udt.packets.DataPacket;
+import udt.packets.MessageDropRequest;
+import udt.packets.NegativeAcknowledgement;
+import udt.packets.PacketFactory;
+import udt.packets.Shutdown;
+
+public class TestPacketFactory extends TestCase {
+
+ public void testData(){
+ String test="sdjfsdjfldskjflds";
+
+ byte[]data=test.getBytes();
+ data[0]=(byte)(data[0] & 0x7f);
+ UDTPacket p=PacketFactory.createPacket(data);
+ DataPacket recv=(DataPacket)p;
+ String t=new String(recv.getEncoded());
+ assertTrue(p instanceof DataPacket);
+ assertEquals(test,t);
+ }
+
+
+ public void testConnectionHandshake(){
+ ConnectionHandshake p1 = new ConnectionHandshake();
+ p1.setMessageNumber(9876);
+ p1.setTimeStamp(3456);
+ p1.setDestinationID(1);
+
+ p1.setConnectionType(1);
+ p1.setSocketType(1);
+ p1.setInitialSeqNo(321);
+ p1.setPacketSize(128);
+ p1.setMaxFlowWndSize(128);
+ p1.setSocketID(1);
+ p1.setUdtVersion(4);
+
+
+ byte[]p1_data=p1.getEncoded();
+
+ UDTPacket p=PacketFactory.createPacket(p1_data);
+ ConnectionHandshake p2=(ConnectionHandshake)p;
+ assertEquals(p1,p2);
+
+ }
+
+ public void testAcknowledgement(){
+ Acknowledgement p1 = new Acknowledgement();
+ p1.setAckSequenceNumber(1234);
+ p1.setMessageNumber(9876);
+ p1.setTimeStamp(3456);
+ p1.setDestinationID(1);
+ p1.setBufferSize(128);
+ p1.setEstimatedLinkCapacity(16);
+ p1.setAckNumber(9870);
+ p1.setPacketReceiveRate(1000);
+ p1.setRoundTripTime(1000);
+ p1.setRoundTripTimeVar(500);
+
+ byte[]p1_data=p1.getEncoded();
+ UDTPacket p=PacketFactory.createPacket(p1_data);
+ Acknowledgement p2=(Acknowledgement)p;
+ assertEquals(p1,p2);
+ }
+
+ public void testAcknowledgementOfAcknowledgement(){
+ Acknowledgment2 p1 = new Acknowledgment2();
+ p1.setAckSequenceNumber(1230);
+ p1.setMessageNumber(9871);
+ p1.setTimeStamp(3451);
+ p1.setDestinationID(1);
+
+ byte[]p1_data=p1.getEncoded();
+ UDTPacket p=PacketFactory.createPacket(p1_data);
+ Acknowledgment2 p2=(Acknowledgment2)p;
+ assertEquals(p1,p2);
+
+
+ }
+
+ public void testNegativeAcknowledgement(){
+ NegativeAcknowledgement p1 = new NegativeAcknowledgement();
+ p1.setMessageNumber(9872);
+ p1.setTimeStamp(3452);
+ p1.setDestinationID(2);
+ p1.addLossInfo(5);
+ p1.addLossInfo(6);
+ p1.addLossInfo(7, 10);
+ byte[]p1_data=p1.getEncoded();
+
+ UDTPacket p=PacketFactory.createPacket(p1_data);
+ NegativeAcknowledgement p2=(NegativeAcknowledgement)p;
+ assertEquals(p1,p2);
+
+ assertEquals((Integer)5, (Integer)p2.getDecodedLossInfo().get(0));
+ assertEquals(6, p2.getDecodedLossInfo().size());
+ }
+
+ public void testNegativeAcknowledgement2(){
+ NegativeAcknowledgement p1 = new NegativeAcknowledgement();
+ p1.setMessageNumber(9872);
+ p1.setTimeStamp(3452);
+ p1.setDestinationID(2);
+ List<Long>loss=new ArrayList<Long>();
+ loss.add(5l);
+ loss.add(6l);
+ loss.add(7l);
+ loss.add(8l);
+ loss.add(9l);
+ loss.add(11l);
+
+ p1.addLossInfo(loss);
+ byte[]p1_data=p1.getEncoded();
+
+ UDTPacket p=PacketFactory.createPacket(p1_data);
+ NegativeAcknowledgement p2=(NegativeAcknowledgement)p;
+ assertEquals(p1,p2);
+
+ assertEquals((Integer)5, (Integer)p2.getDecodedLossInfo().get(0));
+ assertEquals(6, p2.getDecodedLossInfo().size());
+ }
+
+ public void testNegativeAcknowledgement3(){
+ NegativeAcknowledgement p1 = new NegativeAcknowledgement();
+ p1.setMessageNumber(9872);
+ p1.setTimeStamp(3452);
+ p1.setDestinationID(2);
+ p1.addLossInfo(5);
+ p1.addLossInfo(6);
+ p1.addLossInfo(147, 226);
+ byte[]p1_data=p1.getEncoded();
+
+ UDTPacket p=PacketFactory.createPacket(p1_data);
+ NegativeAcknowledgement p2=(NegativeAcknowledgement)p;
+ assertEquals(p1,p2);
+
+
+ }
+
+ public void testShutdown(){
+ Shutdown p1 = new Shutdown();
+ p1.setMessageNumber(9874);
+ p1.setTimeStamp(3453);
+ p1.setDestinationID(3);
+
+
+ byte[]p1_data=p1.getEncoded();
+
+ UDTPacket p=PacketFactory.createPacket(p1_data);
+ Shutdown p2=(Shutdown)p;
+ assertEquals(p1,p2);
+ }
+
+
+
+ public void testMessageDropRequest(){
+ MessageDropRequest p1=new MessageDropRequest();
+ p1.setMessageNumber(9876);
+ p1.setTimeStamp(3456);
+ p1.setDestinationID(4);
+
+ p1.setMsgFirstSeqNo(2);
+ p1.setMsgLastSeqNo(3);
+
+
+ byte[]p1_data=p1.getEncoded();
+
+ UDTPacket p=PacketFactory.createPacket(p1_data);
+ assertTrue(p instanceof MessageDropRequest);
+ MessageDropRequest p2=(MessageDropRequest)p;
+ assertEquals(p1,p2);
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|