blob: 883be89ba9e4a7f80732f8ee7fac3d3513ad8f5d [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
Yuta HIGUCHI1edc36b2018-01-24 23:39:06 -080019import java.util.Arrays;
Mohammad Shahid30fedc52017-08-09 11:49:40 +053020import org.jboss.netty.buffer.ChannelBuffer;
21import com.google.common.base.MoreObjects;
22
23/**
24 * Implementation of EthernetSegmentidentifier.
25 */
26public class BgpEvpnEsi
27 implements Comparable<BgpEvpnEsi> {
28
29 public static final int ESI_LENGTH = 10;
30 private byte[] ethernetSegmentidentifier;
31
32 /**
33 * Resets fields.
34 */
35 public BgpEvpnEsi() {
36 this.ethernetSegmentidentifier = null;
37 }
38
39 /**
40 * Constructor to initialize parameters.
41 *
42 * @param ethernetSegmentidentifier Ethernet Segment identifier
43 */
44 public BgpEvpnEsi(byte[] ethernetSegmentidentifier) {
45 this.ethernetSegmentidentifier = ethernetSegmentidentifier;
46 }
47
48 /**
49 * Reads Ethernet Segment identifier from channelBuffer.
50 *
51 * @param cb channelBuffer
52 * @return object of EthernetSegmentidentifier
53 */
54 public static BgpEvpnEsi read(ChannelBuffer cb) {
55 return new BgpEvpnEsi(cb.readBytes(10).array());
56 }
57
58 /**
59 * writes Ethernet Segment identifier into channelBuffer.
60 *
61 * @param cb channelBuffer
62 * @return length length of written data
63 */
64 public int write(ChannelBuffer cb) {
65 int iLenStartIndex = cb.writerIndex();
66 cb.writeBytes(ethernetSegmentidentifier);
67 return cb.writerIndex() - iLenStartIndex;
68 }
69
70 /**
71 * Returns Ethernet Segment identifier.
72 *
73 * @return Ethernet Segment identifier.
74 */
75 public byte[] getEthernetSegmentidentifier() {
76 return this.ethernetSegmentidentifier;
77 }
78
79 @Override
80 public int hashCode() {
Yuta HIGUCHI1edc36b2018-01-24 23:39:06 -080081 return Arrays.hashCode(ethernetSegmentidentifier);
Mohammad Shahid30fedc52017-08-09 11:49:40 +053082 };
83
84 @Override
85 public boolean equals(Object obj) {
86 if (this == obj) {
87 return true;
88 }
89
90 if (obj instanceof BgpEvpnEsi) {
91 BgpEvpnEsi that = (BgpEvpnEsi) obj;
Yuta HIGUCHI1edc36b2018-01-24 23:39:06 -080092 return Arrays.equals(this.ethernetSegmentidentifier, that.ethernetSegmentidentifier);
Mohammad Shahid30fedc52017-08-09 11:49:40 +053093 }
94
95 return false;
96 }
97
98 @Override
99 public String toString() {
100 return MoreObjects.toStringHelper(getClass())
101 .add("ethernetSegmentidentifier", ethernetSegmentidentifier)
102 .toString();
103 }
104
105 @Override
106 public int compareTo(BgpEvpnEsi rd) {
107 return 0;
108 }
109}