blob: 4ab2b8f55036b7c1ff21fff6636f2034de5ac0cc [file] [log] [blame]
Andreas Papazoisa9964ea2016-01-08 15:58:22 +02001/*
Andreas Papazoise6aebaa2016-05-26 15:25:51 +03002 * Copyright 2016-present Open Networking Laboratory
Andreas Papazoisa9964ea2016-01-08 15:58:22 +02003 *
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.sdxl3;
18
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020024import org.onosproject.app.ApplicationService;
25import org.onosproject.core.ApplicationId;
26import org.onosproject.core.CoreService;
27import org.onosproject.incubator.component.ComponentService;
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020028import org.onosproject.routing.IntentSynchronizationService;
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020029import org.slf4j.Logger;
30
31import java.util.ArrayList;
32import java.util.List;
33
34import static org.slf4j.LoggerFactory.getLogger;
35
36/**
37 * Component for the SDX-L3 application.
38 */
39@Component(immediate = true)
Andreas Papazoise6aebaa2016-05-26 15:25:51 +030040public class SdxL3 {
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020041
42 public static final String SDX_L3_APP = "org.onosproject.sdxl3";
43
44 private final Logger log = getLogger(getClass());
45
46 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
47 protected CoreService coreService;
48
49 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
50 protected ApplicationService applicationService;
51
52 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020053 protected IntentSynchronizationService intentSynchronizer;
54
55 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020056 protected ComponentService componentService;
57
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020058 private ApplicationId appId;
59
60 private static List<String> components = new ArrayList<>();
61 static {
62 components.add("org.onosproject.routing.bgp.BgpSessionManager");
Andreas Papazoisc2c45012016-01-20 14:26:11 +020063 components.add(org.onosproject.sdxl3.impl.SdxL3PeerManager.class.getName());
Andreas papazois47deeaa2016-10-18 12:19:52 +030064 components.add(org.onosproject.sdxl3.impl.SdxL3NeighbourHandler.class.getName());
Andreas Papazoise6aebaa2016-05-26 15:25:51 +030065 components.add(SdxL3Fib.class.getName());
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020066 }
67
68 @Activate
69 protected void activate() {
70 components.forEach(name -> componentService.activate(appId, name));
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020071 appId = coreService.registerApplication(SDX_L3_APP);
Andreas Papazois1f941912016-07-01 11:48:12 +030072
73 applicationService.registerDeactivateHook(appId, () -> {
74 intentSynchronizer.removeIntentsByAppId(appId);
75 });
76
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020077 log.info("SDX-L3 started");
78 }
79
80 @Deactivate
81 protected void deactivate() {
82 components.forEach(name -> componentService.deactivate(appId, name));
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020083 log.info("SDX-L3 stopped");
84 }
Andreas Papazoisa9964ea2016-01-08 15:58:22 +020085}