blob: 9a1871d990b4e55597ee22544fbdfddc2d13c618 [file] [log] [blame]
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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 */
Thomas Vachuskabf916ea2015-05-20 18:24:34 -070016package org.onosproject.incubator.store.tunnel.impl;
jccd8697232015-05-05 14:42:23 +080017
18import static org.slf4j.LoggerFactory.getLogger;
19
20import java.util.ArrayList;
21import java.util.Collection;
22import java.util.Collections;
23import java.util.HashSet;
24import java.util.List;
25import java.util.Objects;
26import java.util.Set;
27
28import org.apache.felix.scr.annotations.Activate;
29import org.apache.felix.scr.annotations.Component;
30import org.apache.felix.scr.annotations.Deactivate;
31import org.apache.felix.scr.annotations.Reference;
32import org.apache.felix.scr.annotations.ReferenceCardinality;
33import org.apache.felix.scr.annotations.Service;
34import org.onlab.util.KryoNamespace;
35import org.onosproject.cluster.ClusterService;
36import org.onosproject.core.ApplicationId;
37import org.onosproject.core.CoreService;
38import org.onosproject.core.IdGenerator;
Thomas Vachuskabf916ea2015-05-20 18:24:34 -070039import org.onosproject.incubator.net.tunnel.DefaultTunnel;
40import org.onosproject.incubator.net.tunnel.Tunnel;
41import org.onosproject.incubator.net.tunnel.Tunnel.Type;
42import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
43import org.onosproject.incubator.net.tunnel.TunnelEvent;
44import org.onosproject.incubator.net.tunnel.TunnelId;
45import org.onosproject.incubator.net.tunnel.TunnelName;
46import org.onosproject.incubator.net.tunnel.TunnelStore;
47import org.onosproject.incubator.net.tunnel.TunnelStoreDelegate;
48import org.onosproject.incubator.net.tunnel.TunnelSubscription;
samuel7a5691a2015-05-23 00:36:32 +080049import org.onosproject.net.Annotations;
50import org.onosproject.net.DefaultAnnotations;
51import org.onosproject.net.SparseAnnotations;
52import org.onosproject.net.provider.ProviderId;
jccd8697232015-05-05 14:42:23 +080053import org.onosproject.store.AbstractStore;
54import org.onosproject.store.app.GossipApplicationStore.InternalState;
55import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
56import org.onosproject.store.serializers.KryoNamespaces;
57import org.onosproject.store.service.EventuallyConsistentMap;
58import org.onosproject.store.service.MultiValuedTimestamp;
59import org.onosproject.store.service.StorageService;
Madan Jampanibcf1a482015-06-24 19:05:56 -070060import org.onosproject.store.service.WallClockTimestamp;
jccd8697232015-05-05 14:42:23 +080061import org.slf4j.Logger;
62
63import com.google.common.base.MoreObjects;
64import com.google.common.collect.ImmutableSet;
65
66/**
67 * Manages inventory of tunnel in distributed data store that uses optimistic
68 * replication and gossip based techniques.
69 */
70@Component(immediate = true)
71@Service
72public class DistributedTunnelStore
73 extends AbstractStore<TunnelEvent, TunnelStoreDelegate>
74 implements TunnelStore {
75
76 private final Logger log = getLogger(getClass());
77
78 /**
79 * The topic used for obtaining globally unique ids.
80 */
Satish Kfc1a6312016-02-23 13:33:04 +053081 private String tunnelOpTopic = "tunnel-ops-ids";
jccd8697232015-05-05 14:42:23 +080082
83 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
84 protected ClusterCommunicationService clusterCommunicator;
85
86 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
87 protected ClusterService clusterService;
88
89 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
90 protected CoreService coreService;
91
92 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
93 protected StorageService storageService;
94
95 // tunnel identity as map key in the store.
96 private EventuallyConsistentMap<TunnelId, Tunnel> tunnelIdAsKeyStore;
97 // tunnel name as map key in the store.
98 private EventuallyConsistentMap<TunnelName, Set<TunnelId>> tunnelNameAsKeyStore;
99 // maintains all the tunnels between source and destination.
100 private EventuallyConsistentMap<TunnelKey, Set<TunnelId>> srcAndDstKeyStore;
101 // maintains all the tunnels by tunnel type.
102 private EventuallyConsistentMap<Tunnel.Type, Set<TunnelId>> typeKeyStore;
103 // maintains records that app subscribes tunnel.
104 private EventuallyConsistentMap<ApplicationId, Set<TunnelSubscription>> orderRelationship;
105
106 private IdGenerator idGenerator;
107
108 @Activate
109 public void activate() {
110 KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
111 .register(KryoNamespaces.API)
112 .register(MultiValuedTimestamp.class)
113 .register(InternalState.class);
114 tunnelIdAsKeyStore = storageService
115 .<TunnelId, Tunnel>eventuallyConsistentMapBuilder()
116 .withName("all_tunnel").withSerializer(serializer)
Madan Jampanibcf1a482015-06-24 19:05:56 -0700117 .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
jccd8697232015-05-05 14:42:23 +0800118 tunnelNameAsKeyStore = storageService
119 .<TunnelName, Set<TunnelId>>eventuallyConsistentMapBuilder()
120 .withName("tunnel_name_tunnel").withSerializer(serializer)
Madan Jampanibcf1a482015-06-24 19:05:56 -0700121 .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
jccd8697232015-05-05 14:42:23 +0800122 srcAndDstKeyStore = storageService
123 .<TunnelKey, Set<TunnelId>>eventuallyConsistentMapBuilder()
124 .withName("src_dst_tunnel").withSerializer(serializer)
Madan Jampanibcf1a482015-06-24 19:05:56 -0700125 .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
jccd8697232015-05-05 14:42:23 +0800126 typeKeyStore = storageService
127 .<Tunnel.Type, Set<TunnelId>>eventuallyConsistentMapBuilder()
128 .withName("type_tunnel").withSerializer(serializer)
Madan Jampanibcf1a482015-06-24 19:05:56 -0700129 .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
samuel7a5691a2015-05-23 00:36:32 +0800130 orderRelationship = storageService
131 .<ApplicationId, Set<TunnelSubscription>>eventuallyConsistentMapBuilder()
132 .withName("type_tunnel").withSerializer(serializer)
Madan Jampanibcf1a482015-06-24 19:05:56 -0700133 .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
Satish Kfc1a6312016-02-23 13:33:04 +0530134 idGenerator = coreService.getIdGenerator(tunnelOpTopic);
jccd8697232015-05-05 14:42:23 +0800135 log.info("Started");
136 }
137
138 @Deactivate
139 public void deactivate() {
Madan Jampani632f16b2015-08-11 12:42:59 -0700140 orderRelationship.destroy();
jccd8697232015-05-05 14:42:23 +0800141 tunnelIdAsKeyStore.destroy();
142 srcAndDstKeyStore.destroy();
143 typeKeyStore.destroy();
144 tunnelNameAsKeyStore.destroy();
145 log.info("Stopped");
146 }
147
148 @Override
149 public TunnelId createOrUpdateTunnel(Tunnel tunnel) {
150 // tunnelIdAsKeyStore.
Satish Kf1b38bc2015-11-22 17:13:51 +0530151 if (tunnel.tunnelId() != null && !"".equals(tunnel.tunnelId().toString())) {
jccd8697232015-05-05 14:42:23 +0800152 Tunnel old = tunnelIdAsKeyStore.get(tunnel.tunnelId());
153 if (old == null) {
154 log.info("This tunnel[" + tunnel.tunnelId() + "] is not available.");
155 return tunnel.tunnelId();
156 }
samuel7a5691a2015-05-23 00:36:32 +0800157 DefaultAnnotations oldAnno = (DefaultAnnotations) old.annotations();
158 SparseAnnotations newAnno = (SparseAnnotations) tunnel.annotations();
159 Tunnel newT = new DefaultTunnel(old.providerId(), old.src(),
160 old.dst(), old.type(),
161 old.state(), old.groupId(),
jccd8697232015-05-05 14:42:23 +0800162 old.tunnelId(),
samuel7a5691a2015-05-23 00:36:32 +0800163 old.tunnelName(),
164 old.path(),
165 DefaultAnnotations.merge(oldAnno, newAnno));
jccd8697232015-05-05 14:42:23 +0800166 tunnelIdAsKeyStore.put(tunnel.tunnelId(), newT);
167 TunnelEvent event = new TunnelEvent(
168 TunnelEvent.Type.TUNNEL_UPDATED,
169 tunnel);
170 notifyDelegate(event);
171 return tunnel.tunnelId();
172 } else {
173 TunnelId tunnelId = TunnelId.valueOf(idGenerator.getNewId());
174 Tunnel newT = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
175 tunnel.dst(), tunnel.type(),
176 tunnel.state(), tunnel.groupId(),
177 tunnelId,
178 tunnel.tunnelName(),
samuel7a5691a2015-05-23 00:36:32 +0800179 tunnel.path(),
jccd8697232015-05-05 14:42:23 +0800180 tunnel.annotations());
181 TunnelKey key = TunnelKey.tunnelKey(tunnel.src(), tunnel.dst());
182 tunnelIdAsKeyStore.put(tunnelId, newT);
183 Set<TunnelId> tunnelnameSet = tunnelNameAsKeyStore.get(tunnel
184 .tunnelName());
185 if (tunnelnameSet == null) {
186 tunnelnameSet = new HashSet<TunnelId>();
187 }
188 tunnelnameSet.add(tunnelId);
189 tunnelNameAsKeyStore.put(tunnel
190 .tunnelName(), tunnelnameSet);
191 Set<TunnelId> srcAndDstKeySet = srcAndDstKeyStore.get(key);
192 if (srcAndDstKeySet == null) {
193 srcAndDstKeySet = new HashSet<TunnelId>();
194 }
195 srcAndDstKeySet.add(tunnelId);
196 srcAndDstKeyStore.put(key, srcAndDstKeySet);
197 Set<TunnelId> typeKeySet = typeKeyStore.get(tunnel.type());
198 if (typeKeySet == null) {
199 typeKeySet = new HashSet<TunnelId>();
200 }
201 typeKeySet.add(tunnelId);
202 typeKeyStore.put(tunnel.type(), typeKeySet);
203 TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED,
204 tunnel);
205 notifyDelegate(event);
206 return tunnelId;
207 }
208 }
209
210 @Override
211 public void deleteTunnel(TunnelId tunnelId) {
212 Tunnel deletedTunnel = tunnelIdAsKeyStore.get(tunnelId);
213 if (deletedTunnel == null) {
214 return;
215 }
216 tunnelNameAsKeyStore.get(deletedTunnel.tunnelName()).remove(tunnelId);
217 tunnelIdAsKeyStore.remove(tunnelId);
218 TunnelKey key = new TunnelKey(deletedTunnel.src(), deletedTunnel.dst());
219 srcAndDstKeyStore.get(key).remove(tunnelId);
220 typeKeyStore.get(deletedTunnel.type()).remove(tunnelId);
221 TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED,
222 deletedTunnel);
223 notifyDelegate(event);
224 }
225
226 @Override
227 public void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst,
228 ProviderId producerName) {
229 TunnelKey key = TunnelKey.tunnelKey(src, dst);
230 Set<TunnelId> idSet = srcAndDstKeyStore.get(key);
231 if (idSet == null) {
232 return;
233 }
234 Tunnel deletedTunnel = null;
235 TunnelEvent event = null;
236 List<TunnelEvent> ls = new ArrayList<TunnelEvent>();
237 for (TunnelId id : idSet) {
238 deletedTunnel = tunnelIdAsKeyStore.get(id);
Satish Kfc1a6312016-02-23 13:33:04 +0530239
240 if (producerName == null || (producerName != null
241 && producerName.equals(deletedTunnel.providerId()))) {
jccd8697232015-05-05 14:42:23 +0800242 tunnelIdAsKeyStore.remove(deletedTunnel.tunnelId());
243 tunnelNameAsKeyStore.get(deletedTunnel.tunnelName())
244 .remove(deletedTunnel.tunnelId());
245 srcAndDstKeyStore.get(key).remove(deletedTunnel.tunnelId());
246 typeKeyStore.get(deletedTunnel.type())
247 .remove(deletedTunnel.tunnelId());
Satish Kfc1a6312016-02-23 13:33:04 +0530248 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED,
249 deletedTunnel);
250 ls.add(event);
jccd8697232015-05-05 14:42:23 +0800251 }
252 }
Satish Kfc1a6312016-02-23 13:33:04 +0530253
254 if (!ls.isEmpty()) {
255 notifyDelegate(ls);
256 }
jccd8697232015-05-05 14:42:23 +0800257 }
258
259 @Override
260 public void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst, Type type,
261 ProviderId producerName) {
262 TunnelKey key = TunnelKey.tunnelKey(src, dst);
263 Set<TunnelId> idSet = srcAndDstKeyStore.get(key);
264 if (idSet == null) {
265 return;
266 }
267 Tunnel deletedTunnel = null;
268 TunnelEvent event = null;
269 List<TunnelEvent> ls = new ArrayList<TunnelEvent>();
270 for (TunnelId id : idSet) {
271 deletedTunnel = tunnelIdAsKeyStore.get(id);
Satish Kfc1a6312016-02-23 13:33:04 +0530272
273 if (type.equals(deletedTunnel.type()) && (producerName == null || (producerName != null
274 && producerName.equals(deletedTunnel.providerId())))) {
jccd8697232015-05-05 14:42:23 +0800275 tunnelIdAsKeyStore.remove(deletedTunnel.tunnelId());
276 tunnelNameAsKeyStore.get(deletedTunnel.tunnelName())
277 .remove(deletedTunnel.tunnelId());
278 srcAndDstKeyStore.get(key).remove(deletedTunnel.tunnelId());
279 typeKeyStore.get(deletedTunnel.type())
280 .remove(deletedTunnel.tunnelId());
Satish Kfc1a6312016-02-23 13:33:04 +0530281 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED,
282 deletedTunnel);
283 ls.add(event);
jccd8697232015-05-05 14:42:23 +0800284 }
285 }
Satish Kfc1a6312016-02-23 13:33:04 +0530286
287 if (!ls.isEmpty()) {
288 notifyDelegate(ls);
289 }
jccd8697232015-05-05 14:42:23 +0800290 }
291
292 @Override
293 public Tunnel borrowTunnel(ApplicationId appId, TunnelId tunnelId,
294 Annotations... annotations) {
295 Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
296 if (orderSet == null) {
297 orderSet = new HashSet<TunnelSubscription>();
298 }
299 TunnelSubscription order = new TunnelSubscription(appId, null, null, tunnelId, null, null,
300 annotations);
301 Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
Satish Kd9722352015-11-20 23:19:52 +0530302 if (result == null || Tunnel.State.INACTIVE.equals(result.state())) {
jccd8697232015-05-05 14:42:23 +0800303 return null;
304 }
Satish Kd9722352015-11-20 23:19:52 +0530305
jccd8697232015-05-05 14:42:23 +0800306 orderSet.add(order);
307 orderRelationship.put(appId, orderSet);
308 return result;
309 }
310
311 @Override
312 public Collection<Tunnel> borrowTunnel(ApplicationId appId,
313 TunnelEndPoint src,
314 TunnelEndPoint dst,
315 Annotations... annotations) {
316 Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
317 if (orderSet == null) {
318 orderSet = new HashSet<TunnelSubscription>();
319 }
320 TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, null, null, annotations);
321 boolean isExist = orderSet.contains(order);
322 if (!isExist) {
323 orderSet.add(order);
324 }
325 orderRelationship.put(appId, orderSet);
326 TunnelKey key = TunnelKey.tunnelKey(src, dst);
327 Set<TunnelId> idSet = srcAndDstKeyStore.get(key);
328 if (idSet == null || idSet.size() == 0) {
329 return Collections.emptySet();
330 }
331 Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
332 for (TunnelId tunnelId : idSet) {
333 Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
334 if (Tunnel.State.ACTIVE.equals(result.state())) {
335 tunnelSet.add(result);
336 }
337 }
338 return tunnelSet;
339 }
340
341 @Override
342 public Collection<Tunnel> borrowTunnel(ApplicationId appId,
343 TunnelEndPoint src,
344 TunnelEndPoint dst, Type type,
345 Annotations... annotations) {
346 Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
347 if (orderSet == null) {
348 orderSet = new HashSet<TunnelSubscription>();
349 }
350 TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, type, null, annotations);
351 boolean isExist = orderSet.contains(order);
352 if (!isExist) {
353 orderSet.add(order);
354 }
355 orderRelationship.put(appId, orderSet);
356 TunnelKey key = TunnelKey.tunnelKey(src, dst);
357 Set<TunnelId> idSet = srcAndDstKeyStore.get(key);
358 if (idSet == null || idSet.size() == 0) {
359 return Collections.emptySet();
360 }
361 Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
362 for (TunnelId tunnelId : idSet) {
363 Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
364 if (type.equals(result.type())
365 && Tunnel.State.ACTIVE.equals(result.state())) {
366 tunnelSet.add(result);
367 }
368 }
369 return tunnelSet;
370 }
371
372 @Override
373 public Collection<Tunnel> borrowTunnel(ApplicationId appId,
374 TunnelName tunnelName,
375 Annotations... annotations) {
376 Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
377 if (orderSet == null) {
378 orderSet = new HashSet<TunnelSubscription>();
379 }
380 TunnelSubscription order = new TunnelSubscription(appId, null, null, null, null, tunnelName,
381 annotations);
382 boolean isExist = orderSet.contains(order);
383 if (!isExist) {
384 orderSet.add(order);
385 }
386 orderRelationship.put(appId, orderSet);
387 Set<TunnelId> idSet = tunnelNameAsKeyStore.get(tunnelName);
388 if (idSet == null || idSet.size() == 0) {
389 return Collections.emptySet();
390 }
391 Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
392 for (TunnelId tunnelId : idSet) {
393 Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
394 if (Tunnel.State.ACTIVE.equals(result.state())) {
395 tunnelSet.add(result);
396 }
397 }
398 return tunnelSet;
399 }
400
401 @Override
402 public boolean returnTunnel(ApplicationId appId, TunnelName tunnelName,
403 Annotations... annotations) {
404 TunnelSubscription order = new TunnelSubscription(appId, null, null, null, null, tunnelName,
405 annotations);
406 return deleteOrder(order);
407 }
408
409 @Override
410 public boolean returnTunnel(ApplicationId appId, TunnelId tunnelId,
411 Annotations... annotations) {
412 TunnelSubscription order = new TunnelSubscription(appId, null, null, tunnelId, null, null,
413 annotations);
414 return deleteOrder(order);
415 }
416
417 @Override
418 public boolean returnTunnel(ApplicationId appId, TunnelEndPoint src,
419 TunnelEndPoint dst, Type type,
420 Annotations... annotations) {
421 TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, type, null, annotations);
422 return deleteOrder(order);
423 }
424
425 @Override
426 public boolean returnTunnel(ApplicationId appId, TunnelEndPoint src,
427 TunnelEndPoint dst, Annotations... annotations) {
428 TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, null, null, annotations);
429 return deleteOrder(order);
430 }
431
432 private boolean deleteOrder(TunnelSubscription order) {
433 Set<TunnelSubscription> orderSet = orderRelationship.get(order.consumerId());
434 if (orderSet == null) {
435 return true;
436 }
437 if (orderSet.contains(order)) {
438 orderSet.remove(order);
439 return true;
440 }
441 return false;
442 }
443
444 @Override
445 public Tunnel queryTunnel(TunnelId tunnelId) {
446 return tunnelIdAsKeyStore.get(tunnelId);
447 }
448
449 @Override
450 public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId appId) {
451 return orderRelationship.get(appId) != null ? ImmutableSet.copyOf(orderRelationship
452 .get(appId)) : Collections.emptySet();
453 }
454
455 @Override
456 public Collection<Tunnel> queryTunnel(Type type) {
457 Collection<Tunnel> result = new HashSet<Tunnel>();
458 Set<TunnelId> tunnelIds = typeKeyStore.get(type);
459 if (tunnelIds == null) {
460 return Collections.emptySet();
461 }
462 for (TunnelId id : tunnelIds) {
463 result.add(tunnelIdAsKeyStore.get(id));
464 }
465 return result.size() == 0 ? Collections.emptySet() : ImmutableSet
466 .copyOf(result);
467 }
468
469 @Override
470 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
471 Collection<Tunnel> result = new HashSet<Tunnel>();
472 TunnelKey key = TunnelKey.tunnelKey(src, dst);
473 Set<TunnelId> tunnelIds = srcAndDstKeyStore.get(key);
474 if (tunnelIds == null) {
475 return Collections.emptySet();
476 }
477 for (TunnelId id : tunnelIds) {
478 result.add(tunnelIdAsKeyStore.get(id));
479 }
480 return result.size() == 0 ? Collections.emptySet() : ImmutableSet
481 .copyOf(result);
482 }
483
484 @Override
samuel7a5691a2015-05-23 00:36:32 +0800485 public Collection<Tunnel> queryAllTunnels() {
486 return tunnelIdAsKeyStore.values();
487 }
488
489 @Override
jccd8697232015-05-05 14:42:23 +0800490 public int tunnelCount() {
491 return tunnelIdAsKeyStore.size();
492 }
493
494 /**
495 * Uses source TunnelPoint and destination TunnelPoint as map key.
496 */
497 private static final class TunnelKey {
498 private final TunnelEndPoint src;
499 private final TunnelEndPoint dst;
500
501 private TunnelKey(TunnelEndPoint src, TunnelEndPoint dst) {
502 this.src = src;
503 this.dst = dst;
504
505 }
506
507 /**
508 * create a map key.
509 *
510 * @param src
511 * @param dst
512 * @return a key using source ip and destination ip
513 */
514 static TunnelKey tunnelKey(TunnelEndPoint src, TunnelEndPoint dst) {
515 return new TunnelKey(src, dst);
516 }
517
518 @Override
519 public int hashCode() {
520 return Objects.hash(src, dst);
521 }
522
523 @Override
524 public boolean equals(Object obj) {
525 if (this == obj) {
526 return true;
527 }
528 if (obj instanceof TunnelKey) {
529 final TunnelKey other = (TunnelKey) obj;
530 return Objects.equals(this.src, other.src)
531 && Objects.equals(this.dst, other.dst);
532 }
533 return false;
534 }
535
536 @Override
537 public String toString() {
538 return MoreObjects.toStringHelper(getClass()).add("src", src)
539 .add("dst", dst).toString();
540 }
541 }
jccd8697232015-05-05 14:42:23 +0800542}