diff --git a/src/main/java/component/CanBePrefix.java b/src/main/java/component/CanBePrefix.java index 2ec6393..8cdae09 100644 --- a/src/main/java/component/CanBePrefix.java +++ b/src/main/java/component/CanBePrefix.java @@ -16,6 +16,7 @@ public class CanBePrefix implements TlvComponentBase,InitialAble, IEncodingAble // 函数 public void setCanBePrefix(boolean canBePrefix){ this.canBePrefix=canBePrefix; + this.doInitial(); } public boolean getCanBePrefix(){ diff --git a/src/main/java/component/CongestionMark.java b/src/main/java/component/CongestionMark.java index 2560215..f2d044b 100644 --- a/src/main/java/component/CongestionMark.java +++ b/src/main/java/component/CongestionMark.java @@ -82,9 +82,9 @@ public class CongestionMark implements TlvComponentBase,InitialAble, IEncodingAb return false; } - // 读取 interestLifeTime + // 读取 CongestionMark long value=TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int()); - if(value==0){ + if(value<0){ return false; } this.setCongestionLevel(value); diff --git a/src/main/java/component/FreshnessPeriod.java b/src/main/java/component/FreshnessPeriod.java index a42beb3..4156b86 100644 --- a/src/main/java/component/FreshnessPeriod.java +++ b/src/main/java/component/FreshnessPeriod.java @@ -20,6 +20,7 @@ public class FreshnessPeriod implements TlvComponentBase,InitialAble, IEncodingA public void setFreshnessPeriod(long freshnessPeriod) { this.freshnessPeriod = freshnessPeriod; + this.doInitial(); } // 接口实现-变量区 @@ -83,7 +84,7 @@ public class FreshnessPeriod implements TlvComponentBase,InitialAble, IEncodingA // 读取 FreshnessPeriod long value=TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int()); - if(value==0){ + if(value<0){ return false; } this.setFreshnessPeriod(value); diff --git a/src/main/java/component/HopLimit.java b/src/main/java/component/HopLimit.java new file mode 100644 index 0000000..6c26e96 --- /dev/null +++ b/src/main/java/component/HopLimit.java @@ -0,0 +1,89 @@ +package component; + +import encoding.*; + +/* + * @Author: Wang Feng + * @Description: + * @Version: 1.0.0 + * @Date: 16:38 2021/3/9 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ +public class HopLimit implements TlvComponentBase,InitialAble, IEncodingAble { + // 成员变量 + private long hopLimit; + + // 成员函数 + public long getHopLimit() { + return hopLimit; + } + + public void setHopLimit(long hopLimit) { + this.hopLimit = hopLimit; + this.doInitial(); + } + + // 接口实现-变量区 + private boolean initial=false; + + // 接口实现-方法区 + @Override + public void doInitial() { + initial=true; + } + + @Override + public boolean isInitial() { + return initial; + } + + /** + * + * @param encoder + * @return + */ + @Override + public int wireEncode(Encoder encoder) { + int totalLength=0; + + // 编码 TLV-VALUE + int tmplen=encoder.prependNonNegativeInteger(this.hopLimit); + if(tmplen==0){ + return 0; + } + totalLength+=tmplen; + + // 编码 TLV-LENGTH + tmplen+=encoder.prependVarNumber(new VlInt(totalLength)); + if(tmplen==0){ + return 0; + } + totalLength+=tmplen; + + // 编码 TLV-TYPE + tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvHopLimit)); + if(tmplen==0){ + return 0; + } + totalLength+=tmplen; + + return totalLength; + } + + @Override + public boolean wireDecode(Block block) { + // 检查 Type 是否正确 + if(!TLV.expectType(block.getTlvType(),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; + } +} diff --git a/src/main/java/component/MustBeRefresh.java b/src/main/java/component/MustBeRefresh.java index 3da2827..c14ee00 100644 --- a/src/main/java/component/MustBeRefresh.java +++ b/src/main/java/component/MustBeRefresh.java @@ -20,6 +20,7 @@ public class MustBeRefresh implements TlvComponentBase,InitialAble, IEncodingAbl public void setMustBeRefresh(boolean mustBeRefresh) { this.mustBeRefresh = mustBeRefresh; + this.doInitial(); } // 接口实现-变量区 diff --git a/src/main/java/component/TTL.java b/src/main/java/component/TTL.java index 7a1bb50..35fe92b 100644 --- a/src/main/java/component/TTL.java +++ b/src/main/java/component/TTL.java @@ -92,7 +92,7 @@ public class TTL implements IEncodingAble { return false; } long value=TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int()); - if(value==0){ + if(value<0){ return false; } this.ttl=value; diff --git a/src/main/java/encoding/TLV.java b/src/main/java/encoding/TLV.java index 0b059ac..4a55963 100644 --- a/src/main/java/encoding/TLV.java +++ b/src/main/java/encoding/TLV.java @@ -123,10 +123,10 @@ public class TLV { */ public static long readNonNegativeInteger(byte[] buffer,int start,int end){ if(start==end){ - return 0; + return -1; } if((start<0)||(end>buffer.length)){ - return 0; + return -1; } int len=end-start; byte[] bytes=new byte[len]; @@ -140,7 +140,7 @@ public class TLV { }else if(len==8){ return ByteHelper.uint64ToLong(bytes); }else{ - return 0; + return -1; } }