blob: 68c2af557ca6418d7906a9573b884abb75e278e7 [file] [log] [blame]
tony-liuf7d2a262016-10-17 16:32:24 +08001/*
2 * Copyright 2016-present Open Networking Laboratory
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 */
16
17package org.onosproject.actn.mdsc.pce.impl;
18
19import com.google.common.collect.Lists;
20import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Service;
24import 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 */
37@Component(immediate = true)
38@Service
39public class TeTunnelPceManager implements TeTunnelPceService {
40
41 private static final Logger log = getLogger(TeTunnelPceManager.class);
42
43 private List<TeTunnelPce> pces = Lists.newLinkedList();
44
45 @Activate
46 protected void activate() {
47 pces.add(0, new DefaultTeTunnelPce());
48 log.info("Started");
49 }
50
51 @Deactivate
52 protected void deactivate() {
53 log.info("Stopped");
54 }
55
56 @Override
57 public Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel) {
58 TeTunnelPce pce = null;
59 synchronized (pces) {
60 for (TeTunnelPce p : pces) {
61 if (p.isSuitable(teTunnel)) {
62 pce = p;
63 }
64 }
65 }
66 return pce.computePaths(teTunnel);
67 }
68
69 @Override
70 public Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel,
71 TeTunnelPce pce) {
72 return pce == null ? null : pce.computePaths(teTunnel);
73 }
74
75 @Override
76 public void registerPce(TeTunnelPce pce) {
77 synchronized (pces) {
78 int index = 0;
79 while (pces.get(index).getPriority() > pce.getPriority()) {
80 index++;
81 }
82
83 pces.add(index, pce);
84 }
85 }
86}