diff options
Diffstat (limited to 'hv-collector-domain/src/main')
3 files changed, 50 insertions, 13 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 = |