finished component: HopLimit

This commit is contained in:
free will committed 2021-03-09 17:11:52 +08:00
1 parent b19477dcf1
commit 9df4cf742a
7 files changed
+99 -7

No files matched your search

+1
View File
@@ -16,6 +16,7 @@ public class CanBePrefix implements TlvComponentBase,InitialAble, IEncodingAble
// 函数
public void setCanBePrefix(boolean canBePrefix){
this.canBePrefix=canBePrefix;
this.doInitial();
}
public boolean getCanBePrefix(){
+2 -2
View File
@@ -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);
+2 -1
View File
@@ -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);
+89
View File
@@ -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;
}
}
@@ -20,6 +20,7 @@ public class MustBeRefresh implements TlvComponentBase,InitialAble, IEncodingAbl
public void setMustBeRefresh(boolean mustBeRefresh) {
this.mustBeRefresh = mustBeRefresh;
this.doInitial();
}
// 接口实现-变量区
+1 -1
View File
@@ -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;
+3 -3
View File
@@ -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;
}
}