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.
17 package org.onosproject.pcepio.types;
19 import java.util.Objects;
21 import org.jboss.netty.buffer.ChannelBuffer;
22 import org.onosproject.pcepio.exceptions.PcepParseException;
23 import org.onosproject.pcepio.protocol.PcepVersion;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import com.google.common.base.MoreObjects;
30 * Provides StatefulRsvpErrorSpecTlv.
32 public class StatefulRsvpErrorSpecTlv implements PcepValueType {
34 protected static final Logger log = LoggerFactory.getLogger(StatefulRsvpErrorSpecTlv.class);
36 /* RSVP-ERROR-SPEC TLV format
37 * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
42 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
43 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 | Type=21 | Length (variable) |
45 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 + RSVP ERROR_SPEC or USER_ERROR_SPEC Object +
49 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 +-------------+-------------+-------------+-------------+
53 | Length (bytes) | Class-Num | C-Type |
54 +-------------+-------------+-------------+-------------+
56 // (Object contents) //
58 +-------------+-------------+-------------+-------------+
60 Ref : ERROR_SPEC @ RFC2205
62 IPv4 ERROR_SPEC object: Class = 6, C-Type = 1
63 +-------------+-------------+-------------+-------------+
64 | IPv4 Error Node Address (4 bytes) |
65 +-------------+-------------+-------------+-------------+
66 | Flags | Error Code | Error Value |
67 +-------------+-------------+-------------+-------------+
70 IPv6 ERROR_SPEC object: Class = 6, C-Type = 2
71 +-------------+-------------+-------------+-------------+
75 + IPv6 Error Node Address (16 bytes) +
79 +-------------+-------------+-------------+-------------+
80 | Flags | Error Code | Error Value |
81 +-------------+-------------+-------------+-------------+
84 Ref : USER_ERROR_SPEC @ RFC5284
85 USER_ERROR_SPEC object: Class = 194, C-Type = 1
87 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
88 +---------------+---------------+---------------+---------------+
90 +---------------+---------------+---------------+---------------+
91 | Sub Org | Err Desc Len | User Error Value |
92 +---------------+---------------+---------------+---------------+
96 +---------------+---------------+---------------+---------------+
98 ~ User-Defined Subobjects ~
100 +---------------+---------------+---------------+---------------+
104 public static final short TYPE = 21;
105 public static final int OBJECT_HEADER_LENGTH = 4;
106 private short hLength;
108 private final PcepRsvpErrorSpec rsvpErrSpecObj;
109 private final boolean isErrSpceObjSet;
112 * Constructor to initialize errSpecObj.
114 * @param rsvpErrSpecObj Rsvp error spec object
116 public StatefulRsvpErrorSpecTlv(PcepRsvpErrorSpec rsvpErrSpecObj) {
117 this.rsvpErrSpecObj = rsvpErrSpecObj;
118 this.isErrSpceObjSet = true;
122 * Returns PcepRsvpErrorSpecObject.
124 * @return rsvpErrSpecObj
126 public PcepRsvpErrorSpec getPcepRsvpErrorSpec() {
127 return this.rsvpErrSpecObj;
131 public PcepVersion getVersion() {
132 return PcepVersion.PCEP_1;
136 public short getType() {
141 public short getLength() {
146 * Reads channel buffer and returns object of StatefulRsvpErrorSpecTlv.
148 * @param cb of type channel buffer
149 * @return object of StatefulRsvpErrorSpecTlv
150 * @throws PcepParseException while parsing this tlv from channel buffer
152 public static PcepValueType read(ChannelBuffer cb) throws PcepParseException {
154 PcepRsvpErrorSpec rsvpErrSpecObj = null;
155 PcepRsvpSpecObjHeader rsvpErrSpecObjHeader;
157 cb.markReaderIndex();
158 rsvpErrSpecObjHeader = PcepRsvpSpecObjHeader.read(cb);
159 cb.resetReaderIndex();
161 if (PcepRsvpIpv4ErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
162 && PcepRsvpIpv4ErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
163 rsvpErrSpecObj = PcepRsvpIpv4ErrorSpec.read(cb);
164 } else if (PcepRsvpIpv6ErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
165 && PcepRsvpIpv6ErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
166 rsvpErrSpecObj = PcepRsvpIpv6ErrorSpec.read(cb);
167 } else if (PcepRsvpUserErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
168 && PcepRsvpUserErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
169 rsvpErrSpecObj = PcepRsvpUserErrorSpec.read(cb);
171 return new StatefulRsvpErrorSpecTlv(rsvpErrSpecObj);
175 public int hashCode() {
176 return Objects.hash(rsvpErrSpecObj.hashCode());
180 public boolean equals(Object obj) {
184 if (obj instanceof StatefulRsvpErrorSpecTlv) {
185 StatefulRsvpErrorSpecTlv other = (StatefulRsvpErrorSpecTlv) obj;
186 return Objects.equals(this.rsvpErrSpecObj, other.rsvpErrSpecObj);
192 public int write(ChannelBuffer c) {
193 int iStartIndex = c.writerIndex();
195 int tlvLenIndex = c.writerIndex();
197 c.writeShort(hLength);
198 if (isErrSpceObjSet) {
199 rsvpErrSpecObj.write(c);
201 hLength = (short) (c.writerIndex() - iStartIndex);
202 c.setShort(tlvLenIndex, (hLength - OBJECT_HEADER_LENGTH));
204 return c.writerIndex() - iStartIndex;
208 public String toString() {
209 return MoreObjects.toStringHelper(getClass())
212 .add("Length", hLength)
213 .add("RSVPErrorSpecObject", rsvpErrSpecObj)