mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 04:50:25 +08:00
72 lines
2.6 KiB
Java
72 lines
2.6 KiB
Java
package packet;
|
||
|
||
import component.ComponentException;
|
||
import component.Identifier;
|
||
import component.TTL;
|
||
import encoding.*;
|
||
import org.junit.Test;
|
||
|
||
import java.util.Arrays;
|
||
|
||
/*
|
||
* @Author: Wang Feng
|
||
* @Description:
|
||
* @Version: 1.0.0
|
||
* @Date: 10:32 2021/4/8
|
||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||
*/
|
||
public class InterestTest_WF {
|
||
@Test
|
||
public void TestInterest_ToUri() throws ComponentException {
|
||
Interest interest=new Interest();
|
||
Identifier name=new Identifier("/wefree/王");
|
||
interest.setName(name);
|
||
System.out.println(interest.getName().toUri());
|
||
}
|
||
|
||
/**
|
||
* Interest wireEncode:
|
||
* [5, 69,
|
||
* 50, 19,
|
||
* 103, 17, 101, 15,
|
||
* 100, 7, 0, 119, 101, 102, 114, 101, 101,
|
||
* 100, 4, 0, -25, -114, -117,
|
||
* 52, 20,
|
||
* -49, 2, 15, -96,
|
||
* -48, 8, 45, -7, 121, 78, -63, 21, -121, -66,
|
||
* -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 ComponentException
|
||
* @throws EncoderException
|
||
* @throws PacketException
|
||
* @throws BlockException
|
||
*/
|
||
@Test
|
||
public void TestInterest_WireEncode() throws ComponentException, EncoderException, PacketException, BlockException {
|
||
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);
|
||
|
||
Encoder encoder=new Encoder();
|
||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||
System.out.println("encode res: "+interest.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()));
|
||
Interest newInterest=new Interest();
|
||
System.out.println("decode res: "+newInterest.wireDecode(block));
|
||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||
System.out.println("encode res: "+newInterest.wireEncode(encoder));
|
||
byte[] newbuf=encoder.getBuffer();
|
||
System.out.println("newbuf: "+ Arrays.toString(newbuf));
|
||
System.out.println("new uri: "+newInterest.toUri()
|
||
+" , ttl; "+newInterest.ttl.ttl());
|
||
}
|
||
}
|