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 2016-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 | /** |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 28 | * Provides IPv4 Router Id Of Remote Node. |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 29 | */ |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 30 | public class IPv4RouterIdOfRemoteNodeSubTlv implements PcepValueType { |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 31 | |
| 32 | /* Reference :[RFC5305]/4.3 |
| 33 | * 0 1 2 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=[TDB28] | Length=4 | |
| 37 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 38 | | IPv4 Router Id Of Remote Node | |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 39 | +-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+- |
| 40 | */ |
| 41 | |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 42 | protected static final Logger log = LoggerFactory.getLogger(IPv4RouterIdOfRemoteNodeSubTlv.class); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 43 | |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 44 | public static final short TYPE = 19; |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 45 | public static final short LENGTH = 4; |
| 46 | |
| 47 | private final int rawValue; |
| 48 | |
| 49 | /** |
| 50 | * Constructor to initialize rawValue. |
| 51 | * |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 52 | * @param rawValue IPv4 RouterId Of Remote Node Tlv |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 53 | */ |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 54 | public IPv4RouterIdOfRemoteNodeSubTlv(int rawValue) { |
| 55 | log.debug("IPv4RouterIdOfRemoteNodeTlv"); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 56 | this.rawValue = rawValue; |
| 57 | } |
| 58 | |
| 59 | /** |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 60 | * Returns newly created IPv4RouterIdOfRemoteNodeTlv object. |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 61 | * |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 62 | * @param raw IPv4 RouterId Of Remote Node |
| 63 | * @return object of IPv4RouterIdOfRemoteNodeTlv |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 64 | */ |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 65 | public static IPv4RouterIdOfRemoteNodeSubTlv of(final int raw) { |
| 66 | return new IPv4RouterIdOfRemoteNodeSubTlv(raw); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 70 | * Returns value of IPv4 Router Id Of Remote Node. |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 71 | * |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 72 | * @return rawValue IPv4 Router Id Of Remote Node |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 73 | */ |
| 74 | public int getInt() { |
| 75 | return rawValue; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public PcepVersion getVersion() { |
| 80 | return PcepVersion.PCEP_1; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public short getType() { |
| 85 | return TYPE; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public short getLength() { |
| 90 | return LENGTH; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public int hashCode() { |
| 95 | return Objects.hash(rawValue); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public boolean equals(Object obj) { |
| 100 | if (this == obj) { |
| 101 | return true; |
| 102 | } |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 103 | if (obj instanceof IPv4RouterIdOfRemoteNodeSubTlv) { |
| 104 | IPv4RouterIdOfRemoteNodeSubTlv other = (IPv4RouterIdOfRemoteNodeSubTlv) obj; |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 105 | return Objects.equals(rawValue, other.rawValue); |
| 106 | } |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public int write(ChannelBuffer c) { |
| 112 | int iLenStartIndex = c.writerIndex(); |
| 113 | c.writeShort(TYPE); |
| 114 | c.writeShort(LENGTH); |
| 115 | c.writeInt(rawValue); |
| 116 | return c.writerIndex() - iLenStartIndex; |
| 117 | } |
| 118 | |
| 119 | /** |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 120 | * Reads the channel buffer and returns object of IPv4RouterIdOfRemoteNodeTlv. |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 121 | * |
| 122 | * @param c input channel buffer |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 123 | * @return object of IPv4RouterIdOfRemoteNodeTlv |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 124 | */ |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 125 | public static IPv4RouterIdOfRemoteNodeSubTlv read(ChannelBuffer c) { |
| 126 | return IPv4RouterIdOfRemoteNodeSubTlv.of(c.readInt()); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public String toString() { |
Sho SHIMIZU | 7cdbcf7 | 2015-09-03 14:43:05 -0700 | [diff] [blame] | 131 | return MoreObjects.toStringHelper(getClass()) |
| 132 | .add("Type", TYPE) |
| 133 | .add("Length", LENGTH) |
| 134 | .add("Value", rawValue) |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 135 | .toString(); |
| 136 | } |
| 137 | } |