bharat saraswal | f7364db | 2015-08-11 13:39:31 +0530 | [diff] [blame] | 1 | /*
|
| 2 | * Copyright 2015 Open Networking Laboratory
|
| 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.pcepio.types;
|
| 18 |
|
| 19 | import java.util.Objects;
|
| 20 |
|
| 21 | import org.jboss.netty.buffer.ChannelBuffer;
|
| 22 | import org.onosproject.pcepio.protocol.PcepNai;
|
| 23 |
|
| 24 | import com.google.common.base.MoreObjects;
|
| 25 |
|
Phanendra Manda | 51fb9c2 | 2015-09-01 16:17:41 +0530 | [diff] [blame] | 26 | /**
|
| 27 | * Provides Pcep Nai Ipv4 Node Id.
|
| 28 | */
|
bharat saraswal | f7364db | 2015-08-11 13:39:31 +0530 | [diff] [blame] | 29 | public class PcepNaiIpv4NodeId implements PcepNai {
|
| 30 |
|
| 31 | public static final byte ST_TYPE = 0x01;
|
| 32 |
|
| 33 | private final int ipv4NodeId;
|
| 34 |
|
| 35 | /**
|
| 36 | * Constructor to initialize ipv4NodeId.
|
| 37 | *
|
| 38 | * @param value ipv4 node id
|
| 39 | */
|
| 40 | public PcepNaiIpv4NodeId(int value) {
|
| 41 | this.ipv4NodeId = value;
|
| 42 | }
|
| 43 |
|
| 44 | /**
|
| 45 | * Returns an object of PcepNaiIpv4NodeId.
|
| 46 | *
|
| 47 | * @param value ipv4 node id
|
| 48 | * @return object of PcepNaiIpv4NodeId
|
| 49 | */
|
| 50 | public static PcepNaiIpv4NodeId of(int value) {
|
| 51 | return new PcepNaiIpv4NodeId(value);
|
| 52 | }
|
| 53 |
|
| 54 | @Override
|
| 55 | public byte getType() {
|
| 56 | return ST_TYPE;
|
| 57 | }
|
| 58 |
|
| 59 | @Override
|
| 60 | public int write(ChannelBuffer bb) {
|
| 61 | int iLenStartIndex = bb.writerIndex();
|
| 62 | bb.writeInt(ipv4NodeId);
|
| 63 | return bb.writerIndex() - iLenStartIndex;
|
| 64 | }
|
| 65 |
|
| 66 | /**
|
| 67 | * Reads from the channel buffer and returns object of PcepNAIIpv4NodeIdVer1.
|
| 68 | *
|
| 69 | * @param bb of channel buffer.
|
| 70 | * @return object of PcepNAIIpv4NodeIdVer1
|
| 71 | */
|
| 72 | public static PcepNaiIpv4NodeId read(ChannelBuffer bb) {
|
| 73 | return new PcepNaiIpv4NodeId(bb.readInt());
|
| 74 | }
|
| 75 |
|
| 76 | @Override
|
| 77 | public int hashCode() {
|
| 78 | return Objects.hash(ipv4NodeId);
|
| 79 | }
|
| 80 |
|
| 81 | @Override
|
| 82 | public boolean equals(Object obj) {
|
| 83 | if (this == obj) {
|
| 84 | return true;
|
| 85 | }
|
| 86 | if (obj instanceof PcepNaiIpv4NodeId) {
|
| 87 | PcepNaiIpv4NodeId other = (PcepNaiIpv4NodeId) obj;
|
| 88 | return Objects.equals(this.ipv4NodeId, other.ipv4NodeId);
|
| 89 | }
|
| 90 | return false;
|
| 91 | }
|
| 92 |
|
| 93 | @Override
|
| 94 | public String toString() {
|
bharat saraswal | e180630 | 2015-08-21 12:16:46 +0530 | [diff] [blame] | 95 | return MoreObjects.toStringHelper(getClass()).add("IPv4NodeId", ipv4NodeId).toString();
|
bharat saraswal | f7364db | 2015-08-11 13:39:31 +0530 | [diff] [blame] | 96 | }
|
| 97 | }
|