add logicface: LogicFaceICN

This commit is contained in:
free will
2021-04-15 19:18:45 +08:00
parent 6d1a272782
commit 9efb1dab8b
9 changed files with 92 additions and 24 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ import packet.LpPacket;
* @Date: 19:44 2021/4/13
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public interface ITransport {
public interface ITransport{
/**
* 关闭
*/
+55 -13
View File
@@ -6,7 +6,6 @@ import component.IdentifierWrapper;
import encoding.TLV;
import encoding.VlIntException;
import packet.*;
import util.CallbackFunction;
import util.ConcurrentHelper;
import util.TimeHelper;
@@ -29,19 +28,19 @@ public class LogicFaceICN extends LogicFace {
public Lock timeoutEventHeapLock; // 锁, mpit 、timeoutEventHeap、recentExpireTime
public TimeoutEventHeap timeoutEventHeap; // 超时事件堆, 以超时时间排序的最小堆
public Map<String, OnInterest> mFib;
public Map<String, OnInterestInterface> mFib;
/**
* 通过最长匹配原则查找FIB表,找到合适的兴趣包处理函数
* @param identifier
* @return
*/
public OnInterest lookUpFib(Identifier identifier) throws LogicFaceException {
public OnInterestInterface lookUpFib(Identifier identifier) throws LogicFaceException {
try {
int idComponentN = identifier.getComponents().length();
for (int i = idComponentN; i > 0; i--) {
Identifier prefix = identifier.getPrefix(i);
OnInterest fibEntry=this.mFib.get(prefix.toUri());
OnInterestInterface fibEntry=this.mFib.get(prefix.toUri());
if(fibEntry!=null) {
return fibEntry;
}
@@ -68,7 +67,7 @@ public class LogicFaceICN extends LogicFace {
}
IdentifierWrapper identifierWrapper=interest.minPacket.identifierField.getIdentifier(0);
PITEntry pitEntry=this.getPitEntryAndDelete(identifierWrapper.getIdentifier());
OnInterest oI=this.lookUpFib(identifierWrapper.getIdentifier());
OnInterestInterface oI=this.lookUpFib(identifierWrapper.getIdentifier());
if(oI!=null){
oI.onInterest(interest);
}
@@ -111,7 +110,7 @@ public class LogicFaceICN extends LogicFace {
if(pitEntry==null){
return;
}
pitEntry.oD.onData(pitEntry.interest,data);
pitEntry.onDataInterface.onData(pitEntry.interest,data);
} catch (PacketException | ComponentException e) {
throw new LogicFaceException("LogicFaceICN.onReceiveData: "+e.getMessage());
}
@@ -133,7 +132,7 @@ public class LogicFaceICN extends LogicFace {
if(pitEntry==null){
return;
}
pitEntry.oN.onNack(pitEntry.interest,nack);
pitEntry.onNackInterface.onNack(pitEntry.interest,nack);
} catch (ComponentException e) {
throw new LogicFaceException("LogicFaceICN.onReceiveNack: "+e.getMessage());
}
@@ -163,7 +162,7 @@ public class LogicFaceICN extends LogicFace {
PITEntry pitEntry=this.mPit.get(timeEvent.key);
if(pitEntry!=null){
if(pitEntry.expireTime<=currentTime){
pitEntry.oT.onTimeOut(pitEntry.interest);
pitEntry.onTimeoutInterface.onTimeOut(pitEntry.interest);
this.mPit.remove(timeEvent.key);
}else{
timeEvent.timeoutTime=pitEntry.expireTime;
@@ -289,11 +288,13 @@ public class LogicFaceICN extends LogicFace {
/**
* 发送一个兴趣包
* @param interest
* @param oD
* @param oT
* @param oN
* @param onDataInterface
* @param onTimeoutInterface
* @param onNackInterface
*/
public void expressInterest(Interest interest,OnData oD,OnTimeout oT,OnNack oN) throws LogicFaceException {
public void expressInterest(Interest interest,
OnDataInterface onDataInterface, OnTimeoutInterface onTimeoutInterface,
OnNackInterface onNackInterface) throws LogicFaceException {
try {
IdentifierWrapper interestName=interest.minPacket.identifierField.getIdentifier(0);
if(interestName==null){
@@ -302,10 +303,51 @@ public class LogicFaceICN extends LogicFace {
}
PITEntry pitEntry = null;
pitEntry.interest=interest;
// pitEntry.oT;
pitEntry.onDataInterface=onDataInterface;
pitEntry.onTimeoutInterface =onTimeoutInterface;
pitEntry.onNackInterface=onNackInterface;
boolean isRepeate=this.insert2PIT(pitEntry,interestName.toUri());
if(isRepeate){
return;
}
if(!this.sendInterest(interest)){
// todo: 日志记录错误
}
} catch (ComponentException e) {
throw new LogicFaceException("LogicFaceICN.expressInterest: "+e.getMessage());
}
}
/**
* 发出一个数据包
* @param data
* @throws LogicFaceException
*/
public void putData(Data data) throws LogicFaceException {
if(!this.sendData(data)){
// todo: 日志记录错误
}
}
public void registerPrefix(Identifier identifier,OnInterestInterface onInterestInterface,
OnRegisterFailInterface onRegisterFailInterface,
OnRegisterSuccessInterface onRegisterSuccessInterface) throws LogicFaceException {
if(this.mFib==null){
this.mFib=new HashMap<>();
}
boolean res=this.registerIdentifier(identifier,3);
if(!res){
onRegisterFailInterface.onRegisterFail(identifier);
return;
}
try {
this.mFib.put(identifier.toUri(),onInterestInterface);
onRegisterSuccessInterface.onRegisterSuccess(identifier);
} catch (ComponentException e) {
throw new LogicFaceException("LogicFaceICN.registerPrefix: "+e.getMessage());
}
}
}
@@ -10,6 +10,6 @@ import packet.Interest;
* @Date: 10:21 2021/4/15
* @Copyright: MIN-Group国家重大科技基础设施未来网络北大实验室深圳市信息论与未来网络重点实验室
*/
public interface OnData {
public interface OnDataInterface {
void onData(Interest interest, Data data);
}
@@ -9,6 +9,6 @@ import packet.Interest;
* @Date: 10:22 2021/4/15
* @Copyright: MIN-Group国家重大科技基础设施未来网络北大实验室深圳市信息论与未来网络重点实验室
*/
public interface OnInterest {
public interface OnInterestInterface {
void onInterest(Interest interest);
}
}
@@ -10,6 +10,6 @@ import packet.Nack;
* @Date: 10:23 2021/4/15
* @Copyright: MIN-Group国家重大科技基础设施未来网络北大实验室深圳市信息论与未来网络重点实验室
*/
public interface OnNack {
public interface OnNackInterface {
void onNack(Interest interest, Nack nack);
}
@@ -0,0 +1,14 @@
package logicface;
import component.Identifier;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 19:11 2021/4/15
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public interface OnRegisterFailInterface {
void onRegisterFail(Identifier identifier);
}
@@ -0,0 +1,14 @@
package logicface;
import component.Identifier;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 19:12 2021/4/15
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public interface OnRegisterSuccessInterface {
void onRegisterSuccess(Identifier identifier);
}
@@ -9,6 +9,6 @@ import packet.Interest;
* @Date: 10:22 2021/4/15
* @Copyright: MIN-Group国家重大科技基础设施未来网络北大实验室深圳市信息论与未来网络重点实验室
*/
public interface OnTimeout {
public interface OnTimeoutInterface {
void onTimeOut(Interest interest);
}
+3 -5
View File
@@ -1,8 +1,6 @@
package logicface;
import packet.Data;
import packet.Interest;
import packet.Nack;
/*
* @Author: Wang Feng
@@ -14,7 +12,7 @@ import packet.Nack;
public class PITEntry{
public Interest interest = new Interest(); // 兴趣包
public long expireTime = 0; // 本PIT表项的超时时间
OnData oD = null; // 收到对应的数据包的处理函数
OnTimeout oT = null; // 兴趣包超时的处理函数
OnNack oN = null; // 兴趣包无路由的处理函数
OnDataInterface onDataInterface = null; // 收到对应的数据包的处理函数
OnTimeoutInterface onTimeoutInterface = null; // 兴趣包超时的处理函数
OnNackInterface onNackInterface = null; // 兴趣包无路由的处理函数
}