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