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 java.util.Objects;
20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.onosproject.pcepio.protocol.PcepVersion;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.google.common.base.MoreObjects;
28 * Provide Link Protection Type.
31 public class LinkProtectionTypeTlv implements PcepValueType {
33 /* Reference :[RFC5307]/1.2
35 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
36 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 | Type=[TDB38] | Length=2 |
38 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 |Protection Cap | Reserved |
40 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 protected static final Logger log = LoggerFactory.getLogger(LinkProtectionTypeTlv.class);
44 public static final short TYPE = 20; //TDB38
45 public static final short LENGTH = 2;
46 private final byte protectionCap;
47 private final byte reserved;
50 * Constructor to initialize protectionCap.
52 * @param protectionCap Protection Cap
54 public LinkProtectionTypeTlv(byte protectionCap) {
55 this.protectionCap = protectionCap;
60 * Constructor to initialize protectionCap, reserved.
62 * @param protectionCap Protection Cap
63 * @param reserved Reserved value
65 public LinkProtectionTypeTlv(byte protectionCap, byte reserved) {
66 this.protectionCap = protectionCap;
67 this.reserved = reserved;
71 * Returns Protection Cap.
73 * @return protectionCap Protection Cap
75 public byte getProtectionCap() {
80 public PcepVersion getVersion() {
81 return PcepVersion.PCEP_1;
85 public short getType() {
90 public short getLength() {
95 public int hashCode() {
96 return Objects.hash(protectionCap, reserved);
100 public boolean equals(Object obj) {
104 if (obj instanceof LinkProtectionTypeTlv) {
105 LinkProtectionTypeTlv other = (LinkProtectionTypeTlv) obj;
106 return Objects.equals(protectionCap, other.protectionCap) && Objects.equals(reserved, other.reserved);
113 public int write(ChannelBuffer c) {
114 int iLenStartIndex = c.writerIndex();
116 c.writeShort(LENGTH);
117 c.writeByte(protectionCap);
118 c.writeByte(reserved);
119 return c.writerIndex() - iLenStartIndex;
123 * Reads the channel buffer and returns object of LinkProtectionTypeTlv.
125 * @param c input channel buffer
126 * @return object of LinkProtectionTypeTlv
128 public static PcepValueType read(ChannelBuffer c) {
129 byte protectionCap = c.readByte();
130 byte reserved = c.readByte();
131 return new LinkProtectionTypeTlv(protectionCap, reserved);
135 public String toString() {
136 return MoreObjects.toStringHelper(getClass())
138 .add("Length", LENGTH)
139 .add("ProtectionCap", protectionCap)