blob: a87aaa994e2e057fde8fc27a137d0eb624750681 [file] [log] [blame]
tony-liuf7d2a262016-10-17 16:32:24 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
tony-liuf7d2a262016-10-17 16:32:24 +08003 *
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 */
16
17package org.onosproject.actn.mdsc.pce.impl;
18
Ray Milkey74e59132018-01-17 15:24:52 -080019import com.google.common.collect.ImmutableList;
tony-liuf7d2a262016-10-17 16:32:24 +080020import com.google.common.collect.Lists;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070021import org.osgi.service.component.annotations.Activate;
22import org.osgi.service.component.annotations.Component;
23import org.osgi.service.component.annotations.Deactivate;
tony-liuf7d2a262016-10-17 16:32:24 +080024import org.onosproject.actn.mdsc.pce.TeTunnelPce;
25import org.onosproject.actn.mdsc.pce.TeTunnelPceService;
26import org.onosproject.tetunnel.api.tunnel.TeTunnel;
27import org.onosproject.tetunnel.api.tunnel.path.TeRouteSubobject;
28import org.slf4j.Logger;
29import static org.slf4j.LoggerFactory.getLogger;
30
31import java.util.Collection;
32import java.util.List;
33
34/**
35 * Implementation of Te Tunnel PCE service.
36 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070037@Component(immediate = true, service = TeTunnelPceService.class)
tony-liuf7d2a262016-10-17 16:32:24 +080038public class TeTunnelPceManager implements TeTunnelPceService {
39
40 private static final Logger log = getLogger(TeTunnelPceManager.class);
41
42 private List<TeTunnelPce> pces = Lists.newLinkedList();
43
44 @Activate
45 protected void activate() {
46 pces.add(0, new DefaultTeTunnelPce());
47 log.info("Started");
48 }
49
50 @Deactivate
51 protected void deactivate() {
52 log.info("Stopped");
53 }
54
55 @Override
56 public Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel) {
57 TeTunnelPce pce = null;
58 synchronized (pces) {
59 for (TeTunnelPce p : pces) {
60 if (p.isSuitable(teTunnel)) {
61 pce = p;
62 }
63 }
64 }
Ray Milkey74e59132018-01-17 15:24:52 -080065 if (pce != null) {
66 return pce.computePaths(teTunnel);
67 } else {
68 return ImmutableList.of();
69 }
tony-liuf7d2a262016-10-17 16:32:24 +080070 }
71
72 @Override
73 public Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel,
74 TeTunnelPce pce) {
75 return pce == null ? null : pce.computePaths(teTunnel);
76 }
77
78 @Override
79 public void registerPce(TeTunnelPce pce) {
80 synchronized (pces) {
81 int index = 0;
82 while (pces.get(index).getPriority() > pce.getPriority()) {
83 index++;
84 }
85
86 pces.add(index, pce);
87 }
88 }
89}