blob: 065ced8b8cd4a67ae5b3a866b211db489cd4c224 [file] [log] [blame]
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-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
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Objects;
22
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040023import com.google.common.annotations.Beta;
jcc4a20a5f2015-04-30 15:43:39 +080024import org.onosproject.core.ApplicationId;
25import org.onosproject.net.AbstractAnnotated;
26import org.onosproject.net.Annotations;
Thomas Vachuskabf916ea2015-05-20 18:24:34 -070027import org.onosproject.incubator.net.tunnel.Tunnel.Type;
jcc4a20a5f2015-04-30 15:43:39 +080028
29import com.google.common.base.MoreObjects;
30
31/**
32 * Represents for a order that consumer subscribe tunnel. ONOS maintains request
33 * information, it means ONOS knows how much resource echo consumer uses in the
34 * ONOS. Although there is no a tunnel that consumer want to use, when producer
35 * creates a new tunnel, ONOS will notify the consumers that want to use it.
36 */
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040037@Beta
jcc4a20a5f2015-04-30 15:43:39 +080038public final class TunnelSubscription extends AbstractAnnotated {
39 private final ApplicationId consumerId;
40 private final TunnelEndPoint src;
41 private final TunnelEndPoint dst;
42 private final Type type;
43 private final TunnelId tunnelId;
44 private final TunnelName tunnelName;
45
46 /**
47 * Creates a TunnelSubscription.
48 *
49 * @param consumerId consumer identity
50 * @param src source tunnel end point of tunnel
51 * @param dst destination tunnel end point of tunnel
52 * @param tunnelId tunnel identity
53 * @param type tunnel type
54 * @param tunnelName the name of a tunnel
55 * @param annotations parameter
56 */
57 public TunnelSubscription(ApplicationId consumerId, TunnelEndPoint src,
58 TunnelEndPoint dst, TunnelId tunnelId, Type type,
59 TunnelName tunnelName, Annotations... annotations) {
60 super(annotations);
61 checkNotNull(consumerId, "consumerId cannot be null");
62 this.consumerId = consumerId;
63 this.src = src;
64 this.dst = dst;
65 this.type = type;
66 this.tunnelId = tunnelId;
67 this.tunnelName = tunnelName;
68 }
69
70 /**
71 * Returns consumer identity.
72 *
73 * @return consumerId consumer id
74 */
75 public ApplicationId consumerId() {
76 return consumerId;
77 }
78
79 /**
80 * Returns source point of tunnel.
81 *
82 * @return source point
83 */
84 public TunnelEndPoint src() {
85 return src;
86 }
87
88 /**
89 * Returns destination point of tunnel.
90 *
91 * @return destination point
92 */
93 public TunnelEndPoint dst() {
94 return dst;
95 }
96
97 /**
98 * Returns tunnel type.
99 *
100 * @return tunnel type
101 */
102 public Type type() {
103 return type;
104 }
105
106 /**
107 * Returns tunnel identity.
108 *
109 * @return tunnel id
110 */
111 public TunnelId tunnelId() {
112 return tunnelId;
113 }
114
115 /**
116 * Returns tunnel name.
117 *
118 * @return tunnel name
119 */
120 public TunnelName tunnelName() {
121 return tunnelName;
122 }
123
124 @Override
125 public int hashCode() {
126 return Objects.hash(consumerId, src, dst, type, tunnelId, tunnelName);
127 }
128
129 @Override
130 public boolean equals(Object obj) {
131 if (this == obj) {
132 return true;
133 }
134 if (obj instanceof TunnelSubscription) {
135 final TunnelSubscription other = (TunnelSubscription) obj;
136 return Objects.equals(this.src, other.src)
137 && Objects.equals(this.dst, other.dst)
138 && Objects.equals(this.consumerId, other.consumerId)
139 && Objects.equals(this.type, other.type)
140 && Objects.equals(this.tunnelId, other.tunnelId)
141 && Objects.equals(this.tunnelName, other.tunnelName);
142 }
143 return false;
144 }
145
146 @Override
147 public String toString() {
148 return MoreObjects.toStringHelper(getClass())
149 .add("src", src)
150 .add("dst", dst)
151 .add("consumerId", consumerId)
152 .add("type", type)
153 .add("tunnelId", tunnelId)
154 .add("tunnelName", tunnelName).toString();
155 }
156}