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 |
|
| 26 | public class PcepNaiIpv4Adjacency implements PcepNai {
|
| 27 |
|
| 28 | public static final byte ST_TYPE = 0x03;
|
| 29 | private final int localIpv4Addr;
|
| 30 | private final int remoteIpv4Addr;
|
| 31 |
|
| 32 | /**
|
| 33 | * Constructor to initialize variables.
|
| 34 | *
|
| 35 | * @param localIpv4 local ipv4 address
|
| 36 | * @param remoteIpv4 remote ipv4 address
|
| 37 | */
|
| 38 | public PcepNaiIpv4Adjacency(int localIpv4, int remoteIpv4) {
|
| 39 | this.localIpv4Addr = localIpv4;
|
| 40 | this.remoteIpv4Addr = remoteIpv4;
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | public byte getType() {
|
| 45 | return ST_TYPE;
|
| 46 | }
|
| 47 |
|
| 48 | @Override
|
| 49 | public int write(ChannelBuffer bb) {
|
| 50 | int iLenStartIndex = bb.writerIndex();
|
| 51 | bb.writeInt(localIpv4Addr);
|
| 52 | bb.writeInt(remoteIpv4Addr);
|
| 53 | return bb.writerIndex() - iLenStartIndex;
|
| 54 | }
|
| 55 |
|
| 56 | /**
|
| 57 | * Reads the channel buffer and returns object of PcepNAIIpv4AdjacencyVer1.
|
| 58 | *
|
| 59 | * @param cb of channel buffer
|
| 60 | * @return object of PcepNAIIpv4Adjacency
|
| 61 | */
|
| 62 | public static PcepNaiIpv4Adjacency read(ChannelBuffer cb) {
|
| 63 | int localIpv4 = cb.readInt();
|
| 64 | int remoteIpv4 = cb.readInt();
|
| 65 | return new PcepNaiIpv4Adjacency(localIpv4, remoteIpv4);
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | public int hashCode() {
|
| 70 | return Objects.hash(localIpv4Addr, remoteIpv4Addr);
|
| 71 | }
|
| 72 |
|
| 73 | @Override
|
| 74 | public boolean equals(Object obj) {
|
| 75 | if (this == obj) {
|
| 76 | return true;
|
| 77 | }
|
| 78 | if (obj instanceof PcepNaiIpv4Adjacency) {
|
| 79 | PcepNaiIpv4Adjacency other = (PcepNaiIpv4Adjacency) obj;
|
| 80 | return Objects.equals(this.localIpv4Addr, other.localIpv4Addr)
|
| 81 | && Objects.equals(this.remoteIpv4Addr, other.remoteIpv4Addr);
|
| 82 | }
|
| 83 | return false;
|
| 84 | }
|
| 85 |
|
| 86 | @Override
|
| 87 | public String toString() {
|
| 88 | return MoreObjects.toStringHelper(getClass())
|
| 89 | .add("local IPv4 Address", localIpv4Addr)
|
| 90 | .add("remote IPv4 Address", remoteIpv4Addr)
|
| 91 | .toString();
|
| 92 | }
|
| 93 | }
|