2  * Copyright 2015 Open Networking Laboratory
 
   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
 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  16 package org.onosproject.pcepio.types;
 
  18 import java.util.Objects;
 
  20 import org.jboss.netty.buffer.ChannelBuffer;
 
  21 import org.onosproject.pcepio.protocol.PcepNai;
 
  23 import com.google.common.base.MoreObjects;
 
  26  * Provides Pcep Nai Unnumbered Adjacency Ipv4.
 
  28 public class PcepNaiUnnumberedAdjacencyIpv4 implements PcepNai {
 
  30      * draft-ietf-pce-segment-routing-03 section    5.3.2.
 
  32     public static final byte ST_TYPE = 0x05;
 
  34     private final int localNodeId;
 
  35     private final int localInterfaceId;
 
  36     private final int remoteNodeId;
 
  37     private final int remoteInterfaceId;
 
  40      * Constructor to initialize all the member variables.
 
  42      * @param localNodeId local node id
 
  43      * @param localInterfaceId local interface id
 
  44      * @param remoteNodeId remote node id
 
  45      * @param remoteInterfaceId remote interface id
 
  47     public PcepNaiUnnumberedAdjacencyIpv4(int localNodeId, int localInterfaceId, int remoteNodeId,
 
  48             int remoteInterfaceId) {
 
  49         this.localNodeId = localNodeId;
 
  50         this.localInterfaceId = localInterfaceId;
 
  51         this.remoteNodeId = remoteNodeId;
 
  52         this.remoteInterfaceId = remoteInterfaceId;
 
  56      * Returns PCEP Nai Unnumbered Adjacency Ipv4 object.
 
  58      * @param localNodeId local node id
 
  59      * @param localInterfaceId local interface if
 
  60      * @param remoteNodeId remote node id
 
  61      * @param remoteInterfaceId remote interface id
 
  62      * @return PCEP Nai Unnumbered Adjacency Ipv4 object
 
  64     public static PcepNaiUnnumberedAdjacencyIpv4 of(int localNodeId, int localInterfaceId, int remoteNodeId,
 
  65             int remoteInterfaceId) {
 
  66         return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
 
  70     public byte getType() {
 
  75     public int write(ChannelBuffer bb) {
 
  76         int iLenStartIndex = bb.writerIndex();
 
  77         bb.writeInt(localNodeId);
 
  78         bb.writeInt(localInterfaceId);
 
  79         bb.writeInt(remoteNodeId);
 
  80         bb.writeInt(remoteInterfaceId);
 
  81         return bb.writerIndex() - iLenStartIndex;
 
  85      * Reads from channel buffer and return object of PcepNAIUnnumberedAdjacencyIpv4.
 
  87      * @param bb of type channel buffer
 
  88      * @return object of PcepNAIUnnumberedAdjacencyIpv4
 
  90     public static PcepNaiUnnumberedAdjacencyIpv4 read(ChannelBuffer bb) {
 
  94         int remoteInterfaceId;
 
  95         localNodeId = bb.readInt();
 
  96         localInterfaceId = bb.readInt();
 
  97         remoteNodeId = bb.readInt();
 
  98         remoteInterfaceId = bb.readInt();
 
  99         return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
 
 103     public int hashCode() {
 
 104         return Objects.hash(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
 
 108     public boolean equals(Object obj) {
 
 112         if (obj instanceof PcepNaiUnnumberedAdjacencyIpv4) {
 
 113             PcepNaiUnnumberedAdjacencyIpv4 other = (PcepNaiUnnumberedAdjacencyIpv4) obj;
 
 114             return Objects.equals(this.localNodeId, other.localNodeId)
 
 115                     && Objects.equals(this.localInterfaceId, other.localInterfaceId)
 
 116                     && Objects.equals(this.remoteNodeId, other.remoteNodeId)
 
 117                     && Objects.equals(this.remoteInterfaceId, other.remoteInterfaceId);
 
 123     public String toString() {
 
 124         return MoreObjects.toStringHelper(getClass())
 
 125                 .add("localNodeId", localNodeId)
 
 126                 .add("localInterfaceId", localInterfaceId)
 
 127                 .add("remoteNodeId", remoteNodeId)
 
 128                 .add("remoteInterfaceId", remoteInterfaceId)