Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / concepts / TunnelIdentifier.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.concepts;
9
10 import org.opendaylight.protocol.concepts.AbstractIdentifier;
11 import org.opendaylight.protocol.util.ByteArray;
12 import com.google.common.base.Objects.ToStringHelper;
13
14 /**
15  * A 16-bit identifier used in the SESSION that remains constant over the life
16  * of the tunnel.
17  */
18 public final class TunnelIdentifier extends AbstractIdentifier<TunnelIdentifier> {
19
20         private static final long serialVersionUID = 137237703900885441L;
21
22         private final byte[] tunnelId;
23
24         /**
25          * Creates TunnelIdentifier using byte array as value.
26          *
27          * @param tunnelId
28          *            value of the TunnelIdentifier TLV. Must be exactly 2 bytes
29          *            long.
30          */
31         public TunnelIdentifier(final byte[] tunnelId) {
32                 if (tunnelId.length != 2)
33                         throw new IllegalArgumentException("Invalid tunnel ID.");
34                 this.tunnelId = tunnelId;
35         }
36
37         @Override
38         public byte[] getBytes() {
39                 return this.tunnelId;
40         }
41
42         @Override
43         protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
44                 return toStringHelper.add("tunnelId", ByteArray.toHexString(tunnelId, "."));
45         }
46 }