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 * Provides IPv4 TE Router Id Of Local Node.
30 public class IPv4TERouterIdOfLocalNodeTlv implements PcepValueType {
32 /* Reference:[RFC5305]/4.3
34 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
35 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 | Type=[TDB25] | Length=4 |
37 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 | IPv4 TE Router Id Of Local Node |
39 +-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-
42 protected static final Logger log = LoggerFactory.getLogger(IPv4TERouterIdOfLocalNodeTlv.class);
44 public static final short TYPE = 134; //TDB25
45 public static final short LENGTH = 4;
47 private final int rawValue;
50 * Constructor to initialize rawValue.
52 * @param rawValue IPv4-TE-RouterId-Of-Local-Node-Tlv
54 public IPv4TERouterIdOfLocalNodeTlv(int rawValue) {
55 this.rawValue = rawValue;
59 * Returns newly created IPv4TERouterIdOfLocalNodeTlv object.
61 * @param raw value of IPv4-TE-RouterId-Of-Local-Node
62 * @return object of IPv4TERouterIdOfLocalNodeTlv
64 public static IPv4TERouterIdOfLocalNodeTlv of(final int raw) {
65 return new IPv4TERouterIdOfLocalNodeTlv(raw);
69 * Returns value of IPv4 TE Router Id Of Local Node.
71 * @return rawValue IPv4 TE Router Id Of Local Node
78 public PcepVersion getVersion() {
79 return PcepVersion.PCEP_1;
83 public short getType() {
88 public short getLength() {
93 public int hashCode() {
94 return Objects.hash(rawValue);
98 public boolean equals(Object obj) {
102 if (obj instanceof IPv4TERouterIdOfLocalNodeTlv) {
103 IPv4TERouterIdOfLocalNodeTlv other = (IPv4TERouterIdOfLocalNodeTlv) obj;
104 return Objects.equals(rawValue, other.rawValue);
110 public int write(ChannelBuffer c) {
111 int iLenStartIndex = c.writerIndex();
113 c.writeShort(LENGTH);
114 c.writeInt(rawValue);
115 return c.writerIndex() - iLenStartIndex;
119 * Reads the channel buffer and returns object of IPv4TERouterIdOfLocalNodeTlv.
121 * @param c input channel buffer
122 * @return object of IPv4TERouterIdOfLocalNodeTlv
124 public static IPv4TERouterIdOfLocalNodeTlv read(ChannelBuffer c) {
125 return IPv4TERouterIdOfLocalNodeTlv.of(c.readInt());
129 public String toString() {
130 return MoreObjects.toStringHelper(getClass())
132 .add("Length", LENGTH)
133 .add("Value", rawValue)