Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -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 | */ |
| 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 RoutingUniverseTLV identifiers. |
| 29 | */ |
Sho SHIMIZU | a5356ec | 2015-09-03 13:27:38 -0700 | [diff] [blame] | 30 | public class RoutingUniverseTlv implements PcepValueType { |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * Reference : draft-dhodylee-pce-pcep-te-data-extn-02, section 9.2.1. |
| 34 | * 0 1 2 3 |
| 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=[TBD7] | Length=8 | |
| 38 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 39 | | Identifier | |
| 40 | | | |
| 41 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 42 | |
| 43 | * |
| 44 | * |
| 45 | * +------------+---------------------+ |
| 46 | | Identifier | Routing Universe | |
| 47 | +------------+---------------------+ |
| 48 | | 0 | L3 packet topology | |
| 49 | | 1 | L1 optical topology | |
| 50 | +------------+---------------------+ |
| 51 | */ |
| 52 | |
Sho SHIMIZU | a5356ec | 2015-09-03 13:27:38 -0700 | [diff] [blame] | 53 | protected static final Logger log = LoggerFactory.getLogger(RoutingUniverseTlv.class); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 54 | |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 55 | public static final short TYPE = (short) 65281; |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 56 | public static final short LENGTH = 8; |
| 57 | |
| 58 | private final long rawValue; |
| 59 | |
| 60 | /** |
| 61 | * Constructor to initialize raw value. |
| 62 | * |
| 63 | * @param rawValue raw value |
| 64 | */ |
Sho SHIMIZU | a5356ec | 2015-09-03 13:27:38 -0700 | [diff] [blame] | 65 | public RoutingUniverseTlv(long rawValue) { |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 66 | this.rawValue = rawValue; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Returns object of RoutingUniverseTLV. |
| 71 | * |
| 72 | * @param raw value |
| 73 | * @return object of RoutingUniverseTLV |
| 74 | */ |
Sho SHIMIZU | a5356ec | 2015-09-03 13:27:38 -0700 | [diff] [blame] | 75 | public static RoutingUniverseTlv of(final long raw) { |
| 76 | return new RoutingUniverseTlv(raw); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns raw value as Identifier. |
| 81 | * |
| 82 | * @return rawValue Identifier |
| 83 | */ |
| 84 | public long getLong() { |
| 85 | return rawValue; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public PcepVersion getVersion() { |
| 90 | return PcepVersion.PCEP_1; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public short getType() { |
| 95 | return TYPE; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public short getLength() { |
| 100 | return LENGTH; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public int hashCode() { |
| 105 | return Objects.hash(rawValue); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public boolean equals(Object obj) { |
| 110 | if (this == obj) { |
| 111 | return true; |
| 112 | } |
Sho SHIMIZU | a5356ec | 2015-09-03 13:27:38 -0700 | [diff] [blame] | 113 | if (obj instanceof RoutingUniverseTlv) { |
| 114 | RoutingUniverseTlv other = (RoutingUniverseTlv) obj; |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 115 | return Objects.equals(this.rawValue, other.rawValue); |
| 116 | } |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public int write(ChannelBuffer c) { |
| 122 | int iLenStartIndex = c.writerIndex(); |
| 123 | c.writeShort(TYPE); |
| 124 | c.writeShort(LENGTH); |
| 125 | c.writeLong(rawValue); |
| 126 | return c.writerIndex() - iLenStartIndex; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Reads from channel buffer and returns object of RoutingUniverseTLV. |
| 131 | * |
| 132 | * @param c input channel buffer |
| 133 | * @return object of RoutingUniverseTLV |
| 134 | */ |
Sho SHIMIZU | a5356ec | 2015-09-03 13:27:38 -0700 | [diff] [blame] | 135 | public static RoutingUniverseTlv read(ChannelBuffer c) { |
| 136 | return RoutingUniverseTlv.of(c.readLong()); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public String toString() { |
Sho SHIMIZU | 7cdbcf7 | 2015-09-03 14:43:05 -0700 | [diff] [blame] | 141 | return MoreObjects.toStringHelper(getClass()) |
| 142 | .add("Type", TYPE) |
| 143 | .add("Length", LENGTH) |
| 144 | .add("Value", rawValue) |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 145 | .toString(); |
| 146 | } |
| 147 | } |