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