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.
17 package org.onosproject.pcepio.types;
19 import java.util.Objects;
21 import org.jboss.netty.buffer.ChannelBuffer;
22 import org.onosproject.pcepio.protocol.PcepVersion;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.MoreObjects;
29 * Provides StatefulIPv4LspIdentidiersTlv.
31 public class StatefulIPv4LspIdentidiersTlv implements PcepValueType {
33 /* IPV4-LSP-IDENTIFIERS TLV format
35 * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 protected static final Logger log = LoggerFactory.getLogger(StatefulIPv4LspIdentidiersTlv.class);
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;
65 * Constructor to initialize member variables.
67 * @param ipv4IngressAddress ingress ipv4 address
69 * @param tunnelId tunnel id
70 * @param extendedTunnelId extended tunnel id
71 * @param ipv4EgressAddress egress ipv4 address
73 public StatefulIPv4LspIdentidiersTlv(int ipv4IngressAddress, short lspId, short tunnelId, int extendedTunnelId,
74 int ipv4EgressAddress) {
76 this.ipv4IngressAddress = ipv4IngressAddress;
78 this.tunnelId = tunnelId;
79 this.extendedTunnelId = extendedTunnelId;
80 this.ipv4EgressAddress = ipv4EgressAddress;
84 * Creates object of StatefulIPv4LspIdentidiersTlv.
86 * @param ipv4IngressAddress ingress ipv4 address
88 * @param tunnelId tunnel id
89 * @param extendedTunnelId extended tunnel id
90 * @param ipv4EgressAddress egress ipv4 address
91 * @return object of StatefulIPv4LspIdentidiersTlv
93 public static StatefulIPv4LspIdentidiersTlv of(int ipv4IngressAddress, short lspId, short tunnelId,
94 int extendedTunnelId, int ipv4EgressAddress) {
95 return new StatefulIPv4LspIdentidiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId,
104 public short getTunnelId() {
105 return this.tunnelId;
109 * Returns extendedTunnelId.
111 * @return extendedTunnelId
113 public int getextendedTunnelId() {
114 return this.extendedTunnelId;
118 public PcepVersion getVersion() {
119 return PcepVersion.PCEP_1;
123 * Returns ipv4IngressAddress.
125 * @return ipv4IngressAddress
127 public int getIpv4IngressAddress() {
128 return ipv4IngressAddress;
132 * Returns ipv4EgressAddress.
134 * @return ipv4EgressAddress
136 public int getIpv4EgressAddress() {
137 return ipv4EgressAddress;
141 public short getType() {
146 public short getLength() {
151 public int hashCode() {
152 return Objects.hash(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, ipv4EgressAddress);
156 public boolean equals(Object obj) {
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);
171 public int write(ChannelBuffer c) {
172 int iLenStartIndex = c.writerIndex();
174 c.writeShort(LENGTH);
175 c.writeInt(ipv4IngressAddress);
177 c.writeShort(tunnelId);
178 c.writeInt(extendedTunnelId);
179 c.writeInt(ipv4EgressAddress);
181 return c.writerIndex() - iLenStartIndex;
185 * Reads the channel buffer and returns object of StatefulIPv4LspIdentidiersTlv.
187 * @param c of type channel buffer
188 * @return object of StatefulIPv4LspIdentidiersTlv
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,
201 public String toString() {
202 return MoreObjects.toStringHelper(getClass())
204 .add("Length:", LENGTH)
205 .add("Ipv4IngressAddress:", ipv4IngressAddress)
206 .add("LspId:", lspId).add("TunnelId:", tunnelId)
207 .add("ExtendedTunnelId:", extendedTunnelId)
208 .add("Ipv4EgressAddress:", ipv4EgressAddress).toString();