blob: 6d8282b752dda39cc1cbcf9b58ca4a5c1b6d511e [file] [log] [blame]
Priyanka Bb2988fa2015-10-09 12:45:36 +05301/*
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
17package org.onosproject.bgpio.types;
18
19import java.util.Objects;
20
21import org.jboss.netty.buffer.ChannelBuffer;
22import org.onosproject.bgpio.protocol.IGPRouterID;
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25
26import com.google.common.base.MoreObjects;
27
28/**
29 * Provides implementation of OSPFNonPseudonode Tlv.
30 */
31public class OSPFNonPseudonode implements IGPRouterID, BGPValueType {
32
33 protected static final Logger log = LoggerFactory.getLogger(OSPFNonPseudonode.class);
34
35 public static final short TYPE = 515;
36 public static final short LENGTH = 4;
37
38 private final int routerID;
39
40 /**
41 * Constructor to initialize routerID.
42 *
43 * @param routerID routerID
44 */
45 public OSPFNonPseudonode(int routerID) {
46 this.routerID = routerID;
47 }
48
49 /**
50 * Returns object of this class with specified routerID.
51 *
52 * @param routerID routerID
53 * @return object of OSPFNonPseudonode
54 */
55 public static OSPFNonPseudonode of(final int routerID) {
56 return new OSPFNonPseudonode(routerID);
57 }
58
59 /**
60 * Returns RouterID.
61 *
62 * @return RouterID
63 */
64 public int getrouterID() {
65 return this.routerID;
66 }
67
68 @Override
69 public int hashCode() {
70 return Objects.hash(routerID);
71 }
72
73 @Override
74 public boolean equals(Object obj) {
75 if (this == obj) {
76 return true;
77 }
78
79 if (obj instanceof OSPFNonPseudonode) {
80 OSPFNonPseudonode other = (OSPFNonPseudonode) obj;
81 return Objects.equals(routerID, other.routerID);
82 }
83 return false;
84 }
85
86 @Override
87 public int write(ChannelBuffer c) {
88 int iLenStartIndex = c.writerIndex();
89 c.writeShort(TYPE);
90 c.writeShort(LENGTH);
91 c.writeInt(routerID);
92 return c.writerIndex() - iLenStartIndex;
93 }
94
95 /**
96 * Reads the channel buffer and returns object of OSPFNonPseudonode.
97 *
98 * @param cb ChannelBuffer
99 * @return object of OSPFNonPseudonode
100 */
101 public static OSPFNonPseudonode read(ChannelBuffer cb) {
102 return OSPFNonPseudonode.of(cb.readInt());
103 }
104
105 @Override
106 public short getType() {
107 return TYPE;
108 }
109
110 @Override
111 public String toString() {
112 return MoreObjects.toStringHelper(getClass())
113 .add("Type", TYPE)
114 .add("Length", LENGTH)
115 .add("RouterID", routerID)
116 .toString();
117 }
118}