Harmonize logging and add new logs
[dcaegen2/collectors/hv-ves.git] / sources / hv-collector-domain / src / main / kotlin / org / onap / dcae / collectors / veshv / domain / errors.kt
1 /*
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.dcae.collectors.veshv.domain
21
22 /**
23  * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
24  * @since June 2018
25  */
26
27 sealed class WireFrameDecodingError(val message: String)
28
29
30 // Invalid frame errors
31
32 sealed class InvalidWireFrame(msg: String) : WireFrameDecodingError(msg)
33
34 class InvalidWireFrameMarker(actualMarker: Short) : InvalidWireFrame(
35         "Invalid start of frame. Expected 0x%02X, but was 0x%02X"
36                 .format(WireFrameMessage.MARKER_BYTE, actualMarker)
37 )
38
39 class PayloadSizeExceeded(maxPayloadSizeBytes: Int) :
40         InvalidWireFrame("payload size exceeds the limit ($maxPayloadSizeBytes bytes)")
41
42 // Missing bytes errors
43
44 sealed class MissingWireFrameBytes(msg: String) : WireFrameDecodingError(msg)
45
46 object MissingWireFrameHeaderBytes : MissingWireFrameBytes("readable bytes < header size")
47 object MissingWireFramePayloadBytes : MissingWireFrameBytes("readable bytes < payload size")
48 object EmptyWireFrame : MissingWireFrameBytes("empty wire frame")
49
50 // WireFrameMessage validation exceptions
51
52 sealed class WireFrameMessageValidationError(val message: String)
53
54 class InvalidMajorVersion(actualVersion: Short) : WireFrameMessageValidationError(
55         "Invalid major version in wire frame header. " +
56                 "Expected ${WireFrameMessage.SUPPORTED_VERSION_MAJOR} but was $actualVersion")
57
58 class UnsupportedPayloadContentType(actualType: Int) : WireFrameMessageValidationError(
59         "Invalid content type in wire frame header. " +
60                 "Expected one of ${PayloadContentType.hexValues}, but was $actualType")
61
62 class NotMatchingPayloadSize(definedInHeader: Int, actual: Int) : WireFrameMessageValidationError(
63         "Payload size does not match one defined in wire frame header.\n" +
64                 "Defined in header: $definedInHeader, but was: $actual")