Merge branch 'master' of gitee.com:willfree/min-dev-java

This commit is contained in:
ghy
2021-04-21 16:18:44 +08:00
38 changed files with 875 additions and 126 deletions
+2 -2
View File
@@ -62,14 +62,14 @@ public class CongestionMark implements TlvComponentBase, InitialAble, IEncodingA
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvCongestionMark));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvCongestionMark));
if (tmplen < 0) {
return -1;
}
@@ -63,14 +63,14 @@ public class ControlParameterCapacity implements TlvComponentBase,InitialAble, I
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvManagementCapacity));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvManagementCapacity));
if (tmplen < 0) {
return -1;
}
@@ -61,14 +61,14 @@ public class ControlParameterCost implements TlvComponentBase,InitialAble,IEncod
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvManagementCost));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvManagementCost));
if (tmplen < 0) {
return -1;
}
@@ -61,14 +61,14 @@ public class ControlParameterCount implements TlvComponentBase,InitialAble, IEnc
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvManagementCount));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvManagementCount));
if (tmplen < 0) {
return -1;
}
@@ -61,14 +61,14 @@ public class ControlParameterExpireTime implements TlvComponentBase,InitialAble,
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvManagementExpireTime));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvManagementExpireTime));
if (tmplen < 0) {
return -1;
}
@@ -65,14 +65,14 @@ public class ControlParameterLocalUri implements TlvComponentBase, InitialAble,
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvManagementLocalUri));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvManagementLocalUri));
if (tmplen < 0) {
return -1;
}
@@ -61,14 +61,14 @@ public class ControlParameterLogicFaceId implements TlvComponentBase,InitialAble
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvManagementLogicFaceId));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvManagementLogicFaceId));
if (tmplen < 0) {
return -1;
}
@@ -61,14 +61,14 @@ public class ControlParameterLogicFacePersistency implements TlvComponentBase,In
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvManagementLogicFacePersistency));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvManagementLogicFacePersistency));
if (tmplen < 0) {
return -1;
}
@@ -58,20 +58,23 @@ public class ControlParameterMtu implements TlvComponentBase,InitialAble,IEncodi
if (tmplen < 0) {
return -1;
}
System.out.println("tmplen-1: "+tmplen);
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
System.out.println("tmplen-2: "+tmplen);
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvManagementMtu));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvManagementMtu));
if (tmplen < 0) {
return -1;
}
System.out.println("tmplen-3: "+tmplen);
totalLength += tmplen;
return totalLength;
@@ -61,14 +61,14 @@ public class ControlParameterPrefix implements TlvComponentBase,InitialAble, IEn
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvManagementPrefix));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvManagementPrefix));
if (tmplen < 0) {
return -1;
}
@@ -65,14 +65,14 @@ public class ControlParameterUri implements TlvComponentBase, InitialAble, IEnco
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvManagementUri));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvManagementUri));
if (tmplen < 0) {
return -1;
}
@@ -61,14 +61,14 @@ public class ControlParameterUriScheme implements TlvComponentBase,InitialAble,I
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvManagementUriScheme));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvManagementUriScheme));
if (tmplen < 0) {
return -1;
}
+2 -2
View File
@@ -63,14 +63,14 @@ public class FreshnessPeriod implements TlvComponentBase, InitialAble, IEncoding
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvFreshnessPeriod));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvFreshnessPeriod));
if (tmplen < 0) {
return -1;
}
+2 -2
View File
@@ -62,14 +62,14 @@ public class HopLimit implements TlvComponentBase,InitialAble, IEncodingAble {
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvHopLimit));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvHopLimit));
if (tmplen < 0) {
return -1;
}
@@ -63,14 +63,14 @@ public class InterestLifeTime implements TlvComponentBase,InitialAble, IEncoding
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvInterestLifeTime));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvInterestLifeTime));
if (tmplen < 0) {
return -1;
}
+2 -2
View File
@@ -66,14 +66,14 @@ public class NackHeader implements TlvComponentBase,InitialAble, IEncodingAble {
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvNackHeader));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvNackHeader));
if (tmplen < 0) {
return -1;
}
+2 -2
View File
@@ -73,14 +73,14 @@ public class Nonce implements TlvComponentBase, InitialAble, IEncodingAble {
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvNonce));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvNonce));
if (tmplen < 0) {
return -1;
}
+2 -2
View File
@@ -89,14 +89,14 @@ public class Payload implements TlvComponentBase,InitialAble, IEncodingAble {
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvPayload));
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvPayload));
if (tmplen < 0) {
return -1;
}
@@ -0,0 +1,37 @@
package component;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 14:03 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlParameterCapacityTest {
@Test
public void testControlParameterCapacityEncoderAndDecode() throws EncoderException, ComponentException, BlockException {
ControlParameterCapacity controlParameterCapacity=new ControlParameterCapacity(Long.MAX_VALUE);
System.out.println("value: "+controlParameterCapacity.getCapacity());
System.out.println("ini: "+controlParameterCapacity.isInitial());
Encoder encoder = new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
System.out.println("encode res: "+controlParameterCapacity.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
Block block=new Block(buf,false);
ControlParameterCapacity controlParameterCapacity1=new ControlParameterCapacity();
System.out.println("decode res: "+controlParameterCapacity1.wireDecode(block));
System.out.println("new value: "+controlParameterCapacity1.getCapacity());
System.out.println("new ini: "+controlParameterCapacity1.isInitial());
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
controlParameterCapacity1.wireEncode(encoder);
System.out.println("new buf: "+Arrays.toString(encoder.getBuffer()));
}
}
@@ -0,0 +1,37 @@
package component;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 14:03 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlParameterCostTest {
@Test
public void testControlParameterCostEncoderAndDecode() throws EncoderException, ComponentException, BlockException {
ControlParameterCost controlParameterCost=new ControlParameterCost(Long.MAX_VALUE);
System.out.println("value: "+controlParameterCost.getCost());
System.out.println("ini: "+controlParameterCost.isInitial());
Encoder encoder = new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
System.out.println("encode res: "+controlParameterCost.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
Block block=new Block(buf,false);
ControlParameterCost controlParameterCost1=new ControlParameterCost();
System.out.println("decode res: "+controlParameterCost1.wireDecode(block));
System.out.println("new value: "+controlParameterCost1.getCost());
System.out.println("new ini: "+controlParameterCost1.isInitial());
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
controlParameterCost1.wireEncode(encoder);
System.out.println("new buf: "+Arrays.toString(encoder.getBuffer()));
}
}
@@ -0,0 +1,37 @@
package component;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 14:03 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlParameterCountTest {
@Test
public void testControlParameterCountEncoderAndDecode() throws EncoderException, ComponentException, BlockException {
ControlParameterCount controlParameterCount=new ControlParameterCount(Long.MAX_VALUE);
System.out.println("value: "+controlParameterCount.getCount());
System.out.println("ini: "+controlParameterCount.isInitial());
Encoder encoder = new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
System.out.println("encode res: "+controlParameterCount.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
Block block=new Block(buf,false);
ControlParameterCount controlParameterCount1=new ControlParameterCount();
System.out.println("decode res: "+controlParameterCount1.wireDecode(block));
System.out.println("new value: "+controlParameterCount1.getCount());
System.out.println("new ini: "+controlParameterCount1.isInitial());
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
controlParameterCount1.wireEncode(encoder);
System.out.println("new buf: "+Arrays.toString(encoder.getBuffer()));
}
}
@@ -0,0 +1,37 @@
package component;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 14:03 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlParameterExpireTimeTest {
@Test
public void testControlParameterExpireTimeEncoderAndDecode() throws EncoderException, ComponentException, BlockException {
ControlParameterExpireTime controlParameterExpireTime=new ControlParameterExpireTime(Long.MAX_VALUE);
System.out.println("value: "+controlParameterExpireTime.getExpireTime());
System.out.println("ini: "+controlParameterExpireTime.isInitial());
Encoder encoder = new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
System.out.println("encode res: "+controlParameterExpireTime.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
Block block=new Block(buf,false);
ControlParameterExpireTime controlParameterExpireTime1=new ControlParameterExpireTime();
System.out.println("decode res: "+controlParameterExpireTime1.wireDecode(block));
System.out.println("new value: "+controlParameterExpireTime1.getExpireTime());
System.out.println("new ini: "+controlParameterExpireTime1.isInitial());
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
controlParameterExpireTime1.wireEncode(encoder);
System.out.println("new buf: "+Arrays.toString(encoder.getBuffer()));
}
}
@@ -0,0 +1,38 @@
package component;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 14:03 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlParameterLocalUriTest {
@Test
public void testControlParameterLocalUriEncoderAndDecode() throws EncoderException, ComponentException, BlockException {
ControlParameterLocalUri controlParameterCost=new ControlParameterLocalUri("wefree");
System.out.println("value: "+controlParameterCost.getLocalUri());
System.out.println("ini: "+controlParameterCost.isInitial());
Encoder encoder = new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
System.out.println("encode res: "+controlParameterCost.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
System.out.println("buf len: "+buf.length);
Block block=new Block(buf,false);
ControlParameterLocalUri controlParameterCost1=new ControlParameterLocalUri();
System.out.println("decode res: "+controlParameterCost1.wireDecode(block));
System.out.println("new value: "+controlParameterCost1.getLocalUri());
System.out.println("new ini: "+controlParameterCost1.isInitial());
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
controlParameterCost1.wireEncode(encoder);
System.out.println("new buf: "+Arrays.toString(encoder.getBuffer()));
}
}
@@ -0,0 +1,37 @@
package component;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 14:03 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlParameterLogicFaceIdTest {
@Test
public void testControlParameterLogicFaceIdEncoderAndDecode() throws EncoderException, ComponentException, BlockException {
ControlParameterLogicFaceId controlParameterLogicFaceId=new ControlParameterLogicFaceId(Long.MAX_VALUE);
System.out.println("value: "+controlParameterLogicFaceId.getLogicFaceId());
System.out.println("ini: "+controlParameterLogicFaceId.isInitial());
Encoder encoder = new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
System.out.println("encode res: "+controlParameterLogicFaceId.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
Block block=new Block(buf,false);
ControlParameterLogicFaceId controlParameterLogicFaceId1=new ControlParameterLogicFaceId();
System.out.println("decode res: "+controlParameterLogicFaceId1.wireDecode(block));
System.out.println("new value: "+controlParameterLogicFaceId1.getLogicFaceId());
System.out.println("new ini: "+controlParameterLogicFaceId1.isInitial());
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
controlParameterLogicFaceId1.wireEncode(encoder);
System.out.println("new buf: "+Arrays.toString(encoder.getBuffer()));
}
}
@@ -0,0 +1,37 @@
package component;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 14:03 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlParameterLogicFacePersistencyTest {
@Test
public void testControlParameterLogicFacePersistencyEncoderAndDecode() throws EncoderException, ComponentException, BlockException {
ControlParameterLogicFacePersistency controlParameterLogicFacePersistency=new ControlParameterLogicFacePersistency(Long.MAX_VALUE);
System.out.println("value: "+controlParameterLogicFacePersistency.getPersistency());
System.out.println("ini: "+controlParameterLogicFacePersistency.isInitial());
Encoder encoder = new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
System.out.println("encode res: "+controlParameterLogicFacePersistency.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
Block block=new Block(buf,false);
ControlParameterLogicFacePersistency controlParameterLogicFacePersistency1=new ControlParameterLogicFacePersistency();
System.out.println("decode res: "+controlParameterLogicFacePersistency1.wireDecode(block));
System.out.println("new value: "+controlParameterLogicFacePersistency1.getPersistency());
System.out.println("new ini: "+controlParameterLogicFacePersistency1.isInitial());
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
controlParameterLogicFacePersistency1.wireEncode(encoder);
System.out.println("new buf: "+Arrays.toString(encoder.getBuffer()));
}
}
@@ -0,0 +1,37 @@
package component;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 14:03 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlParameterMtuTest {
@Test
public void testControlParameterMtuEncoderAndDecode() throws EncoderException, ComponentException, BlockException {
ControlParameterMtu controlParameterMtu=new ControlParameterMtu(Long.MAX_VALUE);
System.out.println("value: "+controlParameterMtu.getMtu());
System.out.println("ini: "+controlParameterMtu.isInitial());
Encoder encoder = new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
System.out.println("encode res: "+controlParameterMtu.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
Block block=new Block(buf,false);
ControlParameterMtu controlParameterMtu1=new ControlParameterMtu();
System.out.println("decode res: "+controlParameterMtu1.wireDecode(block));
System.out.println("new value: "+controlParameterMtu1.getMtu());
System.out.println("new ini: "+controlParameterMtu1.isInitial());
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
controlParameterMtu1.wireEncode(encoder);
System.out.println("new buf: "+Arrays.toString(encoder.getBuffer()));
}
}
@@ -0,0 +1,38 @@
package component;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 14:03 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlParameterPrefixTest {
@Test
public void testControlParameterPrefixEncoderAndDecode() throws EncoderException, ComponentException, BlockException {
Identifier identifier=new Identifier("/pku/wefree/王");
ControlParameterPrefix controlParameterCost=new ControlParameterPrefix(identifier);
System.out.println("value: "+controlParameterCost.getPrefix().toUri());
System.out.println("ini: "+controlParameterCost.isInitial());
Encoder encoder = new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
System.out.println("encode res: "+controlParameterCost.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
Block block=new Block(buf,false);
ControlParameterPrefix controlParameterCost1=new ControlParameterPrefix();
System.out.println("decode res: "+controlParameterCost1.wireDecode(block));
System.out.println("new value: "+controlParameterCost1.getPrefix().toUri());
System.out.println("new ini: "+controlParameterCost1.isInitial());
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
controlParameterCost1.wireEncode(encoder);
System.out.println("new buf: "+Arrays.toString(encoder.getBuffer()));
}
}
@@ -0,0 +1,37 @@
package component;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 14:03 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlParameterUriSchemeTest {
@Test
public void testControlParameterUriSchemeEncoderAndDecode() throws EncoderException, ComponentException, BlockException {
ControlParameterUriScheme controlParameterUriScheme=new ControlParameterUriScheme(Long.MAX_VALUE);
System.out.println("value: "+controlParameterUriScheme.getUriScheme());
System.out.println("ini: "+controlParameterUriScheme.isInitial());
Encoder encoder = new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
System.out.println("encode res: "+controlParameterUriScheme.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
Block block=new Block(buf,false);
ControlParameterUriScheme controlParameterUriScheme1=new ControlParameterUriScheme();
System.out.println("decode res: "+controlParameterUriScheme1.wireDecode(block));
System.out.println("new value: "+controlParameterUriScheme1.getUriScheme());
System.out.println("new ini: "+controlParameterUriScheme1.isInitial());
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
controlParameterUriScheme1.wireEncode(encoder);
System.out.println("new buf: "+Arrays.toString(encoder.getBuffer()));
}
}
@@ -0,0 +1,38 @@
package component;
import encoding.*;
import org.junit.Test;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 14:03 2021/4/8
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlParameterUriTest {
@Test
public void testControlParameterUriEncoderAndDecode() throws EncoderException, ComponentException, BlockException {
ControlParameterUri controlParameterCost=new ControlParameterUri("wefree");
System.out.println("value: "+controlParameterCost.getUri());
System.out.println("ini: "+controlParameterCost.isInitial());
Encoder encoder = new Encoder();
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
System.out.println("encode res: "+controlParameterCost.wireEncode(encoder));
byte[] buf=encoder.getBuffer();
System.out.println("buf: "+ Arrays.toString(buf));
System.out.println("buf len: "+buf.length);
Block block=new Block(buf,false);
ControlParameterUri controlParameterCost1=new ControlParameterUri();
System.out.println("decode res: "+controlParameterCost1.wireDecode(block));
System.out.println("new value: "+controlParameterCost1.getUri());
System.out.println("new ini: "+controlParameterCost1.isInitial());
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize), new SizeT(0));
controlParameterCost1.wireEncode(encoder);
System.out.println("new buf: "+Arrays.toString(encoder.getBuffer()));
}
}
@@ -11,6 +11,7 @@ import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
import org.eclipse.collections.api.partition.ordered.PartitionReversibleIterable;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
@@ -32,13 +33,48 @@ public class SM2Benchmark {
private static SM2PublicKey sm2PublicKey;
private static byte[] digest;
private static byte[] encBytes;
private static String content2;
private static byte[] digest1K;
private static byte[] encBytes1K;
private static byte[] digest8K;
private static byte[] encBytes8K;
private static byte[] payLoad;
private static byte[] payLoad1K;
private static byte[] payLoad8K;
private static byte[] createPayload(int mode){
byte[] res = null;
switch (mode){
case 0:
return new byte[]{1};
case 1:
res = new byte[1024];
for (int i = 0; i < 1024 ; i++) {
res[i] = (byte) (i % 128);
}
return res;
case 8:
res = new byte[8192];
for (int i = 0; i < 8192 ; i++) {
res[i] = (byte) (i % 128);
}
return res;
default:
return res;
}
}
static {
try {
init(); // 初始化类成员公私钥
digest = sm2PrivateKey.sign(ByteUtils.fromHexString(content)); // 初始化类成员摘要
content2 = "hello world";
encBytes = sm2PublicKey.encrypt(content2.getBytes());
payLoad = createPayload(0);
payLoad1K = createPayload(1);
payLoad8K = createPayload(8);
digest = sm2PrivateKey.sign(payLoad); // 初始化类成员摘要
encBytes = sm2PublicKey.encrypt(payLoad);
digest1K = sm2PrivateKey.sign(payLoad1K); // 初始化类成员摘要
encBytes1K = sm2PublicKey.encrypt(payLoad1K);
digest8K = sm2PrivateKey.sign(payLoad8K); // 初始化类成员摘要
encBytes8K = sm2PublicKey.encrypt(payLoad8K);
} catch (CryptoException e) {
e.printStackTrace();
}
@@ -60,12 +96,32 @@ public class SM2Benchmark {
@Benchmark
public void testSign() throws CryptoException {
SM2Benchmark.sm2PrivateKey.sign(ByteUtils.fromHexString(content));
SM2Benchmark.sm2PrivateKey.sign(payLoad);
}
@Benchmark
public void testVerify() throws CryptoException {
SM2Benchmark.sm2PublicKey.verify(ByteUtils.fromHexString(content), digest);
SM2Benchmark.sm2PublicKey.verify(payLoad, digest);
}
@Benchmark
public void testSign1K() throws CryptoException {
SM2Benchmark.sm2PrivateKey.sign(payLoad1K);
}
@Benchmark
public void testVerify1K() throws CryptoException {
SM2Benchmark.sm2PublicKey.verify(payLoad1K, digest1K);
}
@Benchmark
public void testSign8K() throws CryptoException {
SM2Benchmark.sm2PrivateKey.sign(payLoad8K);
}
@Benchmark
public void testVerify8K() throws CryptoException {
SM2Benchmark.sm2PublicKey.verify(payLoad8K, digest8K);
}
@Benchmark
@@ -75,13 +131,33 @@ public class SM2Benchmark {
@Benchmark
public void testEncrypt() throws InvalidCipherTextException {
sm2PublicKey.encrypt(content2.getBytes());
sm2PublicKey.encrypt(payLoad);
}
@Benchmark
public void testDecrypt() throws InvalidCipherTextException {
sm2PrivateKey.decrypt(encBytes);
}
@Benchmark
public void testEncrypt1K() throws InvalidCipherTextException {
sm2PublicKey.encrypt(payLoad1K);
}
@Benchmark
public void testDecrypt1K() throws InvalidCipherTextException {
sm2PrivateKey.decrypt(encBytes1K);
}
@Benchmark
public void testEncrypt8K() throws InvalidCipherTextException {
sm2PublicKey.encrypt(payLoad8K);
}
@Benchmark
public void testDecrypt8K() throws InvalidCipherTextException {
sm2PrivateKey.decrypt(encBytes8K);
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(SM2Benchmark.class.getSimpleName())
@@ -18,9 +18,36 @@ import java.util.concurrent.TimeUnit;
public class SM3Benchmark {
private static HashAlgo hashAlgo;
private static String srcString = "123456";
private static byte[] srcData = srcString.getBytes();
private static byte[] srcData, srcData1K, srcData8K;
static {
hashAlgo = new HashAlgo();
srcData = createPayload(0);
srcData1K = createPayload(1);
srcData8K = createPayload(8);
}
private static byte[] createPayload(int mode){
byte[] res = null;
switch (mode){
case 0:
return new byte[]{1};
case 1:
res = new byte[1024];
for (int i = 0; i < 1024 ; i++) {
res[i] = (byte) (i % 128);
}
return res;
case 8:
res = new byte[8192];
for (int i = 0; i < 8192 ; i++) {
res[i] = (byte) (i % 128);
}
return res;
default:
return res;
}
}
@Benchmark
@@ -28,6 +55,16 @@ public class SM3Benchmark {
hashAlgo.sm3(srcData);
}
@Benchmark
public void testSM31K(){
hashAlgo.sm3(srcData1K);
}
@Benchmark
public void testSM38K(){
hashAlgo.sm3(srcData8K);
}
@Benchmark
public void testSM3ByString(){
hashAlgo.sm3(srcString);
@@ -28,23 +28,68 @@ import static minsecurity.crypto.TestSM4.SRC_DATA_16B;
public class SM4Benchmark {
private static byte[] key;
private static byte[] iv;
private static byte[] payLoad, payLoad1K, payLoad8K;
private static byte[] cipherText;
private static byte[] cipherText2;
private static byte[] cipherText3;
private static byte[] cipherText4;
private static byte[] cipherText5;
private static byte[] cipherText6;
private static byte[] createPayload(int mode){
byte[] res = null;
switch (mode){
case 0:
return new byte[]{1};
case 1:
res = new byte[1024];
for (int i = 0; i < 1024 ; i++) {
res[i] = (byte) (i % 128);
}
return res;
case 8:
res = new byte[8192];
for (int i = 0; i < 8192 ; i++) {
res[i] = (byte) (i % 128);
}
return res;
default:
return res;
}
}
static {
try {
key = SM4.generateKey();
iv = SM4.generateKey();
cipherText = SM4.encrypt_ECB_Padding(key, SRC_DATA_16B);
cipherText2 = SM4.encrypt_CBC_Padding(key, iv, SRC_DATA);
payLoad = createPayload(0);
payLoad1K = createPayload(1);
payLoad8K = createPayload(8);
cipherText = SM4.encrypt_ECB_Padding(key, payLoad);
cipherText2 = SM4.encrypt_CBC_Padding(key, iv, payLoad);
cipherText3 = SM4.encrypt_ECB_Padding(key, payLoad1K);
cipherText4 = SM4.encrypt_CBC_Padding(key, iv, payLoad1K);
cipherText5 = SM4.encrypt_ECB_Padding(key, payLoad8K);
cipherText6 = SM4.encrypt_CBC_Padding(key, iv, payLoad8K);
} catch (Exception e) {
e.printStackTrace();
}
}
@Benchmark
public void testCBCEncrypt() throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
SM4.encrypt_CBC_Padding(key, iv, payLoad);
}
@Benchmark
public void testCBCDecrypt() throws BadPaddingException, NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
SM4.decrypt_CBC_Padding(key, iv, cipherText2);
}
@Benchmark
public void testECBEncrypt() throws NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
SM4.encrypt_ECB_Padding(key, SRC_DATA_16B);
SM4.encrypt_ECB_Padding(key, payLoad);
}
@Benchmark
@@ -53,13 +98,43 @@ public class SM4Benchmark {
}
@Benchmark
public void testCBCEncrypt() throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
SM4.encrypt_CBC_Padding(key, iv, SRC_DATA);
public void testCBCEncrypt1K() throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
SM4.encrypt_CBC_Padding(key, iv, payLoad1K);
}
@Benchmark
public void testCBCDecrypt() throws BadPaddingException, NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
SM4.decrypt_CBC_Padding(key, iv, cipherText2);
public void testCBCDecrypt1K() throws BadPaddingException, NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
SM4.decrypt_CBC_Padding(key, iv, cipherText4);
}
@Benchmark
public void testECBEncrypt1K() throws NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
SM4.encrypt_ECB_Padding(key, payLoad1K);
}
@Benchmark
public void testECBDecrypt1K() throws BadPaddingException, NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
SM4.decrypt_ECB_Padding(key, cipherText3);
}
@Benchmark
public void testCBCEncrypt8K() throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
SM4.encrypt_CBC_Padding(key, iv, payLoad8K);
}
@Benchmark
public void testCBCDecrypt8K() throws BadPaddingException, NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
SM4.decrypt_CBC_Padding(key, iv, cipherText6);
}
@Benchmark
public void testECBEncrypt8K() throws NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
SM4.encrypt_ECB_Padding(key, payLoad8K);
}
@Benchmark
public void testECBDecrypt8K() throws BadPaddingException, NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
SM4.decrypt_ECB_Padding(key, cipherText5);
}
public static void main(String[] args) throws RunnerException {
@@ -28,7 +28,7 @@ public class PersistBenchmark {
// 测试PersistIdentity
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
Identity identity = new Identity();
identity.setName("wzq"+Math.random());
identity.setName("/wzq"+Math.random());
KeyParam keyParam = new KeyParam();
keyParam.PublicKeyAlgorithm = 0;
keyParam.SignatureAlgorithm = 0;
@@ -66,7 +66,7 @@ public class PersistBenchmark {
@Benchmark
public void testSetIdentity() throws Exception {
String name = "wzq0.6597381351293033"; // 预先存储好的身份名
String name = "/wzq0.6597381351293033"; // 预先存储好的身份名
Persist.setDefaultIdentityByNameInStorage(name);
}
@@ -34,7 +34,7 @@ public class TestIdentity {
// 测试PersistIdentity
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
Identity identity = new Identity();
identity.setName("wzq"+Math.random());
identity.setName("/wzq"+Math.random());
KeyParam keyParam = new KeyParam();
keyParam.PublicKeyAlgorithm = 0;
keyParam.SignatureAlgorithm = 0;
@@ -44,7 +44,7 @@ public class TestPersist {
// 测试PersistIdentity
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
Identity identity = new Identity();
identity.setName("wzq"+Math.random());
identity.setName("/wzq"+Math.random());
KeyParam keyParam = new KeyParam();
keyParam.PublicKeyAlgorithm = 0;
keyParam.SignatureAlgorithm = 0;
@@ -30,7 +30,7 @@ public class IdentifyManagerBenchmark {
// 测试PersistIdentity
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
Identity identity = new Identity();
identity.setName("wzq"+Math.random());
identity.setName("/wzq"+Math.random());
KeyParam keyParam = new KeyParam();
keyParam.PublicKeyAlgorithm = 0;
keyParam.SignatureAlgorithm = 0;
@@ -25,7 +25,7 @@ public class IdentifyManagerTest {
// 测试PersistIdentity
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
Identity identity = new Identity();
identity.setName("wzq"+Math.random());
identity.setName("/wzq"+Math.random());
KeyParam keyParam = new KeyParam();
keyParam.PublicKeyAlgorithm = 0;
keyParam.SignatureAlgorithm = 0;
+217 -69
View File
@@ -1,5 +1,6 @@
package security;
import component.ComponentException;
import component.Identifier;
import component.TTL;
import encoding.VlInt;
@@ -9,6 +10,7 @@ import minsecurity.certificate.cert.Certificate;
import minsecurity.crypto.sm2.SM2KeyPair;
import minsecurity.identity.Identity;
import minsecurity.identity.KeyParam;
import org.checkerframework.checker.units.qual.K;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
@@ -35,7 +37,7 @@ public class KeychainBenchmark {
// 测试PersistIdentity
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
Identity identity = new Identity();
identity.setName("wzq"+Math.random());
identity.setName("/wzq"+Math.random());
KeyParam keyParam = new KeyParam();
keyParam.PublicKeyAlgorithm = 0;
keyParam.SignatureAlgorithm = 0;
@@ -64,33 +66,38 @@ public class KeychainBenchmark {
return identity;
}
@Benchmark
public void testCreateKeyChain() throws Exception {
KeyChain keyChain = new KeyChain();
private static KeyChain chain;
private static Interest interest, interest2, interest3, interest4, interest5, interest6; // 用于签名
private static Data data, data2, data3, data4, data5, data6; // 用于签名
private static CPacket cPacket, cPacket2, cPacket3, cPacket4, cPacket5, cPacket6; // 用于签名
private static byte[] createPayload(int mode){
byte[] res = null;
switch (mode){
case 0:
return new byte[]{1};
case 1:
res = new byte[1024];
for (int i = 0; i < 1024 ; i++) {
res[i] = (byte) (i % 128);
}
return res;
case 8:
res = new byte[8192];
for (int i = 0; i < 8192 ; i++) {
res[i] = (byte) (i % 128);
}
return res;
default:
return res;
}
}
@Benchmark
public void testInitialKeyChain() throws Exception {
// 测试设置新身份为当前身份
KeyChain keyChain = new KeyChain();
// Identity id = createRandomIdentity();
// keyChain.getIdentifyManager().setDefaultIdentity(id, true);
// 输入密码用于解锁身份
// keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
}
@Benchmark
public void testSignAndVerifyInterest() throws Exception {
// 测试设置新身份为当前身份
KeyChain keyChain = new KeyChain();
// Identity id = createRandomIdentity();
// keyChain.getIdentifyManager().setDefaultIdentity(id, true);
// 输入密码用于解锁身份
// keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
private static Interest createInterest(byte[] payload) throws ComponentException {
// 身份允许签名与验证签名
Identifier id1 = new Identifier("/min/pku/sz");
Identifier id2 = new Identifier("/install");
//////////////////// 构建兴趣包 ////////////////////////
Interest interest = new Interest();
@@ -102,24 +109,23 @@ public class KeychainBenchmark {
interest.hopLimit.setHopLimit(1234);
interest.congestionMark.setCongestionLevel(1234);
interest.ttl.setTtl(1234);
interest.payload.setValue(new byte[]{1, 2, 3, 4, 5});
interest.payload.setValue(payload);
// 正常测试签名与验签
keyChain.signInterest(interest);
keyChain.verifyInterest(interest);
return interest;
}
@Benchmark
public void testSignAndVerifyCPacket() throws Exception {
// 测试设置新身份为当前身份
KeyChain keyChain = new KeyChain();
// Identity id = createRandomIdentity();
// keyChain.getIdentifyManager().setDefaultIdentity(id, true);
// 输入密码用于解锁身份
// keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
private static Data createData(byte[] payload) throws ComponentException {
Data data = new Data();
data.freshnessPeriod.setFreshnessPeriod(02346345465453L);
data.payload.setValue(payload);
data.congestionMark.setCongestionLevel(1234L);
Identifier id2 = new Identifier("/wzq");
data.setName(id2);
data.minPacket.packetType = new VlInt(3);
return data;
}
// 身份允许签名与验证签名
private static CPacket createCPacket(byte[] payload) throws ComponentException {
Identifier id1 = new Identifier("/min/pku/sz");
Identifier id2 = new Identifier("/install");
@@ -128,47 +134,189 @@ public class KeychainBenchmark {
cPacket.setSrcIdentifier(id1);
cPacket.setDstIdentifier(id2);
cPacket.setTtl(new TTL(16546418374324163L));
cPacket.payload.setValue(new byte[]{1, 2, 3, 4, 6});
cPacket.payload.setValue(payload);
return cPacket;
}
static {
try {
chain = new KeyChain();
byte[] payLoad = createPayload(0);
byte[] payLoad1K = createPayload(1);
byte[] payLoad8K = createPayload(8);
// 1byte 兴趣包准备
interest = createInterest(payLoad);
interest2 = createInterest(payLoad);
chain.signInterest(interest2);
// 1K 兴趣包准备
interest3 = createInterest(payLoad1K);
interest4 = createInterest(payLoad1K);
chain.signInterest(interest4);
// 8K 兴趣包准备
interest5 = createInterest(payLoad8K);
interest6 = createInterest(payLoad8K);
chain.signInterest(interest6);
// 1byte 数据包准备
data = createData(payLoad);
data2 = createData(payLoad);
chain.signData(data2);
// 1K 数据包准备
data3 = createData(payLoad1K);
data4 = createData(payLoad1K);
chain.signData(data4);
// 8K 数据包准备
data5 = createData(payLoad8K);
data6 = createData(payLoad8K);
chain.signData(data6);
// 1byte 普通包准备
cPacket = createCPacket(payLoad);
cPacket2 = createCPacket(payLoad);
chain.signCPacket(cPacket2);
// 1K 普通包准备
cPacket3 = createCPacket(payLoad1K);
cPacket4 = createCPacket(payLoad1K);
chain.signCPacket(cPacket4);
// 8K 普通包准备
cPacket5 = createCPacket(payLoad8K);
cPacket6 = createCPacket(payLoad8K);
chain.signCPacket(cPacket6);
} catch (Exception e) {
e.printStackTrace();
}
}
// @Benchmark
// public void testCreateKeyChain() throws Exception {
// KeyChain keyChain = new KeyChain();
// }
//
// @Benchmark
// public void testInitialKeyChain() throws Exception {
// // 测试设置新身份为当前身份
// KeyChain keyChain = new KeyChain();
// // Identity id = createRandomIdentity();
// // keyChain.getIdentifyManager().setDefaultIdentity(id, true);
// // 输入密码用于解锁身份
// // keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
// }
@Benchmark
public void testSignData() throws Exception {
// 正常测试签名与验签
keyChain.signCPacket(cPacket);
keyChain.verifyCPacket(cPacket);
chain.signData(data);
}
@Benchmark
public void testSignAndVerifyData() throws Exception {
// 测试设置新身份为当前身份
KeyChain keyChain = new KeyChain();
// Identity id = createRandomIdentity();
// keyChain.getIdentifyManager().setDefaultIdentity(id, true);
// 输入密码用于解锁身份
// keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
//////////////////// 构建Data包 ////////////////////////
Data data = new Data();
data.freshnessPeriod.setFreshnessPeriod(02346345465453L);
data.payload.setValue(new byte[]{1, 2, 3, 4, 5});
data.congestionMark.setCongestionLevel(1234L);
Identifier id2 = new Identifier("/wzq");
data.setName(id2);
data.minPacket.packetType = new VlInt(3);
public void testSignData1K() throws Exception {
// 正常测试签名与验签
keyChain.signData(data);
keyChain.verifyData(data);
chain.signData(data3);
}
@Benchmark
public void testExportAndImportSafeBag() throws Exception {
// 测试设置新身份为当前身份
KeyChain keyChain = new KeyChain();
// Identity id = createRandomIdentity();
// keyChain.getIdentifyManager().setDefaultIdentity(id, true);
// 输入密码用于解锁身份
// keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
// 正常导入导出 通过
Identity id2 = createRandomIdentity();
SafeBag bag = keyChain.exportSafeBag(id2, "1234");
keyChain.importSafeBag(bag, "1234", true);
public void testSignData8K() throws Exception {
// 正常测试签名与验签
chain.signData(data5);
}
@Benchmark
public void testVerifyData() throws Exception {
// 正常测试签名与验签
chain.verifyData(data2);
}
@Benchmark
public void testVerifyData1K() throws Exception {
// 正常测试签名与验签
chain.verifyData(data4);
}
@Benchmark
public void testVerifyData8K() throws Exception {
// 正常测试签名与验签
chain.verifyData(data6);
}
@Benchmark
public void testSignCPacket() throws Exception {
// 正常测试签名与验签
chain.signCPacket(cPacket);
}
@Benchmark
public void testSignCPacket1K() throws Exception {
// 正常测试签名与验签
chain.signCPacket(cPacket3);
}
@Benchmark
public void testSignCPacket8K() throws Exception {
// 正常测试签名与验签
chain.signCPacket(cPacket5);
}
@Benchmark
public void testVerifyCPacket() throws Exception {
// 正常测试签名与验签
chain.verifyCPacket(cPacket2);
}
@Benchmark
public void testVerifyCPacket1K() throws Exception {
// 正常测试签名与验签
chain.verifyCPacket(cPacket4);
}
@Benchmark
public void testVerifyCPacket8K() throws Exception {
// 正常测试签名与验签
chain.verifyCPacket(cPacket6);
}
@Benchmark
public void testSignInterest() throws Exception {
// 正常测试签名与验签
chain.signInterest(interest);
}
@Benchmark
public void testSignInterest1K() throws Exception {
// 正常测试签名与验签
chain.signInterest(interest3);
}
@Benchmark
public void testSignInterest8K() throws Exception {
// 正常测试签名与验签
chain.signInterest(interest5);
}
@Benchmark
public void testVerifyInterest() throws Exception {
// 正常测试签名与验签
chain.verifyInterest(interest2);
}
@Benchmark
public void testVerifyInterest1K() throws Exception {
// 正常测试签名与验签
chain.verifyInterest(interest4);
}
@Benchmark
public void testVerifyInterest8K() throws Exception {
// 正常测试签名与验签
chain.verifyInterest(interest6);
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(KeychainBenchmark.class.getSimpleName())