blob: a05b4e584cea9a9f3e8b81c5bb18d6ca0472ee6c [file] [log] [blame]
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -07003 *
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
17package org.onosproject.pcepio.types;
18
19import java.util.Objects;
20
21import org.jboss.netty.buffer.ChannelBuffer;
22import org.onosproject.pcepio.protocol.PcepVersion;
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25
26import com.google.common.base.MoreObjects;
27
28/**
29 * Provides StatefulIPv4LspIdentidiersTlv.
30 */
Avantika-Huawei56c11842016-04-28 00:56:56 +053031public class StatefulIPv4LspIdentifiersTlv implements PcepValueType {
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070032
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 Milkey9c9cde42018-01-12 14:22:06 -080053 private static final Logger log = LoggerFactory.getLogger(StatefulIPv4LspIdentifiersTlv.class);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070054
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-Huawei56c11842016-04-28 00:56:56 +053073 public StatefulIPv4LspIdentifiersTlv(int ipv4IngressAddress, short lspId, short tunnelId, int extendedTunnelId,
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070074 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-Huawei56c11842016-04-28 00:56:56 +053093 public static StatefulIPv4LspIdentifiersTlv of(int ipv4IngressAddress, short lspId, short tunnelId,
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070094 int extendedTunnelId, int ipv4EgressAddress) {
Avantika-Huawei56c11842016-04-28 00:56:56 +053095 return new StatefulIPv4LspIdentifiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId,
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070096 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-Huawei56c11842016-04-28 00:56:56 +0530109 * Returns LSP id.
110 *
111 * @return lspId
112 */
113 public short getLspId() {
114 return this.lspId;
115 }
116
117 /**
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700118 * 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-Huawei56c11842016-04-28 00:56:56 +0530169 if (obj instanceof StatefulIPv4LspIdentifiersTlv) {
170 StatefulIPv4LspIdentifiersTlv other = (StatefulIPv4LspIdentifiersTlv) obj;
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700171 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-Huawei56c11842016-04-28 00:56:56 +0530205 return new StatefulIPv4LspIdentifiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId,
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700206 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}