diff --git a/src/main/java/component/LpPacketFragmentId.java b/src/main/java/component/LpPacketFragmentId.java new file mode 100644 index 0000000..b24e62a --- /dev/null +++ b/src/main/java/component/LpPacketFragmentId.java @@ -0,0 +1,102 @@ +package component; + +import encoding.*; + +/* + * @Author: Wang Feng + * @Description: 表示 LpPacket 中的分片id TLV + * @Version: 1.0.0 + * @Date: 20:45 2021/4/5 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ +public class LpPacketFragmentId implements TlvComponentBase,InitialAble,IEncodingAble{ + // 成员变量 + private long id; + + // 函数 + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + this.doInitial(); + } + + // 接口实现-变量区 + private boolean initial=false; + + // 接口实现-方法区 + @Override + public void doInitial() { + initial=true; + } + + @Override + public boolean isInitial() { + return initial; + } + + /** + * 将 LpPacketFragmentId 线速编码为一个 TLV + * @param encoder + * @return + */ + @Override + public int wireEncode(Encoder encoder) throws ComponentException { + try { + int totalLength=0; + + // 编码 TLV-VALUE + int tmpLen=encoder.prependNonNegativeInteger(this.id); + if(tmpLen<=0){ + return -1; + } + totalLength+=tmpLen; + + // 编码 TLV-TYPE + tmpLen=encoder.prependVarNumber(new VlInt(totalLength)); + if(tmpLen<=0){ + return -1; + } + totalLength+=tmpLen; + + // 编码 TLV-TYPE + tmpLen=encoder.prependVarNumber(new VlInt(TLV.TlvLpPacketFragmentId)); + if(tmpLen<=0){ + return -1; + } + totalLength+=tmpLen; + + return totalLength; + } catch (EncoderException e) { + throw new ComponentException("LpPacketFragmentId.wireEncode: "+e.getMessage()); + } + } + + /** + * 从 TLV Block 中解码一个 LpPacketFragmentId + * @param block + * @return + */ + @Override + public boolean wireDecode(Block block) throws ComponentException { + try { + // 检查 Type 是否正确 + if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvLpPacketFragmentId))) { + return false; + } + + // 读取 value + long value = TLV.readNonNegativeInteger(block.getValue(), 0, block.getLength().getVlIntValue2Int()); + if (value < 0) { + return false; + } + this.setId(value); + + return true; + } catch (TLVException | VlIntException e) { + throw new ComponentException("LpPacketFragmentId.wireDecode: "+e.getMessage()); + } + } +} diff --git a/src/main/java/component/LpPacketFragmentNum.java b/src/main/java/component/LpPacketFragmentNum.java new file mode 100644 index 0000000..d0c01bd --- /dev/null +++ b/src/main/java/component/LpPacketFragmentNum.java @@ -0,0 +1,102 @@ +package component; + +import encoding.*; + +/* + * @Author: Wang Feng + * @Description: 表示 LpPacket 中的分片数量 TLV + * @Version: 1.0.0 + * @Date: 21:05 2021/4/5 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ +public class LpPacketFragmentNum implements TlvComponentBase,InitialAble, IEncodingAble { + // 成员变量 + private long fragmentNum; + + // 函数 + public long getFragmentNum() { + return fragmentNum; + } + + public void setFragmentNum(long fragmentNum) { + this.fragmentNum = fragmentNum; + this.doInitial(); + } + + // 接口实现-变量区 + private boolean initial=false; + + // 接口实现-方法区 + @Override + public void doInitial() { + initial=true; + } + + @Override + public boolean isInitial() { + return initial; + } + + /** + * 将 LpPacketFragmentNum 线速编码为一个 TLV + * @param encoder + * @return + */ + @Override + public int wireEncode(Encoder encoder) throws ComponentException { + try { + int totalLength=0; + + // 编码 TLV-VALUE + int tmpLen=encoder.prependNonNegativeInteger(this.fragmentNum); + if(tmpLen<=0){ + return -1; + } + totalLength+=tmpLen; + + // 编码 TLV-TYPE + tmpLen=encoder.prependVarNumber(new VlInt(totalLength)); + if(tmpLen<=0){ + return -1; + } + totalLength+=tmpLen; + + // 编码 TLV-TYPE + tmpLen=encoder.prependVarNumber(new VlInt(TLV.TlvLpPacketFragmentNum)); + if(tmpLen<=0){ + return -1; + } + totalLength+=tmpLen; + + return totalLength; + } catch (EncoderException e) { + throw new ComponentException("LpPacketFragmentNum.wireEncode: "+e.getMessage()); + } + } + + /** + * 从 TLV Block 中解码一个 LpPacketFragmentNum + * @param block + * @return + */ + @Override + public boolean wireDecode(Block block) throws ComponentException { + try { + // 检查 Type 是否正确 + if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvLpPacketFragmentNum))) { + return false; + } + + // 读取 value + long value = TLV.readNonNegativeInteger(block.getValue(), 0, block.getLength().getVlIntValue2Int()); + if (value < 0) { + return false; + } + this.setFragmentNum(value); + + return true; + } catch (TLVException | VlIntException e) { + throw new ComponentException("LpPacketFragmentNum.wireDecode: "+e.getMessage()); + } + } +} diff --git a/src/main/java/component/LpPacketFragmentSeq.java b/src/main/java/component/LpPacketFragmentSeq.java new file mode 100644 index 0000000..f8c0855 --- /dev/null +++ b/src/main/java/component/LpPacketFragmentSeq.java @@ -0,0 +1,102 @@ +package component; + +import encoding.*; + +/* + * @Author: Wang Feng + * @Description: 表示 LpPacket 中的分片号 TLV + * @Version: 1.0.0 + * @Date: 21:11 2021/4/5 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ +public class LpPacketFragmentSeq implements TlvComponentBase,InitialAble, IEncodingAble { + // 成员变量 + private long fragmentSeq; + + // 函数 + public long getFragmentSeq() { + return fragmentSeq; + } + + public void setFragmentSeq(long fragmentSeq) { + this.fragmentSeq = fragmentSeq; + this.doInitial(); + } + + // 接口实现-变量区 + private boolean initial=false; + + // 接口实现-方法区 + @Override + public void doInitial() { + initial=true; + } + + @Override + public boolean isInitial() { + return initial; + } + + /** + * 将 LpPacketFragmentSeq 线速编码为一个 TLV + * @param encoder + * @return + */ + @Override + public int wireEncode(Encoder encoder) throws ComponentException { + try { + int totalLength=0; + + // 编码 TLV-VALUE + int tmpLen=encoder.prependNonNegativeInteger(this.fragmentSeq); + if(tmpLen<=0){ + return -1; + } + totalLength+=tmpLen; + + // 编码 TLV-TYPE + tmpLen=encoder.prependVarNumber(new VlInt(totalLength)); + if(tmpLen<=0){ + return -1; + } + totalLength+=tmpLen; + + // 编码 TLV-TYPE + tmpLen=encoder.prependVarNumber(new VlInt(TLV.TlvLpPacketFragmentSeq)); + if(tmpLen<=0){ + return -1; + } + totalLength+=tmpLen; + + return totalLength; + } catch (EncoderException e) { + throw new ComponentException("LpPacketFragmentSeq.wireEncode: "+e.getMessage()); + } + } + + /** + * 从 TLV Block 中解码一个 LpPacketFragmentSeq + * @param block + * @return + */ + @Override + public boolean wireDecode(Block block) throws ComponentException { + try { + // 检查 Type 是否正确 + if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvLpPacketFragmentSeq))) { + return false; + } + + // 读取 value + long value = TLV.readNonNegativeInteger(block.getValue(), 0, block.getLength().getVlIntValue2Int()); + if (value < 0) { + return false; + } + this.setFragmentSeq(value); + + return true; + } catch (TLVException | VlIntException e) { + throw new ComponentException("LpPacketFragmentSeq.wireDecode: "+e.getMessage()); + } + } +} diff --git a/src/main/java/component/LpPacketHeader.java b/src/main/java/component/LpPacketHeader.java new file mode 100644 index 0000000..2bdf7e4 --- /dev/null +++ b/src/main/java/component/LpPacketHeader.java @@ -0,0 +1,39 @@ +package component; + +import encoding.Block; +import encoding.Encoder; +import encoding.IEncodingAble; + +/* + * @Author: Wang Feng + * @Description: + * @Version: 1.0.0 + * @Date: 21:18 2021/4/5 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ +public class LpPacketHeader implements TlvComponentBase, IEncodingAble { + // 成员变量 + private LpPacketFragmentId lpPacketFragmentId; + private LpPacketFragmentNum lpPacketFragmentNum; + private LpPacketFragmentSeq lpPacketFragmentSeq; + + /** + * 将 LpPacketHeader 线速编码为一个 TLV + * @param encoder + * @return + */ + @Override + public int wireEncode(Encoder encoder) throws ComponentException { + + } + + /** + * 从 TLV Block 中解码一个 LpPacketHeader + * @param block + * @return + */ + @Override + public boolean wireDecode(Block block) throws ComponentException { + + } +} diff --git a/src/main/java/encoding/TLV.java b/src/main/java/encoding/TLV.java index 7f56cde..f442684 100644 --- a/src/main/java/encoding/TLV.java +++ b/src/main/java/encoding/TLV.java @@ -65,6 +65,13 @@ public class TLV { public static final int TlvCost = 219; // 链路开销 public static final int TlvExpires = 220; // LogicFace超时时间,-1为不超时(never) + // LpPacket + public static final int TlvLpPacket = 250; // LpPacket + public static final int TlvLpPacketHeader = 251; // LpPacket Header + public static final int TlvLpPacketFragmentId = 252; // LpPacket 分片id + public static final int TlvLpPacketFragmentNum = 253; // LpPacket 分片数 + public static final int TlvLpPacketFragmentSeq = 254; // LpPacket 分片号 + // 目前已分配的最大的Tlv值,第一轮分配的最大值为500,超过该值则断定为不合法 // TODO: 目前TLV值的分配,第一轮分配都在500以内,如果以后分配更高值时,需要修改此处的限制 public static final int MaxTlvNum = 500; diff --git a/src/main/java/packet/CPacket.java b/src/main/java/packet/CPacket.java index 5150f48..7f00270 100644 --- a/src/main/java/packet/CPacket.java +++ b/src/main/java/packet/CPacket.java @@ -1,9 +1,6 @@ package packet; -import component.ComponentException; -import component.IdentifierWrapper; -import component.Payload; -import component.TTL; +import component.*; import encoding.*; /* @@ -34,15 +31,74 @@ import encoding.*; // } // public class CPacket implements InteractWithField, IEncodingAble { - private MINPacket minPacket; - private TTL ttl; - private Payload payload; - private String flatIdentifier; // 推式包拥有一个扁平的标识 + public MINPacket minPacket=new MINPacket(); + public TTL ttl=new TTL(); + public Payload payload=new Payload(); + public Identifier srcIdentifier=new Identifier(); + public Identifier dstIdentifier=new Identifier(); - public CPacket() { - minPacket = new MINPacket(); - ttl = new TTL(); - payload = new Payload(); + + /** + * 获取源标识 + * @return + */ + public Identifier getSrcIdentifier() { + return srcIdentifier; + } + + /** + * 设置源标识 + * @param srcIdentifier + */ + public void setSrcIdentifier(Identifier srcIdentifier) { + this.srcIdentifier = srcIdentifier; + } + + /** + * 获取目的标识 + * @return + */ + public Identifier getDstIdentifier() { + return dstIdentifier; + } + + /** + * 设置目的标识 + * @param dstIdentifier + */ + public void setDstIdentifier(Identifier dstIdentifier) { + this.dstIdentifier = dstIdentifier; + } + + /** + * 得到 TTL + * + * @return + */ + public TTL getTtl() { + return ttl; + } + + /** + * 设置 TTL + * + * @param ttl + */ + public void setTtl(TTL ttl) { + this.ttl = ttl; + } + + /** + * 展示目的标识 + * + * @return + */ + public String toUri() throws PacketException { + try { + return this.dstIdentifier.toUri(); + } catch (ComponentException e) { + throw new PacketException("CPacket.toUri() :"+e.getMessage()); + } } /** @@ -59,12 +115,7 @@ public class CPacket implements InteractWithField, IEncodingAble { // 填充可变区 => 非受保护区 // 首先清除所有的Block this.minPacket.mutableField.mutableDangerousField.clearBlocks(); - Block block = null; - try { - block = new SelfEncodingBase().selfWireEncode(this.ttl); - } catch (EncoderException | BlockException | ComponentException e) { - throw new PacketException("CPacket.fillDataToFields: " + e.getMessage()); - } + Block block = new SelfEncodingBase().selfWireEncode(this.ttl); if (block == null) { return false; } @@ -81,13 +132,16 @@ public class CPacket implements InteractWithField, IEncodingAble { // 填充标识区 // 首先清除所有的标识 - this.minPacket.identifierField.clearIdentifiers(); - IdentifierWrapper identifierWrapper = - new IdentifierWrapper().createCommonIdentifierByString(this.flatIdentifier); - if (identifierWrapper == null) { - return false; + if((this.srcIdentifier==null)||(this.dstIdentifier==null)){ + throw new PacketException("CPacket.fillDataToFields: SrcIdentifier or DstIdentifier is null."); } - this.minPacket.identifierField.addIdentifier(identifierWrapper); + this.minPacket.identifierField.clearIdentifiers(); + IdentifierWrapper srcIdentifierWrapper = + new IdentifierWrapper(new VlInt(TLV.TlvIdentifierCommon),this.srcIdentifier); + IdentifierWrapper dstIdentifierWrapper = + new IdentifierWrapper(new VlInt(TLV.TlvIdentifierCommon),this.dstIdentifier); + this.minPacket.identifierField.addIdentifier(srcIdentifierWrapper); + this.minPacket.identifierField.addIdentifier(dstIdentifierWrapper); return true; } catch (EncoderException | BlockException | ComponentException e) { @@ -104,9 +158,7 @@ public class CPacket implements InteractWithField, IEncodingAble { public boolean extraDataFromFields() throws PacketException { try { // 提取 Payload - Block payloadBlock = null; - payloadBlock = this.minPacket.readOnlyField.getBlockByType(new VlInt(TLV.TlvPayload)); - + Block payloadBlock = this.minPacket.readOnlyField.getBlockByType(new VlInt(TLV.TlvPayload)); if (payloadBlock == null) { return false; } @@ -124,14 +176,16 @@ public class CPacket implements InteractWithField, IEncodingAble { } // 提取标识 - IdentifierWrapper commonIdentifier = this.minPacket.identifierField.getIdentifierByType(new VlInt(TLV.TlvIdentifierCommon)); - if (commonIdentifier == null) { + IdentifierWrapper srcIdentifierWrapper = this.minPacket.identifierField.getIdentifier(0); + if (srcIdentifierWrapper == null) { return false; } - String identifierString = commonIdentifier.toUri(); - if ((identifierString.length() > 0) && (identifierString.startsWith("/"))) { - this.flatIdentifier = identifierString.substring(1); + IdentifierWrapper dstIdentifierWrapper = this.minPacket.identifierField.getIdentifier(1); + if (dstIdentifierWrapper == null) { + return false; } + this.srcIdentifier=srcIdentifierWrapper.getIdentifier(); + this.dstIdentifier=dstIdentifierWrapper.getIdentifier(); return true; } catch (ComponentException e) { @@ -149,7 +203,7 @@ public class CPacket implements InteractWithField, IEncodingAble { public int wireEncode(Encoder encoder) throws PacketException { // 首先将属性填充到分区当中 if (!this.fillDataToFields()) { - return 0; + return -1; } // 指定包类型 @@ -172,48 +226,4 @@ public class CPacket implements InteractWithField, IEncodingAble { return this.extraDataFromFields(); } - /** - * 展示平面标识 - * - * @return - */ - public String toUri() { - return this.flatIdentifier; - } - - /** - * 设置推式包的平面标识,eg: asdfsvnjweivnjsdcs - * - * @param identifier - */ - public void setIdentifier(String identifier) { - this.flatIdentifier = identifier; - } - - /** - * 获取推式包的平面标识 - * - * @return - */ - public String getIdentifier() { - return this.flatIdentifier; - } - - /** - * 得到 TTL - * - * @return - */ - public TTL getTtl() { - return ttl; - } - - /** - * 设置 TTL - * - * @param ttl - */ - public void setTtl(TTL ttl) { - this.ttl = ttl; - } } diff --git a/src/main/java/packet/Data.java b/src/main/java/packet/Data.java index b6cf124..692a8fc 100644 --- a/src/main/java/packet/Data.java +++ b/src/main/java/packet/Data.java @@ -33,12 +33,12 @@ import encoding.*; // } // public class Data implements IEncodingAble, InteractWithField { - private MINPacket minPacket; - private FreshnessPeriod freshnessPeriod; - private Payload payload; - private CongestionMark congestionMark; - private NackHeader nackHeader; - private Identifier name; + public MINPacket minPacket=new MINPacket(); + public FreshnessPeriod freshnessPeriod=new FreshnessPeriod(); + public Payload payload=new Payload(); + public CongestionMark congestionMark=new CongestionMark(); + public NackHeader nackHeader=new NackHeader(); + public Identifier name=new Identifier(); /** * 展示数据包的 URI @@ -88,9 +88,7 @@ public class Data implements IEncodingAble, InteractWithField { this.minPacket.mutableField.mutableProtectField.clearBlocks(); // CongestionMark - Block block = null; - block = new SelfEncodingBase().selfWireEncode(this.congestionMark); - + Block block = new SelfEncodingBase().selfWireEncode(this.congestionMark); if (block == null) { return false; } @@ -110,11 +108,7 @@ public class Data implements IEncodingAble, InteractWithField { // FreshnessPeriod if (this.freshnessPeriod.isInitial()) { - try { - block = new SelfEncodingBase().selfWireEncode(this.freshnessPeriod); - } catch (EncoderException | BlockException | ComponentException e) { - throw new PacketException("Data.fillDataToFields: " + e.getMessage()); - } + block = new SelfEncodingBase().selfWireEncode(this.freshnessPeriod); if (block == null) { return false; } @@ -123,11 +117,7 @@ public class Data implements IEncodingAble, InteractWithField { // NackHeader if (this.nackHeader.isInitial()) { - try { - block = new SelfEncodingBase().selfWireEncode(this.nackHeader); - } catch (EncoderException | BlockException | ComponentException e) { - throw new PacketException("Data.fillDataToFields: " + e.getMessage()); - } + block = new SelfEncodingBase().selfWireEncode(this.nackHeader); if (block == null) { return false; } @@ -135,11 +125,7 @@ public class Data implements IEncodingAble, InteractWithField { } // Payload - try { - block = new SelfEncodingBase().selfWireEncode(this.payload); - } catch (EncoderException | BlockException | ComponentException e) { - throw new PacketException("Data.fillDataToFields: " + e.getMessage()); - } + block = new SelfEncodingBase().selfWireEncode(this.payload); if (block == null) { return false; } @@ -186,7 +172,6 @@ public class Data implements IEncodingAble, InteractWithField { if (!this.congestionMark.wireDecode(block)) { return false; } - } ///////////////////////////////////////////////////////////// @@ -199,14 +184,8 @@ public class Data implements IEncodingAble, InteractWithField { ElementContainer elementContainer = this.minPacket.readOnlyField.getBlocks(); int len = elementContainer.length(); for (int i = 0; i < len; i++) { - Block newblock = null; - try { - newblock = elementContainer.getBlock(i); - } catch (BlockException e) { - throw new PacketException("Data.extraDataFromFields: " + e.getMessage()); - } - int type; - type = newblock.getType().getVlIntValue2Int(); + Block newblock = elementContainer.getBlock(i); + int type = newblock.getType().getVlIntValue2Int(); switch (type) { case TLV.TlvFreshnessPeriod: if (!this.freshnessPeriod.wireDecode(newblock)) { @@ -235,7 +214,7 @@ public class Data implements IEncodingAble, InteractWithField { this.setName(interestIdentifierWrapper.getIdentifier()); return true; - } catch (ComponentException | VlIntException e) { + } catch (ComponentException | VlIntException | BlockException e) { throw new PacketException("Data.extraDataFromFields: " + e.getMessage()); } } diff --git a/src/main/java/packet/IMINPacket.java b/src/main/java/packet/IMINPacket.java new file mode 100644 index 0000000..0e95926 --- /dev/null +++ b/src/main/java/packet/IMINPacket.java @@ -0,0 +1,14 @@ +package packet; + +import encoding.IEncodingAble; + +/* + * @Author: Wang Feng + * @Description: + * @Version: 1.0.0 + * @Date: 11:27 2021/4/2 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ +public interface IMINPacket{ + boolean isPacketValid(); +} diff --git a/src/main/java/packet/Interest.java b/src/main/java/packet/Interest.java index 2e987f8..a2dd630 100644 --- a/src/main/java/packet/Interest.java +++ b/src/main/java/packet/Interest.java @@ -24,6 +24,7 @@ import encoding.*; // [InterestLifeTime] // [Nonce] // [HopLimit] +// [NackHeader] // // } // { => 可变区 @@ -31,20 +32,23 @@ import encoding.*; // [CongestionMark] // } // { => 非受保护区 -// "Empty" +// [TTL] // } // } // public class Interest implements InteractWithField, IEncodingAble { - private MINPacket minPacket; - private CanBePrefix canBePrefix; - private MustBeRefresh mustBeRefresh; - private InterestLifeTime interestLifeTime; - private Nonce nonce; - private HopLimit hopLimit; - private Payload payload; - private CongestionMark congestionMark; - private Identifier name; + public MINPacket minPacket=new MINPacket(); + public CanBePrefix canBePrefix=new CanBePrefix(); + private MustBeRefresh mustBeRefresh=new MustBeRefresh(); + private InterestLifeTime interestLifeTime=new InterestLifeTime(); + private Nonce nonce=new Nonce(); + private HopLimit hopLimit=new HopLimit(); + private Payload payload=new Payload(); + private CongestionMark congestionMark=new CongestionMark(); + private TTL ttl=new TTL(); + private NackHeader nackHeader=new NackHeader(); + + private Identifier name=new Identifier(); /** * 获取内容兴趣包的名字 @@ -72,7 +76,6 @@ public class Interest implements InteractWithField, IEncodingAble { */ public boolean matchesName(Identifier identifier) { throw new Error("implement me"); -// return identifier.toUri().equals(this.name.toUri()); } /** @@ -83,7 +86,6 @@ public class Interest implements InteractWithField, IEncodingAble { */ public boolean matchesData(Data data) { throw new Error("implement me"); -// return data.toUri().equals(this.) } /** @@ -128,6 +130,13 @@ public class Interest implements InteractWithField, IEncodingAble { this.minPacket.mutableField.mutableProtectField.addBlock(block); // 填充可变非受保护区(无) + this.minPacket.mutableField.mutableDangerousField.clearBlocks(); + // ttl + block = new SelfEncodingBase().selfWireEncode(this.ttl); + if (block == null) { + return false; + } + this.minPacket.mutableField.mutableDangerousField.addBlock(block); ///////////////////////////////////////////////////////////// //// 填充只读区 @@ -183,6 +192,15 @@ public class Interest implements InteractWithField, IEncodingAble { this.minPacket.readOnlyField.addBlock(block); } + // NackHeader + if(this.nackHeader.isInitial()){ + block = new SelfEncodingBase().selfWireEncode(this.nackHeader); + if (block == null) { + return false; + } + this.minPacket.readOnlyField.addBlock(block); + } + // Payload block = new SelfEncodingBase().selfWireEncode(this.payload); if (block == null) { @@ -201,7 +219,6 @@ public class Interest implements InteractWithField, IEncodingAble { } this.minPacket.identifierField.addIdentifier(identifierWrapper); - return true; } catch (EncoderException | BlockException | ComponentException e) { throw new PacketException("Interest.fillDataToFields: " + e.getMessage()); @@ -223,17 +240,22 @@ public class Interest implements InteractWithField, IEncodingAble { // [CongestionMark] // } // { => 非受保护区 - // "Empty" + // [TTL] // } // } ///////////////////////////////////////////////////////////// - Block block = this.minPacket.mutableField.mutableProtectField.getBlockByType(new VlInt(TLV.TlvCongestionMark)); if (block != null) { if (!this.congestionMark.wireDecode(block)) { return false; } } + block=this.minPacket.mutableField.mutableDangerousField.getBlockByType(new VlInt(TLV.TlvTTL)); + if (block != null) { + if (!this.ttl.wireDecode(block)) { + return false; + } + } ///////////////////////////////////////////////////////////// //// 解析只读区 @@ -249,8 +271,7 @@ public class Interest implements InteractWithField, IEncodingAble { ElementContainer elementContainer = this.minPacket.readOnlyField.getBlocks(); int len = elementContainer.length(); for (int i = 0; i < len; i++) { - Block newblock = null; - newblock = elementContainer.getBlock(i); + Block newblock = elementContainer.getBlock(i); int type; type = newblock.getType().getVlIntValue2Int(); switch (type) { @@ -279,6 +300,11 @@ public class Interest implements InteractWithField, IEncodingAble { return false; } break; + case TLV.TlvNackHeader: + if(!this.nackHeader.wireDecode(newblock)){ + return false; + } + break; case TLV.TlvPayload: if (!this.payload.wireDecode(newblock)) { return false; diff --git a/src/main/java/packet/LpPacket.java b/src/main/java/packet/LpPacket.java new file mode 100644 index 0000000..6b4ac63 --- /dev/null +++ b/src/main/java/packet/LpPacket.java @@ -0,0 +1,11 @@ +package packet; + +/* + * @Author: Wang Feng + * @Description: + * @Version: 1.0.0 + * @Date: 17:33 2021/4/2 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ +public class LpPacket { +} diff --git a/src/main/java/packet/MINPacket.java b/src/main/java/packet/MINPacket.java index 958b98d..7753f2d 100644 --- a/src/main/java/packet/MINPacket.java +++ b/src/main/java/packet/MINPacket.java @@ -10,12 +10,12 @@ import encoding.*; * @Date: 22:07 2021/3/13 * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 */ -public class MINPacket implements IEncodingAble { - public IdentifierField identifierField; // 标识区 - private SignatureField signatureField; // 签名区 - public ReadOnlyField readOnlyField; // 只读区 - public MutableField mutableField; // 可变区 - public VlInt packetType; // 包类型 +public class MINPacket implements IEncodingAble,IMINPacket { + public IdentifierField identifierField=new IdentifierField(); // 标识区 + public SignatureField signatureField=new SignatureField(); // 签名区 + public ReadOnlyField readOnlyField=new ReadOnlyField(); // 只读区 + public MutableField mutableField=new MutableField(); // 可变区 + public VlInt packetType=new VlInt(TLV.TlvInvalid); // 包类型 /** * 判断 MIN 包是否是一个有效的包 @@ -44,8 +44,7 @@ public class MINPacket implements IEncodingAble { // 编码 TLV-VALUE // 可变区 - int tmplen = 0; - tmplen = this.mutableField.wireEncode(encoder); + int tmplen = this.mutableField.wireEncode(encoder); if (tmplen <= 0) { return -1; } @@ -81,7 +80,6 @@ public class MINPacket implements IEncodingAble { // 编码包 TLV-TYPE tmplen = encoder.prependVarNumber(this.packetType); - if (tmplen <= 0) { return -1; } @@ -122,14 +120,8 @@ public class MINPacket implements IEncodingAble { // 解析四个标识区 int elementSize = block.getSubElements().length(); for (int i = 0; i < elementSize; i++) { - Block cacheBlock = null; - try { - cacheBlock = block.getSubElements().getBlock(i); - } catch (BlockException e) { - throw new Error("MINPacket.wireDecode: " + e.getMessage()); - } - int judgeType = 0; - judgeType = cacheBlock.getType().getVlIntValue2Int(); + Block cacheBlock = block.getSubElements().getBlock(i); + int judgeType = cacheBlock.getType().getVlIntValue2Int(); switch (judgeType) { case TLV.TlvIdentifierField: // 目的标识区 // 解析标识区,保证其中至少存在一个标识 diff --git a/src/main/java/packet/Nack.java b/src/main/java/packet/Nack.java new file mode 100644 index 0000000..5463e6c --- /dev/null +++ b/src/main/java/packet/Nack.java @@ -0,0 +1,11 @@ +package packet; + +/* + * @Author: Wang Feng + * @Description: + * @Version: 1.0.0 + * @Date: 17:34 2021/4/2 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ +public class Nack { +} diff --git a/src/main/java/security/KeyChain.java b/src/main/java/security/KeyChain.java index b20c04f..4b6a7f9 100644 --- a/src/main/java/security/KeyChain.java +++ b/src/main/java/security/KeyChain.java @@ -2,8 +2,6 @@ package security; import minsecurity.identity.Identity; import minsecurity.identity.IdentityException; -import org.checkerframework.checker.units.qual.K; - /* * @Author: hongyu guo * @Description: 用于给网络包签名和验签 @@ -80,6 +78,7 @@ public class KeyChain { } } + // TODO: packet类暂未完成 // public void getIdentifierAndReadOnlyValueFromPacket(){ // diff --git a/src/test/java/packet/MINPacketTest.java b/src/test/java/packet/MINPacketTest.java new file mode 100644 index 0000000..25e7268 --- /dev/null +++ b/src/test/java/packet/MINPacketTest.java @@ -0,0 +1,12 @@ +package packet; + +/* + * @Author: Wang Feng + * @Description: + * @Version: 1.0.0 + * @Date: 11:17 2021/4/2 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ +public class MINPacketTest { + +}