Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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 | |
| 17 | package org.onosproject.pcepio.types; |
| 18 | |
| 19 | import java.util.Objects; |
| 20 | |
| 21 | import org.jboss.netty.buffer.ChannelBuffer; |
| 22 | import org.onosproject.pcepio.protocol.PcepVersion; |
| 23 | import org.slf4j.Logger; |
| 24 | import org.slf4j.LoggerFactory; |
| 25 | |
| 26 | import com.google.common.base.MoreObjects; |
| 27 | |
| 28 | /** |
| 29 | * Provides StatefulLspDbVerTlv. |
| 30 | */ |
| 31 | public class StatefulLspDbVerTlv implements PcepValueType { |
| 32 | |
| 33 | /* LSP-DB-VERSION TLV format |
| 34 | * |
| 35 | * Reference : Optimizations of Label Switched Path State Synchronization Procedures |
| 36 | for a Stateful PCE draft-ietf-pce-stateful-sync-optimizations-02 |
| 37 | * |
| 38 | * |
| 39 | |
| 40 | 0 1 2 3 |
| 41 | 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 |
| 42 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 43 | | Type=23 | Length=8 | |
| 44 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 45 | | LSP State DB Version | |
| 46 | | | |
| 47 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 48 | |
| 49 | */ |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 50 | private static final Logger log = LoggerFactory.getLogger(StatefulLspDbVerTlv.class); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 51 | |
| 52 | public static final short TYPE = 23; |
| 53 | public static final short LENGTH = 8; |
| 54 | private final long rawValue; |
| 55 | |
| 56 | /** |
| 57 | * Constructor to initialize rawValue. |
| 58 | * |
| 59 | * @param rawValue value |
| 60 | */ |
| 61 | public StatefulLspDbVerTlv(final long rawValue) { |
| 62 | this.rawValue = rawValue; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns object of StatefulLspDbVerTlv. |
| 67 | * |
| 68 | * @param raw is LSP State DB Version |
| 69 | * @return object of StatefulLspDbVerTlv |
| 70 | */ |
| 71 | public static StatefulLspDbVerTlv of(final long raw) { |
| 72 | return new StatefulLspDbVerTlv(raw); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public PcepVersion getVersion() { |
| 77 | return PcepVersion.PCEP_1; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns LSP State DB Version. |
| 82 | * |
| 83 | * @return rawValue value |
| 84 | */ |
| 85 | public long getLong() { |
| 86 | return rawValue; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public short getLength() { |
| 91 | return LENGTH; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public short getType() { |
| 96 | return TYPE; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public int hashCode() { |
| 101 | return Objects.hash(rawValue); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public boolean equals(Object obj) { |
| 106 | if (this == obj) { |
| 107 | return true; |
| 108 | } |
| 109 | if (obj instanceof StatefulLspDbVerTlv) { |
| 110 | StatefulLspDbVerTlv other = (StatefulLspDbVerTlv) obj; |
| 111 | return Objects.equals(this.rawValue, other.rawValue); |
| 112 | } |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public int write(ChannelBuffer c) { |
| 118 | c.writeShort(TYPE); |
| 119 | c.writeShort(LENGTH); |
| 120 | c.writeLong(rawValue); |
| 121 | return c.writerIndex(); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Reads the channel buffer and returns object of StatefulLspDbVerTlv. |
| 126 | * |
| 127 | * @param c input channel buffer |
| 128 | * @return object of StatefulLspDbVerTlv |
| 129 | */ |
| 130 | public static StatefulLspDbVerTlv read(ChannelBuffer c) { |
| 131 | return StatefulLspDbVerTlv.of(c.readLong()); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public String toString() { |
Sho SHIMIZU | 7cdbcf7 | 2015-09-03 14:43:05 -0700 | [diff] [blame] | 136 | return MoreObjects.toStringHelper(getClass()) |
| 137 | .add("Type", TYPE) |
| 138 | .add("Length", LENGTH) |
| 139 | .add("Value", rawValue) |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 140 | .toString(); |
| 141 | } |
| 142 | } |