Fix more rib-impl checkstyle
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPMessageHeaderDecoder.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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.protocol.bgp.rib.impl;
9
10 import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
11
12 /**
13  * Decoder for BGP message headers.
14  * @see <a href="http://tools.ietf.org/html/rfc4271#section-4.1">BGP Message Header</a>
15  */
16 final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
17
18     private static final int MARKER_SIZE = 16;
19
20     /*
21      * the length field represents the length of the whole message including the header
22      */
23     private static final int LENGTH_SIZE = 2;
24
25     private static final int MAX_FRAME_SIZE = 4096;
26
27     private static final int EXTENDED_MAX_FRAME_SIZE = 65535;
28
29     /*
30
31      0                   1                   2                   3
32       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
33       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34       |                                                               |
35       |                                                               |
36       |                                                               |
37       |                                                               |
38       |                           Marker                              |
39       |                                                               |
40       |                                                               |
41       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42       |          Length               |      Type     |
43       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44
45      */
46
47
48     private BGPMessageHeaderDecoder(final int maxFrameSize) {
49         super(maxFrameSize, MARKER_SIZE, LENGTH_SIZE, -MARKER_SIZE - LENGTH_SIZE, 0);
50     }
51
52     static BGPMessageHeaderDecoder getBGPMessageHeaderDecoder() {
53         return new BGPMessageHeaderDecoder(MAX_FRAME_SIZE);
54     }
55
56     static BGPMessageHeaderDecoder getExtendedBGPMessageHeaderDecoder() {
57         return new BGPMessageHeaderDecoder(EXTENDED_MAX_FRAME_SIZE);
58     }
59
60
61 }