blob: a02c3f6ff89c5776d9fa198963dc0cbea1ef64c2 [file] [log] [blame]
Jonathan Hart3604bbc2016-01-07 11:16:42 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jonathan Hart3604bbc2016-01-07 11:16:42 -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 */
16package org.onosproject.vrouter;
17
Charles Chan00d8b5f2016-12-04 17:17:39 -080018import com.google.common.collect.Lists;
Jonathan Hart3604bbc2016-01-07 11:16:42 -080019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
Charles Chan00d8b5f2016-12-04 17:17:39 -080022import org.apache.felix.scr.annotations.Modified;
23import org.apache.felix.scr.annotations.Property;
Jonathan Hart3604bbc2016-01-07 11:16:42 -080024import org.apache.felix.scr.annotations.Reference;
25import org.apache.felix.scr.annotations.ReferenceCardinality;
Charles Chan00d8b5f2016-12-04 17:17:39 -080026import org.onlab.util.Tools;
Charles Chan0214ded2016-11-18 17:48:37 -080027import org.onosproject.cfg.ComponentConfigService;
Jonathan Hart3604bbc2016-01-07 11:16:42 -080028import org.onosproject.core.ApplicationId;
29import org.onosproject.core.CoreService;
30import org.onosproject.incubator.component.ComponentService;
Charles Chan00d8b5f2016-12-04 17:17:39 -080031import org.osgi.service.component.ComponentContext;
Jonathan Hart3604bbc2016-01-07 11:16:42 -080032import org.slf4j.Logger;
33import org.slf4j.LoggerFactory;
34
Charles Chan00d8b5f2016-12-04 17:17:39 -080035import java.util.Dictionary;
Jonathan Hart3604bbc2016-01-07 11:16:42 -080036import java.util.List;
37
38/**
39 * Virtual router (vRouter) application.
40 */
41@Component(immediate = true)
42public class Vrouter {
43
44 private final Logger log = LoggerFactory.getLogger(getClass());
45
46 private static final String APP_NAME = "org.onosproject.vrouter";
Charles Chan00d8b5f2016-12-04 17:17:39 -080047 private static final String FPM_MANAGER = "org.onosproject.routing.fpm.FpmManager";
48 private static final String FIB_INSTALLER = "org.onosproject.routing.impl.SingleSwitchFibInstaller";
49 private static final String CP_REDIRECT = "org.onosproject.routing.impl.ControlPlaneRedirectManager";
50 private static final String DIRECT_HOST_MGR = "org.onosproject.routing.impl.DirectHostManager";
Jonathan Hart3604bbc2016-01-07 11:16:42 -080051
52 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan00d8b5f2016-12-04 17:17:39 -080053 private CoreService coreService;
Jonathan Hart3604bbc2016-01-07 11:16:42 -080054
55 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan00d8b5f2016-12-04 17:17:39 -080056 private ComponentService componentService;
Jonathan Hart3604bbc2016-01-07 11:16:42 -080057
Charles Chan0214ded2016-11-18 17:48:37 -080058 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan00d8b5f2016-12-04 17:17:39 -080059 private ComponentConfigService componentConfigService;
60
61 /**
62 * vRouter will push flows to the switches when receiving routes by enabling
63 * FIB installer.
64 * <p>
65 * It should be turned off when vRouter is deployed in a scenario where
66 * other components that pushes the routes.
67 */
Jian Li220c2c22017-01-12 19:11:55 +090068 @Property(name = "fibInstallerEnabled", boolValue = true,
Charles Chan00d8b5f2016-12-04 17:17:39 -080069 label = "Enable single switch fib installer; default is true")
Jian Li220c2c22017-01-12 19:11:55 +090070 private boolean fibInstallerEnabled = true;
Charles Chan0214ded2016-11-18 17:48:37 -080071
Jonathan Hart3604bbc2016-01-07 11:16:42 -080072 private ApplicationId appId;
73
Charles Chan00d8b5f2016-12-04 17:17:39 -080074 private List<String> baseComponents = Lists.newArrayList(FPM_MANAGER, CP_REDIRECT, DIRECT_HOST_MGR);
Jonathan Hart63eeac32016-06-20 15:55:16 -070075
Jonathan Hart3604bbc2016-01-07 11:16:42 -080076 @Activate
Charles Chan00d8b5f2016-12-04 17:17:39 -080077 protected void activate(ComponentContext context) {
Jonathan Hart3604bbc2016-01-07 11:16:42 -080078 appId = coreService.registerApplication(APP_NAME);
Charles Chan00d8b5f2016-12-04 17:17:39 -080079 componentConfigService.registerProperties(getClass());
Jonathan Hart3604bbc2016-01-07 11:16:42 -080080
Charles Chan0214ded2016-11-18 17:48:37 -080081 componentConfigService.preSetProperty(
82 "org.onosproject.incubator.store.routing.impl.RouteStoreImpl",
83 "distributed", "true");
84
Charles Chan00d8b5f2016-12-04 17:17:39 -080085 baseComponents.forEach(name -> componentService.activate(appId, name));
86 modified(context);
Jonathan Hart3604bbc2016-01-07 11:16:42 -080087
88 log.info("Started");
89 }
90
91 @Deactivate
92 protected void deactivate() {
Charles Chan0214ded2016-11-18 17:48:37 -080093 componentConfigService.preSetProperty(
94 "org.onosproject.incubator.store.routing.impl.RouteStoreImpl",
95 "distributed", "false");
96
Jonathan Hart3604bbc2016-01-07 11:16:42 -080097 log.info("Stopped");
98 }
99
Charles Chan00d8b5f2016-12-04 17:17:39 -0800100 @Modified
101 private void modified(ComponentContext context) {
102 Dictionary<?, ?> properties = context.getProperties();
103 if (properties == null) {
104 return;
105 }
106
Jian Li220c2c22017-01-12 19:11:55 +0900107 Boolean newFibInstallerEnabled = Tools.isPropertyEnabled(properties, "fibInstalledEnabled");
108 if (newFibInstallerEnabled == null) {
109 log.info("fibInstallerEnabled is not configured, " +
110 "using current value of {}", fibInstallerEnabled);
111 } else {
112 fibInstallerEnabled = newFibInstallerEnabled;
113 log.info("Configured. fibInstallerEnabled set to {}, ",
114 fibInstallerEnabled ? "enabled" : "disabled");
115 }
Charles Chan00d8b5f2016-12-04 17:17:39 -0800116
117 if (fibInstallerEnabled) {
118 componentService.activate(appId, FIB_INSTALLER);
119 } else {
120 componentService.deactivate(appId, FIB_INSTALLER);
121 }
122 }
Jonathan Hart3604bbc2016-01-07 11:16:42 -0800123}