diff options
author | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-06-19 10:27:53 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-02 09:57:34 +0200 |
commit | bd8d6302d61a4b688c2b108549de99fca7f7175c (patch) | |
tree | 31d482f71e90e57380446afeb4a5b08d16a7886e /hv-collector-domain/src | |
parent | 67689405071acdad2b26d5112b3662605e474ce9 (diff) |
Include payload content type in wire frame
Closes ONAP-404
Change-Id: I6adfb542ffdafad678e7bc6e062d3d59c250b39e
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-domain/src')
4 files changed, 75 insertions, 26 deletions
diff --git a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/PayloadContentType.kt b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/PayloadContentType.kt new file mode 100644 index 00000000..0ba4b81d --- /dev/null +++ b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/PayloadContentType.kt @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2018 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.domain + +/** + * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> + * @since June 2018 + */ +enum class PayloadContentType(val hexValue: Short) { + GOOGLE_PROTOCOL_BUFFER(0x01); + + companion object { + private val hexValues = PayloadContentType.values().map { it.hexValue } + + fun isValidHexValue(hex: Short) = hexValues.contains(hex) + } +} diff --git a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrame.kt b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrame.kt index caf13c53..db6e1070 100644 --- a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrame.kt +++ b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrame.kt @@ -28,7 +28,7 @@ package org.onap.dcae.collectors.veshv.domain * ├─────┼──┬──┬──┬──┬──┬──┬──┬──┼──┬──┬──┬──┬──┬──┬──┬──┼──┬──┬──┬──┬──┬──┬──┬──┤ * │ bit │ 0│ │ │ │ │ │ │ │ 8│ │ │ │ │ │ │ │16│ │ │ │ │ │ │ │ ... * ├─────┼──┴──┴──┴──┴──┴──┴──┴──┼──┴──┴──┴──┴──┴──┴──┴──┼──┴──┴──┴──┴──┴──┴──┴──┤ - * │field│ 0xFF │ major version │ minor version │ + * │field│ 0xFF │ version │ payload content type │ * └─────┴───────────────────────┴───────────────────────┴───────────────────────┘ * ┌─────┬───────────────────────┬───────────────────────┬───────────────────────┬───────────────────────┐ * │octet│ 3 │ 4 │ 5 │ 6 │ @@ -50,24 +50,27 @@ package org.onap.dcae.collectors.veshv.domain * @since May 2018 */ data class WireFrame(val payload: ByteData, - val majorVersion: Short, - val minorVersion: Short, + val version: Short, + val payloadTypeRaw: Short, val payloadSize: Int) { - constructor(payload: ByteArray) : this(ByteData(payload), 1, 0, payload.size) + constructor(payload: ByteArray) : this( + ByteData(payload), + SUPPORTED_VERSION, + PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue, + payload.size) fun isValid(): Boolean = - majorVersion == SUPPORTED_MAJOR_VERSION + version == SUPPORTED_VERSION + && PayloadContentType.isValidHexValue(payloadTypeRaw) && payload.size() == payloadSize companion object { - const val SUPPORTED_MAJOR_VERSION: Short = 1 + const val SUPPORTED_VERSION: Short = 1 const val HEADER_SIZE = 3 * java.lang.Byte.BYTES + 1 * java.lang.Integer.BYTES const val MARKER_BYTE: Short = 0xFF - } - } diff --git a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt index d6804c7d..3cd9b19a 100644 --- a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt +++ b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt @@ -35,8 +35,8 @@ class WireFrameEncoder(val allocator: ByteBufAllocator) { val bb = allocator.buffer(WireFrame.HEADER_SIZE + frame.payload.size()) bb.writeByte(WireFrame.MARKER_BYTE.toInt()) - bb.writeByte(frame.majorVersion.toInt()) - bb.writeByte(frame.minorVersion.toInt()) + bb.writeByte(frame.version.toInt()) + bb.writeByte(frame.payloadTypeRaw.toInt()) bb.writeInt(frame.payloadSize) frame.payload.writeTo(bb) @@ -57,12 +57,12 @@ class WireFrameDecoder { verifyMarker(byteBuf) verifyMinimumSize(byteBuf) - val majorVersion = byteBuf.readUnsignedByte() - val minorVersion = byteBuf.readUnsignedByte() + val version = byteBuf.readUnsignedByte() + val payloadTypeRaw = byteBuf.readUnsignedByte() val payloadSize = verifyPayloadSize(byteBuf) val payload = ByteData.readFrom(byteBuf, payloadSize) - return WireFrame(payload, majorVersion, minorVersion, payloadSize) + return WireFrame(payload, version, payloadTypeRaw, payloadSize) } private fun verifyPayloadSize(byteBuf: ByteBuf): Int = diff --git a/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrameCodecsTest.kt b/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrameCodecsTest.kt index ed64f3b3..9694caf7 100644 --- a/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrameCodecsTest.kt +++ b/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrameCodecsTest.kt @@ -50,11 +50,23 @@ object WireFrameCodecsTest : Spek({ describe("Wire Frame invariants") { - given("input with unsupported major version") { + given("input with unsupported version") { val input = WireFrame( payload = ByteData.EMPTY, - majorVersion = 100, - minorVersion = 2, + version = 100, + payloadTypeRaw = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue, + payloadSize = 0) + + it("should fail validation") { + assertThat(input.isValid()).isFalse() + } + } + + given("input with unsupported payload type") { + val input = WireFrame( + payload = ByteData.EMPTY, + version = 1, + payloadTypeRaw = 0x69, payloadSize = 0) it("should fail validation") { @@ -65,8 +77,8 @@ object WireFrameCodecsTest : Spek({ given("input with too small payload size") { val input = WireFrame( payload = ByteData(byteArrayOf(1, 2, 3)), - majorVersion = 1, - minorVersion = 0, + version = 1, + payloadTypeRaw = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue, payloadSize = 1) it("should fail validation") { @@ -77,8 +89,8 @@ object WireFrameCodecsTest : Spek({ given("input with too big payload size") { val input = WireFrame( payload = ByteData(byteArrayOf(1, 2, 3)), - majorVersion = 1, - minorVersion = 0, + version = 1, + payloadTypeRaw = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue, payloadSize = 8) it("should fail validation") { @@ -90,8 +102,8 @@ object WireFrameCodecsTest : Spek({ val payload = byteArrayOf(6, 9, 8, 6) val input = WireFrame( payload = ByteData(payload), - majorVersion = 1, - minorVersion = 0, + version = 1, + payloadTypeRaw = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue, payloadSize = payload.size) it("should pass validation") { @@ -109,12 +121,12 @@ object WireFrameCodecsTest : Spek({ val encoded = encodeSampleFrame() val decoded = decoder.decodeFirst(encoded) - it("should decode major version") { - assertThat(decoded.majorVersion).isEqualTo(frame.majorVersion) + it("should decode version") { + assertThat(decoded.version).isEqualTo(frame.version) } - it("should decode minor version") { - assertThat(decoded.minorVersion).isEqualTo(frame.minorVersion) + it("should decode payload type") { + assertThat(decoded.payloadTypeRaw).isEqualTo(frame.payloadTypeRaw) } it("should decode payload size") { |