add mgmt: Command

This commit is contained in:
free will
2021-04-13 17:17:24 +08:00
parent 0166bf38ac
commit 43c9348330
+34 -4
View File
@@ -1,5 +1,11 @@
package mgmt;
import component.ComponentException;
import component.Identifier;
import component.IdentifierComponent;
import encoding.Encoder;
import encoding.EncoderException;
import encoding.SizeT;
import packet.Interest;
/*
@@ -10,9 +16,33 @@ import packet.Interest;
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class Command {
public static Interest CreateCommandIdentifierInterest(){
Interest interest=new Interest();
// ...
return interest;
/**
* 根据传入的控制参数和前缀创建一个命令兴趣包
*
* @param parameters 控制参数
* @param prefix 前缀 /min-mir/mgmt/localhost
* @return
*/
public static Interest createCommandIdentifierInterest(ControlParameters parameters, String prefix) throws MgmtException {
try {
// /min-mir/mgmt/localhop/<模块名称>/<命令>/<参数>/[版本号]/[分片号]
Interest interest = new Interest();
Identifier commandIdentifier = new Identifier(prefix);
Encoder encoder=new Encoder();
if(!encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0))){
throw new MgmtException("Command.createCommandIdentifierInterest: encoder reset error.");
}
if(parameters.wireEncode(encoder)<0){
throw new MgmtException("Command.createCommandIdentifierInterest: wireEncode error.");
}
byte[] controlParametersbuf=encoder.getBuffer();
commandIdentifier.append(new IdentifierComponent(controlParametersbuf));
interest.setName(commandIdentifier);
return interest;
} catch (ComponentException | EncoderException e) {
throw new MgmtException("Command.createCommandIdentifierInterest: " + e.getMessage());
}
}
}