From c38a860881da1d2880dae694d2f01d8d4dddf46c Mon Sep 17 00:00:00 2001 From: free will <2647778488@qq.com> Date: Tue, 9 Mar 2021 16:09:50 +0800 Subject: [PATCH] finished component: CongestionMark --- src/main/java/component/CongestionMark.java | 94 +++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/main/java/component/CongestionMark.java diff --git a/src/main/java/component/CongestionMark.java b/src/main/java/component/CongestionMark.java new file mode 100644 index 0000000..dc870cf --- /dev/null +++ b/src/main/java/component/CongestionMark.java @@ -0,0 +1,94 @@ +package component; + +import encoding.*; + +/* + * @Author: Wang Feng + * @Description:表示一个拥塞标记 TLV 组件 + * @Version: 1.0.0 + * @Date: 15:54 2021/3/9 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ +public class CongestionMark implements TlvComponentBase,InitialAble, IEncodingAble { + // 成员变量 todo: 越界问题 + private long congestionMark; + + // 函数 + public long getCongestionLevel(){ + return this.congestionMark; + } + + public void setCongestionLevel(long congestionMark){ + this.congestionMark=congestionMark; + this.doInitial(); + } + + // 接口实现-变量区 + private boolean initial=false; + + // 接口实现-方法区 + @Override + public void doInitial() { + initial=true; + } + + @Override + public boolean isInitial() { + return initial; + } + + /** + * 将 CongestionMark 线速编码为一个 TLV + * @param encoder + * @return + */ + @Override + public int wireEncode(Encoder encoder) { + int totalLength=0; + + // 编码 TLV-VALUE + int tmplen=encoder.prependNonNegativeInteger(this.congestionMark); + 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.TlvCongestionMark)); + if(tmplen==0){ + return 0; + } + totalLength+=tmplen; + + return 0; + } + + /** + * 从 TLV Block 中解码出一个 CongestionMark + * @param block + * @return + */ + @Override + public boolean wireDecode(Block block) { + // 检查 Type 是否正确 + if(!TLV.expectType(block.getTlvType(),new VlInt(TLV.TlvCongestionMark))){ + return false; + } + + // 读取 interestLifeTime + long value=TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int()); + if(value==0){ + return false; + } + this.setCongestionLevel(value); + + return true; + } +}