update LogicFaceICN: add pendingPakcetList

This commit is contained in:
free will
2021-04-20 16:01:02 +08:00
parent 4635adafac
commit c932864f8f
2 changed files with 50 additions and 3 deletions
+28 -3
View File
@@ -28,7 +28,7 @@ import java.util.concurrent.locks.ReentrantLock;
public class LogicFaceICN extends LogicFace {
public Timer timer; // 定时器,在processEvent函数中就被设置成很大的值
public long recentExpireTime; // 最近将要超时的时间戳
public Map<String, PITEntry> mPit=new ConcurrentHashMap<>(); // PIT表
public Map<String, PITEntry> mPit; // PIT表。不初始化,可以根据它来判断本face是否初始化
public Lock timeoutEventHeapLock=new ReentrantLock(); // 锁, mpit 、timeoutEventHeap、recentExpireTime
// 超时事件堆, 以超时时间排序的最小堆,初始化大小为1000
public PriorityBlockingQueue<TimeoutEvent> timeoutEventHeap
@@ -38,8 +38,8 @@ public class LogicFaceICN extends LogicFace {
return Long.compare(o1.timeoutTime,o2.timeoutTime);
}
});
public Map<String, OnInterestInterface> mFib=new ConcurrentHashMap<>();
public List<PendingPacket> pendingPacketList=new LinkedList<>();
/**
* 通过最长匹配原则查找FIB表,找到合适的兴趣包处理函数
@@ -215,7 +215,7 @@ public class LogicFaceICN extends LogicFace {
* 在 processEvent之前先初始化一些东西主要 包括初始化PIT表,和将定时器启动起来
*/
public void initBeforeProcessEvent(){
this.mPit=new HashMap<>();
this.mPit=new ConcurrentHashMap<>();
this.timer=new Timer();
this.timer.schedule(new TimerTask() {
@Override
@@ -258,6 +258,15 @@ public class LogicFaceICN extends LogicFace {
*/
public void processEvent() throws LogicFaceException {
this.initBeforeProcessEvent();
for (int i = 0; i < this.pendingPacketList.size(); i++) {
if(this.pendingPacketList.get(i).data!=null){
this.putData(this.pendingPacketList.get(i).data);
continue;
}
this.expressInterest(this.pendingPacketList.get(i).interest,this.pendingPacketList.get(i).onDataInterface,
this.pendingPacketList.get(i).onTimeoutInterface,this.pendingPacketList.get(i).onNackInterface);
}
this.pendingPacketList=null; // release the memory of pendingPacketLt
this.doReceivePacket();
}
@@ -328,6 +337,16 @@ public class LogicFaceICN extends LogicFace {
OnDataInterface onDataInterface, OnTimeoutInterface onTimeoutInterface,
OnNackInterface onNackInterface) throws LogicFaceException {
try {
if(this.mPit==null){ // 未启动processEvent
PendingPacket pendingPacket=new PendingPacket();
pendingPacket.interest=interest;
pendingPacket.onDataInterface=onDataInterface;
pendingPacket.onNackInterface=onNackInterface;
pendingPacket.onTimeoutInterface=onTimeoutInterface;
this.pendingPacketList.add(pendingPacket);
return;
}
IdentifierWrapper interestName=interest.minPacket.identifierField.getIdentifier(0);
if(interestName==null){
LoggerHelper.logger.debug("LogicFaceICN.expressInterest: minPacket getIdentifier null");
@@ -358,6 +377,12 @@ public class LogicFaceICN extends LogicFace {
* @throws LogicFaceException
*/
public void putData(Data data) throws LogicFaceException {
if(this.mPit==null){ // 未启动processEvent
PendingPacket pendingPacket=new PendingPacket();
pendingPacket.data=data;
this.pendingPacketList.add(pendingPacket);
return;
}
if(!this.sendData(data)){
LoggerHelper.logger.debug("LogicFaceICN.putData: send Data false");
}
@@ -0,0 +1,22 @@
package logicface;
import logicface.CallbackInterface.OnDataInterface;
import logicface.CallbackInterface.OnNackInterface;
import logicface.CallbackInterface.OnTimeoutInterface;
import packet.Data;
import packet.Interest;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 15:44 2021/4/20
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class PendingPacket {
public Interest interest=new Interest();
public Data data=new Data();
OnDataInterface onDataInterface = null; // 收到对应的数据包的处理函数
OnTimeoutInterface onTimeoutInterface = null; // 兴趣包超时的处理函数
OnNackInterface onNackInterface = null; // 兴趣包无路由的处理函数
}