diff --git a/build.gradle b/build.gradle index 643f0d3b814b1321e9cb38b22fd72dd51d7d1510..6f925af1987f8c0b502b39b0f8809bf8d6692f35 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { group 'org.bdware.doip' -version '1.5.5' +version '1.5.6' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 repositories { diff --git a/src/main/codec/org/bdware/doip/codec/v3/DOIPV3Codec.java b/src/main/codec/org/bdware/doip/codec/v3/DOIPV3Codec.java index 785ad0b960ad5453921fd15d1e4cb27c39536e20..d1716cf1080243ef18c15d446b2add0e0acb44ad 100644 --- a/src/main/codec/org/bdware/doip/codec/v3/DOIPV3Codec.java +++ b/src/main/codec/org/bdware/doip/codec/v3/DOIPV3Codec.java @@ -15,7 +15,7 @@ public class DOIPV3Codec extends ByteToMessageCodec { @Override protected void encode(ChannelHandlerContext ctx, DOIPV3Message msg, ByteBuf out) throws Exception { - LOGGER.info("[DOIPV3Codec Send] " + msg.prettyPrint() + " from:" + ctx.channel().remoteAddress().toString()); + LOGGER.info("[DOIPV3Codec Send] " + msg.prettyPrint() + " to:" + ctx.channel().remoteAddress().toString()); msg.writeTo(out); } @Override diff --git a/src/main/codec/org/bdware/doip/codec/v3/ExtensionPartFactory.java b/src/main/codec/org/bdware/doip/codec/v3/ExtensionPartFactory.java index dc40a89521dd96e942f76fa9cfddf3e011ff6b15..87fe4b83efeb2acd9134941024325282d5561fea 100644 --- a/src/main/codec/org/bdware/doip/codec/v3/ExtensionPartFactory.java +++ b/src/main/codec/org/bdware/doip/codec/v3/ExtensionPartFactory.java @@ -15,6 +15,8 @@ public class ExtensionPartFactory { return new VDNHeader(bf); case ExceptionHead: return new ExceptionHead(bf); + case TOKENHeader: + return new TOKENHeader(bf); default: return null; } diff --git a/src/main/codec/org/bdware/doip/codec/v3/headers/DOLHeader.java b/src/main/codec/org/bdware/doip/codec/v3/headers/DOLHeader.java index 43ab592c2cc97f9d6dada6f3336c0852821a6e0f..e42ae851b3fe195cb4e7a8224ec54fd8e3da3e31 100644 --- a/src/main/codec/org/bdware/doip/codec/v3/headers/DOLHeader.java +++ b/src/main/codec/org/bdware/doip/codec/v3/headers/DOLHeader.java @@ -33,6 +33,10 @@ public class DOLHeader extends ExtensionPart { } } + public byte[] getDol() { + return dol; + } + @Override public void writeTo(ByteBuf bf) { //keep the correctness of nextType @@ -46,7 +50,7 @@ public class DOLHeader extends ExtensionPart { @Override public int length() { - return 1 + 4 + ((dol == null) ? 0 : dol.length); + return 4 + 4 + ((dol == null) ? 0 : dol.length); } @Override diff --git a/src/main/codec/org/bdware/doip/codec/v3/headers/ExtensionType.java b/src/main/codec/org/bdware/doip/codec/v3/headers/ExtensionType.java index 88ed9f090c43d071f938865802063044093c6b4d..a2a29c4f206fe3a8fc91e3ef251f871b7cc7fec3 100644 --- a/src/main/codec/org/bdware/doip/codec/v3/headers/ExtensionType.java +++ b/src/main/codec/org/bdware/doip/codec/v3/headers/ExtensionType.java @@ -1,7 +1,8 @@ package org.bdware.doip.codec.v3.headers; public enum ExtensionType { - DOLHeader(0), ENVELOPE(1), VDNHeader(2), ExceptionHead(3), UNKNOWN((-1)); + DOLHeader(0), ENVELOPE(1), VDNHeader(2), ExceptionHead(3), UNKNOWN(-1), + TOKENHeader(4); public final int value; ExtensionType(int i) { @@ -18,6 +19,8 @@ public enum ExtensionType { return VDNHeader; case 3: return ExceptionHead; + case 4: + return TOKENHeader; default: return UNKNOWN; } diff --git a/src/main/codec/org/bdware/doip/codec/v3/headers/TOKENHeader.java b/src/main/codec/org/bdware/doip/codec/v3/headers/TOKENHeader.java new file mode 100644 index 0000000000000000000000000000000000000000..ed9503b1baeb897294b5ac4c326021304474c0ed --- /dev/null +++ b/src/main/codec/org/bdware/doip/codec/v3/headers/TOKENHeader.java @@ -0,0 +1,50 @@ +package org.bdware.doip.codec.v3.headers; + +import io.netty.buffer.ByteBuf; + +public class TOKENHeader extends ExtensionPart { + public int nextHeader; + public int tokenLength; + public byte[] token; //string to byte[] + public TOKENHeader(ByteBuf bf) { + super(); + nextHeader = bf.readInt(); + nextType = ExtensionType.fromInt(nextHeader); + tokenLength = bf.readInt(); + if (tokenLength > 0) { + token = new byte[tokenLength]; + bf.readBytes(token); + } + } + + public TOKENHeader() { + } + + @Override + public void writeTo(ByteBuf bf) { + //keep the correctness of nextType + nextHeader = nextType.value; + bf.writeInt(nextHeader); + if (token != null && token.length > 0) { + bf.writeInt(token.length); + bf.writeBytes(token); + } else bf.writeInt(0); + } + + @Override + public int length() { + return 4 + 4 + ((token == null) ? 0 : token.length); + } + + + @Override + public ExtensionType getType() { + return ExtensionType.TOKENHeader; + } + + @Override + public String prettyPrint() { + return getType().name() + " token:" + token; + } + +} diff --git a/src/main/codec/org/bdware/doip/codec/v3/operations/BasicOperationsV3.java b/src/main/codec/org/bdware/doip/codec/v3/operations/BasicOperationsV3.java new file mode 100644 index 0000000000000000000000000000000000000000..4e467ee9b2f765c998985bd4bdf5314825d7caa7 --- /dev/null +++ b/src/main/codec/org/bdware/doip/codec/v3/operations/BasicOperationsV3.java @@ -0,0 +1,33 @@ +package org.bdware.doip.codec.v3.operations; +public enum BasicOperationsV3 { + CreateVPN("0.DOIP/Op.CreateVPN"), //todo: VPN->VDN + RetrieveVPN("0.DOIP/Op.UpdateVPN"), + InitVDN("0.DOIP/Op.InitVDN"), + UpdateVDN("0.DOIP/Op.UpdateVDN"), + AddGWToVDN("0.DOIP/Op.AddGWToVDN"), + DeleteGWFromVDN("0.DOIP/Op.DeleteGWFromVDN"), + DeleteVDN("0.DOIP/Op.DeleteVDN"), + InquireVDN("0.DOIP/Op.InquireVDN"), + SearchVDN("0.DOIP/Op.InitVDN"), + Unknown("0.DOIP/Op.Unknown"); + + private final String name; + + BasicOperationsV3(String displayName) { + this.name = displayName; + } + + public static BasicOperationsV3 getDoOp(String opStr) { + for (BasicOperationsV3 op : BasicOperationsV3.values()) { + if (op.getName().equals(opStr)) { + return op; + } + } + return Unknown; + } + + public String getName() { + return name; + } +} +