mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 04:50:25 +08:00
add component: ControlParameters
This commit is contained in:
@@ -0,0 +1,252 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
import logicface.LogicFaceException;
|
||||
import mgmt.MgmtException;
|
||||
import packet.PacketException;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 20:01 2021/4/22
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class ControlParameters implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
// fib add 必须字段
|
||||
public ControlParameterPrefix controlParameterPrefix=new ControlParameterPrefix();
|
||||
public ControlParameterLogicFaceId controlParameterLogicFaceId=new ControlParameterLogicFaceId();
|
||||
public ControlParameterCost controlParameterCost=new ControlParameterCost();
|
||||
public ControlParameterCapacity controlParameterCapacity=new ControlParameterCapacity();
|
||||
public ControlParameterCount controlParameterCount=new ControlParameterCount();
|
||||
public ControlParameterExpireTime controlParameterExpireTime=new ControlParameterExpireTime();
|
||||
public ControlParameterUri controlParameterUri=new ControlParameterUri();
|
||||
public ControlParameterLocalUri controlParameterLocalUri=new ControlParameterLocalUri();
|
||||
public ControlParameterLogicFacePersistency controlParameterLogicFacePersistency=new ControlParameterLogicFacePersistency();
|
||||
public ControlParameterUriScheme controlParameterUriScheme=new ControlParameterUriScheme();
|
||||
public ControlParameterMtu controlParameterMtu=new ControlParameterMtu();
|
||||
|
||||
// 接口实现-变量区
|
||||
private boolean initial = false;
|
||||
|
||||
// 接口实现-方法区
|
||||
@Override
|
||||
public void doInitial() {
|
||||
initial = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitial() {
|
||||
return initial;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 ControlParameters 编码成一个 TLV
|
||||
* @param encoder
|
||||
* @return
|
||||
* @throws ComponentException
|
||||
* @throws PacketException
|
||||
* @throws MgmtException
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) throws ComponentException{
|
||||
try {
|
||||
int totalLength = 0;
|
||||
int tmpLen;
|
||||
|
||||
// 编码 TLV-VALUE
|
||||
if (this.controlParameterPrefix.isInitial()) {
|
||||
tmpLen = this.controlParameterPrefix.wireEncode(encoder);
|
||||
if (tmpLen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
}
|
||||
|
||||
if (this.controlParameterLogicFaceId.isInitial()) {
|
||||
tmpLen = this.controlParameterLogicFaceId.wireEncode(encoder);
|
||||
if (tmpLen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
}
|
||||
|
||||
if (this.controlParameterCost.isInitial()) {
|
||||
tmpLen = this.controlParameterCost.wireEncode(encoder);
|
||||
if (tmpLen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
}
|
||||
|
||||
if (this.controlParameterCapacity.isInitial()) {
|
||||
tmpLen = this.controlParameterCapacity.wireEncode(encoder);
|
||||
if (tmpLen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
}
|
||||
|
||||
if (this.controlParameterCount.isInitial()) {
|
||||
tmpLen = this.controlParameterCount.wireEncode(encoder);
|
||||
if (tmpLen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
}
|
||||
|
||||
if (this.controlParameterExpireTime.isInitial()) {
|
||||
tmpLen = this.controlParameterExpireTime.wireEncode(encoder);
|
||||
if (tmpLen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
}
|
||||
|
||||
if (this.controlParameterUri.isInitial()) {
|
||||
tmpLen = this.controlParameterUri.wireEncode(encoder);
|
||||
if (tmpLen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
}
|
||||
|
||||
if (this.controlParameterLocalUri.isInitial()) {
|
||||
tmpLen = this.controlParameterLocalUri.wireEncode(encoder);
|
||||
if (tmpLen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
}
|
||||
|
||||
if (this.controlParameterLogicFacePersistency.isInitial()) {
|
||||
tmpLen = this.controlParameterLogicFacePersistency.wireEncode(encoder);
|
||||
if (tmpLen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
}
|
||||
|
||||
if (this.controlParameterUriScheme.isInitial()) {
|
||||
tmpLen = this.controlParameterUriScheme.wireEncode(encoder);
|
||||
if (tmpLen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
}
|
||||
|
||||
if (this.controlParameterMtu.isInitial()) {
|
||||
tmpLen = this.controlParameterMtu.wireEncode(encoder);
|
||||
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.TlvManagementControlParameters));
|
||||
if (tmpLen<0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
|
||||
return totalLength;
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("ControlParameters.wireEncode: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 TLV Block 中解码出一个 ControlParameters
|
||||
* @param block
|
||||
* @return
|
||||
* @throws ComponentException
|
||||
* @throws PacketException
|
||||
* @throws MgmtException
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) throws ComponentException{
|
||||
try {
|
||||
// 首先解析子 Block
|
||||
if(!block.parseSubElements()){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 提取参数
|
||||
ElementContainer elementContainer=block.getSubElements();
|
||||
for (int i = 0; i < elementContainer.length(); i++) {
|
||||
Block cacheBlock=elementContainer.getBlock(i);
|
||||
int type=cacheBlock.getType().getVlIntValue2Int();
|
||||
switch (type){
|
||||
case TLV.TlvManagementPrefix:
|
||||
if(!this.controlParameterPrefix.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case TLV.TlvManagementLogicFaceId:
|
||||
if(!this.controlParameterLogicFaceId.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case TLV.TlvManagementCost:
|
||||
if(!this.controlParameterCost.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case TLV.TlvManagementCapacity:
|
||||
if(!this.controlParameterCapacity.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case TLV.TlvManagementCount:
|
||||
if(!this.controlParameterCount.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case TLV.TlvManagementExpireTime:
|
||||
if(!this.controlParameterExpireTime.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case TLV.TlvManagementUri:
|
||||
if(!this.controlParameterUri.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case TLV.TlvManagementLocalUri:
|
||||
if(!this.controlParameterLocalUri.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case TLV.TlvManagementLogicFacePersistency:
|
||||
if(!this.controlParameterLogicFacePersistency.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case TLV.TlvManagementUriScheme:
|
||||
if(!this.controlParameterUriScheme.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case TLV.TlvManagementMtu:
|
||||
if(!this.controlParameterMtu.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.doInitial();
|
||||
return true;
|
||||
} catch (BlockException | VlIntException e) {
|
||||
throw new ComponentException("ControlParameters.wireDecode: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user