blob: c9867805caf8a248d48e4e620d2503e773ef7444 [file] [log] [blame]
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -07003 *
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 */
16package org.onosproject.pcepio.types;
17
18import java.util.Objects;
19
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.onosproject.pcepio.protocol.PcepVersion;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
25import com.google.common.base.MoreObjects;
26
27/**
28 * Provides Local and remote Link Identifiers.
29 */
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053030public class LinkLocalRemoteIdentifiersSubTlv implements PcepValueType {
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070031
32 /* Reference :RFC5307
33 * 0 1 2 3
34 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 | Type=4 | Length=8 |
37 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 | Link Local Identifier |
39 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 | Link Remote Identifier |
41 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42
43 */
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053044 protected static final Logger log = LoggerFactory.getLogger(LinkLocalRemoteIdentifiersSubTlv.class);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070045
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053046 public static final short TYPE = 6;
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070047 public static final short LENGTH = 8;
48 private final int iLinkLocalIdentifier;
49 private final int iLinkRemoteIdentifier;
50
51 /**
52 * Constructor to initialize iLinkLocalIdentifier , iLinkRemoteIdentifier.
53 *
54 * @param iLinkLocalIdentifier Link Local identifier
55 * @param iLinkRemoteIdentifier Link Remote identifier
56 */
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053057 public LinkLocalRemoteIdentifiersSubTlv(int iLinkLocalIdentifier, int iLinkRemoteIdentifier) {
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070058 this.iLinkLocalIdentifier = iLinkLocalIdentifier;
59 this.iLinkRemoteIdentifier = iLinkRemoteIdentifier;
60 }
61
62 /**
63 * Retruns an object of Link Local Remote Identifiers Tlv.
64 *
65 * @param iLinkLocalIdentifier Link Local identifier
66 * @param iLinkRemoteIdentifier Link Remote identifier
67 * @return object of LinkLocalRemoteIdentifiersTlv
68 */
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053069 public static LinkLocalRemoteIdentifiersSubTlv of(int iLinkLocalIdentifier, int iLinkRemoteIdentifier) {
70 return new LinkLocalRemoteIdentifiersSubTlv(iLinkLocalIdentifier, iLinkRemoteIdentifier);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070071 }
72
73 /**
74 * Returns Link-Local-Identifier.
75 *
76 * @return iLinkLocalIdentifier Link Local Identifier
77 */
78 public int getLinkLocalIdentifier() {
79 return iLinkLocalIdentifier;
80 }
81
82 /**
83 * Returns Link-Remote-Identifier.
84 *
85 * @return iLinkRemoteIdentifier Link Remote Identifier.
86 */
87 public int getLinkRemoteIdentifier() {
88 return iLinkRemoteIdentifier;
89 }
90
91 @Override
92 public PcepVersion getVersion() {
93 return PcepVersion.PCEP_1;
94 }
95
96 @Override
97 public short getLength() {
98 return LENGTH;
99 }
100
101 @Override
102 public short getType() {
103 return TYPE;
104 }
105
106 @Override
107 public int hashCode() {
108 return Objects.hash(iLinkLocalIdentifier, iLinkRemoteIdentifier);
109 }
110
111 @Override
112 public boolean equals(Object obj) {
113 if (this == obj) {
114 return true;
115 }
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530116 if (obj instanceof LinkLocalRemoteIdentifiersSubTlv) {
117 LinkLocalRemoteIdentifiersSubTlv other = (LinkLocalRemoteIdentifiersSubTlv) obj;
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700118 return Objects.equals(iLinkLocalIdentifier, other.iLinkLocalIdentifier)
119 && Objects.equals(iLinkRemoteIdentifier, other.iLinkRemoteIdentifier);
120 }
121 return false;
122 }
123
124 @Override
125 public int write(ChannelBuffer c) {
126 int iStartIndex = c.writerIndex();
127 c.writeShort(TYPE);
128 c.writeShort(LENGTH);
129 c.writeInt(iLinkLocalIdentifier);
130 c.writeInt(iLinkRemoteIdentifier);
131 return c.writerIndex() - iStartIndex;
132 }
133
134 /**
135 * Reads the channel buffer and returns object of LinkLocalRemoteIdentifiersTlv.
136 *
137 * @param c input channel buffer
138 * @return object of LinkLocalRemoteIdentifiersTlv
139 */
140 public static PcepValueType read(ChannelBuffer c) {
141 int iLinkLocalIdentifier = c.readInt();
142 int iLinkRemoteIdentifier = c.readInt();
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +0530143 return new LinkLocalRemoteIdentifiersSubTlv(iLinkLocalIdentifier, iLinkRemoteIdentifier);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700144 }
145
146 @Override
147 public String toString() {
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -0700148 return MoreObjects.toStringHelper(getClass())
149 .add("Type", TYPE)
150 .add("Length", LENGTH)
151 .add("LinkLocalIdentifier", iLinkLocalIdentifier)
152 .add("LinkRemoteIdentifier", iLinkRemoteIdentifier)
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700153 .toString();
154 }
155}