Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [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 | package org.onosproject.vrouter; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
| 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; |
Charles Chan | 0214ded | 2016-11-18 17:48:37 -0800 | [diff] [blame^] | 24 | import org.onosproject.cfg.ComponentConfigService; |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 25 | import org.onosproject.core.ApplicationId; |
| 26 | import org.onosproject.core.CoreService; |
| 27 | import org.onosproject.incubator.component.ComponentService; |
| 28 | import org.slf4j.Logger; |
| 29 | import org.slf4j.LoggerFactory; |
| 30 | |
| 31 | import java.util.List; |
| 32 | |
| 33 | /** |
| 34 | * Virtual router (vRouter) application. |
| 35 | */ |
| 36 | @Component(immediate = true) |
| 37 | public class Vrouter { |
| 38 | |
| 39 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 40 | |
| 41 | private static final String APP_NAME = "org.onosproject.vrouter"; |
| 42 | |
| 43 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 44 | protected CoreService coreService; |
| 45 | |
| 46 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 47 | protected ComponentService componentService; |
| 48 | |
Charles Chan | 0214ded | 2016-11-18 17:48:37 -0800 | [diff] [blame^] | 49 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 50 | protected ComponentConfigService componentConfigService; |
| 51 | |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 52 | private ApplicationId appId; |
| 53 | |
| 54 | private final List<String> components = ImmutableList.<String>builder() |
| 55 | .add("org.onosproject.routing.fpm.FpmManager") |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 56 | .add("org.onosproject.routing.impl.SingleSwitchFibInstaller") |
Jonathan Hart | 6344f57 | 2015-12-15 08:26:25 -0800 | [diff] [blame] | 57 | .add("org.onosproject.routing.impl.ControlPlaneRedirectManager") |
Jonathan Hart | 63eeac3 | 2016-06-20 15:55:16 -0700 | [diff] [blame] | 58 | .add("org.onosproject.routing.impl.DirectHostManager") |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 59 | .build(); |
| 60 | |
Jonathan Hart | 63eeac3 | 2016-06-20 15:55:16 -0700 | [diff] [blame] | 61 | |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 62 | @Activate |
| 63 | protected void activate() { |
| 64 | appId = coreService.registerApplication(APP_NAME); |
| 65 | |
Charles Chan | 0214ded | 2016-11-18 17:48:37 -0800 | [diff] [blame^] | 66 | componentConfigService.preSetProperty( |
| 67 | "org.onosproject.incubator.store.routing.impl.RouteStoreImpl", |
| 68 | "distributed", "true"); |
| 69 | |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 70 | components.forEach(name -> componentService.activate(appId, name)); |
| 71 | |
| 72 | log.info("Started"); |
| 73 | } |
| 74 | |
| 75 | @Deactivate |
| 76 | protected void deactivate() { |
Charles Chan | 0214ded | 2016-11-18 17:48:37 -0800 | [diff] [blame^] | 77 | componentConfigService.preSetProperty( |
| 78 | "org.onosproject.incubator.store.routing.impl.RouteStoreImpl", |
| 79 | "distributed", "false"); |
| 80 | |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 81 | log.info("Stopped"); |
| 82 | } |
| 83 | |
| 84 | } |