Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.topology.impl; |
tom | 4774c8f | 2014-09-16 11:17:08 -0700 | [diff] [blame] | 17 | |
Nikhil Cheerla | 2ec191f | 2015-07-09 12:34:54 -0700 | [diff] [blame] | 18 | import org.onosproject.net.DisjointPath; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.ElementId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.net.Link; |
| 21 | import org.onosproject.net.Path; |
Yuta HIGUCHI | 90e1229 | 2016-08-02 18:02:53 -0700 | [diff] [blame] | 22 | import org.onosproject.net.host.HostService; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 23 | import org.onosproject.net.topology.AbstractPathService; |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 24 | import org.onosproject.net.topology.LinkWeigher; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.topology.PathService; |
Yuta HIGUCHI | 90e1229 | 2016-08-02 18:02:53 -0700 | [diff] [blame] | 26 | import org.onosproject.net.topology.TopologyService; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 27 | import org.osgi.service.component.annotations.Activate; |
| 28 | import org.osgi.service.component.annotations.Component; |
| 29 | import org.osgi.service.component.annotations.Deactivate; |
| 30 | import org.osgi.service.component.annotations.Reference; |
| 31 | import org.osgi.service.component.annotations.ReferenceCardinality; |
tom | 4774c8f | 2014-09-16 11:17:08 -0700 | [diff] [blame] | 32 | import org.slf4j.Logger; |
| 33 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 34 | import java.util.Map; |
tom | 4774c8f | 2014-09-16 11:17:08 -0700 | [diff] [blame] | 35 | import java.util.Set; |
Yuta HIGUCHI | a684b6e | 2017-05-18 22:29:22 -0700 | [diff] [blame] | 36 | import java.util.stream.Stream; |
Nikhil Cheerla | 2ec191f | 2015-07-09 12:34:54 -0700 | [diff] [blame] | 37 | |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 38 | import static org.onosproject.security.AppGuard.checkPermission; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 39 | import static org.onosproject.security.AppPermission.Type.TOPOLOGY_READ; |
| 40 | import static org.slf4j.LoggerFactory.getLogger; |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 41 | |
tom | 4774c8f | 2014-09-16 11:17:08 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Provides implementation of a path selection service atop the current |
| 45 | * topology and host services. |
| 46 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 47 | @Component(immediate = true, service = PathService.class) |
Claudine Chiu | 45920dd | 2016-07-28 19:19:46 +0000 | [diff] [blame] | 48 | public class PathManager extends AbstractPathService implements PathService { |
tom | 4774c8f | 2014-09-16 11:17:08 -0700 | [diff] [blame] | 49 | |
tom | 4774c8f | 2014-09-16 11:17:08 -0700 | [diff] [blame] | 50 | private final Logger log = getLogger(getClass()); |
| 51 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 52 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Yuta HIGUCHI | 90e1229 | 2016-08-02 18:02:53 -0700 | [diff] [blame] | 53 | protected TopologyService topologyService; |
| 54 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Yuta HIGUCHI | 90e1229 | 2016-08-02 18:02:53 -0700 | [diff] [blame] | 56 | protected HostService hostService; |
| 57 | |
tom | 4774c8f | 2014-09-16 11:17:08 -0700 | [diff] [blame] | 58 | @Activate |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 59 | public void activate() { |
Yuta HIGUCHI | 90e1229 | 2016-08-02 18:02:53 -0700 | [diff] [blame] | 60 | // initialize AbstractPathService |
| 61 | super.topologyService = this.topologyService; |
| 62 | super.hostService = this.hostService; |
tom | 4774c8f | 2014-09-16 11:17:08 -0700 | [diff] [blame] | 63 | log.info("Started"); |
| 64 | } |
| 65 | |
| 66 | @Deactivate |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 67 | public void deactivate() { |
tom | 4774c8f | 2014-09-16 11:17:08 -0700 | [diff] [blame] | 68 | log.info("Stopped"); |
| 69 | } |
| 70 | |
| 71 | @Override |
tom | cbefa23 | 2014-09-16 14:17:20 -0700 | [diff] [blame] | 72 | public Set<Path> getPaths(ElementId src, ElementId dst) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 73 | checkPermission(TOPOLOGY_READ); |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 74 | |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 75 | return getPaths(src, dst, (LinkWeigher) null); |
tom | 4774c8f | 2014-09-16 11:17:08 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 79 | public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeigher weigher) { |
| 80 | checkPermission(TOPOLOGY_READ); |
| 81 | return super.getPaths(src, dst, weigher); |
| 82 | } |
| 83 | |
Yuta HIGUCHI | a684b6e | 2017-05-18 22:29:22 -0700 | [diff] [blame] | 84 | @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 Chiu | 45920dd | 2016-07-28 19:19:46 +0000 | [diff] [blame] | 90 | |
Nikhil Cheerla | 2ec191f | 2015-07-09 12:34:54 -0700 | [diff] [blame] | 91 | @Override |
| 92 | public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst) { |
Heedo Kang | 4a47a30 | 2016-02-29 17:40:23 +0900 | [diff] [blame] | 93 | checkPermission(TOPOLOGY_READ); |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 94 | return getDisjointPaths(src, dst, (LinkWeigher) null); |
Nikhil Cheerla | 2ec191f | 2015-07-09 12:34:54 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 98 | 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 Vachuska | 48e64e4 | 2015-09-22 15:32:55 -0700 | [diff] [blame] | 104 | public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, |
| 105 | Map<Link, Object> riskProfile) { |
Heedo Kang | 4a47a30 | 2016-02-29 17:40:23 +0900 | [diff] [blame] | 106 | checkPermission(TOPOLOGY_READ); |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 107 | return getDisjointPaths(src, dst, (LinkWeigher) null, riskProfile); |
Nikhil Cheerla | 2ec191f | 2015-07-09 12:34:54 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | @Override |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 111 | 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 | |
tom | 4774c8f | 2014-09-16 11:17:08 -0700 | [diff] [blame] | 117 | } |