blob: cc9cc531d590e86c406f1dae3714b254913d96f7 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.topology.impl;
tom4774c8f2014-09-16 11:17:08 -070017
tom4774c8f2014-09-16 11:17:08 -070018import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
Yuta HIGUCHI90e12292016-08-02 18:02:53 -070021import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
tom4774c8f2014-09-16 11:17:08 -070023import org.apache.felix.scr.annotations.Service;
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -070024import org.onosproject.net.DisjointPath;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.ElementId;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import org.onosproject.net.Link;
27import org.onosproject.net.Path;
Yuta HIGUCHI90e12292016-08-02 18:02:53 -070028import org.onosproject.net.host.HostService;
Andrey Komarov2398d962016-09-26 15:11:23 +030029import org.onosproject.net.topology.LinkWeigher;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.net.topology.PathService;
Yuta HIGUCHI90e12292016-08-02 18:02:53 -070031import org.onosproject.net.topology.TopologyService;
Claudine Chiu45920dd2016-07-28 19:19:46 +000032import org.onosproject.net.topology.AbstractPathService;
tom4774c8f2014-09-16 11:17:08 -070033import org.slf4j.Logger;
34
tom4774c8f2014-09-16 11:17:08 -070035import java.util.Set;
Yuta HIGUCHIa684b6e2017-05-18 22:29:22 -070036import java.util.stream.Stream;
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -070037import java.util.Map;
38
tom4774c8f2014-09-16 11:17:08 -070039
tom4774c8f2014-09-16 11:17:08 -070040import static org.slf4j.LoggerFactory.getLogger;
Changhoon Yoon541ef712015-05-23 17:18:34 +090041import static org.onosproject.security.AppGuard.checkPermission;
Changhoon Yoonb856b812015-08-10 03:47:19 +090042import static org.onosproject.security.AppPermission.Type.*;
Changhoon Yoon541ef712015-05-23 17:18:34 +090043
tom4774c8f2014-09-16 11:17:08 -070044
45/**
46 * Provides implementation of a path selection service atop the current
47 * topology and host services.
48 */
49@Component(immediate = true)
50@Service
Claudine Chiu45920dd2016-07-28 19:19:46 +000051public class PathManager extends AbstractPathService implements PathService {
tom4774c8f2014-09-16 11:17:08 -070052
tom4774c8f2014-09-16 11:17:08 -070053 private final Logger log = getLogger(getClass());
54
Yuta HIGUCHI90e12292016-08-02 18:02:53 -070055 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
56 protected TopologyService topologyService;
57
58 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
59 protected HostService hostService;
60
tom4774c8f2014-09-16 11:17:08 -070061 @Activate
tomca90c462014-09-22 11:40:58 -070062 public void activate() {
Yuta HIGUCHI90e12292016-08-02 18:02:53 -070063 // initialize AbstractPathService
64 super.topologyService = this.topologyService;
65 super.hostService = this.hostService;
tom4774c8f2014-09-16 11:17:08 -070066 log.info("Started");
67 }
68
69 @Deactivate
tomca90c462014-09-22 11:40:58 -070070 public void deactivate() {
tom4774c8f2014-09-16 11:17:08 -070071 log.info("Stopped");
72 }
73
74 @Override
tomcbefa232014-09-16 14:17:20 -070075 public Set<Path> getPaths(ElementId src, ElementId dst) {
Changhoon Yoonb856b812015-08-10 03:47:19 +090076 checkPermission(TOPOLOGY_READ);
Changhoon Yoon541ef712015-05-23 17:18:34 +090077
Andrey Komarov2398d962016-09-26 15:11:23 +030078 return getPaths(src, dst, (LinkWeigher) null);
tom4774c8f2014-09-16 11:17:08 -070079 }
80
81 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +030082 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeigher weigher) {
83 checkPermission(TOPOLOGY_READ);
84 return super.getPaths(src, dst, weigher);
85 }
86
Yuta HIGUCHIa684b6e2017-05-18 22:29:22 -070087 @Override
88 public Stream<Path> getKShortestPaths(ElementId src, ElementId dst,
89 LinkWeigher weigher) {
90 checkPermission(TOPOLOGY_READ);
91 return super.getKShortestPaths(src, dst, weigher);
92 }
Claudine Chiu45920dd2016-07-28 19:19:46 +000093
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -070094 @Override
95 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst) {
Heedo Kang4a47a302016-02-29 17:40:23 +090096 checkPermission(TOPOLOGY_READ);
Andrey Komarov2398d962016-09-26 15:11:23 +030097 return getDisjointPaths(src, dst, (LinkWeigher) null);
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -070098 }
99
100 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +0300101 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeigher weigher) {
102 checkPermission(TOPOLOGY_READ);
103 return super.getDisjointPaths(src, dst, weigher);
104 }
105
106 @Override
Thomas Vachuska48e64e42015-09-22 15:32:55 -0700107 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst,
108 Map<Link, Object> riskProfile) {
Heedo Kang4a47a302016-02-29 17:40:23 +0900109 checkPermission(TOPOLOGY_READ);
Andrey Komarov2398d962016-09-26 15:11:23 +0300110 return getDisjointPaths(src, dst, (LinkWeigher) null, riskProfile);
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -0700111 }
112
113 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +0300114 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeigher weigher,
115 Map<Link, Object> riskProfile) {
116 checkPermission(TOPOLOGY_READ);
117 return super.getDisjointPaths(src, dst, weigher, riskProfile);
118 }
119
tom4774c8f2014-09-16 11:17:08 -0700120}