2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.tlv;
10 import java.nio.ByteBuffer;
11 import java.nio.charset.CharacterCodingException;
12 import java.nio.charset.Charset;
13 import java.util.Arrays;
15 import org.opendaylight.protocol.pcep.PCEPTlv;
18 * Structure of Node Identifier TLV.
20 * @see draft-ietf-pce-stateful-pce-01 (sec. 7.1.3) - NODE_IDENTIFIER_TLV
22 public class NodeIdentifierTlv implements PCEPTlv {
23 private static final long serialVersionUID = -7959631526276210055L;
24 private final byte[] value;
27 * Constructs new Node Identifier TLV.
32 public NodeIdentifierTlv(byte[] value) {
34 throw new IllegalArgumentException("Value is mandatory.");
35 if (value.length == 0)
36 throw new IllegalArgumentException("Value has to be long at least 1 byte.");
42 * Gets value of Node Identifier TLV as Bytes Array.
46 public byte[] getValue() {
51 public int hashCode() {
54 result = prime * result + Arrays.hashCode(this.value);
59 public boolean equals(Object obj) {
64 if (this.getClass() != obj.getClass())
66 final NodeIdentifierTlv other = (NodeIdentifierTlv) obj;
67 if (!Arrays.equals(this.value, other.value))
73 public String toString() {
74 final StringBuilder builder = new StringBuilder();
75 builder.append("NodeIdentifierTlv [value=");
77 builder.append(Charset.forName("UTF-8").newDecoder().decode(ByteBuffer.wrap(this.value)).toString());
78 } catch (final CharacterCodingException e) {
79 builder.append(Arrays.toString(this.value));
82 return builder.toString();