blob: 7eade7a321f6b45877c8f20006b8be2f94d34d31 [file] [log] [blame]
bharat saraswalf7364db2015-08-11 13:39:31 +05301package org.onosproject.pcepio.types;
2
3import org.jboss.netty.buffer.ChannelBuffer;
4import org.onosproject.pcepio.protocol.PcepVersion;
5
6import com.google.common.base.MoreObjects;
7
8public class PcepRsvpIpv6ErrorSpec implements PcepRsvpErrorSpec {
9
10 /*
11 0 1 2 3
12 +-------------+-------------+-------------+-------------+
13 | Length (bytes) | Class-Num | C-Type |
14 +-------------+-------------+-------------+-------------+
15 | |
16 // (Object contents) //
17 | |
18 +-------------+-------------+-------------+-------------+
19
20 Ref : ERROR_SPEC @ RFC2205
21
22 IPv6 ERROR_SPEC object: Class = 6, C-Type = 2
23 +-------------+-------------+-------------+-------------+
24 | |
25 + +
26 | |
27 + IPv6 Error Node Address (16 bytes) +
28 | |
29 + +
30 | |
31 +-------------+-------------+-------------+-------------+
32 | Flags | Error Code | Error Value |
33 +-------------+-------------+-------------+-------------+ */
34
35 PcepRsvpSpecObjHeader objHeader;
36 public static final byte CLASS_NUM = 0x06;
37 public static final byte CLASS_TYPE = 0x02;
38 public static final byte CLASS_LENGTH = 0x18;
39 public static final byte IPV6_LEN = 0x10;
40
41 private byte[] ipv6Addr;
42 private byte flags;
43 private byte errCode;
44 private short errValue;
45
46 /**
47 * Constructor to initialize obj header, ipv6 addr, flags, err code and err value.
48 *
49 * @param objHeader rsvp ipv6 error spec object header
50 * @param ipv6Addr ipv6 address
51 * @param flags flags value
52 * @param errCode error code
53 * @param errValue error value
54 */
55 public PcepRsvpIpv6ErrorSpec(PcepRsvpSpecObjHeader objHeader, byte[] ipv6Addr, byte flags, byte errCode,
56 short errValue) {
57 this.objHeader = objHeader;
58 this.ipv6Addr = ipv6Addr;
59 this.flags = flags;
60 this.errCode = errCode;
61 this.errValue = errValue;
62 }
63
64 /**
65 * Constructor to initialize ipv6 addr, flags, err code and err value.
66 *
67 * @param ipv6Addr ipv6 address
68 * @param flags flags value
69 * @param errCode error code
70 * @param errValue error value
71 */
72 public PcepRsvpIpv6ErrorSpec(byte[] ipv6Addr, byte flags, byte errCode, short errValue) {
73 this.objHeader = new PcepRsvpSpecObjHeader(CLASS_LENGTH, CLASS_NUM, CLASS_TYPE);
74 this.ipv6Addr = ipv6Addr;
75 this.flags = flags;
76 this.errCode = errCode;
77 this.errValue = errValue;
78 }
79
80 @Override
81 public int write(ChannelBuffer cb) {
82 int objLenIndex = objHeader.write(cb);
83 cb.writeBytes(ipv6Addr);
84 cb.writeByte(flags);
85 cb.writeByte(errCode);
86 cb.writeShort(errValue);
87 short objLen = (short) (cb.writerIndex() - objLenIndex);
88 cb.setShort(objLenIndex, objLen);
89 return objLen;
90 }
91
92 /**
93 * Returns PCEP rsvp IPv6 error spce object.
94 *
95 * @param cb channel buffer
96 * @return PCEP rsvp IPv6 error spce object
97 */
98 public static PcepRsvpErrorSpec read(ChannelBuffer cb) {
99 PcepRsvpSpecObjHeader objHeader;
100 byte[] ipv6Addr = new byte[IPV6_LEN];
101 byte flags;
102 byte errCode;
103 short errValue;
104
105 objHeader = PcepRsvpSpecObjHeader.read(cb);
106 cb.readBytes(ipv6Addr, 0, IPV6_LEN);
107 flags = cb.readByte();
108 errCode = cb.readByte();
109 errValue = cb.readShort();
110 return new PcepRsvpIpv6ErrorSpec(objHeader, ipv6Addr, flags, errCode, errValue);
111 }
112
113 @Override
114 public PcepVersion getVersion() {
115 return PcepVersion.PCEP_1;
116 }
117
118 @Override
119 public short getType() {
120 return StatefulRsvpErrorSpecTlv.TYPE;
121 }
122
123 @Override
124 public short getLength() {
125 return CLASS_LENGTH;
126 }
127
128 @Override
129 public byte getClassNum() {
130 return CLASS_NUM;
131 }
132
133 @Override
134 public byte getClassType() {
135 return CLASS_TYPE;
136 }
137
138 @Override
bharat saraswalf7364db2015-08-11 13:39:31 +0530139 public String toString() {
140 return MoreObjects.toStringHelper(getClass())
bharat saraswale1806302015-08-21 12:16:46 +0530141 .add("IPv6Address:", ipv6Addr)
bharat saraswalf7364db2015-08-11 13:39:31 +0530142 .add("flags:", flags)
bharat saraswale1806302015-08-21 12:16:46 +0530143 .add("errorCode:", errCode)
144 .add("errorValue:", errValue)
bharat saraswalf7364db2015-08-11 13:39:31 +0530145 .toString();
146 }
147}