Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | */ |
| 31 | public class StatefulIPv4LspIdentidiersTlv implements PcepValueType { |
| 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 | */ |
| 53 | protected static final Logger log = LoggerFactory.getLogger(StatefulIPv4LspIdentidiersTlv.class); |
| 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 | */ |
| 73 | public StatefulIPv4LspIdentidiersTlv(int ipv4IngressAddress, short lspId, short tunnelId, int extendedTunnelId, |
| 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 | */ |
| 93 | public static StatefulIPv4LspIdentidiersTlv of(int ipv4IngressAddress, short lspId, short tunnelId, |
| 94 | int extendedTunnelId, int ipv4EgressAddress) { |
| 95 | return new StatefulIPv4LspIdentidiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, |
| 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 | /** |
| 109 | * Returns extendedTunnelId. |
| 110 | * |
| 111 | * @return extendedTunnelId |
| 112 | */ |
| 113 | public int getextendedTunnelId() { |
| 114 | return this.extendedTunnelId; |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public PcepVersion getVersion() { |
| 119 | return PcepVersion.PCEP_1; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Returns ipv4IngressAddress. |
| 124 | * |
| 125 | * @return ipv4IngressAddress |
| 126 | */ |
| 127 | public int getIpv4IngressAddress() { |
| 128 | return ipv4IngressAddress; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Returns ipv4EgressAddress. |
| 133 | * |
| 134 | * @return ipv4EgressAddress |
| 135 | */ |
| 136 | public int getIpv4EgressAddress() { |
| 137 | return ipv4EgressAddress; |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public short getType() { |
| 142 | return TYPE; |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public short getLength() { |
| 147 | return LENGTH; |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public int hashCode() { |
| 152 | return Objects.hash(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, ipv4EgressAddress); |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public boolean equals(Object obj) { |
| 157 | if (this == obj) { |
| 158 | return true; |
| 159 | } |
| 160 | if (obj instanceof StatefulIPv4LspIdentidiersTlv) { |
| 161 | StatefulIPv4LspIdentidiersTlv other = (StatefulIPv4LspIdentidiersTlv) obj; |
| 162 | return Objects.equals(this.ipv4IngressAddress, other.ipv4IngressAddress) |
| 163 | && Objects.equals(this.lspId, other.lspId) && Objects.equals(this.tunnelId, other.tunnelId) |
| 164 | && Objects.equals(this.extendedTunnelId, other.extendedTunnelId) |
| 165 | && Objects.equals(this.ipv4EgressAddress, other.ipv4EgressAddress); |
| 166 | } |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public int write(ChannelBuffer c) { |
| 172 | int iLenStartIndex = c.writerIndex(); |
| 173 | c.writeShort(TYPE); |
| 174 | c.writeShort(LENGTH); |
| 175 | c.writeInt(ipv4IngressAddress); |
| 176 | c.writeShort(lspId); |
| 177 | c.writeShort(tunnelId); |
| 178 | c.writeInt(extendedTunnelId); |
| 179 | c.writeInt(ipv4EgressAddress); |
| 180 | |
| 181 | return c.writerIndex() - iLenStartIndex; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Reads the channel buffer and returns object of StatefulIPv4LspIdentidiersTlv. |
| 186 | * |
| 187 | * @param c of type channel buffer |
| 188 | * @return object of StatefulIPv4LspIdentidiersTlv |
| 189 | */ |
| 190 | public static PcepValueType read(ChannelBuffer c) { |
| 191 | int ipv4IngressAddress = c.readInt(); |
| 192 | short lspId = c.readShort(); |
| 193 | short tunnelId = c.readShort(); |
| 194 | int extendedTunnelId = c.readInt(); |
| 195 | int ipv4EgressAddress = c.readInt(); |
| 196 | return new StatefulIPv4LspIdentidiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, |
| 197 | ipv4EgressAddress); |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public String toString() { |
| 202 | return MoreObjects.toStringHelper(getClass()) |
| 203 | .add("Type:", TYPE) |
| 204 | .add("Length:", LENGTH) |
| 205 | .add("Ipv4IngressAddress:", ipv4IngressAddress) |
| 206 | .add("LspId:", lspId).add("TunnelId:", tunnelId) |
| 207 | .add("ExtendedTunnelId:", extendedTunnelId) |
| 208 | .add("Ipv4EgressAddress:", ipv4EgressAddress).toString(); |
| 209 | } |
| 210 | } |