blob: 530e6d3c9b4bc3388018cdf1469c89f055801395 [file] [log] [blame]
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -08001/*
2 * Copyright 2014 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 */
16package org.onlab.onos.sdnip;
17
18import java.util.Collection;
19import java.util.HashMap;
20import java.util.LinkedList;
21import java.util.List;
22import java.util.Map;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080023import java.util.Objects;
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080024import java.util.concurrent.ConcurrentHashMap;
25import java.util.concurrent.ExecutorService;
26import java.util.concurrent.Executors;
27import java.util.concurrent.Semaphore;
28
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080029import org.onlab.onos.core.ApplicationId;
30import org.onlab.onos.net.flow.criteria.Criteria.IPCriterion;
31import org.onlab.onos.net.flow.criteria.Criterion;
32import org.onlab.onos.net.intent.Intent;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080033import org.onlab.onos.net.intent.IntentOperations;
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080034import org.onlab.onos.net.intent.IntentService;
35import org.onlab.onos.net.intent.IntentState;
36import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080037import org.onlab.onos.net.intent.PointToPointIntent;
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080038import org.onlab.packet.Ip4Prefix;
39import org.slf4j.Logger;
40import org.slf4j.LoggerFactory;
41
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080042import com.google.common.util.concurrent.ThreadFactoryBuilder;
43
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080044import static com.google.common.base.Preconditions.checkArgument;
45
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080046public class IntentSynchronizer {
47 private static final Logger log =
48 LoggerFactory.getLogger(IntentSynchronizer.class);
49
50 private final ApplicationId appId;
51 private final IntentService intentService;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080052 private final Map<IntentKey, PointToPointIntent> peerIntents;
53 private final Map<Ip4Prefix, MultiPointToSinglePointIntent> routeIntents;
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080054
55 //
56 // State to deal with SDN-IP Leader election and pushing Intents
57 //
58 private final ExecutorService bgpIntentsSynchronizerExecutor;
59 private final Semaphore intentsSynchronizerSemaphore = new Semaphore(0);
60 private volatile boolean isElectedLeader = false;
61 private volatile boolean isActivatedLeader = false;
62
63 /**
64 * Class constructor.
65 *
66 * @param appId the Application ID
67 * @param intentService the intent service
68 */
69 IntentSynchronizer(ApplicationId appId, IntentService intentService) {
70 this.appId = appId;
71 this.intentService = intentService;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080072 peerIntents = new ConcurrentHashMap<>();
73 routeIntents = new ConcurrentHashMap<>();
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080074
75 bgpIntentsSynchronizerExecutor = Executors.newSingleThreadExecutor(
76 new ThreadFactoryBuilder()
Pavlin Radoslavov8b752442014-11-18 14:34:37 -080077 .setNameFormat("sdnip-intents-synchronizer-%d").build());
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080078 }
79
80 /**
81 * Starts the synchronizer.
82 */
83 public void start() {
84 bgpIntentsSynchronizerExecutor.execute(new Runnable() {
85 @Override
86 public void run() {
87 doIntentSynchronizationThread();
88 }
89 });
90 }
91
92 /**
93 * Stops the synchronizer.
94 */
95 public void stop() {
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080096 synchronized (this) {
97 // Stop the thread(s)
98 bgpIntentsSynchronizerExecutor.shutdownNow();
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080099
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800100 //
101 // Withdraw all SDN-IP intents
102 //
103 if (!isElectedLeader) {
104 return; // Nothing to do: not the leader anymore
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800105 }
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800106
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800107 //
108 // Build a batch operation to withdraw all intents from this
109 // application.
110 //
111 log.debug("Withdrawing all SDN-IP Intents...");
112 IntentOperations.Builder builder = IntentOperations.builder();
113 for (Intent intent : intentService.getIntents()) {
114 // Skip the intents from other applications
115 if (!intent.appId().equals(appId)) {
116 continue;
117 }
118
119 // Skip the intents that are already withdrawn
120 IntentState intentState =
121 intentService.getIntentState(intent.id());
122 if (intentState.equals(IntentState.WITHDRAWING) ||
123 intentState.equals(IntentState.WITHDRAWN)) {
124 continue;
125 }
126
127 builder.addWithdrawOperation(intent.id());
128 }
129 intentService.execute(builder.build());
130 leaderChanged(false);
131
132 peerIntents.clear();
133 routeIntents.clear();
134 }
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800135 }
136
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800137 public void leaderChanged(boolean isLeader) {
138 log.debug("Leader changed: {}", isLeader);
139
140 if (!isLeader) {
141 this.isElectedLeader = false;
142 this.isActivatedLeader = false;
143 return; // Nothing to do
144 }
145 this.isActivatedLeader = false;
146 this.isElectedLeader = true;
147
148 //
149 // Tell the Intents Synchronizer thread to start the synchronization
150 //
151 intentsSynchronizerSemaphore.release();
152 }
153
154 /**
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800155 * Gets the route intents.
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800156 *
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800157 * @return the route intents
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800158 */
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800159 public Collection<MultiPointToSinglePointIntent> getRouteIntents() {
160 List<MultiPointToSinglePointIntent> result = new LinkedList<>();
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800161
162 for (Map.Entry<Ip4Prefix, MultiPointToSinglePointIntent> entry :
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800163 routeIntents.entrySet()) {
164 result.add(entry.getValue());
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800165 }
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800166 return result;
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800167 }
168
169 /**
170 * Thread for Intent Synchronization.
171 */
172 private void doIntentSynchronizationThread() {
173 boolean interrupted = false;
174 try {
175 while (!interrupted) {
176 try {
177 intentsSynchronizerSemaphore.acquire();
178 //
179 // Drain all permits, because a single synchronization is
180 // sufficient.
181 //
182 intentsSynchronizerSemaphore.drainPermits();
183 } catch (InterruptedException e) {
184 log.debug("Interrupted while waiting to become " +
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800185 "Intent Synchronization leader");
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800186 interrupted = true;
187 break;
188 }
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800189 synchronizeIntents();
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800190 }
191 } finally {
192 if (interrupted) {
193 Thread.currentThread().interrupt();
194 }
195 }
196 }
197
198 /**
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800199 * Submits a collection of point-to-point intents.
200 *
201 * @param intents the intents to submit
202 */
203 void submitPeerIntents(Collection<PointToPointIntent> intents) {
204 synchronized (this) {
205 // Store the intents in memory
206 for (PointToPointIntent intent : intents) {
207 peerIntents.put(new IntentKey(intent), intent);
208 }
209
210 // Push the intents
211 if (isElectedLeader && isActivatedLeader) {
212 log.debug("Submitting all SDN-IP Peer Intents...");
213 // TODO: We should use a single Intent batch operation
214 for (Intent intent : intents) {
215 intentService.submit(intent);
216 }
217 }
218 }
219 }
220
221 /**
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800222 * Submits a multi-point-to-single-point intent.
223 *
224 * @param prefix the IPv4 matching prefix for the intent to submit
225 * @param intent the intent to submit
226 */
227 void submitRouteIntent(Ip4Prefix prefix,
228 MultiPointToSinglePointIntent intent) {
229 synchronized (this) {
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800230 MultiPointToSinglePointIntent oldIntent =
231 routeIntents.put(prefix, intent);
232
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800233 if (isElectedLeader && isActivatedLeader) {
234 log.debug("Intent installation: adding Intent for prefix: {}",
235 prefix);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800236 if (oldIntent != null) {
237 //
238 // TODO: Short-term solution to explicitly withdraw
239 // instead of using "replace" operation.
240 //
241 intentService.withdraw(oldIntent);
242 }
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800243 intentService.submit(intent);
244 }
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800245 }
246 }
247
248 /**
249 * Withdraws a multi-point-to-single-point intent.
250 *
251 * @param prefix the IPv4 matching prefix for the intent to withdraw.
252 */
253 void withdrawRouteIntent(Ip4Prefix prefix) {
254 synchronized (this) {
255 MultiPointToSinglePointIntent intent =
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800256 routeIntents.remove(prefix);
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800257
258 if (intent == null) {
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800259 log.debug("There is no Intent in routeIntents to " +
260 "delete for prefix: {}", prefix);
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800261 return;
262 }
263
264 if (isElectedLeader && isActivatedLeader) {
265 log.debug("Intent installation: deleting Intent for prefix: {}",
266 prefix);
267 intentService.withdraw(intent);
268 }
269 }
270 }
271
272 /**
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800273 * Synchronize the in-memory Intents with the Intents in the Intent
274 * framework.
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800275 */
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800276 void synchronizeIntents() {
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800277 synchronized (this) {
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800278
279 Map<IntentKey, Intent> localIntents = new HashMap<>();
280 Map<IntentKey, Intent> fetchedIntents = new HashMap<>();
281 Collection<Intent> storeInMemoryIntents = new LinkedList<>();
282 Collection<Intent> addIntents = new LinkedList<>();
283 Collection<Intent> deleteIntents = new LinkedList<>();
284
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800285 if (!isElectedLeader) {
286 return; // Nothing to do: not the leader anymore
287 }
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800288 log.debug("Syncing SDN-IP Intents...");
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800289
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800290 // Prepare the local intents
291 for (Intent intent : routeIntents.values()) {
292 localIntents.put(new IntentKey(intent), intent);
293 }
294 for (Intent intent : peerIntents.values()) {
295 localIntents.put(new IntentKey(intent), intent);
296 }
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800297
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800298 // Fetch all intents for this application
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800299 for (Intent intent : intentService.getIntents()) {
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800300 if (!intent.appId().equals(appId)) {
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800301 continue;
302 }
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800303 fetchedIntents.put(new IntentKey(intent), intent);
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800304 }
305
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800306 computeIntentsDelta(localIntents, fetchedIntents,
307 storeInMemoryIntents, addIntents,
308 deleteIntents);
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800309
310 //
311 // Perform the actions:
312 // 1. Store in memory fetched intents that are same. Can be done
313 // even if we are not the leader anymore
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800314 // 2. Delete intents: check if the leader before the operation
315 // 3. Add intents: check if the leader before the operation
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800316 //
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800317 for (Intent intent : storeInMemoryIntents) {
318 // Store the intent in memory based on its type
319 if (intent instanceof MultiPointToSinglePointIntent) {
320 MultiPointToSinglePointIntent mp2pIntent =
321 (MultiPointToSinglePointIntent) intent;
322 // Find the IP prefix
323 Criterion c =
324 mp2pIntent.selector().getCriterion(Criterion.Type.IPV4_DST);
325 if (c != null && c instanceof IPCriterion) {
326 IPCriterion ipCriterion = (IPCriterion) c;
327 Ip4Prefix ip4Prefix = ipCriterion.ip().getIp4Prefix();
328 if (ip4Prefix == null) {
329 // TODO: For now we support only IPv4
330 continue;
331 }
332 log.debug("Intent synchronization: updating " +
333 "in-memory Route Intent for prefix {}",
334 ip4Prefix);
335 routeIntents.put(ip4Prefix, mp2pIntent);
336 } else {
337 log.warn("No IPV4_DST criterion found for Intent {}",
338 mp2pIntent.id());
339 }
340 continue;
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800341 }
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800342 if (intent instanceof PointToPointIntent) {
343 PointToPointIntent p2pIntent = (PointToPointIntent) intent;
344 log.debug("Intent synchronization: updating " +
345 "in-memory Peer Intent {}", p2pIntent);
346 peerIntents.put(new IntentKey(intent), p2pIntent);
347 continue;
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800348 }
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800349 }
350
351 // Withdraw Intents
352 IntentOperations.Builder builder = IntentOperations.builder();
353 for (Intent intent : deleteIntents) {
354 builder.addWithdrawOperation(intent.id());
355 log.debug("Intent synchronization: deleting Intent {}",
356 intent);
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800357 }
358 if (!isElectedLeader) {
359 isActivatedLeader = false;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800360 return;
361 }
362 intentService.execute(builder.build());
363
364 // Add Intents
365 builder = IntentOperations.builder();
366 for (Intent intent : addIntents) {
367 builder.addSubmitOperation(intent);
368 log.debug("Intent synchronization: adding Intent {}", intent);
369 }
370 if (!isElectedLeader) {
371 isActivatedLeader = false;
372 return;
373 }
374 intentService.execute(builder.build());
375
376 if (isElectedLeader) {
377 isActivatedLeader = true; // Allow push of Intents
378 } else {
379 isActivatedLeader = false;
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800380 }
381 log.debug("Syncing SDN-IP routes completed.");
382 }
383 }
384
385 /**
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800386 * Computes the delta in two sets of Intents: local in-memory Intents,
387 * and intents fetched from the Intent framework.
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800388 *
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800389 * @param localIntents the local in-memory Intents
390 * @param fetchedIntents the Intents fetched from the Intent framework
391 * @param storeInMemoryIntents the Intents that should be stored in memory.
392 * Note: This Collection must be allocated by the caller, and it will
393 * be populated by this method.
394 * @param addIntents the Intents that should be added to the Intent
395 * framework. Note: This Collection must be allocated by the caller, and
396 * it will be populated by this method.
397 * @param deleteIntents the Intents that should be deleted from the Intent
398 * framework. Note: This Collection must be allocated by the caller, and
399 * it will be populated by this method.
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800400 */
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800401 private void computeIntentsDelta(
402 final Map<IntentKey, Intent> localIntents,
403 final Map<IntentKey, Intent> fetchedIntents,
404 Collection<Intent> storeInMemoryIntents,
405 Collection<Intent> addIntents,
406 Collection<Intent> deleteIntents) {
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800407
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800408 //
409 // Compute the deltas between the LOCAL in-memory Intents and the
410 // FETCHED Intents:
411 // - If an Intent is in both the LOCAL and FETCHED sets:
412 // If the FETCHED Intent is WITHDRAWING or WITHDRAWN, then
413 // the LOCAL Intent should be added/installed; otherwise the
414 // FETCHED intent should be stored in the local memory
415 // (i.e., override the LOCAL Intent) to preserve the original
416 // Intent ID.
417 // - if a LOCAL Intent is not in the FETCHED set, then the LOCAL
418 // Intent should be added/installed.
419 // - If a FETCHED Intent is not in the LOCAL set, then the FETCHED
420 // Intent should be deleted/withdrawn.
421 //
422 for (Map.Entry<IntentKey, Intent> entry : localIntents.entrySet()) {
423 IntentKey intentKey = entry.getKey();
424 Intent localIntent = entry.getValue();
425 Intent fetchedIntent = fetchedIntents.get(intentKey);
426
427 if (fetchedIntent == null) {
428 //
429 // No FETCHED Intent found: push the LOCAL Intent.
430 //
431 addIntents.add(localIntent);
432 continue;
433 }
434
435 IntentState state =
436 intentService.getIntentState(fetchedIntent.id());
437 if (state == IntentState.WITHDRAWING ||
438 state == IntentState.WITHDRAWN) {
439 // The intent has been withdrawn but according to our route
440 // table it should be installed. We'll reinstall it.
441 addIntents.add(localIntent);
442 continue;
443 }
444 storeInMemoryIntents.add(fetchedIntent);
445 }
446
447 for (Map.Entry<IntentKey, Intent> entry : fetchedIntents.entrySet()) {
448 IntentKey intentKey = entry.getKey();
449 Intent fetchedIntent = entry.getValue();
450 Intent localIntent = localIntents.get(intentKey);
451
452 if (localIntent != null) {
453 continue;
454 }
455
456 IntentState state =
457 intentService.getIntentState(fetchedIntent.id());
458 if (state == IntentState.WITHDRAWING ||
459 state == IntentState.WITHDRAWN) {
460 // Nothing to do. The intent has been already withdrawn.
461 continue;
462 }
463 //
464 // No LOCAL Intent found: delete/withdraw the FETCHED Intent.
465 //
466 deleteIntents.add(fetchedIntent);
467 }
468 }
469
470 /**
471 * Helper class that can be used to compute the key for an Intent by
472 * by excluding the Intent ID.
473 */
474 static final class IntentKey {
475 private final Intent intent;
476
477 /**
478 * Constructor.
479 *
480 * @param intent the intent to use
481 */
482 IntentKey(Intent intent) {
483 checkArgument((intent instanceof MultiPointToSinglePointIntent) ||
484 (intent instanceof PointToPointIntent),
485 "Intent type not recognized", intent);
486 this.intent = intent;
487 }
488
489 /**
490 * Compares two Multi-Point to Single-Point Intents whether they
491 * represent same logical intention.
492 *
493 * @param intent1 the first Intent to compare
494 * @param intent2 the second Intent to compare
495 * @return true if both Intents represent same logical intention,
496 * otherwise false
497 */
498 static boolean equalIntents(MultiPointToSinglePointIntent intent1,
499 MultiPointToSinglePointIntent intent2) {
500 return Objects.equals(intent1.appId(), intent2.appId()) &&
501 Objects.equals(intent1.selector(), intent2.selector()) &&
502 Objects.equals(intent1.treatment(), intent2.treatment()) &&
503 Objects.equals(intent1.ingressPoints(), intent2.ingressPoints()) &&
504 Objects.equals(intent1.egressPoint(), intent2.egressPoint());
505 }
506
507 /**
508 * Compares two Point-to-Point Intents whether they represent
509 * same logical intention.
510 *
511 * @param intent1 the first Intent to compare
512 * @param intent2 the second Intent to compare
513 * @return true if both Intents represent same logical intention,
514 * otherwise false
515 */
516 static boolean equalIntents(PointToPointIntent intent1,
517 PointToPointIntent intent2) {
518 return Objects.equals(intent1.appId(), intent2.appId()) &&
519 Objects.equals(intent1.selector(), intent2.selector()) &&
520 Objects.equals(intent1.treatment(), intent2.treatment()) &&
521 Objects.equals(intent1.ingressPoint(), intent2.ingressPoint()) &&
522 Objects.equals(intent1.egressPoint(), intent2.egressPoint());
523 }
524
525 @Override
526 public int hashCode() {
527 if (intent instanceof PointToPointIntent) {
528 PointToPointIntent p2pIntent = (PointToPointIntent) intent;
529 return Objects.hash(p2pIntent.appId(),
530 p2pIntent.resources(),
531 p2pIntent.selector(),
532 p2pIntent.treatment(),
533 p2pIntent.constraints(),
534 p2pIntent.ingressPoint(),
535 p2pIntent.egressPoint());
536 }
537 if (intent instanceof MultiPointToSinglePointIntent) {
538 MultiPointToSinglePointIntent m2pIntent =
539 (MultiPointToSinglePointIntent) intent;
540 return Objects.hash(m2pIntent.appId(),
541 m2pIntent.resources(),
542 m2pIntent.selector(),
543 m2pIntent.treatment(),
544 m2pIntent.constraints(),
545 m2pIntent.ingressPoints(),
546 m2pIntent.egressPoint());
547 }
548 checkArgument(false, "Intent type not recognized", intent);
549 return 0;
550 }
551
552 @Override
553 public boolean equals(Object obj) {
554 if (this == obj) {
555 return true;
556 }
557 if ((obj == null) || (!(obj instanceof IntentKey))) {
558 return false;
559 }
560 IntentKey other = (IntentKey) obj;
561
562 if (this.intent instanceof PointToPointIntent) {
563 if (!(other.intent instanceof PointToPointIntent)) {
564 return false;
565 }
566 return equalIntents((PointToPointIntent) this.intent,
567 (PointToPointIntent) other.intent);
568 }
569 if (this.intent instanceof MultiPointToSinglePointIntent) {
570 if (!(other.intent instanceof MultiPointToSinglePointIntent)) {
571 return false;
572 }
573 return equalIntents(
574 (MultiPointToSinglePointIntent) this.intent,
575 (MultiPointToSinglePointIntent) other.intent);
576 }
577 checkArgument(false, "Intent type not recognized", intent);
578 return false;
579 }
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800580 }
581}