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 org.jboss.netty.buffer.ChannelBuffer;
19 import org.onosproject.pcepio.protocol.PcepVersion;
21 import com.google.common.base.MoreObjects;
24 * Provides Pcep Rsvp Ipv6 Error Spec.
26 public class PcepRsvpIpv6ErrorSpec implements PcepRsvpErrorSpec {
30 +-------------+-------------+-------------+-------------+
31 | Length (bytes) | Class-Num | C-Type |
32 +-------------+-------------+-------------+-------------+
34 // (Object contents) //
36 +-------------+-------------+-------------+-------------+
38 Ref : ERROR_SPEC @ RFC2205
40 IPv6 ERROR_SPEC object: Class = 6, C-Type = 2
41 +-------------+-------------+-------------+-------------+
45 + IPv6 Error Node Address (16 bytes) +
49 +-------------+-------------+-------------+-------------+
50 | Flags | Error Code | Error Value |
51 +-------------+-------------+-------------+-------------+ */
53 PcepRsvpSpecObjHeader objHeader;
54 public static final byte CLASS_NUM = 0x06;
55 public static final byte CLASS_TYPE = 0x02;
56 public static final byte CLASS_LENGTH = 0x18;
57 public static final byte IPV6_LEN = 0x10;
59 private byte[] ipv6Addr;
62 private short errValue;
65 * Constructor to initialize obj header, ipv6 addr, flags, err code and err value.
67 * @param objHeader rsvp ipv6 error spec object header
68 * @param ipv6Addr ipv6 address
69 * @param flags flags value
70 * @param errCode error code
71 * @param errValue error value
73 public PcepRsvpIpv6ErrorSpec(PcepRsvpSpecObjHeader objHeader, byte[] ipv6Addr, byte flags, byte errCode,
75 this.objHeader = objHeader;
76 this.ipv6Addr = ipv6Addr;
78 this.errCode = errCode;
79 this.errValue = errValue;
83 * Constructor to initialize ipv6 addr, flags, err code and err value.
85 * @param ipv6Addr ipv6 address
86 * @param flags flags value
87 * @param errCode error code
88 * @param errValue error value
90 public PcepRsvpIpv6ErrorSpec(byte[] ipv6Addr, byte flags, byte errCode, short errValue) {
91 this.objHeader = new PcepRsvpSpecObjHeader(CLASS_LENGTH, CLASS_NUM, CLASS_TYPE);
92 this.ipv6Addr = ipv6Addr;
94 this.errCode = errCode;
95 this.errValue = errValue;
99 public int write(ChannelBuffer cb) {
100 int objLenIndex = objHeader.write(cb);
101 cb.writeBytes(ipv6Addr);
103 cb.writeByte(errCode);
104 cb.writeShort(errValue);
105 short objLen = (short) (cb.writerIndex() - objLenIndex);
106 cb.setShort(objLenIndex, objLen);
111 * Returns PCEP rsvp IPv6 error spce object.
113 * @param cb channel buffer
114 * @return PCEP rsvp IPv6 error spce object
116 public static PcepRsvpErrorSpec read(ChannelBuffer cb) {
117 PcepRsvpSpecObjHeader objHeader;
118 byte[] ipv6Addr = new byte[IPV6_LEN];
123 objHeader = PcepRsvpSpecObjHeader.read(cb);
124 cb.readBytes(ipv6Addr, 0, IPV6_LEN);
125 flags = cb.readByte();
126 errCode = cb.readByte();
127 errValue = cb.readShort();
128 return new PcepRsvpIpv6ErrorSpec(objHeader, ipv6Addr, flags, errCode, errValue);
132 public PcepVersion getVersion() {
133 return PcepVersion.PCEP_1;
137 public short getType() {
138 return StatefulRsvpErrorSpecTlv.TYPE;
142 public short getLength() {
147 public byte getClassNum() {
152 public byte getClassType() {
157 public String toString() {
158 return MoreObjects.toStringHelper(getClass())
159 .add("IPv6Address", ipv6Addr)
161 .add("errorCode", errCode)
162 .add("errorValue", errValue)