update ControlParameters、CPacket、Data

This commit is contained in:
free will
2021-05-25 17:20:41 +08:00
parent 7eeff6fbc5
commit cb79358683
4 changed files with 78 additions and 12 deletions
@@ -24,6 +24,8 @@ public class ControlParameters implements TlvComponentBase,InitialAble, IEncodin
public ControlParameterLogicFacePersistency controlParameterLogicFacePersistency=new ControlParameterLogicFacePersistency();
public ControlParameterUriScheme controlParameterUriScheme=new ControlParameterUriScheme();
public ControlParameterMtu controlParameterMtu=new ControlParameterMtu();
public ControlParameterPasswd controlParameterPasswd=new ControlParameterPasswd();
public ControlParameterCommonString controlParameterCommonString=new ControlParameterCommonString();
// 接口实现-变量区
private boolean initial = false;
@@ -142,6 +144,22 @@ public class ControlParameters implements TlvComponentBase,InitialAble, IEncodin
totalLength += tmpLen;
}
if (this.controlParameterPasswd.commonString.isInitial()) {
tmpLen = this.controlParameterPasswd.wireEncode(encoder);
if (tmpLen < 0) {
return -1;
}
totalLength += tmpLen;
}
if (this.controlParameterCommonString.commonString.isInitial()) {
tmpLen = this.controlParameterCommonString.wireEncode(encoder);
if (tmpLen < 0) {
return -1;
}
totalLength += tmpLen;
}
// 编码 TLV-LENGTH
tmpLen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmpLen<0){
@@ -239,6 +257,16 @@ public class ControlParameters implements TlvComponentBase,InitialAble, IEncodin
return false;
}
break;
case TLV.TlvManagementPasswd:
if(!this.controlParameterPasswd.wireDecode(cacheBlock)){
return false;
}
break;
case TLV.TlvManagementCommonString:
if(!this.controlParameterCommonString.wireDecode(cacheBlock)){
return false;
}
break;
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ import encoding.*;
/*
* @Author: Wang Feng
* @Description:
* @Description:
* @Version: 1.0.0
* @Date: 11:33 2021/3/9
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
+1
View File
@@ -55,6 +55,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
public CPacket createCPacketByMINPacket(MINPacket minPacket) throws PacketException {
try {
CPacket cPacket=new CPacket();
cPacket.minPacket.signatureField.setSignatures(this.minPacket.signatureField.getSignatures());
if(!cPacket.doExtraDataFromFields(minPacket)){
return null;
}
+48 -11
View File
@@ -21,7 +21,7 @@ import mgmt.MgmtException;
// { Signature } => 签名区
// { => 只读区
// [FreshnessPeriod]
// [NackHeader]
// [NoCache]
// <Payload>
// }
// { => 可变区
@@ -29,28 +29,30 @@ import mgmt.MgmtException;
// [CongestionMark]
// }
// { => 非受保护区
// "Empty"
// [TTL]
// }
// }
//
public class Data implements IEncodingAble, InteractWithField {
public MINPacket minPacket = new MINPacket();
public FreshnessPeriod freshnessPeriod = new FreshnessPeriod();
public NoCache noCache=new NoCache();
public Payload payload = new Payload();
public CongestionMark congestionMark = new CongestionMark();
public NackHeader nackHeader = new NackHeader();
public TTL ttl = new TTL();
public Identifier name = new Identifier();
public Data() {
}
public Data(Identifier name, Payload payload, FreshnessPeriod freshnessPeriod,
CongestionMark congestionMark, NackHeader nackHeader) {
NoCache noCache,CongestionMark congestionMark, TTL ttl) {
this.name = name;
this.payload = payload;
this.freshnessPeriod = freshnessPeriod;
this.noCache=noCache;
this.congestionMark = congestionMark;
this.nackHeader = nackHeader;
this.ttl = ttl;
}
/**
@@ -61,6 +63,7 @@ public class Data implements IEncodingAble, InteractWithField {
public Data createDataByMINPacket(MINPacket minPacket) throws PacketException {
try {
Data data = new Data();
data.minPacket.signatureField.setSignatures(this.minPacket.signatureField.getSignatures());
if (!data.doExtraDataFromFields(minPacket)) {
return null;
}
@@ -95,6 +98,20 @@ public class Data implements IEncodingAble, InteractWithField {
this.name = name;
}
/**
* 使用字符串设置数据包的名字
* @param name
* @throws PacketException
*/
public void setNameByString(String name) throws PacketException {
try {
Identifier identifier = new Identifier(name);
this.setName(identifier);
} catch (ComponentException e) {
throw new PacketException("Data.setNameByString: "+e.getMessage());
}
}
/**
* 将 Data 的各项属性填充到 MINPacket 中定义的对应分区当中
*
@@ -115,7 +132,6 @@ public class Data implements IEncodingAble, InteractWithField {
try {
// 填充可变受保护区
minPacket.mutableField.mutableProtectField.clearBlocks();
// CongestionMark
Block block = new SelfEncodingBase().selfWireEncode(this.congestionMark);
if (block == null) {
@@ -123,7 +139,14 @@ public class Data implements IEncodingAble, InteractWithField {
}
minPacket.mutableField.mutableProtectField.addBlock(block);
// 填充可变非受保护区(无)
// 填充可变非受保护区
minPacket.mutableField.mutableDangerousField.clearBlocks();
// TTL
block = new SelfEncodingBase().selfWireEncode(this.ttl);
if (block == null) {
return false;
}
minPacket.mutableField.mutableDangerousField.addBlock(block);
/////////////////////////////////////////////////////////////
//// 填充只读区
@@ -144,9 +167,9 @@ public class Data implements IEncodingAble, InteractWithField {
minPacket.readOnlyField.addBlock(block);
}
// NackHeader
if (this.nackHeader.isInitial()) {
block = new SelfEncodingBase().selfWireEncode(this.nackHeader);
// NoCache
if (this.noCache.isInitial()) {
block = new SelfEncodingBase().selfWireEncode(this.noCache);
if (block == null) {
return false;
}
@@ -203,10 +226,11 @@ public class Data implements IEncodingAble, InteractWithField {
// [CongestionMark]
// }
// { => 非受保护区
// "Empty"
// [TTL]
// }
// }
/////////////////////////////////////////////////////////////
// CongestionMark
Block block = minPacket.mutableField.mutableProtectField.getBlockByType(new VlInt(TLV.TlvCongestionMark));
if (block != null) {
if (!this.congestionMark.wireDecode(block)) {
@@ -214,6 +238,14 @@ public class Data implements IEncodingAble, InteractWithField {
}
}
// TTL
block = minPacket.mutableField.mutableDangerousField.getBlockByType(new VlInt(TLV.TlvTTL));
if (block != null) {
if (!this.ttl.wireDecode(block)) {
return false;
}
}
/////////////////////////////////////////////////////////////
//// 解析只读区
// { => 只读区
@@ -237,6 +269,11 @@ public class Data implements IEncodingAble, InteractWithField {
return false;
}
break;
case TLV.TlvNoCache:
if (!this.noCache.wireDecode(newblock)) {
return false;
}
break;
default:
// TODO: 这边可以规定哪些范围是自定义的,哪些是预留的,然后根据需要这边抛出错误