blob: c5d73921c7198e4c71a9d7bf178b011f889bf790 [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
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -070018import org.onosproject.net.DisjointPath;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.net.ElementId;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.Link;
21import org.onosproject.net.Path;
Yuta HIGUCHI90e12292016-08-02 18:02:53 -070022import org.onosproject.net.host.HostService;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070023import org.onosproject.net.topology.AbstractPathService;
Andrey Komarov2398d962016-09-26 15:11:23 +030024import org.onosproject.net.topology.LinkWeigher;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.topology.PathService;
Yuta HIGUCHI90e12292016-08-02 18:02:53 -070026import org.onosproject.net.topology.TopologyService;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070027import org.osgi.service.component.annotations.Activate;
28import org.osgi.service.component.annotations.Component;
29import org.osgi.service.component.annotations.Deactivate;
30import org.osgi.service.component.annotations.Reference;
31import org.osgi.service.component.annotations.ReferenceCardinality;
tom4774c8f2014-09-16 11:17:08 -070032import org.slf4j.Logger;
33
Ray Milkeyd84f89b2018-08-17 14:54:17 -070034import java.util.Map;
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 -070037
Changhoon Yoon541ef712015-05-23 17:18:34 +090038import static org.onosproject.security.AppGuard.checkPermission;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070039import static org.onosproject.security.AppPermission.Type.TOPOLOGY_READ;
40import static org.slf4j.LoggerFactory.getLogger;
Changhoon Yoon541ef712015-05-23 17:18:34 +090041
tom4774c8f2014-09-16 11:17:08 -070042
43/**
44 * Provides implementation of a path selection service atop the current
45 * topology and host services.
46 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070047@Component(immediate = true, service = PathService.class)
Claudine Chiu45920dd2016-07-28 19:19:46 +000048public class PathManager extends AbstractPathService implements PathService {
tom4774c8f2014-09-16 11:17:08 -070049
tom4774c8f2014-09-16 11:17:08 -070050 private final Logger log = getLogger(getClass());
51
Ray Milkeyd84f89b2018-08-17 14:54:17 -070052 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Yuta HIGUCHI90e12292016-08-02 18:02:53 -070053 protected TopologyService topologyService;
54
Ray Milkeyd84f89b2018-08-17 14:54:17 -070055 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Yuta HIGUCHI90e12292016-08-02 18:02:53 -070056 protected HostService hostService;
57
tom4774c8f2014-09-16 11:17:08 -070058 @Activate
tomca90c462014-09-22 11:40:58 -070059 public void activate() {
Yuta HIGUCHI90e12292016-08-02 18:02:53 -070060 // initialize AbstractPathService
61 super.topologyService = this.topologyService;
62 super.hostService = this.hostService;
tom4774c8f2014-09-16 11:17:08 -070063 log.info("Started");
64 }
65
66 @Deactivate
tomca90c462014-09-22 11:40:58 -070067 public void deactivate() {
tom4774c8f2014-09-16 11:17:08 -070068 log.info("Stopped");
69 }
70
71 @Override
tomcbefa232014-09-16 14:17:20 -070072 public Set<Path> getPaths(ElementId src, ElementId dst) {
Changhoon Yoonb856b812015-08-10 03:47:19 +090073 checkPermission(TOPOLOGY_READ);
Changhoon Yoon541ef712015-05-23 17:18:34 +090074
Andrey Komarov2398d962016-09-26 15:11:23 +030075 return getPaths(src, dst, (LinkWeigher) null);
tom4774c8f2014-09-16 11:17:08 -070076 }
77
78 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +030079 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeigher weigher) {
80 checkPermission(TOPOLOGY_READ);
81 return super.getPaths(src, dst, weigher);
82 }
83
Yuta HIGUCHIa684b6e2017-05-18 22:29:22 -070084 @Override
85 public Stream<Path> getKShortestPaths(ElementId src, ElementId dst,
86 LinkWeigher weigher) {
87 checkPermission(TOPOLOGY_READ);
88 return super.getKShortestPaths(src, dst, weigher);
89 }
Claudine Chiu45920dd2016-07-28 19:19:46 +000090
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -070091 @Override
92 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst) {
Heedo Kang4a47a302016-02-29 17:40:23 +090093 checkPermission(TOPOLOGY_READ);
Andrey Komarov2398d962016-09-26 15:11:23 +030094 return getDisjointPaths(src, dst, (LinkWeigher) null);
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -070095 }
96
97 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +030098 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeigher weigher) {
99 checkPermission(TOPOLOGY_READ);
100 return super.getDisjointPaths(src, dst, weigher);
101 }
102
103 @Override
Thomas Vachuska48e64e42015-09-22 15:32:55 -0700104 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst,
105 Map<Link, Object> riskProfile) {
Heedo Kang4a47a302016-02-29 17:40:23 +0900106 checkPermission(TOPOLOGY_READ);
Andrey Komarov2398d962016-09-26 15:11:23 +0300107 return getDisjointPaths(src, dst, (LinkWeigher) null, riskProfile);
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -0700108 }
109
110 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +0300111 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeigher weigher,
112 Map<Link, Object> riskProfile) {
113 checkPermission(TOPOLOGY_READ);
114 return super.getDisjointPaths(src, dst, weigher, riskProfile);
115 }
116
tom4774c8f2014-09-16 11:17:08 -0700117}