make class public & writting logicface: LogicFaceICN

This commit is contained in:
free will
2021-04-15 17:16:04 +08:00
parent 8e92ee9451
commit 6d1a272782
8 changed files with 259 additions and 151 deletions
@@ -0,0 +1,80 @@
package component;
import encoding.VlInt;
import java.util.LinkedList;
import java.util.List;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 17:11 2021/4/15
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class IdentifierContainer {
private List<IdentifierWrapper> identifierWrappers=new LinkedList<>();
public IdentifierContainer() {
}
/**
* 组件个数
*
* @return
*/
public int length() {
return identifierWrappers.size();
}
/**
* 清空所有组件
*/
public void clear() {
identifierWrappers.clear();
}
/**
* 增加一个组件
*
* @param identifierWrapper
*/
public void addElement(IdentifierWrapper identifierWrapper) {
identifierWrappers.add(identifierWrapper);
}
/**
* 获取指定索引位置的组件
*
* @param index
* @return
*/
public IdentifierWrapper getElement(int index) throws ComponentException {
if (index >= this.length()) {
throw new ComponentException("IdentifierWrappers.getElement: index is out of bound.");
}
return this.identifierWrappers.get(index);
}
/**
* 获取标识区中第一个指定类型标识
*
* @param vlInt
* @return
*/
public IdentifierWrapper getElementByType(VlInt vlInt) throws ComponentException {
for (int i = 0; i < identifierWrappers.size(); i++) {
if (identifierWrappers.get(i).getTlvType().isEqual(vlInt)) {
return identifierWrappers.get(i);
}
}
throw new ComponentException("IdentifierWrappers.getElementByType: no found the tlvType");
}
public void setElement(int index, IdentifierWrapper wrapper) {
if (index >= this.length()) {
return;
}
this.identifierWrappers.set(index, wrapper);
}
}
@@ -13,73 +13,6 @@ import java.util.List;
* @Date: 11:02 2021/3/12
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
class IdentifierContainer {
private List<IdentifierWrapper> identifierWrappers=new LinkedList<>();
public IdentifierContainer() {
}
/**
* 组件个数
*
* @return
*/
public int length() {
return identifierWrappers.size();
}
/**
* 清空所有组件
*/
public void clear() {
identifierWrappers.clear();
}
/**
* 增加一个组件
*
* @param identifierWrapper
*/
public void addElement(IdentifierWrapper identifierWrapper) {
identifierWrappers.add(identifierWrapper);
}
/**
* 获取指定索引位置的组件
*
* @param index
* @return
*/
public IdentifierWrapper getElement(int index) throws ComponentException {
if (index >= this.length()) {
throw new ComponentException("IdentifierWrappers.getElement: index is out of bound.");
}
return this.identifierWrappers.get(index);
}
/**
* 获取标识区中第一个指定类型标识
*
* @param vlInt
* @return
*/
public IdentifierWrapper getElementByType(VlInt vlInt) throws ComponentException {
for (int i = 0; i < identifierWrappers.size(); i++) {
if (identifierWrappers.get(i).getTlvType().isEqual(vlInt)) {
return identifierWrappers.get(i);
}
}
throw new ComponentException("IdentifierWrappers.getElementByType: no found the tlvType");
}
public void setElement(int index, IdentifierWrapper wrapper) {
if (index >= this.length()) {
return;
}
this.identifierWrappers.set(index, wrapper);
}
}
public class IdentifierField implements TlvComponentBase, IEncodingAble {
private IdentifierContainer identifiers=new IdentifierContainer();
@@ -0,0 +1,25 @@
package component;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 17:13 2021/4/15
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class SignatureAlgorithm{
public int getSignatureAlgorithm() {
return signatureAlgorithm;
}
public void setSignatureAlgorithm(int signatureAlgorithm) {
this.signatureAlgorithm = signatureAlgorithm;
}
private int signatureAlgorithm;
public SignatureAlgorithm(){
}
public SignatureAlgorithm(int value){
this.signatureAlgorithm=value;
}
}
@@ -0,0 +1,71 @@
package component;
import java.util.LinkedList;
import java.util.List;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 17:12 2021/4/15
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class SignatureContainer {
private List<Signature> signatures= new LinkedList<>();;
public SignatureContainer() {
}
/**
* 组件个数
*
* @return
*/
public int length() {
return signatures.size();
}
/**
* 清空组件
*/
public void clear() {
signatures.clear();
}
/**
* 增加一个组件
*
* @param signature
*/
public void addElement(Signature signature) {
signatures.add(signature);
}
/**
* 获取指定索引位置的组件
*
* @param index
* @return
*/
public Signature getElement(int index) throws ComponentException {
if (index >= length()) {
throw new ComponentException("Signatures.getElement: index is out of bound.");
}
return signatures.get(index);
}
/**
* 设置指定索引位置的组件
*
* @param index
* @param signature
* @return
*/
public boolean setElement(int index, Signature signature) {
if (index >= length()) {
return false;
}
signatures.set(index, signature);
return true;
}
}
@@ -12,66 +12,6 @@ import java.util.List;
* @Date: 21:24 2021/3/15
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
class SignatureContainer {
private List<Signature> signatures= new LinkedList<>();;
public SignatureContainer() {
}
/**
* 组件个数
*
* @return
*/
public int length() {
return signatures.size();
}
/**
* 清空组件
*/
public void clear() {
signatures.clear();
}
/**
* 增加一个组件
*
* @param signature
*/
public void addElement(Signature signature) {
signatures.add(signature);
}
/**
* 获取指定索引位置的组件
*
* @param index
* @return
*/
public Signature getElement(int index) throws ComponentException {
if (index >= length()) {
throw new ComponentException("Signatures.getElement: index is out of bound.");
}
return signatures.get(index);
}
/**
* 设置指定索引位置的组件
*
* @param index
* @param signature
* @return
*/
public boolean setElement(int index, Signature signature) {
if (index >= length()) {
return false;
}
signatures.set(index, signature);
return true;
}
}
public class SignatureField implements TlvComponentBase, IEncodingAble {
private SignatureContainer signatures= new SignatureContainer();
@@ -28,22 +28,6 @@ import minsecurity.Common;
// this.signatureTypeValue = signatureTypeValue;
// }
//}
class SignatureAlgorithm{
public int getSignatureAlgorithm() {
return signatureAlgorithm;
}
public void setSignatureAlgorithm(int signatureAlgorithm) {
this.signatureAlgorithm = signatureAlgorithm;
}
private int signatureAlgorithm;
public SignatureAlgorithm(){
}
public SignatureAlgorithm(int value){
this.signatureAlgorithm=value;
}
}
public class SignatureType implements TlvComponentBase, IEncodingAble {
private SignatureAlgorithm value=new SignatureAlgorithm(); // SignatureAlgorithm
+79 -4
View File
@@ -111,7 +111,7 @@ public class LogicFaceICN extends LogicFace {
if(pitEntry==null){
return;
}
pitEntry.onData(pitEntry.interest,data);
pitEntry.oD.onData(pitEntry.interest,data);
} catch (PacketException | ComponentException e) {
throw new LogicFaceException("LogicFaceICN.onReceiveData: "+e.getMessage());
}
@@ -133,7 +133,7 @@ public class LogicFaceICN extends LogicFace {
if(pitEntry==null){
return;
}
pitEntry.onNack(pitEntry.interest,nack);
pitEntry.oN.onNack(pitEntry.interest,nack);
} catch (ComponentException e) {
throw new LogicFaceException("LogicFaceICN.onReceiveNack: "+e.getMessage());
}
@@ -163,7 +163,7 @@ public class LogicFaceICN extends LogicFace {
PITEntry pitEntry=this.mPit.get(timeEvent.key);
if(pitEntry!=null){
if(pitEntry.expireTime<=currentTime){
pitEntry.onTimeOut(pitEntry.interest);
pitEntry.oT.onTimeOut(pitEntry.interest);
this.mPit.remove(timeEvent.key);
}else{
timeEvent.timeoutTime=pitEntry.expireTime;
@@ -230,7 +230,82 @@ public class LogicFaceICN extends LogicFace {
/**
* 初始化一些变量,然后启动接收包阻塞线程
*/
public void processEvent(){
public void processEvent() throws LogicFaceException {
this.initBeforeProcessEvent();
this.doReceivePacket();
}
/**
* 尝试重新设置定时器超时时间
* // (1)每次发出一个兴趣包,会产生一个定时事件,放入超时事件堆 timeoutEventHeap
* // 2)如果超时时事放入timeoutEventHeap后,timeoutEventHeap 数组头的超时事件的超时时间 小于 最近即将发生的超时事
* // 件时间 recentExpireTime
* // 则将 timer 超时时间重新设置为 timeoutEventHeap 数组头的超时事件的超时时间 ,
* // recentExpireTime 也设置为timeoutEventHeap 数组头的超时事件的超时时间。
*/
public void tryResetTimer(){
this.timeoutEventHeapLock.lock();
if(this.timeoutEventHeap.len()<=0){
this.timeoutEventHeapLock.unlock();
return;
}
if(this.timeoutEventHeap.get(0).timeoutTime<this.recentExpireTime){
long durationMs=this.timeoutEventHeap.get(0).timeoutTime-TimeHelper.getTimestampMS();
this.recentExpireTime=this.timeoutEventHeap.get(0).timeoutTime;
// todo: this.timer.Reset
}
this.timeoutEventHeapLock.unlock();
}
/**
* 将兴趣包放入PIT表中, 并在 timeoutEventHeap 添加超时事件,然后调用 tryResetTimer 尝试重新设置 timer定时器
* @param entry
* @param interestNameStr
* @return
*/
public boolean insert2PIT(PITEntry entry,String interestNameStr){
long interestExpireTime=TimeHelper.getTimestampMS()+
entry.interest.interestLifeTime.getInterestLifeTime();
this.timeoutEventHeapLock.lock();
PITEntry pitEntryIn=this.mPit.get(interestNameStr);
if(pitEntryIn!=null){
if(pitEntryIn.expireTime<interestExpireTime){
this.mPit.put(interestNameStr,entry);
}
this.timeoutEventHeapLock.unlock();
return true;
}
TimeoutEvent timeEvent=new TimeoutEvent();
timeEvent.key = interestNameStr;
timeEvent.timeoutTime=interestExpireTime;
this.timeoutEventHeapLock.lock();
this.mPit.put(interestNameStr,entry);
this.timeoutEventHeap.push(timeEvent);
this.timeoutEventHeapLock.unlock();
this.tryResetTimer();
return false;
}
/**
* 发送一个兴趣包
* @param interest
* @param oD
* @param oT
* @param oN
*/
public void expressInterest(Interest interest,OnData oD,OnTimeout oT,OnNack oN) throws LogicFaceException {
try {
IdentifierWrapper interestName=interest.minPacket.identifierField.getIdentifier(0);
if(interestName==null){
// todo: 日志记录错误
return;
}
PITEntry pitEntry = null;
pitEntry.interest=interest;
// pitEntry.oT;
} catch (ComponentException e) {
throw new LogicFaceException("LogicFaceICN.expressInterest: "+e.getMessage());
}
}
}
+4 -4
View File
@@ -11,10 +11,10 @@ import packet.Nack;
* @Date: 9:38 2021/4/15
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public abstract class PITEntry implements OnData,OnTimeout,OnNack{
public class PITEntry{
public Interest interest = new Interest(); // 兴趣包
public long expireTime = 0; // 本PIT表项的超时时间
// OnData oD = null; // 收到对应的数据包的处理函数
// OnTimeout oT = null; // 兴趣包超时的处理函数
// OnNack oN = null; // 兴趣包无路由的处理函数
OnData oD = null; // 收到对应的数据包的处理函数
OnTimeout oT = null; // 兴趣包超时的处理函数
OnNack oN = null; // 兴趣包无路由的处理函数
}