Mohammad Shahid | 30fedc5 | 2017-08-09 11:49:40 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.bgpio.types; |
| 18 | |
| 19 | import java.util.Objects; |
| 20 | import org.jboss.netty.buffer.ChannelBuffer; |
| 21 | import com.google.common.base.MoreObjects; |
| 22 | |
| 23 | /** |
| 24 | * Implementation of EthernetSegmentidentifier. |
| 25 | */ |
| 26 | public 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() { |
| 81 | return Objects.hash(ethernetSegmentidentifier); |
| 82 | }; |
| 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; |
| 92 | if (this.ethernetSegmentidentifier == that.ethernetSegmentidentifier) { |
| 93 | return true; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public String toString() { |
| 102 | return MoreObjects.toStringHelper(getClass()) |
| 103 | .add("ethernetSegmentidentifier", ethernetSegmentidentifier) |
| 104 | .toString(); |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public int compareTo(BgpEvpnEsi rd) { |
| 109 | return 0; |
| 110 | } |
| 111 | } |