1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*
* ============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
/**
* Wire frame structure is presented bellow using ASN.1 notation. Please note that official supported specification
* should be available on
* [RTD documentation](https://onap.readthedocs.io/en/latest/submodules/dcaegen2.git/docs/sections/apis/ves-hv.html).
*
* ```
* -- Wire Transfer Protocol (binary, defined using ASN.1 notation)
* -- Encoding: use "direct encoding" to the number of octets indicated in the comment [n], using network byte order.
*
* WTP DEFINITIONS ::= BEGIN
*
* -- Used to sent data from the data provider
* WtpData ::= SEQUENCE {
* magic INTEGER (0..255), -- [1] always 0xAA
* versionMajor INTEGER (0..255), -- [1] major interface version, forward incompatible
* -- with previous major version, current value: 1
* versionMinor INTEGER (0..255), -- [1] minor interface version, forward compatible
* -- with previous minor version, current value: 0
* reserved OCTET STRING (SIZE (3)), -- [3] reserved for future use (ignored, but use 0)
* payloadId INTEGER (0..65535), -- [2] payload type: 0x0000=undefined, 0x0001=ONAP VesEvent (protobuf)
* payloadLength INTEGER (0..4294967295). -- [4] payload length in octets
* payload OCTET STRING -- [length as per payloadLength]
* }
*
* END
* ```
*
* @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
* @since May 2018
*/
data class WireFrameMessage(val payload: ByteData,
val versionMajor: Short,
val versionMinor: Short,
val payloadType: Int,
val payloadSize: Int
) {
constructor(payload: ByteArray) : this(
ByteData(payload),
SUPPORTED_VERSION_MAJOR,
SUPPORTED_VERSION_MINOR,
PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue,
payload.size)
fun isValid(): Boolean =
versionMajor == SUPPORTED_VERSION_MAJOR
&& PayloadContentType.isValidHexValue(payloadType)
&& payload.size() == payloadSize
companion object {
const val MARKER_BYTE: Short = 0xAA
const val RESERVED_BYTE_COUNT: Int = 3
const val SUPPORTED_VERSION_MAJOR: Short = 1
const val SUPPORTED_VERSION_MINOR: Short = 0
const val HEADER_SIZE =
1 * java.lang.Byte.BYTES + // marker
2 * java.lang.Byte.BYTES + // single byte fields
1 * java.lang.Short.BYTES + // double byte fields
RESERVED_BYTE_COUNT * java.lang.Byte.BYTES + // reserved bytes
1 * java.lang.Integer.BYTES // payload length
const val DEFAULT_MAX_PAYLOAD_SIZE_BYTES = 1024 * 1024
}
}
|