refresh test: ttl,etc...

This commit is contained in:
free will committed 2021-03-31 10:44:47 +08:00
1 parent dc060c2fc2
commit fafde2b015
14 files changed
+307 -347

No files matched your search

+23 -27
View File
@@ -44,37 +44,32 @@ public class CanBePrefix implements TlvComponentBase,InitialAble, IEncodingAble
*/
@Override
public int wireEncode(Encoder encoder) throws ComponentException {
// 这是一个存在性组件,所以如果值为false,则无需编码
if(!this.canBePrefix){
return -1;
}
int totalLength=0;
// 编码 TLV-LENGTH
int tmplen= 0;
try {
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
// 这是一个存在性组件,所以如果值为false,则无需编码
if (!this.canBePrefix) {
return -1;
}
int totalLength = 0;
// 编码 TLV-LENGTH
int tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvCanBePrefix));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
} catch (EncoderException e) {
throw new ComponentException("CanBePrefix.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-TYPE
try {
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvCanBePrefix));
} catch (EncoderException e) {
throw new ComponentException("CanBePrefix.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
return totalLength;
}
/**
@@ -91,6 +86,7 @@ public class CanBePrefix implements TlvComponentBase,InitialAble, IEncodingAble
// 这是一个存在性组件,所以存在则为 true
this.canBePrefix=true;
this.doInitial();
return true;
}
}
+49 -55
View File
@@ -9,27 +9,27 @@ import encoding.*;
* @Date: 15:54 2021/3/9
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class CongestionMark implements TlvComponentBase,InitialAble, IEncodingAble {
public class CongestionMark implements TlvComponentBase, InitialAble, IEncodingAble {
// 成员变量 todo: 越界问题
private long congestionMark;
// 函数
public long getCongestionLevel(){
public long getCongestionLevel() {
return this.congestionMark;
}
public void setCongestionLevel(long congestionMark){
this.congestionMark=congestionMark;
public void setCongestionLevel(long congestionMark) {
this.congestionMark = congestionMark;
this.doInitial();
}
// 接口实现-变量区
private boolean initial=false;
private boolean initial = false;
// 接口实现-方法区
@Override
public void doInitial() {
initial=true;
initial = true;
}
@Override
@@ -39,74 +39,68 @@ public class CongestionMark implements TlvComponentBase,InitialAble, IEncodingAb
/**
* 将 CongestionMark 线速编码为一个 TLV
*
* @param encoder
* @return
*/
@Override
public int wireEncode(Encoder encoder) throws ComponentException {
int totalLength=0;
// 编码 TLV-VALUE
int tmplen= 0;
try {
tmplen = encoder.prependNonNegativeInteger(this.congestionMark);
} catch (EncoderException e) {
throw new ComponentException("CongestionMark.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
int totalLength = 0;
// 编码 TLV-LENGTH
try {
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
} catch (EncoderException e) {
throw new ComponentException("CongestionMark.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-VALUE
int tmplen = encoder.prependNonNegativeInteger(this.congestionMark);
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
try {
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvCongestionMark));
} catch (EncoderException e) {
throw new ComponentException("CongestionMark.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvCongestionMark));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
} catch (EncoderException e) {
throw new ComponentException("CongestionMark.wireEncode: " + e.getMessage());
}
}
/**
* 从 TLV Block 中解码出一个 CongestionMark
*
* @param block
* @return
*/
@Override
public boolean wireDecode(Block block) throws ComponentException {
// 检查 Type 是否正确
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvCongestionMark))){
return false;
}
// 读取 CongestionMark
long value = 0;
try {
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
} catch (TLVException | VlIntException e) {
throw new ComponentException("CongestionMark.wireDecode: "+e.getMessage());
}
if(value<0){
return false;
}
this.setCongestionLevel(value);
// 检查 Type 是否正确
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvCongestionMark))) {
return false;
}
return true;
// 读取 CongestionMark
long value = 0;
value = TLV.readNonNegativeInteger(block.getValue(), 0, block.getLength().getVlIntValue2Int());
if (value < 0) {
return false;
}
this.setCongestionLevel(value);
return true;
} catch (TLVException | VlIntException e) {
throw new ComponentException("CongestionMark.wireDecode: " + e.getMessage());
}
}
}
+44 -52
View File
@@ -9,7 +9,7 @@ import encoding.*;
* @Date: 16:10 2021/3/9
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class FreshnessPeriod implements TlvComponentBase,InitialAble, IEncodingAble {
public class FreshnessPeriod implements TlvComponentBase, InitialAble, IEncodingAble {
// 成员变量
private long freshnessPeriod;
@@ -24,12 +24,12 @@ public class FreshnessPeriod implements TlvComponentBase,InitialAble, IEncodingA
}
// 接口实现-变量区
private boolean initial=false;
private boolean initial = false;
// 接口实现-方法区
@Override
public void doInitial() {
initial=true;
initial = true;
}
@Override
@@ -39,74 +39,66 @@ public class FreshnessPeriod implements TlvComponentBase,InitialAble, IEncodingA
/**
* 将 FreshnessPeriod 线速编码为一个 TLV
*
* @param encoder
* @return
*/
@Override
public int wireEncode(Encoder encoder) throws ComponentException {
int totalLength=0;
// 编码 TLV-VALUE
int tmplen= 0;
try {
tmplen = encoder.prependNonNegativeInteger(this.freshnessPeriod);
} catch (EncoderException e) {
throw new ComponentException("FreshnessPeriod.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
int totalLength = 0;
// 编码 TLV-LENGTH
try {
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
} catch (EncoderException e) {
throw new ComponentException("FreshnessPeriod.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-VALUE
int tmplen = encoder.prependNonNegativeInteger(this.freshnessPeriod);
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
try {
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvFreshnessPeriod));
} catch (EncoderException e) {
throw new ComponentException("FreshnessPeriod.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvFreshnessPeriod));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
} catch (EncoderException e) {
throw new ComponentException("FreshnessPeriod.wireEncode: " + e.getMessage());
}
}
/**
* 从 TLV Block 中解码出一个 FreshnessPeriod
*
* @param block
* @return
*/
@Override
public boolean wireDecode(Block block) throws ComponentException {
// 检查 Type 是否正确
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvFreshnessPeriod))){
return false;
}
// 读取 value
long value= 0;
try {
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
} catch (TLVException | VlIntException e) {
throw new ComponentException("FreshnessPeriod.wireDecode: "+e.getMessage());
}
if(value<0){
return false;
}
this.setFreshnessPeriod(value);
// 检查 Type 是否正确
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvFreshnessPeriod))) {
return false;
}
return true;
// 读取 value
long value = TLV.readNonNegativeInteger(block.getValue(), 0, block.getLength().getVlIntValue2Int());
if (value < 0) {
return false;
}
this.setFreshnessPeriod(value);
return true;
} catch (TLVException | VlIntException e) {
throw new ComponentException("FreshnessPeriod.wireDecode: " + e.getMessage());
}
}
}
+37 -47
View File
@@ -44,64 +44,54 @@ public class HopLimit implements TlvComponentBase,InitialAble, IEncodingAble {
*/
@Override
public int wireEncode(Encoder encoder) throws ComponentException {
int totalLength=0;
// 编码 TLV-VALUE
int tmplen= 0;
try {
tmplen = encoder.prependNonNegativeInteger(this.hopLimit);
int totalLength = 0;
// 编码 TLV-VALUE
int tmplen = encoder.prependNonNegativeInteger(this.hopLimit);
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvHopLimit));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
} catch (EncoderException e) {
throw new ComponentException("HopLimit.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-LENGTH
try {
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
} catch (EncoderException e) {
throw new ComponentException("HopLimit.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-TYPE
try {
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvHopLimit));
} catch (EncoderException e) {
throw new ComponentException("HopLimit.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
return totalLength;
}
@Override
public boolean wireDecode(Block block) throws ComponentException {
// 检查 Type 是否正确
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvHopLimit))){
return false;
}
// 读取 HopLimit
long value= 0;
try {
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
// 检查 Type 是否正确
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvHopLimit))) {
return false;
}
// 读取 HopLimit
long value = TLV.readNonNegativeInteger(block.getValue(), 0, block.getLength().getVlIntValue2Int());
if (value < 0) {
return false;
}
this.setHopLimit(value);
return true;
} catch (TLVException | VlIntException e) {
throw new ComponentException("HopLimit.wireDecode: "+e.getMessage());
}
if(value<0){
return false;
}
this.setHopLimit(value);
return true;
}
}
+31 -33
View File
@@ -9,7 +9,7 @@ import encoding.*;
* @Date: 16:30 2021/3/9
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class MustBeRefresh implements TlvComponentBase,InitialAble, IEncodingAble {
public class MustBeRefresh implements TlvComponentBase, InitialAble, IEncodingAble {
// 成员变量
private boolean mustBeRefresh;
@@ -24,12 +24,12 @@ public class MustBeRefresh implements TlvComponentBase,InitialAble, IEncodingAbl
}
// 接口实现-变量区
private boolean initial=false;
private boolean initial = false;
// 接口实现-方法区
@Override
public void doInitial() {
initial=true;
initial = true;
}
@Override
@@ -39,58 +39,56 @@ public class MustBeRefresh implements TlvComponentBase,InitialAble, IEncodingAbl
/**
* 将 MustBeRefresh 线速编码为一个 TLV
*
* @param encoder
* @return
*/
@Override
public int wireEncode(Encoder encoder) throws ComponentException {
// 这是一个存在性组件,所以如果值为false,则无需编码
if(!this.mustBeRefresh){
return -1;
}
int totalLength=0;
// 编码 TLV-LENGTH
int tmplen= 0;
try {
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
} catch (EncoderException e) {
throw new ComponentException("MustBeRefresh.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 这是一个存在性组件,所以如果值为false,则无需编码
if (!this.mustBeRefresh) {
return -1;
}
// 编码 TLV-TYPE
try {
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvMustBeRefresh));
} catch (EncoderException e) {
throw new ComponentException("MustBeRefresh.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
int totalLength = 0;
return totalLength;
// 编码 TLV-LENGTH
int tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvMustBeRefresh));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
} catch (EncoderException e) {
throw new ComponentException("MustBeRefresh.wireEncode: " + e.getMessage());
}
}
/**
* 从 TLV Block 中解码出一个 MustBeRefresh
*
* @param block
* @return
*/
@Override
public boolean wireDecode(Block block) {
// 检查 Type 是否正确
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvMustBeRefresh))){
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvMustBeRefresh))) {
return false;
}
// 这是一个存在性组件,所以存在则为 true
this.mustBeRefresh=true;
this.mustBeRefresh = true;
this.doInitial();
return true;
}
}
+46 -54
View File
@@ -11,7 +11,7 @@ import java.util.Random;
* @Date: 17:13 2021/3/9
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class Nonce implements TlvComponentBase,InitialAble, IEncodingAble {
public class Nonce implements TlvComponentBase, InitialAble, IEncodingAble {
// 成员变量
private long nonce;
@@ -28,18 +28,18 @@ public class Nonce implements TlvComponentBase,InitialAble, IEncodingAble {
/**
* 刷新Nonce,随机生成一个数值传递给Nonce
*/
public void refreshNonce(){
long randomLong=Math.abs(new Random().nextLong());
public void refreshNonce() {
long randomLong = Math.abs(new Random().nextLong());
this.setNonce(randomLong);
}
// 接口实现-变量区
private boolean initial=false;
private boolean initial = false;
// 接口实现-方法区
@Override
public void doInitial() {
initial=true;
initial = true;
}
@Override
@@ -49,74 +49,66 @@ public class Nonce implements TlvComponentBase,InitialAble, IEncodingAble {
/**
* 将 Nonce 线速编码为一个 TLV
*
* @param encoder
* @return
*/
@Override
public int wireEncode(Encoder encoder) throws ComponentException {
int totalLength=0;
// 编码 TLV-VALUE
int tmplen= 0;
try {
tmplen = encoder.prependNonNegativeInteger(this.nonce);
} catch (EncoderException e) {
throw new ComponentException("Nonce.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
int totalLength = 0;
// 编码 TLV-LENGTH
try {
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
} catch (EncoderException e) {
throw new ComponentException("Nonce.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-VALUE
int tmplen = encoder.prependNonNegativeInteger(this.nonce);
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
try {
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvNonce));
} catch (EncoderException e) {
throw new ComponentException("Nonce.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvNonce));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
} catch (EncoderException e) {
throw new ComponentException("Nonce.wireEncode: " + e.getMessage());
}
}
/**
* 从 TLV Block 中解码出一个 Nonce
*
* @param block
* @return
*/
@Override
public boolean wireDecode(Block block) throws ComponentException {
// 检查 Type 是否正确
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvNonce))){
return false;
}
// 读取 value
long value= 0;
try {
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
} catch (TLVException | VlIntException e) {
throw new ComponentException("Nonce.wireDecode: "+e.getMessage());
}
if(value<0){
return false;
}
this.setNonce(value);
// 检查 Type 是否正确
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvNonce))) {
return false;
}
return true;
// 读取 value
long value = TLV.readNonNegativeInteger(block.getValue(), 0, block.getLength().getVlIntValue2Int());
if (value < 0) {
return false;
}
this.setNonce(value);
return true;
} catch (TLVException | VlIntException e) {
throw new ComponentException("Nonce.wireDecode: " + e.getMessage());
}
}
}
+45 -50
View File
@@ -15,11 +15,11 @@ public class TTL implements IEncodingAble {
* todo: 后台使用的uint64,故这里用long表示,则理论上可能越界
* // @Description:
* 1. 格式如下:
* TTL = TTL-TYPE TLV-LENGTH NonNegativeInteger
*/
* TTL = TTL-TYPE TLV-LENGTH NonNegativeInteger
*/
private long ttl;
public TTL(){
public TTL() {
}
public TTL(Block block) throws ComponentException {
@@ -28,6 +28,7 @@ public class TTL implements IEncodingAble {
/**
* 根据 TLV Block 初始化一个 TTL
*
* @param block
* @return
*/
@@ -37,86 +38,80 @@ public class TTL implements IEncodingAble {
/**
* 获取 TTL 值
*
* @return
*/
public long ttl(){
public long ttl() {
return this.ttl;
}
/**
* 设置 TTL 值
*
* @param ttl
*/
public void setTtl(long ttl){
this.ttl=ttl;
public void setTtl(long ttl) {
this.ttl = ttl;
}
/**
* 将 TTL 线速编码为一个 TLV
*
* @param encoder
* @return
*/
@Override
public int wireEncode(Encoder encoder) throws ComponentException {
int totalLength=0;
// 编码 TLV-VALUE
int tmpLen= 0;
try {
tmpLen = encoder.prependNonNegativeInteger(this.ttl);
} catch (EncoderException e) {
throw new ComponentException("TTL.wireEncode: "+e.getMessage());
}
if(tmpLen<=0){
return -1;
}
totalLength+=tmpLen;
int totalLength = 0;
// 编码 TLV-VALUE
int tmpLen = encoder.prependNonNegativeInteger(this.ttl);
if (tmpLen <= 0) {
return -1;
}
totalLength += tmpLen;
// 编码 TLV-LENGTH
try {
tmpLen=encoder.prependVarNumber(new VlInt(totalLength));
} catch (EncoderException e) {
throw new ComponentException("TTL.wireEncode: "+e.getMessage());
}
if(tmpLen<=0){
return -1;
}
totalLength+=tmpLen;
// 编码 TLV-LENGTH
tmpLen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmpLen <= 0) {
return -1;
}
totalLength += tmpLen;
// 编码 TLV-TYPE
try {
tmpLen=encoder.prependVarNumber(new VlInt(TLV.TlvTTL));
} catch (EncoderException e) {
throw new ComponentException("TTL.wireEncode: "+e.getMessage());
}
if(tmpLen<=0){
return -1;
}
totalLength+=tmpLen;
// 编码 TLV-TYPE
tmpLen = encoder.prependVarNumber(new VlInt(TLV.TlvTTL));
if (tmpLen <= 0) {
return -1;
}
totalLength += tmpLen;
return totalLength;
return totalLength;
} catch (EncoderException e) {
throw new ComponentException("TTL.wireEncode: " + e.getMessage());
}
}
/**
* 从 TLV Block 中解码出一个 TTL
*
* @param block
* @return
*/
@Override
public boolean wireDecode(Block block) throws ComponentException {
// 检查Type是否正确
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvTTL))){
return false;
}
long value= 0;
try {
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
// 检查Type是否正确
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvTTL))) {
return false;
}
long value = TLV.readNonNegativeInteger(block.getValue(), 0, block.getLength().getVlIntValue2Int());
if (value < 0) {
return false;
}
this.ttl = value;
return true;
} catch (TLVException | VlIntException e) {
throw new ComponentException("TTL.wireDecode: "+e.getMessage());
throw new ComponentException("TTL.wireDecode: " + e.getMessage());
}
if(value<0){
return false;
}
this.ttl=value;
return true;
}
}