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 Ipv4 Error Spec.
26 public class PcepRsvpIpv4ErrorSpec implements PcepRsvpErrorSpec {
29 RSVP error spec object header.
31 +-------------+-------------+-------------+-------------+
32 | Length (bytes) | Class-Num | C-Type |
33 +-------------+-------------+-------------+-------------+
35 // (Object contents) //
37 +-------------+-------------+-------------+-------------+
39 Ref : ERROR_SPEC @ RFC2205
41 IPv4 ERROR_SPEC object: Class = 6, C-Type = 1
42 +-------------+-------------+-------------+-------------+
43 | IPv4 Error Node Address (4 bytes) |
44 +-------------+-------------+-------------+-------------+
45 | Flags | Error Code | Error Value |
46 +-------------+-------------+-------------+-------------+
50 PcepRsvpSpecObjHeader objHeader;
51 public static final byte CLASS_NUM = 0x06;
52 public static final byte CLASS_TYPE = 0x01;
53 public static final byte CLASS_LENGTH = 0x0c;
57 private short errValue;
60 * Constructor to initialize obj header, ipv4 addr, flags, err code and err value.
62 * @param objHeader rsvp ipv4 error spec object header
63 * @param ipv4Addr ipv4 address
64 * @param flags flags value
65 * @param errCode error code value
66 * @param errValue error value
68 public PcepRsvpIpv4ErrorSpec(PcepRsvpSpecObjHeader objHeader, int ipv4Addr, byte flags, byte errCode,
70 this.objHeader = objHeader;
71 this.ipv4Addr = ipv4Addr;
73 this.errCode = errCode;
74 this.errValue = errValue;
78 * Constructor to initialize ipv4 address, flags, err code and err value.
80 * @param ipv4Addr ipv4 address
81 * @param flags flags value
82 * @param errCode error code
83 * @param errValue error value
85 public PcepRsvpIpv4ErrorSpec(int ipv4Addr, byte flags, byte errCode, short errValue) {
86 this.objHeader = new PcepRsvpSpecObjHeader(CLASS_LENGTH, CLASS_NUM, CLASS_TYPE);
87 this.ipv4Addr = ipv4Addr;
89 this.errCode = errCode;
90 this.errValue = errValue;
94 public int write(ChannelBuffer cb) {
95 int objLenIndex = objHeader.write(cb);
96 cb.writeInt(ipv4Addr);
98 cb.writeByte(errCode);
99 cb.writeShort(errValue);
100 short objLen = (short) (cb.writerIndex() - objLenIndex);
101 cb.setShort(objLenIndex, objLen);
106 * Reads PCPE RSVP error spec from channel buffer and returns PCEP rsvp IPv4 error spec object.
108 * @param cb channel buffer
109 * @return PCEP rsvp IPv4 error spec object
111 public static PcepRsvpErrorSpec read(ChannelBuffer cb) {
112 PcepRsvpSpecObjHeader objHeader;
118 objHeader = PcepRsvpSpecObjHeader.read(cb);
119 ipv4Addr = cb.readInt();
120 flags = cb.readByte();
121 errCode = cb.readByte();
122 errValue = cb.readShort();
123 return new PcepRsvpIpv4ErrorSpec(objHeader, ipv4Addr, flags, errCode, errValue);
127 public PcepVersion getVersion() {
128 return PcepVersion.PCEP_1;
132 public short getType() {
133 return StatefulRsvpErrorSpecTlv.TYPE;
137 public short getLength() {
142 public byte getClassNum() {
147 public byte getClassType() {
152 public String toString() {
153 return MoreObjects.toStringHelper(getClass())
154 .add("IPv4Address", ipv4Addr)
156 .add("errorCode", errCode)
157 .add("errorValue", errValue)