blob: 60348ace07c3cce1345b1c738103e70e80363cb7 [file] [log] [blame]
Mohammad Shahid30fedc52017-08-09 11:49:40 +05301/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.bgpio.types;
18
19import java.util.Objects;
20import org.jboss.netty.buffer.ChannelBuffer;
21import com.google.common.base.MoreObjects;
22
23public class BgpEvpnLabel implements Comparable<BgpEvpnLabel> {
24
25 public static final int MPLS_LABEL_LENGTH = 3;
26 private byte[] mplsLabel;
27
28 /**
29 * Resets fields.
30 */
31 public BgpEvpnLabel() {
32 this.mplsLabel = null;
33 }
34
35 /**
36 * Constructor to initialize parameters.
37 *
38 * @param bgpEvpnLabel mpls label
39 */
40 public BgpEvpnLabel(byte[] bgpEvpnLabel) {
41 this.mplsLabel = bgpEvpnLabel;
42 }
43
44 /**
45 * Reads mpls label from channelBuffer.
46 *
47 * @param cb channelBuffer
48 * @return object of mpls label
49 */
50 public static BgpEvpnLabel read(ChannelBuffer cb) {
51 return new BgpEvpnLabel(cb.readBytes(3).array());
52 }
53
54 /**
55 * writes mpls label into channelBuffer.
56 *
57 * @param cb channelBuffer
58 * @return length length of written data
59 */
60 public int write(ChannelBuffer cb) {
61 int iLenStartIndex = cb.writerIndex();
62 cb.writeBytes(mplsLabel);
63 return cb.writerIndex() - iLenStartIndex;
64 }
65
66 /**
67 * Returns mpls label.
68 *
69 * @return mpls label
70 */
71 public byte[] getMplsLabel() {
72 return this.mplsLabel;
73 }
74
75 @Override
76 public int compareTo(BgpEvpnLabel mplsLabel) {
77 return 0;
78 }
79
80 @Override
81 public boolean equals(Object obj) {
82 if (this == obj) {
83 return true;
84 }
85
86 if (obj instanceof BgpEvpnLabel) {
87
88 BgpEvpnLabel that = (BgpEvpnLabel) obj;
89
90 if (this.mplsLabel == that.mplsLabel) {
91 return true;
92 }
93 }
94
95 return false;
96 }
97
98 @Override
99 public int hashCode() {
100 return Objects.hashCode(mplsLabel);
101 }
102
103 @Override
104 public String toString() {
105 return MoreObjects.toStringHelper(getClass())
106 .add("mplsLabel", mplsLabel).toString();
107 }
108}