blob: 103720846bc59053037aee55d675c0d77e9fde8a [file] [log] [blame]
Priyanka Bb2988fa2015-10-09 12:45:36 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Priyanka Bb2988fa2015-10-09 12:45:36 +05303 *
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
Priyanka Bb2988fa2015-10-09 12:45:36 +053019import com.google.common.base.MoreObjects;
Jonathan Hart51539b82015-10-29 09:53:04 -070020import org.jboss.netty.buffer.ChannelBuffer;
21import org.onosproject.bgpio.protocol.IgpRouterId;
22
23import java.util.Objects;
Priyanka Bb2988fa2015-10-09 12:45:36 +053024
25/**
26 * Provides implementation of OSPFNonPseudonode Tlv.
27 */
Jonathan Hart51539b82015-10-29 09:53:04 -070028public class OspfNonPseudonode implements IgpRouterId, BgpValueType {
Priyanka Bb2988fa2015-10-09 12:45:36 +053029 public static final short TYPE = 515;
30 public static final short LENGTH = 4;
31
32 private final int routerID;
33
34 /**
35 * Constructor to initialize routerID.
36 *
37 * @param routerID routerID
38 */
Jonathan Hart51539b82015-10-29 09:53:04 -070039 public OspfNonPseudonode(int routerID) {
Priyanka Bb2988fa2015-10-09 12:45:36 +053040 this.routerID = routerID;
41 }
42
43 /**
44 * Returns object of this class with specified routerID.
45 *
46 * @param routerID routerID
47 * @return object of OSPFNonPseudonode
48 */
Jonathan Hart51539b82015-10-29 09:53:04 -070049 public static OspfNonPseudonode of(final int routerID) {
50 return new OspfNonPseudonode(routerID);
Priyanka Bb2988fa2015-10-09 12:45:36 +053051 }
52
53 /**
54 * Returns RouterID.
55 *
56 * @return RouterID
57 */
58 public int getrouterID() {
59 return this.routerID;
60 }
61
62 @Override
63 public int hashCode() {
64 return Objects.hash(routerID);
65 }
66
67 @Override
68 public boolean equals(Object obj) {
69 if (this == obj) {
70 return true;
71 }
72
Jonathan Hart51539b82015-10-29 09:53:04 -070073 if (obj instanceof OspfNonPseudonode) {
74 OspfNonPseudonode other = (OspfNonPseudonode) obj;
Priyanka Bb2988fa2015-10-09 12:45:36 +053075 return Objects.equals(routerID, other.routerID);
76 }
77 return false;
78 }
79
80 @Override
81 public int write(ChannelBuffer c) {
82 int iLenStartIndex = c.writerIndex();
83 c.writeShort(TYPE);
84 c.writeShort(LENGTH);
85 c.writeInt(routerID);
86 return c.writerIndex() - iLenStartIndex;
87 }
88
89 /**
90 * Reads the channel buffer and returns object of OSPFNonPseudonode.
91 *
92 * @param cb ChannelBuffer
93 * @return object of OSPFNonPseudonode
94 */
Jonathan Hart51539b82015-10-29 09:53:04 -070095 public static OspfNonPseudonode read(ChannelBuffer cb) {
96 return OspfNonPseudonode.of(cb.readInt());
Priyanka Bb2988fa2015-10-09 12:45:36 +053097 }
98
99 @Override
100 public short getType() {
101 return TYPE;
102 }
103
104 @Override
Priyanka B02040732015-11-29 11:30:29 +0530105 public int compareTo(Object o) {
106 if (this.equals(o)) {
107 return 0;
108 }
Jonathan Hart51539b82015-10-29 09:53:04 -0700109 return ((Integer) (this.routerID)).compareTo((Integer) (((OspfNonPseudonode) o).routerID));
Priyanka B02040732015-11-29 11:30:29 +0530110 }
111
112 @Override
Priyanka Bb2988fa2015-10-09 12:45:36 +0530113 public String toString() {
114 return MoreObjects.toStringHelper(getClass())
115 .add("Type", TYPE)
116 .add("Length", LENGTH)
117 .add("RouterID", routerID)
118 .toString();
119 }
Jonathan Hart51539b82015-10-29 09:53:04 -0700120}