blob: b0efe8049b2c9de6ace5fa8ef9ad38714c83ddbf [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;
21import org.apache.felix.scr.annotations.Activate;
22import org.apache.felix.scr.annotations.Component;
23import org.apache.felix.scr.annotations.Deactivate;
24import org.apache.felix.scr.annotations.Service;
25import org.onosproject.actn.mdsc.pce.TeTunnelPce;
26import org.onosproject.actn.mdsc.pce.TeTunnelPceService;
27import org.onosproject.tetunnel.api.tunnel.TeTunnel;
28import org.onosproject.tetunnel.api.tunnel.path.TeRouteSubobject;
29import org.slf4j.Logger;
30import static org.slf4j.LoggerFactory.getLogger;
31
32import java.util.Collection;
33import java.util.List;
34
35/**
36 * Implementation of Te Tunnel PCE service.
37 */
38@Component(immediate = true)
39@Service
40public class TeTunnelPceManager implements TeTunnelPceService {
41
42 private static final Logger log = getLogger(TeTunnelPceManager.class);
43
44 private List<TeTunnelPce> pces = Lists.newLinkedList();
45
46 @Activate
47 protected void activate() {
48 pces.add(0, new DefaultTeTunnelPce());
49 log.info("Started");
50 }
51
52 @Deactivate
53 protected void deactivate() {
54 log.info("Stopped");
55 }
56
57 @Override
58 public Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel) {
59 TeTunnelPce pce = null;
60 synchronized (pces) {
61 for (TeTunnelPce p : pces) {
62 if (p.isSuitable(teTunnel)) {
63 pce = p;
64 }
65 }
66 }
Ray Milkey74e59132018-01-17 15:24:52 -080067 if (pce != null) {
68 return pce.computePaths(teTunnel);
69 } else {
70 return ImmutableList.of();
71 }
tony-liuf7d2a262016-10-17 16:32:24 +080072 }
73
74 @Override
75 public Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel,
76 TeTunnelPce pce) {
77 return pce == null ? null : pce.computePaths(teTunnel);
78 }
79
80 @Override
81 public void registerPce(TeTunnelPce pce) {
82 synchronized (pces) {
83 int index = 0;
84 while (pces.get(index).getPriority() > pce.getPriority()) {
85 index++;
86 }
87
88 pces.add(index, pce);
89 }
90 }
91}