Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 3 | * |
| 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 SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 16 | package org.onosproject.pcepio.types; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import org.jboss.netty.buffer.ChannelBuffer; |
| 21 | import org.onosproject.pcepio.protocol.PcepVersion; |
| 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
| 25 | import com.google.common.base.MoreObjects; |
| 26 | |
| 27 | /** |
| 28 | * Provides PcepSetup type tlv. |
| 29 | */ |
| 30 | public class PathSetupTypeTlv implements PcepValueType { |
| 31 | |
| 32 | /* |
| 33 | Reference : draft-sivabalan-pce-lsp-setup-type-02. |
| 34 | |
| 35 | 0 1 2 3 |
| 36 | 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 |
| 37 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 38 | | Type | Length | |
| 39 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 40 | | Reserved | PST | |
| 41 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 42 | |
| 43 | Figure 1: PATH-SETUP-TYPE TLV |
| 44 | |
| 45 | */ |
| 46 | protected static final Logger log = LoggerFactory.getLogger(PathSetupTypeTlv.class); |
| 47 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 48 | public static final short TYPE = 28; |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 49 | public static final short LENGTH = 4; |
| 50 | |
| 51 | private final byte pst; |
| 52 | private final int rawValue; |
| 53 | private final boolean isRawValueSet; |
| 54 | |
| 55 | /** |
| 56 | * Constructor to initialize parameters for path setup type tlv. |
| 57 | * |
| 58 | * @param rawValue parameter for path setup type tlv |
| 59 | */ |
| 60 | public PathSetupTypeTlv(final int rawValue) { |
| 61 | this.rawValue = rawValue; |
| 62 | this.isRawValueSet = true; |
| 63 | this.pst = (byte) rawValue; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Constructor to initialize pst. |
| 68 | * |
| 69 | * @param pst PST |
| 70 | */ |
| 71 | public PathSetupTypeTlv(byte pst) { |
| 72 | this.pst = pst; |
| 73 | this.rawValue = 0; |
| 74 | this.isRawValueSet = false; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns Object of path setup type tlv. |
| 79 | * |
| 80 | * @param raw parameter for path setup type tlv |
| 81 | * @return object of PathSetupTypeTlv |
| 82 | */ |
| 83 | public static PathSetupTypeTlv of(final int raw) { |
| 84 | return new PathSetupTypeTlv(raw); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public PcepVersion getVersion() { |
| 89 | return PcepVersion.PCEP_1; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns parameters for path setup type tlv. |
| 94 | * |
| 95 | * @return parameters for path setup type tlv |
| 96 | */ |
| 97 | public int getInt() { |
| 98 | return rawValue; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns the pst value. |
| 103 | * |
| 104 | * @return pst value |
| 105 | */ |
| 106 | public byte getPst() { |
| 107 | return pst; |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public short getType() { |
| 112 | return TYPE; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public short getLength() { |
| 117 | return LENGTH; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public int hashCode() { |
| 122 | return Objects.hash(pst); |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public boolean equals(Object obj) { |
| 127 | if (this == obj) { |
| 128 | return true; |
| 129 | } |
| 130 | if (obj instanceof PathSetupTypeTlv) { |
| 131 | PathSetupTypeTlv other = (PathSetupTypeTlv) obj; |
| 132 | return Objects.equals(this.pst, other.pst); |
| 133 | } |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public int write(ChannelBuffer c) { |
| 139 | int iLenStartIndex = c.writerIndex(); |
| 140 | c.writeShort(TYPE); |
| 141 | c.writeShort(LENGTH); |
| 142 | c.writeInt(pst); |
| 143 | return c.writerIndex() - iLenStartIndex; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Returns the object of type PathSetupTypeTlv. |
| 148 | * |
| 149 | * @param c is type Channel buffer |
| 150 | * @return object of PathSetupTypeTlv |
| 151 | */ |
| 152 | public static PathSetupTypeTlv read(ChannelBuffer c) { |
| 153 | return PathSetupTypeTlv.of(c.readInt()); |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public String toString() { |
Sho SHIMIZU | 7cdbcf7 | 2015-09-03 14:43:05 -0700 | [diff] [blame] | 158 | return MoreObjects.toStringHelper(getClass()) |
| 159 | .add("Type", TYPE) |
| 160 | .add("Length", LENGTH) |
| 161 | .add("PST", pst) |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 162 | .toString(); |
| 163 | } |
| 164 | } |