writing mgmt: CommandExecutor

This commit is contained in:
free will committed 2021-04-23 22:14:52 +08:00
1 parent a814a13143
commit 8074b49e0c
6 files changed
+213 -23

No files matched your search

-20
View File
@@ -1,20 +0,0 @@
package mgmt;
import component.ComponentException;
import component.Identifier;
import component.IdentifierComponent;
import encoding.Encoder;
import encoding.EncoderException;
import encoding.SizeT;
import packet.Interest;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 20:21 2021/4/12
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class Command {
}
+4
View File
@@ -16,6 +16,10 @@ import packet.Interest;
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class CommandBase {
public static final String ManagementModuleFaceMgmt ="face-mgmt";
public static final String ManagementModuleFibMgmt ="fib-mgmt";
public static final String ManagementModuleCsMgmt = "cs-mgmt";
public String topPrefix; // 顶级前缀
public String moduleName; // 模块名称
public String action; // 命令动作
+142
View File
@@ -0,0 +1,142 @@
package mgmt;
import component.ComponentException;
import component.Identifier;
import jnr.ffi.annotations.In;
import logicface.LogicFace;
import packet.Data;
import packet.Interest;
/*
* @Author: Wang Feng
* @Description: CommandExecutor 表示一个命令执行器
* @Version: 1.0.0
* @Date: 21:37 2021/4/23
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class CommandExecutor {
// 默认兴趣包生存期
public static final int defaultInterestLifetime=4000;
//默认TTL
// @Description:
// 1. 默认TTL为1,表示当前管理命令只能传递给一跳路由器,即只能做本地管理用
// 2. 如果想通过控制管理命令做远程管理,需要显示设置这个值,将其设置为一个较大值,这样才能将命令兴趣包转发到多跳路由器上
public static final int defaultTTL=1;
// 要执行的命令
public IControlCommand command;
// 命令兴趣包的生存期
public long interestLifeTime;
// 命令兴趣包的 TTL
public long ttl;
// ICN 逻辑接口,用于和路由器进行ICN通信
public LogicFace logicFace;
// 是否在命令执行完成后自动执行 LogicFace 的关闭操作
public boolean autoShutdown;
/**
* Init 初始化命令执行器
* @param command
* @param logicFace
*/
public void init(IControlCommand command,LogicFace logicFace){
this.command=command;
this.interestLifeTime=defaultInterestLifetime;
this.ttl=defaultTTL;
this.logicFace=logicFace;
this.autoShutdown=false;
}
/**
* GetInterestLifeTime 获取命令兴趣包的生存期
* @return
*/
public long getInterestLifeTime() {
return interestLifeTime;
}
/**
* SetInterestLifeTime 设置命令兴趣包的生存期
* @param interestLifeTime
*/
public void setInterestLifeTime(long interestLifeTime) {
this.interestLifeTime = interestLifeTime;
}
/**
* GetTtl 获取命令兴趣包的 TTL
* @return
*/
public long getTtl() {
return ttl;
}
/**
* SetTtl 设置命令兴趣包的 TTL
* @param ttl
*/
public void setTtl(long ttl) {
this.ttl = ttl;
}
/**
* GetAutoShutdown 获取当前命令执行器是否在命令执行完成后自动关闭
* @return
*/
public boolean isAutoShutdown() {
return autoShutdown;
}
/**
* SetAutoShutdown 设置当前命令执行器是否在命令执行完成后自动关闭
* @param autoShutdown
*/
public void setAutoShutdown(boolean autoShutdown) {
this.autoShutdown = autoShutdown;
}
/**
* Shutdown 命令请求结束之后,如果想要关闭使用的 LogicFace,需要调用本函数关闭LogicFace
* @return
*/
public boolean shutdown(){
return this.logicFace.shutDown();
}
/**
* newCommandInterest 根据请求命令构造对应的命令兴趣包
* @return
* @throws MgmtException
*/
public Interest newCommandInterest() throws MgmtException {
try {
Interest interest=new Interest();
Identifier identifier=new Identifier(this.buildPrefix(this.command));
interest.setName(identifier);
interest.ttl.setTtl(this.ttl);
interest.interestLifeTime.setInterestLifeTime(this.interestLifeTime);
interest.isCommandInterest=true;
return interest;
} catch (ComponentException e) {
throw new MgmtException("CommandExecutor.newCommandInterest: "+e.getMessage());
}
}
/**
* onReceiveFirstMetaData 收到命令请求的第一个回复包
* @param data
* @return
*/
// public ControlParameters onReceiveFirstMetaData(Data data){
//
// }
/**
* buildPrefix 构造命令兴趣包请求前缀
* @param command
* @return
*/
public String buildPrefix(IControlCommand command){
return command.getTopPrefix()+"/"+command.getModuleName()+"/"+command.getAction();
}
}
+37 -3
View File
@@ -10,7 +10,41 @@ import util.StringHelper;
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ControlResponse {
public int Code; // 状态码
public String Msg; // 信息
public String Data; // 数据
// 状态码
// 请求成功
public static final int ControlResponseCodeSuccess=200;
// 请求到元数据,实际数据较大,已经分片,需要发起多个请求拉取分片
public static final int ControlResponseCodeContinue=201;
// 请求错误,包含错误信息
public static final int ControlResponseCodeCommonError=400;
// Data 域格式
// string类型
public static final String ControlResponseTypeString = "string";
// 元数据类型
public static final String ControlResponseTypeMeta = "meta";
// 字节数组类型
public static final String ControlResponseTypeBytes = "bytes";
// Data类型
public String type;
// 状态码
public int code;
// 信息
public String msg;
// 数据
public interface data{};
/**
* GetString 按字符串类型访问 Data
* @return
*/
// public String getString(){
// return this.d
// }
// public void setString(String str){
// this.type=ControlResponseTypeString;
// this.da
// }
}
+27
View File
@@ -0,0 +1,27 @@
package mgmt;
/*
* @Author: Wang Feng
* @Description: ControlCommand 控制命令接口
// @Description:
// eg. /min-mir/mgmt/localhost/face-mgmt/list
// - topPrefix => /min-mir/mgmt/localhost
// - moduleName => face-mgmt
// - action => list
* @Version: 1.0.0
* @Date: 21:41 2021/4/23
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public interface IControlCommand {
// GetTopPrefix 获取顶级前缀
String getTopPrefix();
// GetModuleName 获取模块名称
String getModuleName();
// GetAction 获取命令动作
String getAction();
// GetParameters 获取管理命令请求参数
ControlParameters getParameters();
}
+3
View File
@@ -51,6 +51,9 @@ public class Interest implements InteractWithField, IEncodingAble {
public Identifier name=new Identifier();
// 标识是否是命令包
public boolean isCommandInterest;
public Interest(){
}