alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [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.net.flowobjective.impl; |
| 17 | |
Pier Luigi | 9789311 | 2018-03-05 11:09:42 +0100 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Harshada Chaundkar | 5a198b0 | 2019-07-03 16:27:45 +0000 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableList; |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 20 | import com.google.common.collect.Lists; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 21 | import com.google.common.collect.Maps; |
Thomas Vachuska | d27097c | 2016-06-14 19:10:41 -0700 | [diff] [blame] | 22 | import com.google.common.collect.Sets; |
Harshada Chaundkar | 5a198b0 | 2019-07-03 16:27:45 +0000 | [diff] [blame] | 23 | import org.apache.commons.lang3.tuple.Pair; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 24 | import org.onlab.osgi.DefaultServiceDirectory; |
| 25 | import org.onlab.osgi.ServiceDirectory; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 26 | import org.onlab.util.ItemNotFoundException; |
Yi Tseng | 374c5f3 | 2017-03-05 22:51:35 -0800 | [diff] [blame] | 27 | import org.onlab.util.Tools; |
| 28 | import org.onosproject.cfg.ComponentConfigService; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 29 | import org.onosproject.cluster.ClusterService; |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 30 | import org.onosproject.net.Device; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 31 | import org.onosproject.net.DeviceId; |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 32 | import org.onosproject.net.behaviour.NextGroup; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 33 | import org.onosproject.net.behaviour.Pipeliner; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 34 | import org.onosproject.net.behaviour.PipelinerContext; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 35 | import org.onosproject.net.device.DeviceEvent; |
| 36 | import org.onosproject.net.device.DeviceListener; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 37 | import org.onosproject.net.device.DeviceService; |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 38 | import org.onosproject.net.driver.DriverEvent; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 39 | import org.onosproject.net.driver.DriverHandler; |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 40 | import org.onosproject.net.driver.DriverListener; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 41 | import org.onosproject.net.driver.DriverService; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 42 | import org.onosproject.net.flow.FlowRuleService; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 43 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 44 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 45 | import org.onosproject.net.flowobjective.FlowObjectiveStore; |
| 46 | import org.onosproject.net.flowobjective.FlowObjectiveStoreDelegate; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 47 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 48 | import org.onosproject.net.flowobjective.NextObjective; |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 49 | import org.onosproject.net.flowobjective.Objective; |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 50 | import org.onosproject.net.flowobjective.Objective.Operation; |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 51 | import org.onosproject.net.flowobjective.ObjectiveError; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 52 | import org.onosproject.net.flowobjective.ObjectiveEvent; |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 53 | import org.onosproject.net.flowobjective.ObjectiveEvent.Type; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 54 | import org.onosproject.net.group.GroupService; |
Yi Tseng | 374c5f3 | 2017-03-05 22:51:35 -0800 | [diff] [blame] | 55 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 56 | import org.osgi.service.component.annotations.Activate; |
| 57 | import org.osgi.service.component.annotations.Component; |
| 58 | import org.osgi.service.component.annotations.Deactivate; |
| 59 | import org.osgi.service.component.annotations.Modified; |
| 60 | import org.osgi.service.component.annotations.Reference; |
| 61 | import org.osgi.service.component.annotations.ReferenceCardinality; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 62 | import org.slf4j.Logger; |
| 63 | import org.slf4j.LoggerFactory; |
| 64 | |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 65 | import java.util.ArrayList; |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 66 | import java.util.List; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 67 | import java.util.Map; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 68 | import java.util.Objects; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 69 | import java.util.Set; |
Harshada Chaundkar | 5a198b0 | 2019-07-03 16:27:45 +0000 | [diff] [blame] | 70 | import java.util.HashMap; |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 71 | import java.util.concurrent.ExecutorService; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 72 | |
Sho SHIMIZU | f45d85d | 2015-07-01 14:39:11 -0700 | [diff] [blame] | 73 | import static com.google.common.base.Preconditions.checkNotNull; |
Yi Tseng | 374c5f3 | 2017-03-05 22:51:35 -0800 | [diff] [blame] | 74 | import static com.google.common.base.Strings.isNullOrEmpty; |
Thomas Vachuska | 866b46a | 2015-04-30 00:26:55 -0700 | [diff] [blame] | 75 | import static java.util.concurrent.Executors.newFixedThreadPool; |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 76 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 77 | import static org.onlab.util.Tools.groupedThreads; |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 78 | import static org.onosproject.net.AnnotationKeys.DRIVER; |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 79 | import static org.onosproject.net.OsgiPropertyConstants.FOM_NUM_THREADS; |
| 80 | import static org.onosproject.net.OsgiPropertyConstants.FOM_NUM_THREADS_DEFAULT; |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 81 | import static org.onosproject.net.OsgiPropertyConstants.FOM_ACCUMULATOR_MAX_OBJECTIVES; |
| 82 | import static org.onosproject.net.OsgiPropertyConstants.FOM_ACCUMULATOR_MAX_OBJECTIVES_DEFAULT; |
| 83 | import static org.onosproject.net.OsgiPropertyConstants.FOM_ACCUMULATOR_MAX_IDLE_MILLIS; |
| 84 | import static org.onosproject.net.OsgiPropertyConstants.FOM_ACCUMULATOR_MAX_IDLE_MILLIS_DEFAULT; |
| 85 | import static org.onosproject.net.OsgiPropertyConstants.FOM_ACCUMULATOR_MAX_BATCH_MILLIS; |
| 86 | import static org.onosproject.net.OsgiPropertyConstants.FOM_ACCUMULATOR_MAX_BATCH_MILLIS_DEFAULT; |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 87 | import static org.onosproject.security.AppGuard.checkPermission; |
Thomas Vachuska | d27097c | 2016-06-14 19:10:41 -0700 | [diff] [blame] | 88 | import static org.onosproject.security.AppPermission.Type.FLOWRULE_WRITE; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 91 | * Provides implementation of the flow objective programming service. |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 92 | */ |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 93 | @Component( |
| 94 | enabled = false, |
| 95 | service = FlowObjectiveService.class, |
| 96 | property = { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 97 | FOM_NUM_THREADS + ":Integer=" + FOM_NUM_THREADS_DEFAULT, |
| 98 | FOM_ACCUMULATOR_MAX_OBJECTIVES + ":Integer=" + FOM_ACCUMULATOR_MAX_OBJECTIVES_DEFAULT, |
| 99 | FOM_ACCUMULATOR_MAX_IDLE_MILLIS + ":Integer=" + FOM_ACCUMULATOR_MAX_IDLE_MILLIS_DEFAULT, |
| 100 | FOM_ACCUMULATOR_MAX_BATCH_MILLIS + ":Integer=" + FOM_ACCUMULATOR_MAX_BATCH_MILLIS_DEFAULT, |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 101 | } |
| 102 | ) |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 103 | public class FlowObjectiveManager implements FlowObjectiveService { |
| 104 | |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 105 | private static final int INSTALL_RETRY_ATTEMPTS = 5; |
| 106 | private static final long INSTALL_RETRY_INTERVAL = 1000; // ms |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 107 | |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 108 | private static final String INSTALLER_PATTERN = "installer-%d"; |
| 109 | private static final String VERIFIER_PATTERN = "verifier-%d"; |
| 110 | private static final String GROUP_THREAD_NAME = "onos/objective"; |
Yi Tseng | 374c5f3 | 2017-03-05 22:51:35 -0800 | [diff] [blame] | 111 | |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 112 | private final Logger log = LoggerFactory.getLogger(getClass()); |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 113 | |
Thomas Vachuska | f566fa2 | 2018-10-30 14:03:36 -0700 | [diff] [blame] | 114 | /** Number of worker threads. */ |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 115 | private int numThreads = FOM_NUM_THREADS_DEFAULT; |
Yi Tseng | 374c5f3 | 2017-03-05 22:51:35 -0800 | [diff] [blame] | 116 | |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 117 | // Parameters for the accumulator, each pipeline can implement |
| 118 | // its own accumulation logic. The following parameters are used |
| 119 | // to control the accumulator. |
| 120 | |
pierventre | 3433e31 | 2020-10-27 16:08:48 +0100 | [diff] [blame] | 121 | /** Max number of objs to accumulate before processing is triggered. */ |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 122 | private int accumulatorMaxObjectives = FOM_ACCUMULATOR_MAX_OBJECTIVES_DEFAULT; |
pierventre | 3433e31 | 2020-10-27 16:08:48 +0100 | [diff] [blame] | 123 | /** Max of ms between objs before processing is triggered. */ |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 124 | private int accumulatorMaxIdleMillis = FOM_ACCUMULATOR_MAX_IDLE_MILLIS_DEFAULT; |
pierventre | 3433e31 | 2020-10-27 16:08:48 +0100 | [diff] [blame] | 125 | /** Max number of ms allowed since the first obj before processing is triggered. */ |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 126 | private int accumulatorMaxBatchMillis = FOM_ACCUMULATOR_MAX_BATCH_MILLIS_DEFAULT; |
| 127 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 128 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 129 | protected DriverService driverService; |
| 130 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 131 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 132 | protected DeviceService deviceService; |
| 133 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 134 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 135 | protected ClusterService clusterService; |
| 136 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 137 | // Note: The following dependencies are added on behalf of the pipeline |
| 138 | // driver behaviours to assure these services are available for their |
| 139 | // initialization. |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 140 | @SuppressWarnings("unused") |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 141 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 142 | protected FlowRuleService flowRuleService; |
| 143 | |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 144 | @SuppressWarnings("unused") |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 145 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 146 | protected GroupService groupService; |
| 147 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 148 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 149 | protected FlowObjectiveStore flowObjectiveStore; |
| 150 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 151 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Yi Tseng | 374c5f3 | 2017-03-05 22:51:35 -0800 | [diff] [blame] | 152 | protected ComponentConfigService cfgService; |
| 153 | |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 154 | final FlowObjectiveStoreDelegate delegate = new InternalStoreDelegate(); |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 155 | |
| 156 | private final Map<DeviceId, DriverHandler> driverHandlers = Maps.newConcurrentMap(); |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 157 | protected final Map<DeviceId, Pipeliner> pipeliners = Maps.newConcurrentMap(); |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 158 | |
| 159 | private final PipelinerContext context = new InnerPipelineContext(); |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 160 | private final DeviceListener deviceListener = new InnerDeviceListener(); |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 161 | private final DriverListener driverListener = new InnerDriverListener(); |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 162 | |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 163 | private ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 164 | |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 165 | // local stores for queuing fwd and next objectives that are waiting for an |
| 166 | // associated next objective execution to complete. The signal for completed |
| 167 | // execution comes from a pipeline driver, in this or another controller |
| 168 | // instance, via the DistributedFlowObjectiveStore. |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 169 | // TODO Making these cache and timeout the entries |
| 170 | final Map<Integer, Set<PendingFlowObjective>> pendingForwards = Maps.newConcurrentMap(); |
| 171 | final Map<Integer, List<PendingFlowObjective>> pendingNexts = Maps.newConcurrentMap(); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 172 | |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 173 | // local store to track which nextObjectives were sent to which device |
| 174 | // for debugging purposes |
| 175 | private Map<Integer, DeviceId> nextToDevice = Maps.newConcurrentMap(); |
| 176 | |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 177 | ExecutorService installerExecutor; |
| 178 | ExecutorService verifierExecutor; |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 179 | protected ExecutorService devEventExecutor; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 180 | |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 181 | @Activate |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 182 | protected void activate(ComponentContext context) { |
Ray Milkey | 1f0764a | 2019-03-01 08:40:37 -0800 | [diff] [blame] | 183 | cfgService.registerProperties(FlowObjectiveManager.class); |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 184 | installerExecutor = newFixedThreadPool(numThreads, |
| 185 | groupedThreads(GROUP_THREAD_NAME, INSTALLER_PATTERN, log)); |
| 186 | verifierExecutor = newFixedThreadPool(numThreads, |
| 187 | groupedThreads(GROUP_THREAD_NAME, VERIFIER_PATTERN, log)); |
| 188 | |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 189 | modified(context); |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 190 | devEventExecutor = newSingleThreadScheduledExecutor( |
| 191 | groupedThreads("onos/flowobj-dev-events", "events-%d", log)); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 192 | flowObjectiveStore.setDelegate(delegate); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 193 | deviceService.addListener(deviceListener); |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 194 | driverService.addListener(driverListener); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 195 | log.info("Started"); |
| 196 | } |
| 197 | |
| 198 | @Deactivate |
| 199 | protected void deactivate() { |
Yi Tseng | 374c5f3 | 2017-03-05 22:51:35 -0800 | [diff] [blame] | 200 | cfgService.unregisterProperties(getClass(), false); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 201 | flowObjectiveStore.unsetDelegate(delegate); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 202 | deviceService.removeListener(deviceListener); |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 203 | driverService.removeListener(driverListener); |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 204 | installerExecutor.shutdown(); |
| 205 | verifierExecutor.shutdown(); |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 206 | devEventExecutor.shutdownNow(); |
| 207 | devEventExecutor = null; |
Thomas Vachuska | 866b46a | 2015-04-30 00:26:55 -0700 | [diff] [blame] | 208 | pipeliners.clear(); |
| 209 | driverHandlers.clear(); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 210 | nextToDevice.clear(); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 211 | log.info("Stopped"); |
| 212 | } |
| 213 | |
Yi Tseng | 374c5f3 | 2017-03-05 22:51:35 -0800 | [diff] [blame] | 214 | @Modified |
| 215 | protected void modified(ComponentContext context) { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 216 | if (context != null) { |
| 217 | readComponentConfiguration(context); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Extracts properties from the component configuration context. |
| 223 | * |
| 224 | * @param context the component context |
| 225 | */ |
pierventre | 3433e31 | 2020-10-27 16:08:48 +0100 | [diff] [blame] | 226 | protected void readComponentConfiguration(ComponentContext context) { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 227 | String propertyValue = Tools.get(context.getProperties(), FOM_NUM_THREADS); |
Yi Tseng | 374c5f3 | 2017-03-05 22:51:35 -0800 | [diff] [blame] | 228 | int newNumThreads = isNullOrEmpty(propertyValue) ? numThreads : Integer.parseInt(propertyValue); |
| 229 | |
| 230 | if (newNumThreads != numThreads && newNumThreads > 0) { |
| 231 | numThreads = newNumThreads; |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 232 | ExecutorService oldWorkerExecutor = installerExecutor; |
| 233 | installerExecutor = newFixedThreadPool(numThreads, |
| 234 | groupedThreads(GROUP_THREAD_NAME, INSTALLER_PATTERN, log)); |
| 235 | if (oldWorkerExecutor != null) { |
| 236 | oldWorkerExecutor.shutdown(); |
| 237 | } |
| 238 | oldWorkerExecutor = verifierExecutor; |
| 239 | verifierExecutor = newFixedThreadPool(numThreads, |
| 240 | groupedThreads(GROUP_THREAD_NAME, VERIFIER_PATTERN, log)); |
Yi Tseng | 374c5f3 | 2017-03-05 22:51:35 -0800 | [diff] [blame] | 241 | if (oldWorkerExecutor != null) { |
| 242 | oldWorkerExecutor.shutdown(); |
| 243 | } |
| 244 | log.info("Reconfigured number of worker threads to {}", numThreads); |
| 245 | } |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 246 | |
| 247 | // Reconfiguration of the accumulator parameters is allowed |
| 248 | // Note: it will affect only pipelines going through init method |
| 249 | propertyValue = Tools.get(context.getProperties(), FOM_ACCUMULATOR_MAX_OBJECTIVES); |
| 250 | int newMaxObjs = isNullOrEmpty(propertyValue) ? |
| 251 | accumulatorMaxObjectives : Integer.parseInt(propertyValue); |
| 252 | if (newMaxObjs != accumulatorMaxObjectives && newMaxObjs > 0) { |
| 253 | accumulatorMaxObjectives = newMaxObjs; |
| 254 | log.info("Reconfigured maximum number of objectives to accumulate to {}", |
| 255 | accumulatorMaxObjectives); |
| 256 | } |
| 257 | |
| 258 | propertyValue = Tools.get(context.getProperties(), FOM_ACCUMULATOR_MAX_IDLE_MILLIS); |
| 259 | int newMaxIdleMS = isNullOrEmpty(propertyValue) ? |
| 260 | accumulatorMaxIdleMillis : Integer.parseInt(propertyValue); |
| 261 | if (newMaxIdleMS != accumulatorMaxIdleMillis && newMaxIdleMS > 0) { |
| 262 | accumulatorMaxIdleMillis = newMaxIdleMS; |
| 263 | log.info("Reconfigured maximum number of millis between objectives to {}", |
| 264 | accumulatorMaxIdleMillis); |
| 265 | } |
| 266 | |
| 267 | propertyValue = Tools.get(context.getProperties(), FOM_ACCUMULATOR_MAX_BATCH_MILLIS); |
| 268 | int newMaxBatchMS = isNullOrEmpty(propertyValue) ? |
| 269 | accumulatorMaxBatchMillis : Integer.parseInt(propertyValue); |
| 270 | if (newMaxBatchMS != accumulatorMaxBatchMillis && newMaxBatchMS > 0) { |
| 271 | accumulatorMaxBatchMillis = newMaxBatchMS; |
| 272 | log.info("Reconfigured maximum number of millis allowed since the first objective to {}", |
| 273 | accumulatorMaxBatchMillis); |
| 274 | } |
| 275 | |
Yi Tseng | 374c5f3 | 2017-03-05 22:51:35 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 278 | /** |
| 279 | * Task that passes the flow objective down to the driver. The task will |
| 280 | * make a few attempts to find the appropriate driver, then eventually give |
| 281 | * up and report an error if no suitable driver could be found. |
| 282 | */ |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 283 | class ObjectiveProcessor implements Runnable { |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 284 | final DeviceId deviceId; |
| 285 | final Objective objective; |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 286 | final ExecutorService executor; |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 287 | |
Sho SHIMIZU | f45d85d | 2015-07-01 14:39:11 -0700 | [diff] [blame] | 288 | private final int numAttempts; |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 289 | |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 290 | ObjectiveProcessor(DeviceId deviceId, Objective objective, |
| 291 | ExecutorService executorService) { |
| 292 | this(deviceId, objective, 1, executorService); |
Sho SHIMIZU | f45d85d | 2015-07-01 14:39:11 -0700 | [diff] [blame] | 293 | } |
| 294 | |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 295 | ObjectiveProcessor(DeviceId deviceId, Objective objective, int attempts, |
| 296 | ExecutorService executorService) { |
Sho SHIMIZU | f45d85d | 2015-07-01 14:39:11 -0700 | [diff] [blame] | 297 | this.deviceId = checkNotNull(deviceId); |
| 298 | this.objective = checkNotNull(objective); |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 299 | this.executor = checkNotNull(executorService); |
| 300 | this.numAttempts = attempts; |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 301 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 302 | |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 303 | @Override |
| 304 | public void run() { |
| 305 | try { |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 306 | Pipeliner pipeliner = getDevicePipeliner(deviceId); |
| 307 | |
pier | 2d8ecd1 | 2020-05-20 22:50:30 +0200 | [diff] [blame] | 308 | if (pipeliner != null) { |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 309 | if (objective instanceof NextObjective) { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 310 | nextToDevice.put(objective.id(), deviceId); |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 311 | pipeliner.next((NextObjective) objective); |
| 312 | } else if (objective instanceof ForwardingObjective) { |
| 313 | pipeliner.forward((ForwardingObjective) objective); |
| 314 | } else { |
| 315 | pipeliner.filter((FilteringObjective) objective); |
| 316 | } |
Andrea Campanella | 1f8188d | 2016-02-29 13:24:54 -0800 | [diff] [blame] | 317 | //Attempts to check if pipeliner is null for retry attempts |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 318 | } else if (numAttempts < INSTALL_RETRY_ATTEMPTS) { |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 319 | Thread.sleep(INSTALL_RETRY_INTERVAL); |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 320 | executor.execute(new ObjectiveProcessor(deviceId, objective, |
| 321 | numAttempts + 1, executor)); |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 322 | } else { |
| 323 | // Otherwise we've tried a few times and failed, report an |
| 324 | // error back to the user. |
| 325 | objective.context().ifPresent( |
Andrea Campanella | 1f8188d | 2016-02-29 13:24:54 -0800 | [diff] [blame] | 326 | c -> c.onError(objective, ObjectiveError.NOPIPELINER)); |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 327 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 328 | //Exception thrown |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 329 | } catch (Exception e) { |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 330 | log.warn("Exception while processing flow objective", e); |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void filter(DeviceId deviceId, FilteringObjective filteringObjective) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 337 | checkPermission(FLOWRULE_WRITE); |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 338 | installerExecutor.execute(new ObjectiveProcessor(deviceId, filteringObjective, installerExecutor)); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | @Override |
Thomas Vachuska | 866b46a | 2015-04-30 00:26:55 -0700 | [diff] [blame] | 342 | public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 343 | checkPermission(FLOWRULE_WRITE); |
Yi Tseng | 1666b50 | 2017-05-17 11:05:18 -0700 | [diff] [blame] | 344 | if (forwardingObjective.nextId() == null || |
Yi Tseng | 1666b50 | 2017-05-17 11:05:18 -0700 | [diff] [blame] | 345 | flowObjectiveStore.getNextGroup(forwardingObjective.nextId()) != null || |
| 346 | !queueFwdObjective(deviceId, forwardingObjective)) { |
| 347 | // fast path |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 348 | installerExecutor.execute(new ObjectiveProcessor(deviceId, forwardingObjective, installerExecutor)); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 349 | } |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 350 | } |
| 351 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 352 | @Override |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 353 | public void next(DeviceId deviceId, NextObjective nextObjective) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 354 | checkPermission(FLOWRULE_WRITE); |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 355 | if (nextObjective.op() == Operation.VERIFY) { |
| 356 | // Verify does not need to wait |
| 357 | verifierExecutor.execute(new ObjectiveProcessor(deviceId, nextObjective, verifierExecutor)); |
| 358 | } else if (nextObjective.op() == Operation.ADD || |
Yi Tseng | 1666b50 | 2017-05-17 11:05:18 -0700 | [diff] [blame] | 359 | flowObjectiveStore.getNextGroup(nextObjective.id()) != null || |
| 360 | !queueNextObjective(deviceId, nextObjective)) { |
| 361 | // either group exists or we are trying to create it - let it through |
pier | 7b7e8ac | 2020-01-27 17:45:03 +0100 | [diff] [blame] | 362 | installerExecutor.execute(new ObjectiveProcessor(deviceId, nextObjective, installerExecutor)); |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 363 | } |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 364 | } |
| 365 | |
alshabib | f6ea9e6 | 2015-04-21 17:08:26 -0700 | [diff] [blame] | 366 | @Override |
| 367 | public int allocateNextId() { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 368 | checkPermission(FLOWRULE_WRITE); |
alshabib | f6ea9e6 | 2015-04-21 17:08:26 -0700 | [diff] [blame] | 369 | return flowObjectiveStore.allocateNextId(); |
| 370 | } |
| 371 | |
Xin Jin | 313708b | 2015-07-09 13:43:04 -0700 | [diff] [blame] | 372 | @Override |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 373 | public void initPolicy(String policy) { |
| 374 | } |
Xin Jin | 313708b | 2015-07-09 13:43:04 -0700 | [diff] [blame] | 375 | |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 376 | boolean queueFwdObjective(DeviceId deviceId, ForwardingObjective fwd) { |
Thomas Vachuska | d27097c | 2016-06-14 19:10:41 -0700 | [diff] [blame] | 377 | boolean queued = false; |
| 378 | synchronized (pendingForwards) { |
| 379 | // double check the flow objective store, because this block could run |
| 380 | // after a notification arrives |
| 381 | if (flowObjectiveStore.getNextGroup(fwd.nextId()) == null) { |
| 382 | pendingForwards.compute(fwd.nextId(), (id, pending) -> { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 383 | PendingFlowObjective pendfo = new PendingFlowObjective(deviceId, fwd); |
Thomas Vachuska | d27097c | 2016-06-14 19:10:41 -0700 | [diff] [blame] | 384 | if (pending == null) { |
Pier Luigi | 9789311 | 2018-03-05 11:09:42 +0100 | [diff] [blame] | 385 | return Sets.newLinkedHashSet(ImmutableSet.of(pendfo)); |
Thomas Vachuska | d27097c | 2016-06-14 19:10:41 -0700 | [diff] [blame] | 386 | } else { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 387 | pending.add(pendfo); |
Thomas Vachuska | d27097c | 2016-06-14 19:10:41 -0700 | [diff] [blame] | 388 | return pending; |
| 389 | } |
| 390 | }); |
| 391 | queued = true; |
| 392 | } |
| 393 | } |
| 394 | if (queued) { |
Saurav Das | c568c34 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 395 | log.debug("Queued forwarding objective {} for nextId {} meant for device {}", |
Thomas Vachuska | d27097c | 2016-06-14 19:10:41 -0700 | [diff] [blame] | 396 | fwd.id(), fwd.nextId(), deviceId); |
| 397 | } |
| 398 | return queued; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 401 | boolean queueNextObjective(DeviceId deviceId, NextObjective next) { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 402 | // we need to hold off on other operations till we get notified that the |
| 403 | // initial group creation has succeeded |
| 404 | boolean queued = false; |
| 405 | synchronized (pendingNexts) { |
| 406 | // double check the flow objective store, because this block could run |
| 407 | // after a notification arrives |
| 408 | if (flowObjectiveStore.getNextGroup(next.id()) == null) { |
| 409 | pendingNexts.compute(next.id(), (id, pending) -> { |
| 410 | PendingFlowObjective pendfo = new PendingFlowObjective(deviceId, next); |
| 411 | if (pending == null) { |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 412 | return Lists.newArrayList(pendfo); |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 413 | } else { |
| 414 | pending.add(pendfo); |
| 415 | return pending; |
| 416 | } |
| 417 | }); |
| 418 | queued = true; |
| 419 | } |
| 420 | } |
| 421 | if (queued) { |
Saurav Das | c568c34 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 422 | log.debug("Queued next objective {} with operation {} meant for device {}", |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 423 | next.id(), next.op(), deviceId); |
| 424 | } |
| 425 | return queued; |
| 426 | } |
| 427 | |
Pier Ventre | 57a61cd | 2016-09-07 10:55:41 -0700 | [diff] [blame] | 428 | /** |
| 429 | * Retrieves (if it exists) the device pipeline behaviour from the cache. |
| 430 | * Otherwise it warms the caches and triggers the init method of the Pipeline. |
| 431 | * |
| 432 | * @param deviceId the id of the device associated to the pipeline |
| 433 | * @return the implementation of the Pipeliner behaviour |
| 434 | */ |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 435 | private Pipeliner getDevicePipeliner(DeviceId deviceId) { |
Yuta HIGUCHI | 1fb0a8c | 2016-08-12 10:59:24 -0700 | [diff] [blame] | 436 | return pipeliners.computeIfAbsent(deviceId, this::initPipelineHandler); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Yuta HIGUCHI | 1fb0a8c | 2016-08-12 10:59:24 -0700 | [diff] [blame] | 439 | /** |
Pier Ventre | 57a61cd | 2016-09-07 10:55:41 -0700 | [diff] [blame] | 440 | * Retrieves (if it exists) the device pipeline behaviour from the cache and |
| 441 | * and triggers the init method of the pipeline. Otherwise (DEVICE_ADDED) it warms |
| 442 | * the caches and triggers the init method of the Pipeline. The rationale of this |
| 443 | * method is for managing the scenario of a switch that goes down for a failure |
| 444 | * and goes up after a while. |
| 445 | * |
| 446 | * @param deviceId the id of the device associated to the pipeline |
| 447 | * @return the implementation of the Pipeliner behaviour |
| 448 | */ |
| 449 | private Pipeliner getAndInitDevicePipeliner(DeviceId deviceId) { |
| 450 | return pipeliners.compute(deviceId, (deviceIdValue, pipelinerValue) -> { |
| 451 | if (pipelinerValue != null) { |
| 452 | pipelinerValue.init(deviceId, context); |
| 453 | return pipelinerValue; |
| 454 | } |
| 455 | return this.initPipelineHandler(deviceId); |
| 456 | }); |
| 457 | } |
| 458 | |
| 459 | /** |
Yuta HIGUCHI | 1fb0a8c | 2016-08-12 10:59:24 -0700 | [diff] [blame] | 460 | * Creates and initialize {@link Pipeliner}. |
| 461 | * <p> |
| 462 | * Note: Expected to be called under per-Device lock. |
| 463 | * e.g., {@code pipeliners}' Map#compute family methods |
| 464 | * |
| 465 | * @param deviceId Device to initialize pipeliner |
| 466 | * @return {@link Pipeliner} instance or null |
| 467 | */ |
| 468 | private Pipeliner initPipelineHandler(DeviceId deviceId) { |
| 469 | start = now(); |
Thomas Vachuska | 866b46a | 2015-04-30 00:26:55 -0700 | [diff] [blame] | 470 | |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 471 | // Attempt to lookup the handler in the cache |
| 472 | DriverHandler handler = driverHandlers.get(deviceId); |
Thomas Vachuska | b19bffb | 2015-07-22 10:56:16 -0700 | [diff] [blame] | 473 | cTime = now(); |
| 474 | |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 475 | if (handler == null) { |
| 476 | try { |
| 477 | // Otherwise create it and if it has pipeline behaviour, cache it |
| 478 | handler = driverService.createHandler(deviceId); |
Thomas Vachuska | b19bffb | 2015-07-22 10:56:16 -0700 | [diff] [blame] | 479 | dTime = now(); |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 480 | if (!handler.driver().hasBehaviour(Pipeliner.class)) { |
Yuta HIGUCHI | a2a4f34 | 2017-03-17 11:38:57 -0700 | [diff] [blame] | 481 | log.debug("Pipeline behaviour not supported for device {}", |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 482 | deviceId); |
Yuta HIGUCHI | 1fb0a8c | 2016-08-12 10:59:24 -0700 | [diff] [blame] | 483 | return null; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 484 | } |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 485 | } catch (ItemNotFoundException e) { |
| 486 | log.warn("No applicable driver for device {}", deviceId); |
Yuta HIGUCHI | 1fb0a8c | 2016-08-12 10:59:24 -0700 | [diff] [blame] | 487 | return null; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 490 | driverHandlers.put(deviceId, handler); |
Thomas Vachuska | b19bffb | 2015-07-22 10:56:16 -0700 | [diff] [blame] | 491 | eTime = now(); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 492 | } |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 493 | |
| 494 | // Always (re)initialize the pipeline behaviour |
| 495 | log.info("Driver {} bound to device {} ... initializing driver", |
| 496 | handler.driver().name(), deviceId); |
Thomas Vachuska | 0121a61 | 2015-07-21 11:18:09 -0700 | [diff] [blame] | 497 | hTime = now(); |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 498 | Pipeliner pipeliner = handler.behaviour(Pipeliner.class); |
Thomas Vachuska | 94c3cf4 | 2015-07-20 13:01:12 -0700 | [diff] [blame] | 499 | hbTime = now(); |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 500 | pipeliner.init(deviceId, context); |
Yuta HIGUCHI | 1fb0a8c | 2016-08-12 10:59:24 -0700 | [diff] [blame] | 501 | stopWatch(); |
| 502 | return pipeliner; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 503 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 504 | |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 505 | private void invalidatePipelinerIfNecessary(Device device) { |
| 506 | DriverHandler handler = driverHandlers.get(device.id()); |
| 507 | if (handler != null && |
| 508 | !Objects.equals(handler.driver().name(), |
| 509 | device.annotations().value(DRIVER))) { |
| 510 | invalidatePipeliner(device.id()); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | private void invalidatePipeliner(DeviceId id) { |
| 515 | log.info("Invalidating cached pipeline behaviour for {}", id); |
| 516 | driverHandlers.remove(id); |
pier | 2d8ecd1 | 2020-05-20 22:50:30 +0200 | [diff] [blame] | 517 | pipeliners.remove(id); |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 518 | if (deviceService.isAvailable(id)) { |
| 519 | getAndInitDevicePipeliner(id); |
| 520 | } |
| 521 | } |
| 522 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 523 | // Triggers driver setup when a device is (re)detected. |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 524 | private class InnerDeviceListener implements DeviceListener { |
| 525 | @Override |
| 526 | public void event(DeviceEvent event) { |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 527 | if (devEventExecutor != null) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 528 | switch (event.type()) { |
| 529 | case DEVICE_ADDED: |
| 530 | case DEVICE_AVAILABILITY_CHANGED: |
Madan Jampani | 0174f45 | 2015-05-29 11:52:05 -0700 | [diff] [blame] | 531 | log.debug("Device either added or availability changed {}", |
Thomas Vachuska | 9c9ff7c | 2015-07-20 10:38:59 -0700 | [diff] [blame] | 532 | event.subject().id()); |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 533 | devEventExecutor.execute(() -> { |
| 534 | if (deviceService.isAvailable(event.subject().id())) { |
Madan Jampani | 0174f45 | 2015-05-29 11:52:05 -0700 | [diff] [blame] | 535 | log.debug("Device is now available {}", event.subject().id()); |
Pier Ventre | 57a61cd | 2016-09-07 10:55:41 -0700 | [diff] [blame] | 536 | getAndInitDevicePipeliner(event.subject().id()); |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 537 | } else { |
Yuta HIGUCHI | 1fb0a8c | 2016-08-12 10:59:24 -0700 | [diff] [blame] | 538 | log.debug("Device is no longer available {}", event.subject().id()); |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 539 | } |
| 540 | }); |
alshabib | 4313d10 | 2015-04-08 18:55:08 -0700 | [diff] [blame] | 541 | break; |
| 542 | case DEVICE_UPDATED: |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 543 | // Invalidate pipeliner and handler caches if the driver name |
| 544 | // device annotation changed. |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 545 | devEventExecutor.execute(() -> invalidatePipelinerIfNecessary(event.subject())); |
alshabib | 4313d10 | 2015-04-08 18:55:08 -0700 | [diff] [blame] | 546 | break; |
| 547 | case DEVICE_REMOVED: |
Yuta HIGUCHI | ad0c990 | 2016-08-23 10:37:32 -0700 | [diff] [blame] | 548 | // evict Pipeliner and Handler cache, when |
| 549 | // the Device was administratively removed. |
| 550 | // |
| 551 | // System expect the user to clear all existing flows, |
| 552 | // before removing device, especially if they intend to |
| 553 | // replace driver/pipeliner assigned to the device. |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 554 | devEventExecutor.execute(() -> { |
pier | f37ce52 | 2020-03-20 11:00:38 +0100 | [diff] [blame] | 555 | driverHandlers.remove(event.subject().id()); |
pier | 2d8ecd1 | 2020-05-20 22:50:30 +0200 | [diff] [blame] | 556 | pipeliners.remove(event.subject().id()); |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 557 | }); |
alshabib | 4313d10 | 2015-04-08 18:55:08 -0700 | [diff] [blame] | 558 | break; |
Yuta HIGUCHI | ad0c990 | 2016-08-23 10:37:32 -0700 | [diff] [blame] | 559 | case DEVICE_SUSPENDED: |
| 560 | break; |
alshabib | 4313d10 | 2015-04-08 18:55:08 -0700 | [diff] [blame] | 561 | case PORT_ADDED: |
| 562 | break; |
| 563 | case PORT_UPDATED: |
| 564 | break; |
| 565 | case PORT_REMOVED: |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 566 | break; |
| 567 | default: |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 568 | break; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 569 | } |
Ruchi Sahota | e4934e1 | 2019-03-01 16:56:07 +0000 | [diff] [blame] | 570 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 571 | } |
| 572 | } |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 573 | |
Thomas Vachuska | cfeff19 | 2017-08-23 15:29:34 -0700 | [diff] [blame] | 574 | // Monitors driver configuration changes and invalidates the pipeliner cache entries. |
| 575 | // Note that this may leave stale entries on the device if the driver changes |
| 576 | // in manner where the new driver does not produce backward compatible flow objectives. |
| 577 | // In such cases, it is the operator's responsibility to force device re-connect. |
| 578 | private class InnerDriverListener implements DriverListener { |
| 579 | @Override |
| 580 | public void event(DriverEvent event) { |
| 581 | String driverName = event.subject().name(); |
| 582 | driverHandlers.entrySet().stream() |
| 583 | .filter(e -> driverName.equals(e.getValue().driver().name())) |
| 584 | .map(Map.Entry::getKey) |
| 585 | .distinct() |
| 586 | .forEach(FlowObjectiveManager.this::invalidatePipeliner); |
| 587 | } |
| 588 | } |
| 589 | |
Thomas Vachuska | 174bb91 | 2015-07-16 21:27:14 -0700 | [diff] [blame] | 590 | // Temporary mechanism to monitor pipeliner setup time-cost; there are |
| 591 | // intermittent time where this takes in excess of 2 seconds. Why? |
Thomas Vachuska | 9c9ff7c | 2015-07-20 10:38:59 -0700 | [diff] [blame] | 592 | private long start = 0, totals = 0, count = 0; |
Thomas Vachuska | b19bffb | 2015-07-22 10:56:16 -0700 | [diff] [blame] | 593 | private long cTime, dTime, eTime, hTime, hbTime; |
Thomas Vachuska | 9c9ff7c | 2015-07-20 10:38:59 -0700 | [diff] [blame] | 594 | private static final long LIMIT = 500; |
Thomas Vachuska | 174bb91 | 2015-07-16 21:27:14 -0700 | [diff] [blame] | 595 | |
Thomas Vachuska | 9c9ff7c | 2015-07-20 10:38:59 -0700 | [diff] [blame] | 596 | private long now() { |
Thomas Vachuska | 174bb91 | 2015-07-16 21:27:14 -0700 | [diff] [blame] | 597 | return System.currentTimeMillis(); |
| 598 | } |
| 599 | |
Thomas Vachuska | 9c9ff7c | 2015-07-20 10:38:59 -0700 | [diff] [blame] | 600 | private void stopWatch() { |
Thomas Vachuska | 174bb91 | 2015-07-16 21:27:14 -0700 | [diff] [blame] | 601 | long duration = System.currentTimeMillis() - start; |
| 602 | totals += duration; |
| 603 | count += 1; |
| 604 | if (duration > LIMIT) { |
Thomas Vachuska | b19bffb | 2015-07-22 10:56:16 -0700 | [diff] [blame] | 605 | log.info("Pipeline setup took {} ms; avg {} ms; cTime={}, dTime={}, eTime={}, hTime={}, hbTime={}", |
| 606 | duration, totals / count, diff(cTime), diff(dTime), diff(eTime), diff(hTime), diff(hbTime)); |
Thomas Vachuska | 174bb91 | 2015-07-16 21:27:14 -0700 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
Thomas Vachuska | 9c9ff7c | 2015-07-20 10:38:59 -0700 | [diff] [blame] | 610 | private long diff(long bTime) { |
Thomas Vachuska | b19bffb | 2015-07-22 10:56:16 -0700 | [diff] [blame] | 611 | long diff = bTime - start; |
| 612 | return diff < 0 ? 0 : diff; |
Thomas Vachuska | 9c9ff7c | 2015-07-20 10:38:59 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 615 | // Processing context for initializing pipeline driver behaviours. |
| 616 | private class InnerPipelineContext implements PipelinerContext { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 617 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 618 | @Override |
| 619 | public ServiceDirectory directory() { |
| 620 | return serviceDirectory; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 621 | } |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 622 | |
| 623 | @Override |
| 624 | public FlowObjectiveStore store() { |
| 625 | return flowObjectiveStore; |
| 626 | } |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 627 | |
| 628 | @Override |
| 629 | public int accumulatorMaxObjectives() { |
| 630 | return accumulatorMaxObjectives; |
| 631 | } |
| 632 | |
| 633 | @Override |
| 634 | public int accumulatorMaxIdleMillis() { |
| 635 | return accumulatorMaxIdleMillis; |
| 636 | } |
| 637 | |
| 638 | @Override |
| 639 | public int accumulatorMaxBatchMillis() { |
| 640 | return accumulatorMaxBatchMillis; |
| 641 | } |
| 642 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | private class InternalStoreDelegate implements FlowObjectiveStoreDelegate { |
| 646 | @Override |
| 647 | public void notify(ObjectiveEvent event) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 648 | if (event.type() == Type.ADD) { |
| 649 | log.debug("Received notification of obj event {}", event); |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 650 | Set<PendingFlowObjective> pending; |
| 651 | |
| 652 | // first send all pending flows |
Thomas Vachuska | d27097c | 2016-06-14 19:10:41 -0700 | [diff] [blame] | 653 | synchronized (pendingForwards) { |
| 654 | // needs to be synchronized for queueObjective lookup |
| 655 | pending = pendingForwards.remove(event.subject()); |
| 656 | } |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 657 | if (pending == null) { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 658 | log.debug("No forwarding objectives pending for this " |
| 659 | + "obj event {}", event); |
| 660 | } else { |
| 661 | log.debug("Processing {} pending forwarding objectives for nextId {}", |
| 662 | pending.size(), event.subject()); |
| 663 | pending.forEach(p -> getDevicePipeliner(p.deviceId()) |
| 664 | .forward((ForwardingObjective) p.flowObjective())); |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 665 | } |
| 666 | |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 667 | // now check for pending next-objectives |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 668 | List<PendingFlowObjective> pendNexts; |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 669 | synchronized (pendingNexts) { |
| 670 | // needs to be synchronized for queueObjective lookup |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 671 | pendNexts = pendingNexts.remove(event.subject()); |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 672 | } |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 673 | if (pendNexts == null) { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 674 | log.debug("No next objectives pending for this " |
| 675 | + "obj event {}", event); |
| 676 | } else { |
| 677 | log.debug("Processing {} pending next objectives for nextId {}", |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 678 | pendNexts.size(), event.subject()); |
| 679 | pendNexts.forEach(p -> getDevicePipeliner(p.deviceId()) |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 680 | .next((NextObjective) p.flowObjective())); |
| 681 | } |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 682 | } |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
| 686 | /** |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 687 | * Data class used to hold a pending flow objective that could not |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 688 | * be processed because the associated next object was not present. |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 689 | * Note that this pending flow objective could be a forwarding objective |
| 690 | * waiting for a next objective to complete execution. Or it could a |
| 691 | * next objective (with a different operation - remove, addToExisting, or |
| 692 | * removeFromExisting) waiting for a next objective with the same id to |
| 693 | * complete execution. |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 694 | */ |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 695 | protected class PendingFlowObjective { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 696 | private final DeviceId deviceId; |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 697 | private final Objective flowObj; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 698 | |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 699 | PendingFlowObjective(DeviceId deviceId, Objective flowObj) { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 700 | this.deviceId = deviceId; |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 701 | this.flowObj = flowObj; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | public DeviceId deviceId() { |
| 705 | return deviceId; |
| 706 | } |
| 707 | |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 708 | public Objective flowObjective() { |
| 709 | return flowObj; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 710 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 711 | |
| 712 | @Override |
| 713 | public int hashCode() { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 714 | return Objects.hash(deviceId, flowObj); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | @Override |
| 718 | public boolean equals(final Object obj) { |
| 719 | if (this == obj) { |
| 720 | return true; |
| 721 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 722 | if (!(obj instanceof PendingFlowObjective)) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 723 | return false; |
| 724 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 725 | final PendingFlowObjective other = (PendingFlowObjective) obj; |
Charles Chan | a7903c8 | 2018-03-15 20:14:16 -0700 | [diff] [blame] | 726 | |
| 727 | return this.deviceId.equals(other.deviceId) && |
| 728 | this.flowObj.equals(other.flowObj); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 729 | } |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 730 | } |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 731 | |
| 732 | @Override |
| 733 | public List<String> getNextMappings() { |
| 734 | List<String> mappings = new ArrayList<>(); |
| 735 | Map<Integer, NextGroup> allnexts = flowObjectiveStore.getAllGroups(); |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 736 | // XXX if the NextGroup after de-serialization actually stored info of the deviceId |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 737 | // then info on any nextObj could be retrieved from one controller instance. |
| 738 | // Right now the drivers on one instance can only fetch for next-ids that came |
| 739 | // to them. |
| 740 | // Also, we still need to send the right next-id to the right driver as potentially |
| 741 | // there can be different drivers for different devices. But on that account, |
| 742 | // no instance should be decoding for another instance's nextIds. |
| 743 | |
| 744 | for (Map.Entry<Integer, NextGroup> e : allnexts.entrySet()) { |
| 745 | // get the device this next Objective was sent to |
| 746 | DeviceId deviceId = nextToDevice.get(e.getKey()); |
| 747 | mappings.add("NextId " + e.getKey() + ": " + |
| 748 | ((deviceId != null) ? deviceId : "nextId not in this onos instance")); |
| 749 | if (deviceId != null) { |
| 750 | // this instance of the controller sent the nextObj to a driver |
| 751 | Pipeliner pipeliner = getDevicePipeliner(deviceId); |
| 752 | List<String> nextMappings = pipeliner.getNextMappings(e.getValue()); |
| 753 | if (nextMappings != null) { |
| 754 | mappings.addAll(nextMappings); |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | return mappings; |
| 759 | } |
Saurav Das | b5c236e | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 760 | |
| 761 | @Override |
Harshada Chaundkar | 5a198b0 | 2019-07-03 16:27:45 +0000 | [diff] [blame] | 762 | public Map<Pair<Integer, DeviceId>, List<String>> getNextMappingsChain() { |
| 763 | Map<Pair<Integer, DeviceId>, List<String>> nextObjGroupMap = new HashMap<>(); |
| 764 | Map<Integer, NextGroup> allnexts = flowObjectiveStore.getAllGroups(); |
| 765 | |
| 766 | // XXX if the NextGroup after de-serialization actually stored info of the deviceId |
| 767 | // then info on any nextObj could be retrieved from one controller instance. |
| 768 | // Right now the drivers on one instance can only fetch for next-ids that came |
| 769 | // to them. |
| 770 | // Also, we still need to send the right next-id to the right driver as potentially |
| 771 | // there can be different drivers for different devices. But on that account, |
| 772 | // no instance should be decoding for another instance's nextIds. |
| 773 | |
| 774 | for (Map.Entry<Integer, NextGroup> e : allnexts.entrySet()) { |
| 775 | // get the device this next Objective was sent to |
| 776 | DeviceId deviceId = nextToDevice.get(e.getKey()); |
| 777 | if (deviceId != null) { |
| 778 | // this instance of the controller sent the nextObj to a driver |
| 779 | Pipeliner pipeliner = getDevicePipeliner(deviceId); |
| 780 | List<String> nextMappings = pipeliner.getNextMappings(e.getValue()); |
| 781 | if (nextMappings != null) { |
| 782 | //mappings.addAll(nextMappings); |
| 783 | nextObjGroupMap.put(Pair.of(e.getKey(), deviceId), nextMappings); |
| 784 | } |
| 785 | } else { |
| 786 | nextObjGroupMap.put(Pair.of(e.getKey(), deviceId), ImmutableList.of("nextId not in this onos instance")); |
| 787 | } |
| 788 | } |
| 789 | return nextObjGroupMap; |
| 790 | } |
| 791 | |
| 792 | |
| 793 | @Override |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 794 | public List<String> getPendingFlowObjectives() { |
| 795 | List<String> pendingFlowObjectives = new ArrayList<>(); |
Charles Chan | 5473471 | 2017-03-29 11:07:55 -0700 | [diff] [blame] | 796 | |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 797 | for (Integer nextId : pendingForwards.keySet()) { |
| 798 | Set<PendingFlowObjective> pfwd = pendingForwards.get(nextId); |
Sho SHIMIZU | 81470a5 | 2016-08-12 17:24:55 -0700 | [diff] [blame] | 799 | StringBuilder pend = new StringBuilder(); |
Charles Chan | 5473471 | 2017-03-29 11:07:55 -0700 | [diff] [blame] | 800 | pend.append("NextId: ") |
| 801 | .append(nextId); |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 802 | for (PendingFlowObjective pf : pfwd) { |
Charles Chan | 5473471 | 2017-03-29 11:07:55 -0700 | [diff] [blame] | 803 | pend.append("\n FwdId: ") |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 804 | .append(String.format("%11s", pf.flowObjective().id())) |
| 805 | .append(", DeviceId: ") |
| 806 | .append(pf.deviceId()) |
| 807 | .append(", Selector: ") |
| 808 | .append(((ForwardingObjective) pf.flowObjective()) |
| 809 | .selector().criteria()); |
| 810 | } |
| 811 | pendingFlowObjectives.add(pend.toString()); |
| 812 | } |
| 813 | |
| 814 | for (Integer nextId : pendingNexts.keySet()) { |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 815 | List<PendingFlowObjective> pnext = pendingNexts.get(nextId); |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 816 | StringBuilder pend = new StringBuilder(); |
| 817 | pend.append("NextId: ") |
| 818 | .append(nextId); |
| 819 | for (PendingFlowObjective pn : pnext) { |
| 820 | pend.append("\n NextOp: ") |
| 821 | .append(pn.flowObjective().op()) |
Charles Chan | 5473471 | 2017-03-29 11:07:55 -0700 | [diff] [blame] | 822 | .append(", DeviceId: ") |
| 823 | .append(pn.deviceId()) |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 824 | .append(", Treatments: ") |
| 825 | .append(((NextObjective) pn.flowObjective()) |
| 826 | .next()); |
Saurav Das | b5c236e | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 827 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 828 | pendingFlowObjectives.add(pend.toString()); |
Saurav Das | b5c236e | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 829 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 830 | |
| 831 | return pendingFlowObjectives; |
| 832 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 833 | } |