Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 1 | /* |
Andreas Papazois | e6aebaa | 2016-05-26 15:25:51 +0300 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [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 | */ |
| 16 | |
| 17 | package org.onosproject.sdxl3; |
| 18 | |
| 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 24 | import org.onosproject.app.ApplicationService; |
| 25 | import org.onosproject.core.ApplicationId; |
| 26 | import org.onosproject.core.CoreService; |
| 27 | import org.onosproject.incubator.component.ComponentService; |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 28 | import org.onosproject.routing.IntentSynchronizationService; |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 29 | import org.slf4j.Logger; |
| 30 | |
| 31 | import java.util.ArrayList; |
| 32 | import java.util.List; |
| 33 | |
| 34 | import static org.slf4j.LoggerFactory.getLogger; |
| 35 | |
| 36 | /** |
| 37 | * Component for the SDX-L3 application. |
| 38 | */ |
| 39 | @Component(immediate = true) |
Andreas Papazois | e6aebaa | 2016-05-26 15:25:51 +0300 | [diff] [blame] | 40 | public class SdxL3 { |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 41 | |
| 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 Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 53 | protected IntentSynchronizationService intentSynchronizer; |
| 54 | |
| 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 56 | protected ComponentService componentService; |
| 57 | |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 58 | private ApplicationId appId; |
| 59 | |
| 60 | private static List<String> components = new ArrayList<>(); |
| 61 | static { |
| 62 | components.add("org.onosproject.routing.bgp.BgpSessionManager"); |
Andreas Papazois | c2c4501 | 2016-01-20 14:26:11 +0200 | [diff] [blame] | 63 | components.add(org.onosproject.sdxl3.impl.SdxL3PeerManager.class.getName()); |
Andreas papazois | 47deeaa | 2016-10-18 12:19:52 +0300 | [diff] [blame] | 64 | components.add(org.onosproject.sdxl3.impl.SdxL3NeighbourHandler.class.getName()); |
Andreas Papazois | e6aebaa | 2016-05-26 15:25:51 +0300 | [diff] [blame] | 65 | components.add(SdxL3Fib.class.getName()); |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Activate |
| 69 | protected void activate() { |
| 70 | components.forEach(name -> componentService.activate(appId, name)); |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 71 | appId = coreService.registerApplication(SDX_L3_APP); |
Andreas Papazois | 1f94191 | 2016-07-01 11:48:12 +0300 | [diff] [blame] | 72 | |
| 73 | applicationService.registerDeactivateHook(appId, () -> { |
| 74 | intentSynchronizer.removeIntentsByAppId(appId); |
| 75 | }); |
| 76 | |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 77 | log.info("SDX-L3 started"); |
| 78 | } |
| 79 | |
| 80 | @Deactivate |
| 81 | protected void deactivate() { |
| 82 | components.forEach(name -> componentService.deactivate(appId, name)); |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 83 | log.info("SDX-L3 stopped"); |
| 84 | } |
Andreas Papazois | a9964ea | 2016-01-08 15:58:22 +0200 | [diff] [blame] | 85 | } |