blob: f15d47b63b7fced44b55235c9d61067dba4bddad [file] [log] [blame]
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07001/*
Thomas Vachuska52f2cd12018-11-08 21:20:04 -08002 * Copyright 2018-present Open Networking Foundation
Thomas Vachuskabf916ea2015-05-20 18:24:34 -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.incubator.net.tunnel;
jcc4a20a5f2015-04-30 15:43:39 +080018
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040019import com.google.common.annotations.Beta;
20
jcc4a20a5f2015-04-30 15:43:39 +080021import java.util.Objects;
22
23/**
24 * Represents for a unique tunnel name. TunnelId is generated by ONOS while
25 * TunnelName is given by producer. The consumer can borrow tunnels with
26 * TunnelId or TunnelName.
27 */
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040028@Beta
jcc4a20a5f2015-04-30 15:43:39 +080029public final class TunnelName {
30 private final String str;
31
32 // Default constructor for serialization
33 private TunnelName(String tunnelName) {
34 this.str = tunnelName;
35 }
36
37
38 /**
39 * Creates a tunnel name using the supplied URI string.
40 *
41 * @param tunnelName tunnel name string
42 * @return tunnel name object
43 */
44 public static TunnelName tunnelName(String tunnelName) {
45 return new TunnelName(tunnelName);
46 }
47
48 /**
49 * The string of tunnel name.
50 *
51 * @return the string of tunnel name
52 */
53 public String value() {
54 return str;
55 }
56
57 @Override
58 public int hashCode() {
59 return Objects.hash(str);
60 }
61
62 @Override
63 public boolean equals(Object obj) {
64 if (this == obj) {
65 return true;
66 }
67 if (obj instanceof TunnelName) {
68 final TunnelName that = (TunnelName) obj;
69 return this.getClass() == that.getClass()
70 && Objects.equals(this.str, that.str);
71 }
72 return false;
73 }
74
75 @Override
76 public String toString() {
77 return str;
78 }
79}