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 2016-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 StatefulIPv4LspIdentidiersTlv. |
| 30 | */ |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 31 | public class StatefulIPv4LspIdentifiersTlv implements PcepValueType { |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 32 | |
| 33 | /* IPV4-LSP-IDENTIFIERS TLV format |
| 34 | * |
| 35 | * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10 |
| 36 | * |
| 37 | |
| 38 | 0 1 2 3 |
| 39 | 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 |
| 40 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 41 | | Type=18 | Length=16 | |
| 42 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 43 | | IPv4 Tunnel Sender Address | |
| 44 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 45 | | LSP ID | Tunnel ID | |
| 46 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 47 | | Extended Tunnel ID | |
| 48 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 49 | | IPv4 Tunnel Endpoint Address | |
| 50 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 51 | |
| 52 | */ |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 53 | private static final Logger log = LoggerFactory.getLogger(StatefulIPv4LspIdentifiersTlv.class); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 54 | |
| 55 | public static final short TYPE = 18; |
| 56 | public static final short LENGTH = 16; |
| 57 | public static final int VALUE_LENGTH = 16; |
| 58 | private final int ipv4IngressAddress; |
| 59 | private final short lspId; |
| 60 | private final short tunnelId; |
| 61 | private final int extendedTunnelId; |
| 62 | private final int ipv4EgressAddress; |
| 63 | |
| 64 | /** |
| 65 | * Constructor to initialize member variables. |
| 66 | * |
| 67 | * @param ipv4IngressAddress ingress ipv4 address |
| 68 | * @param lspId lsp id |
| 69 | * @param tunnelId tunnel id |
| 70 | * @param extendedTunnelId extended tunnel id |
| 71 | * @param ipv4EgressAddress egress ipv4 address |
| 72 | */ |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 73 | public StatefulIPv4LspIdentifiersTlv(int ipv4IngressAddress, short lspId, short tunnelId, int extendedTunnelId, |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 74 | int ipv4EgressAddress) { |
| 75 | |
| 76 | this.ipv4IngressAddress = ipv4IngressAddress; |
| 77 | this.lspId = lspId; |
| 78 | this.tunnelId = tunnelId; |
| 79 | this.extendedTunnelId = extendedTunnelId; |
| 80 | this.ipv4EgressAddress = ipv4EgressAddress; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Creates object of StatefulIPv4LspIdentidiersTlv. |
| 85 | * |
| 86 | * @param ipv4IngressAddress ingress ipv4 address |
| 87 | * @param lspId lsp id |
| 88 | * @param tunnelId tunnel id |
| 89 | * @param extendedTunnelId extended tunnel id |
| 90 | * @param ipv4EgressAddress egress ipv4 address |
| 91 | * @return object of StatefulIPv4LspIdentidiersTlv |
| 92 | */ |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 93 | public static StatefulIPv4LspIdentifiersTlv of(int ipv4IngressAddress, short lspId, short tunnelId, |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 94 | int extendedTunnelId, int ipv4EgressAddress) { |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 95 | return new StatefulIPv4LspIdentifiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 96 | ipv4EgressAddress); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Returns tunnel id. |
| 101 | * |
| 102 | * @return tunnelId |
| 103 | */ |
| 104 | public short getTunnelId() { |
| 105 | return this.tunnelId; |
| 106 | } |
| 107 | |
| 108 | /** |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 109 | * Returns LSP id. |
| 110 | * |
| 111 | * @return lspId |
| 112 | */ |
| 113 | public short getLspId() { |
| 114 | return this.lspId; |
| 115 | } |
| 116 | |
| 117 | /** |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 118 | * Returns extendedTunnelId. |
| 119 | * |
| 120 | * @return extendedTunnelId |
| 121 | */ |
| 122 | public int getextendedTunnelId() { |
| 123 | return this.extendedTunnelId; |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public PcepVersion getVersion() { |
| 128 | return PcepVersion.PCEP_1; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Returns ipv4IngressAddress. |
| 133 | * |
| 134 | * @return ipv4IngressAddress |
| 135 | */ |
| 136 | public int getIpv4IngressAddress() { |
| 137 | return ipv4IngressAddress; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Returns ipv4EgressAddress. |
| 142 | * |
| 143 | * @return ipv4EgressAddress |
| 144 | */ |
| 145 | public int getIpv4EgressAddress() { |
| 146 | return ipv4EgressAddress; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public short getType() { |
| 151 | return TYPE; |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public short getLength() { |
| 156 | return LENGTH; |
| 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public int hashCode() { |
| 161 | return Objects.hash(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, ipv4EgressAddress); |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public boolean equals(Object obj) { |
| 166 | if (this == obj) { |
| 167 | return true; |
| 168 | } |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 169 | if (obj instanceof StatefulIPv4LspIdentifiersTlv) { |
| 170 | StatefulIPv4LspIdentifiersTlv other = (StatefulIPv4LspIdentifiersTlv) obj; |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 171 | return Objects.equals(this.ipv4IngressAddress, other.ipv4IngressAddress) |
| 172 | && Objects.equals(this.lspId, other.lspId) && Objects.equals(this.tunnelId, other.tunnelId) |
| 173 | && Objects.equals(this.extendedTunnelId, other.extendedTunnelId) |
| 174 | && Objects.equals(this.ipv4EgressAddress, other.ipv4EgressAddress); |
| 175 | } |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public int write(ChannelBuffer c) { |
| 181 | int iLenStartIndex = c.writerIndex(); |
| 182 | c.writeShort(TYPE); |
| 183 | c.writeShort(LENGTH); |
| 184 | c.writeInt(ipv4IngressAddress); |
| 185 | c.writeShort(lspId); |
| 186 | c.writeShort(tunnelId); |
| 187 | c.writeInt(extendedTunnelId); |
| 188 | c.writeInt(ipv4EgressAddress); |
| 189 | |
| 190 | return c.writerIndex() - iLenStartIndex; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Reads the channel buffer and returns object of StatefulIPv4LspIdentidiersTlv. |
| 195 | * |
| 196 | * @param c of type channel buffer |
| 197 | * @return object of StatefulIPv4LspIdentidiersTlv |
| 198 | */ |
| 199 | public static PcepValueType read(ChannelBuffer c) { |
| 200 | int ipv4IngressAddress = c.readInt(); |
| 201 | short lspId = c.readShort(); |
| 202 | short tunnelId = c.readShort(); |
| 203 | int extendedTunnelId = c.readInt(); |
| 204 | int ipv4EgressAddress = c.readInt(); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 205 | return new StatefulIPv4LspIdentifiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 206 | ipv4EgressAddress); |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public String toString() { |
| 211 | return MoreObjects.toStringHelper(getClass()) |
| 212 | .add("Type:", TYPE) |
| 213 | .add("Length:", LENGTH) |
| 214 | .add("Ipv4IngressAddress:", ipv4IngressAddress) |
| 215 | .add("LspId:", lspId).add("TunnelId:", tunnelId) |
| 216 | .add("ExtendedTunnelId:", extendedTunnelId) |
| 217 | .add("Ipv4EgressAddress:", ipv4EgressAddress).toString(); |
| 218 | } |
| 219 | } |