add packet test: NackTest

This commit is contained in:
free will
2021-04-08 11:29:12 +08:00
parent 43468b0999
commit c1a5ebed1a
+64
View File
@@ -0,0 +1,64 @@
package packet;
import component.*;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 11:23 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class NackTest {
/**
* Nack wireEncode:
* [5, 73,
* 50, 19,
* 103, 17, 101, 15,
* 100, 7, 0, 119, 101, 102, 114, 101, 101,
* 100, 4, 0, -25, -114, -117,
* 52, 24,
* -49, 2, 15, -96,
* -48, 8, 28, -40, -82, -73, -63, -103, -15, -43,
* -43, 2, 9, 29,
* -52, 4, -124, -35, -33, 25,
* 53, 24, 54, 10, -45, 8, 127, -1, -1, -1, -1, -1, -1, -1, 55, 10, -44, 8, 127, -1, -1, -1, -1, -1, -1, -1]
* @throws EncoderException
* @throws PacketException
* @throws BlockException
* @throws ComponentException
*/
@Test
public void TestNack_wireEncode() throws EncoderException, PacketException, BlockException, ComponentException {
Interest interest=new Interest();
interest.ttl.setTtl(Long.MAX_VALUE);
byte[] value={(byte)132,(byte)221,(byte)223,(byte)25};
interest.payload.setValue(value);
interest.congestionMark.setCongestionLevel(Long.MAX_VALUE);
Identifier name=new Identifier("/wefree/王");
interest.setName(name);
Nack nack=new Nack(interest,2333);
Encoder encoder=new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
System.out.println("encode res: "+nack.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
Block block=new Block(buf,false);
System.out.println("block buf: "+Arrays.toString(block.getValue()));
Nack newNack=new Nack();
System.out.println("decode res: "+newNack.wireDecode(block));
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
System.out.println("encode res: "+newNack.wireEncode(encoder));
byte[] newbuf=encoder.getBuffer();
System.out.println("newbuf: "+ Arrays.toString(newbuf));
System.out.println("new uri: "+newNack.interest.toUri()
+" , ttl "+newNack.interest.ttl.ttl()
+" ,reason: "+newNack.getNackReason());
}
}