Mahesh Poojary S | 5afd06c | 2015-08-21 14:51:04 +0530 | [diff] [blame^] | 1 | /*
|
| 2 | * Copyright 2014 Open Networking Laboratory
|
| 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 | */
|
| 16 | package org.onosproject.pcepio.types;
|
| 17 |
|
| 18 | import java.util.Objects;
|
| 19 | import org.jboss.netty.buffer.ChannelBuffer;
|
| 20 | import org.onosproject.pcepio.protocol.PcepVersion;
|
| 21 | import org.slf4j.Logger;
|
| 22 | import org.slf4j.LoggerFactory;
|
| 23 |
|
| 24 | import com.google.common.base.MoreObjects;
|
| 25 |
|
| 26 | /**
|
| 27 | * Provides area ID for OSPF area.
|
| 28 | */
|
| 29 | public class OSPFareaIDsubTlv implements PcepValueType {
|
| 30 |
|
| 31 | /* Reference :draft-ietf-idr-ls-distribution-10.
|
| 32 | * 0 1 2 3
|
| 33 | 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
|
| 34 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 35 | | Type=[TBD12] | Length=4 |
|
| 36 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 37 | | opaque value (32 Bit AS Number) |
|
| 38 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 39 | */
|
| 40 |
|
| 41 | protected static final Logger log = LoggerFactory.getLogger(OSPFareaIDsubTlv.class);
|
| 42 |
|
| 43 | public static final short TYPE = 600; //TODD:change this TBD12
|
| 44 | public static final short LENGTH = 4;
|
| 45 |
|
| 46 | private final int rawValue;
|
| 47 |
|
| 48 | /**
|
| 49 | * constructor to initialize rawValue.
|
| 50 | *
|
| 51 | * @param rawValue area ID for OSPF area.
|
| 52 | */
|
| 53 | public OSPFareaIDsubTlv(int rawValue) {
|
| 54 | this.rawValue = rawValue;
|
| 55 | }
|
| 56 |
|
| 57 | /**
|
| 58 | * Returns newly created OSPFareaIDsubTlv object.
|
| 59 | *
|
| 60 | * @param raw opaque value of AreaID
|
| 61 | * @return new object of OSPF area ID sub TLV
|
| 62 | */
|
| 63 | public static OSPFareaIDsubTlv of(final int raw) {
|
| 64 | return new OSPFareaIDsubTlv(raw);
|
| 65 | }
|
| 66 |
|
| 67 | /**
|
| 68 | * Returns RawValue opaque value of AreaID.
|
| 69 | *
|
| 70 | * @return rawValue Area ID
|
| 71 | */
|
| 72 | public int getInt() {
|
| 73 | return rawValue;
|
| 74 | }
|
| 75 |
|
| 76 | @Override
|
| 77 | public PcepVersion getVersion() {
|
| 78 | return PcepVersion.PCEP_1;
|
| 79 | }
|
| 80 |
|
| 81 | @Override
|
| 82 | public short getType() {
|
| 83 | return TYPE;
|
| 84 | }
|
| 85 |
|
| 86 | @Override
|
| 87 | public short getLength() {
|
| 88 | return LENGTH;
|
| 89 | }
|
| 90 |
|
| 91 | @Override
|
| 92 | public int hashCode() {
|
| 93 | return Objects.hash(rawValue);
|
| 94 | }
|
| 95 |
|
| 96 | @Override
|
| 97 | public boolean equals(Object obj) {
|
| 98 | if (this == obj) {
|
| 99 | return true;
|
| 100 | }
|
| 101 | if (obj instanceof OSPFareaIDsubTlv) {
|
| 102 | OSPFareaIDsubTlv other = (OSPFareaIDsubTlv) obj;
|
| 103 | return Objects.equals(this.rawValue, other.rawValue);
|
| 104 | }
|
| 105 | return false;
|
| 106 | }
|
| 107 |
|
| 108 | @Override
|
| 109 | public int write(ChannelBuffer c) {
|
| 110 | int iLenStartIndex = c.writerIndex();
|
| 111 | c.writeShort(TYPE);
|
| 112 | c.writeShort(LENGTH);
|
| 113 | c.writeInt(rawValue);
|
| 114 | return c.writerIndex() - iLenStartIndex;
|
| 115 | }
|
| 116 |
|
| 117 | /**
|
| 118 | * Reads the channel buffer and returns object of OSPFAreaIdSubTlv.
|
| 119 | *
|
| 120 | * @param c input channel buffer
|
| 121 | * @return object of OSPFAreaIdSubTlv
|
| 122 | */
|
| 123 | public static OSPFareaIDsubTlv read(ChannelBuffer c) {
|
| 124 | return OSPFareaIDsubTlv.of(c.readInt());
|
| 125 | }
|
| 126 |
|
| 127 | @Override
|
| 128 | public String toString() {
|
| 129 | return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
|
| 130 | .toString();
|
| 131 | }
|
| 132 | }
|