blob: ec43e08e1b5a76e9531998dafc9a202c6d162a59 [file] [log] [blame]
Jonathan Hart96c5a4a2015-07-31 14:23:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Jonathan Hart96c5a4a2015-07-31 14:23:33 -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 */
16package org.onosproject.net.intent.constraint;
17
18import org.onosproject.net.Link;
19import org.onosproject.net.Path;
20import org.onosproject.net.intent.ConnectivityIntent;
21import org.onosproject.net.intent.Constraint;
22import org.onosproject.net.intent.Intent;
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080023import org.onosproject.net.intent.ResourceContext;
Jonathan Hart96c5a4a2015-07-31 14:23:33 -070024
25/**
26 * A constraint that allows intents that can only be partially compiled
27 * (i.e. MultiPointToSinglePointIntent or SinglePointToMultiPointIntent)
28 * to be installed when some endpoints or paths are not found.
29 */
30public class PartialFailureConstraint implements Constraint {
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080031 // doesn't use LinkResourceService
Jonathan Hart96c5a4a2015-07-31 14:23:33 -070032 @Override
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080033 public double cost(Link link, ResourceContext context) {
Jonathan Hart96c5a4a2015-07-31 14:23:33 -070034 return 1;
35 }
36
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080037 // doesn't use LinkResourceService
Jonathan Hart96c5a4a2015-07-31 14:23:33 -070038 @Override
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080039 public boolean validate(Path path, ResourceContext context) {
Jonathan Hart96c5a4a2015-07-31 14:23:33 -070040 return true;
41 }
42
43 public static boolean intentAllowsPartialFailure(Intent intent) {
44 if (intent instanceof ConnectivityIntent) {
45 ConnectivityIntent connectivityIntent = (ConnectivityIntent) intent;
46 return connectivityIntent.constraints().stream()
47 .anyMatch(c -> c instanceof PartialFailureConstraint);
48 }
49 return false;
50 }
Yuta HIGUCHId0598ee2016-12-20 18:11:34 -080051
52 @Override
53 public String toString() {
54 return "PartialFailureConstraint";
55 }
Jonathan Hart96c5a4a2015-07-31 14:23:33 -070056}