Netty Replicator - improve the reconnection and keepalive mechanisms
[mdsal.git] / replicate / mdsal-replicate-netty / src / main / java / org / opendaylight / mdsal / replicate / netty / Constants.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.replicate.netty;
9
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.Unpooled;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14
15 final class Constants {
16     /**
17      * Subscribe request message. This is the only valid initial message in the sink->source direction. Its payload is
18      * composed of a binary normalized node stream. The stream must contain a {@link LogicalDatastoreType} serialized
19      * via {@link LogicalDatastoreType#writeTo(java.io.DataOutput)} followed by a single {@link YangInstanceIdentifier}.
20      */
21     static final byte MSG_SUBSCRIBE_REQ = 1;
22     /**
23      * Initial data indicating non-presence of the subscribed path.
24      */
25     static final byte MSG_EMPTY_DATA    = 2;
26     /**
27      * A chunk of the DataTreeCandidate serialization stream. May be followed by another chunk or
28      * {@link #MSG_DTC_APPLY}.
29      */
30     static final byte MSG_DTC_CHUNK     = 3;
31     /**
32      * End-of-DataTreeCandidate serialization stream. The payload is empty.
33      */
34     static final byte MSG_DTC_APPLY     = 4;
35     /**
36      * Verify the connection is alive.
37      */
38     static final int MSG_PING           = 5;
39     /**
40      * Verify the connection is alive.
41      */
42     static final int MSG_PONG           = 6;
43
44     /**
45      * Length of the length field in each transmitted frame.
46      */
47     static final int LENGTH_FIELD_LENGTH = 4;
48     /**
49      * Maximum frame size allowed by encoding, 1MiB.
50      */
51     static final int LENGTH_FIELD_MAX    = 1024 * 1024;
52
53     static final ByteBuf EMPTY_DATA = Unpooled.unreleasableBuffer(
54         Unpooled.wrappedBuffer(new byte[] { MSG_EMPTY_DATA }));
55
56     static final ByteBuf DTC_APPLY = Unpooled.unreleasableBuffer(Unpooled.wrappedBuffer(new byte[] { MSG_DTC_APPLY }));
57
58     static final ByteBuf PING = Unpooled.unreleasableBuffer(
59         Unpooled.wrappedBuffer(new byte[] { MSG_PING }));
60
61     static final ByteBuf PONG = Unpooled.unreleasableBuffer(
62         Unpooled.wrappedBuffer(new byte[] { MSG_PONG }));
63
64     private Constants() {
65         // Hidden on purpose
66     }
67 }