2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.domain
22 import arrow.core.Either
23 import arrow.core.Either.Companion.left
24 import arrow.core.Either.Companion.right
28 * Wire frame structure is presented bellow using ASN.1 notation. Please note that official supported specification
29 * should be available on
30 * [RTD documentation](https://onap.readthedocs.io/en/latest/submodules/dcaegen2.git/docs/sections/apis/ves-hv.html).
33 * -- Wire Transfer Protocol (binary, defined using ASN.1 notation)
34 * -- Encoding: use "direct encoding" to the number of octets indicated in the comment [n], using network byte order.
36 * WTP DEFINITIONS ::= BEGIN
38 * -- Used to sent data from the data provider
39 * WtpData ::= SEQUENCE {
40 * magic INTEGER (0..255), -- [1] always 0xAA
41 * versionMajor INTEGER (0..255), -- [1] major interface version, forward incompatible
42 * -- with previous major version, current value: 1
43 * versionMinor INTEGER (0..255), -- [1] minor interface version, forward compatible
44 * -- with previous minor version, current value: 0
45 * reserved OCTET STRING (SIZE (3)), -- [3] reserved for future use (ignored, but use 0)
46 * payloadId INTEGER (0..65535), -- [2] payload type: 0x0000=undefined, 0x0001=ONAP VesEvent (protobuf)
47 * payloadLength INTEGER (0..4294967295). -- [4] payload length in octets
48 * payload OCTET STRING -- [length as per payloadLength]
54 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
57 data class WireFrameMessage(val payload: ByteData,
58 val versionMajor: Short,
59 val versionMinor: Short,
63 constructor(payload: ByteArray) : this(
65 SUPPORTED_VERSION_MAJOR,
66 SUPPORTED_VERSION_MINOR,
67 PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue,
70 fun validate(): Either<WireFrameMessageValidationError, WireFrameMessage> =
72 versionMajor != SUPPORTED_VERSION_MAJOR -> left(InvalidMajorVersion(versionMajor))
73 !PayloadContentType.isValidHexValue(payloadType) -> left(UnsupportedPayloadContentType(payloadType))
74 payload.size() != payloadSize -> left(NotMatchingPayloadSize(payload.size(), payloadSize))
79 const val MARKER_BYTE: Short = 0xAA
80 const val RESERVED_BYTE_COUNT: Int = 3
82 const val SUPPORTED_VERSION_MAJOR: Short = 1
83 const val SUPPORTED_VERSION_MINOR: Short = 0
85 const val HEADER_SIZE =
86 1 * java.lang.Byte.BYTES + // marker
87 2 * java.lang.Byte.BYTES + // single byte fields
88 1 * java.lang.Short.BYTES + // double byte fields
89 RESERVED_BYTE_COUNT * java.lang.Byte.BYTES + // reserved bytes
90 1 * java.lang.Integer.BYTES // payload length
92 const val DEFAULT_MAX_PAYLOAD_SIZE_BYTES = 1024 * 1024