blob: 7256a55086a657d3204a6a4f6408ec66a7dc5f22 [file] [log] [blame]
Jonathan Hart96c5a4a2015-07-31 14:23:33 -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 */
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 }
51}