blob: 1897f9dd43445ec08c106bf3cc1c8aad844037f7 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska58de4162015-09-10 16:15:33 -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 */
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070016package org.onosproject.pcepio.types;
17
18import org.jboss.netty.buffer.ChannelBuffer;
19import org.onosproject.pcepio.protocol.PcepVersion;
20
21import com.google.common.base.MoreObjects;
22
23/**
24 * Provides Pcep Rsvp Ipv6 Error Spec.
25 */
26public class PcepRsvpIpv6ErrorSpec implements PcepRsvpErrorSpec {
27
28 /*
29 0 1 2 3
30 +-------------+-------------+-------------+-------------+
31 | Length (bytes) | Class-Num | C-Type |
32 +-------------+-------------+-------------+-------------+
33 | |
34 // (Object contents) //
35 | |
36 +-------------+-------------+-------------+-------------+
37
38 Ref : ERROR_SPEC @ RFC2205
39
40 IPv6 ERROR_SPEC object: Class = 6, C-Type = 2
41 +-------------+-------------+-------------+-------------+
42 | |
43 + +
44 | |
45 + IPv6 Error Node Address (16 bytes) +
46 | |
47 + +
48 | |
49 +-------------+-------------+-------------+-------------+
50 | Flags | Error Code | Error Value |
51 +-------------+-------------+-------------+-------------+ */
52
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;
58
59 private byte[] ipv6Addr;
60 private byte flags;
61 private byte errCode;
62 private short errValue;
63
64 /**
65 * Constructor to initialize obj header, ipv6 addr, flags, err code and err value.
66 *
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
72 */
73 public PcepRsvpIpv6ErrorSpec(PcepRsvpSpecObjHeader objHeader, byte[] ipv6Addr, byte flags, byte errCode,
74 short errValue) {
75 this.objHeader = objHeader;
76 this.ipv6Addr = ipv6Addr;
77 this.flags = flags;
78 this.errCode = errCode;
79 this.errValue = errValue;
80 }
81
82 /**
83 * Constructor to initialize ipv6 addr, flags, err code and err value.
84 *
85 * @param ipv6Addr ipv6 address
86 * @param flags flags value
87 * @param errCode error code
88 * @param errValue error value
89 */
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;
93 this.flags = flags;
94 this.errCode = errCode;
95 this.errValue = errValue;
96 }
97
98 @Override
99 public int write(ChannelBuffer cb) {
100 int objLenIndex = objHeader.write(cb);
101 cb.writeBytes(ipv6Addr);
102 cb.writeByte(flags);
103 cb.writeByte(errCode);
104 cb.writeShort(errValue);
105 short objLen = (short) (cb.writerIndex() - objLenIndex);
106 cb.setShort(objLenIndex, objLen);
107 return objLen;
108 }
109
110 /**
111 * Returns PCEP rsvp IPv6 error spce object.
112 *
113 * @param cb channel buffer
114 * @return PCEP rsvp IPv6 error spce object
115 */
116 public static PcepRsvpErrorSpec read(ChannelBuffer cb) {
117 PcepRsvpSpecObjHeader objHeader;
118 byte[] ipv6Addr = new byte[IPV6_LEN];
119 byte flags;
120 byte errCode;
121 short errValue;
122
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);
129 }
130
131 @Override
132 public PcepVersion getVersion() {
133 return PcepVersion.PCEP_1;
134 }
135
136 @Override
137 public short getType() {
138 return StatefulRsvpErrorSpecTlv.TYPE;
139 }
140
141 @Override
142 public short getLength() {
143 return CLASS_LENGTH;
144 }
145
146 @Override
147 public byte getClassNum() {
148 return CLASS_NUM;
149 }
150
151 @Override
152 public byte getClassType() {
153 return CLASS_TYPE;
154 }
155
156 @Override
157 public String toString() {
158 return MoreObjects.toStringHelper(getClass())
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -0700159 .add("IPv6Address", ipv6Addr)
160 .add("flags", flags)
161 .add("errorCode", errCode)
162 .add("errorValue", errValue)
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700163 .toString();
164 }
165}