blob: 14187c0976c4c080b0a48b0af59aeb24ea75d1d9 [file] [log] [blame]
sanghob35a6192015-04-01 13:05:26 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.segmentrouting;
17
sangho20eff1d2015-04-13 15:15:58 -070018import com.google.common.collect.Maps;
19import com.google.common.collect.Sets;
sangho666cd6d2015-04-14 16:27:13 -070020import org.onlab.packet.Ip4Address;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070021import org.onlab.packet.Ip4Prefix;
sanghob35a6192015-04-01 13:05:26 -070022import org.onlab.packet.IpPrefix;
23import org.onosproject.net.Device;
24import org.onosproject.net.DeviceId;
sangho20eff1d2015-04-13 15:15:58 -070025import org.onosproject.net.Link;
sanghob35a6192015-04-01 13:05:26 -070026import org.onosproject.net.MastershipRole;
sanghob35a6192015-04-01 13:05:26 -070027import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
29
30import java.util.ArrayList;
31import java.util.HashMap;
32import java.util.HashSet;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070033import java.util.List;
sanghob35a6192015-04-01 13:05:26 -070034import java.util.Set;
35
36import static com.google.common.base.Preconditions.checkNotNull;
37
38public class DefaultRoutingHandler {
39
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070040 private static Logger log = LoggerFactory
41 .getLogger(DefaultRoutingHandler.class);
sanghob35a6192015-04-01 13:05:26 -070042
43 private SegmentRoutingManager srManager;
44 private RoutingRulePopulator rulePopulator;
sangho20eff1d2015-04-13 15:15:58 -070045 private HashMap<DeviceId, ECMPShortestPathGraph> currentEcmpSpgMap;
sangho45b009c2015-05-07 13:30:57 -070046 private HashMap<DeviceId, ECMPShortestPathGraph> updatedEcmpSpgMap;
sangho666cd6d2015-04-14 16:27:13 -070047 private DeviceConfiguration config;
sanghob35a6192015-04-01 13:05:26 -070048 private Status populationStatus;
49
50 /**
51 * Represents the default routing population status.
52 */
53 public enum Status {
54 // population process is not started yet.
55 IDLE,
56
57 // population process started.
58 STARTED,
59
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070060 // population process was aborted due to errors, mostly for groups not
61 // found.
sanghob35a6192015-04-01 13:05:26 -070062 ABORTED,
63
64 // population process was finished successfully.
65 SUCCEEDED
66 }
67
68 /**
69 * Creates a DefaultRoutingHandler object.
70 *
71 * @param srManager SegmentRoutingManager object
72 */
73 public DefaultRoutingHandler(SegmentRoutingManager srManager) {
74 this.srManager = srManager;
75 this.rulePopulator = checkNotNull(srManager.routingRulePopulator);
sangho666cd6d2015-04-14 16:27:13 -070076 this.config = checkNotNull(srManager.deviceConfiguration);
sanghob35a6192015-04-01 13:05:26 -070077 this.populationStatus = Status.IDLE;
sangho20eff1d2015-04-13 15:15:58 -070078 this.currentEcmpSpgMap = Maps.newHashMap();
sanghob35a6192015-04-01 13:05:26 -070079 }
80
81 /**
82 * Populates all routing rules to all connected routers, including default
83 * routing rules, adjacency rules, and policy rules if any.
84 *
85 * @return true if it succeeds in populating all rules, otherwise false
86 */
87 public boolean populateAllRoutingRules() {
88
89 populationStatus = Status.STARTED;
sangho20eff1d2015-04-13 15:15:58 -070090 rulePopulator.resetCounter();
sanghob35a6192015-04-01 13:05:26 -070091 log.info("Starts to populate routing rules");
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070092 log.debug("populateAllRoutingRules: populationStatus is STARTED");
sanghob35a6192015-04-01 13:05:26 -070093
94 for (Device sw : srManager.deviceService.getDevices()) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070095 if (srManager.mastershipService.getLocalRole(sw.id()) != MastershipRole.MASTER) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070096 log.debug("populateAllRoutingRules: skipping device {}...we are not master",
97 sw.id());
sanghob35a6192015-04-01 13:05:26 -070098 continue;
99 }
100
sangho20eff1d2015-04-13 15:15:58 -0700101 ECMPShortestPathGraph ecmpSpg = new ECMPShortestPathGraph(sw.id(), srManager);
102 if (!populateEcmpRoutingRules(sw.id(), ecmpSpg)) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700103 log.debug("populateAllRoutingRules: populationStatus is ABORTED");
sanghob35a6192015-04-01 13:05:26 -0700104 populationStatus = Status.ABORTED;
105 log.debug("Abort routing rule population");
106 return false;
107 }
sangho20eff1d2015-04-13 15:15:58 -0700108 currentEcmpSpgMap.put(sw.id(), ecmpSpg);
sanghob35a6192015-04-01 13:05:26 -0700109
110 // TODO: Set adjacency routing rule for all switches
111 }
112
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700113 log.debug("populateAllRoutingRules: populationStatus is SUCCEEDED");
sanghob35a6192015-04-01 13:05:26 -0700114 populationStatus = Status.SUCCEEDED;
sangho20eff1d2015-04-13 15:15:58 -0700115 log.info("Completes routing rule population. Total # of rules pushed : {}",
116 rulePopulator.getCounter());
sanghob35a6192015-04-01 13:05:26 -0700117 return true;
118 }
119
sangho20eff1d2015-04-13 15:15:58 -0700120 /**
121 * Populates the routing rules according to the route changes due to the link
122 * failure or link add. It computes the routes changed due to the link changes and
123 * repopulates the rules only for the routes.
124 *
125 * @param linkFail link failed, null for link added
126 * @return true if it succeeds to populate all rules, false otherwise
127 */
128 public boolean populateRoutingRulesForLinkStatusChange(Link linkFail) {
129
130 synchronized (populationStatus) {
131
132 if (populationStatus == Status.STARTED) {
sangho52abe3a2015-05-05 14:13:34 -0700133 log.warn("Previous rule population is not finished.");
sangho20eff1d2015-04-13 15:15:58 -0700134 return true;
135 }
136
sangho45b009c2015-05-07 13:30:57 -0700137 // Take the snapshots of the links
138 updatedEcmpSpgMap = new HashMap<>();
139 for (Device sw : srManager.deviceService.getDevices()) {
140 if (srManager.mastershipService.
141 getLocalRole(sw.id()) != MastershipRole.MASTER) {
142 continue;
143 }
144 ECMPShortestPathGraph ecmpSpgUpdated =
145 new ECMPShortestPathGraph(sw.id(), srManager);
146 updatedEcmpSpgMap.put(sw.id(), ecmpSpgUpdated);
147 }
148
sangho52abe3a2015-05-05 14:13:34 -0700149 log.info("Starts rule population from link change");
150
sangho20eff1d2015-04-13 15:15:58 -0700151 Set<ArrayList<DeviceId>> routeChanges;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700152 log.trace("populateRoutingRulesForLinkStatusChange: "
153 + "populationStatus is STARTED");
sangho20eff1d2015-04-13 15:15:58 -0700154 populationStatus = Status.STARTED;
155 if (linkFail == null) {
156 // Compare all routes of existing ECMP SPG with the new ones
157 routeChanges = computeRouteChange();
158 } else {
159 // Compare existing ECMP SPG only with the link removed
160 routeChanges = computeDamagedRoutes(linkFail);
161 }
162
163 if (routeChanges.isEmpty()) {
sangho52abe3a2015-05-05 14:13:34 -0700164 log.info("No route changes for the link status change");
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700165 log.debug("populateRoutingRulesForLinkStatusChange: populationStatus is SUCCEEDED");
sangho20eff1d2015-04-13 15:15:58 -0700166 populationStatus = Status.SUCCEEDED;
167 return true;
168 }
169
170 if (repopulateRoutingRulesForRoutes(routeChanges)) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700171 log.debug("populateRoutingRulesForLinkStatusChange: populationStatus is SUCCEEDED");
sangho20eff1d2015-04-13 15:15:58 -0700172 populationStatus = Status.SUCCEEDED;
173 log.info("Complete to repopulate the rules. # of rules populated : {}",
174 rulePopulator.getCounter());
175 return true;
176 } else {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700177 log.debug("populateRoutingRulesForLinkStatusChange: populationStatus is ABORTED");
sangho20eff1d2015-04-13 15:15:58 -0700178 populationStatus = Status.ABORTED;
179 log.warn("Failed to repopulate the rules.");
180 return false;
181 }
182 }
183 }
184
185 private boolean repopulateRoutingRulesForRoutes(Set<ArrayList<DeviceId>> routes) {
186 rulePopulator.resetCounter();
187 for (ArrayList<DeviceId> link: routes) {
sangho834e4b02015-05-01 09:38:25 -0700188 // When only the source device is defined, reinstall routes to all other devices
sangho20eff1d2015-04-13 15:15:58 -0700189 if (link.size() == 1) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700190 log.trace("repopulateRoutingRulesForRoutes: running ECMP graph for device {}", link.get(0));
sangho20eff1d2015-04-13 15:15:58 -0700191 ECMPShortestPathGraph ecmpSpg = new ECMPShortestPathGraph(link.get(0), srManager);
192 if (populateEcmpRoutingRules(link.get(0), ecmpSpg)) {
193 currentEcmpSpgMap.put(link.get(0), ecmpSpg);
sangho52abe3a2015-05-05 14:13:34 -0700194 } else {
sangho45b009c2015-05-07 13:30:57 -0700195 log.warn("Failed to populate the flow rules from {} to all", link.get(0));
sangho52abe3a2015-05-05 14:13:34 -0700196 return false;
sangho20eff1d2015-04-13 15:15:58 -0700197 }
sangho45b009c2015-05-07 13:30:57 -0700198 } else {
199 DeviceId src = link.get(0);
200 DeviceId dst = link.get(1);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700201 log.trace("repopulateRoutingRulesForRoutes: running ECMP graph for device {}", dst);
sangho45b009c2015-05-07 13:30:57 -0700202 ECMPShortestPathGraph ecmpSpg = updatedEcmpSpgMap.get(dst);
203 HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> switchVia =
204 ecmpSpg.getAllLearnedSwitchesAndVia();
205 for (Integer itrIdx : switchVia.keySet()) {
206 HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>> swViaMap =
207 switchVia.get(itrIdx);
208 for (DeviceId targetSw : swViaMap.keySet()) {
209 if (!targetSw.equals(src)) {
210 continue;
211 }
212 Set<DeviceId> nextHops = new HashSet<>();
213 for (ArrayList<DeviceId> via : swViaMap.get(targetSw)) {
214 if (via.isEmpty()) {
215 nextHops.add(dst);
216 } else {
217 nextHops.add(via.get(0));
218 }
219 }
220 if (!populateEcmpRoutingRulePartial(targetSw, dst, nextHops)) {
221 return false;
sangho20eff1d2015-04-13 15:15:58 -0700222 }
223 }
sangho20eff1d2015-04-13 15:15:58 -0700224 }
sangho45b009c2015-05-07 13:30:57 -0700225 currentEcmpSpgMap.put(dst, ecmpSpg);
sangho20eff1d2015-04-13 15:15:58 -0700226 }
227 }
228 return true;
229 }
230
231 private Set<ArrayList<DeviceId>> computeDamagedRoutes(Link linkFail) {
232
233 Set<ArrayList<DeviceId>> routes = new HashSet<>();
234
235 for (Device sw : srManager.deviceService.getDevices()) {
236 if (srManager.mastershipService.
237 getLocalRole(sw.id()) != MastershipRole.MASTER) {
238 continue;
239 }
240 ECMPShortestPathGraph ecmpSpg = currentEcmpSpgMap.get(sw.id());
241 if (ecmpSpg == null) {
242 log.error("No existing ECMP path for switch {}", sw.id());
243 continue;
244 }
245 HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> switchVia =
246 ecmpSpg.getAllLearnedSwitchesAndVia();
247 for (Integer itrIdx : switchVia.keySet()) {
248 HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>> swViaMap =
249 switchVia.get(itrIdx);
250 for (DeviceId targetSw : swViaMap.keySet()) {
251 DeviceId destSw = sw.id();
252 Set<ArrayList<DeviceId>> subLinks =
253 computeLinks(targetSw, destSw, swViaMap);
254 for (ArrayList<DeviceId> alink: subLinks) {
255 if (alink.get(0).equals(linkFail.src().deviceId()) &&
256 alink.get(1).equals(linkFail.dst().deviceId())) {
257 ArrayList<DeviceId> aRoute = new ArrayList<>();
258 aRoute.add(targetSw);
259 aRoute.add(destSw);
260 routes.add(aRoute);
261 break;
262 }
263 }
264 }
265 }
sangho45b009c2015-05-07 13:30:57 -0700266
sangho20eff1d2015-04-13 15:15:58 -0700267 }
268
269 return routes;
270 }
271
272 private Set<ArrayList<DeviceId>> computeRouteChange() {
273
274 Set<ArrayList<DeviceId>> routes = new HashSet<>();
275
276 for (Device sw : srManager.deviceService.getDevices()) {
277 if (srManager.mastershipService.
278 getLocalRole(sw.id()) != MastershipRole.MASTER) {
sangho45b009c2015-05-07 13:30:57 -0700279 log.warn("No mastership for {} and skip route optimization");
sangho20eff1d2015-04-13 15:15:58 -0700280 continue;
281 }
sangho45b009c2015-05-07 13:30:57 -0700282
283 log.trace("link of {} - ", sw.id());
284 for (Link link: srManager.linkService.getDeviceLinks(sw.id())) {
285 log.trace("{} -> {} ", link.src().deviceId(), link.dst().deviceId());
286 }
287
288 log.debug("Checking route change for switch {}", sw.id());
sangho20eff1d2015-04-13 15:15:58 -0700289 ECMPShortestPathGraph ecmpSpg = currentEcmpSpgMap.get(sw.id());
290 if (ecmpSpg == null) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700291 log.debug("No existing ECMP graph for device {}", sw.id());
sangho20eff1d2015-04-13 15:15:58 -0700292 ArrayList<DeviceId> route = new ArrayList<>();
293 route.add(sw.id());
294 routes.add(route);
295 continue;
296 }
sangho45b009c2015-05-07 13:30:57 -0700297 ECMPShortestPathGraph newEcmpSpg = updatedEcmpSpgMap.get(sw.id());
298 currentEcmpSpgMap.put(sw.id(), newEcmpSpg);
sangho20eff1d2015-04-13 15:15:58 -0700299 HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> switchVia =
300 ecmpSpg.getAllLearnedSwitchesAndVia();
301 HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> switchViaUpdated =
302 newEcmpSpg.getAllLearnedSwitchesAndVia();
303
sangho45b009c2015-05-07 13:30:57 -0700304 for (Integer itrIdx : switchViaUpdated.keySet()) {
305 HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>> swViaMapUpdated =
306 switchViaUpdated.get(itrIdx);
307 for (DeviceId srcSw : swViaMapUpdated.keySet()) {
308 ArrayList<ArrayList<DeviceId>> viaUpdated = swViaMapUpdated.get(srcSw);
309 ArrayList<ArrayList<DeviceId>> via = getVia(switchVia, srcSw);
310 if (via.isEmpty() || !viaUpdated.equals(via)) {
sangho20eff1d2015-04-13 15:15:58 -0700311 ArrayList<DeviceId> route = new ArrayList<>();
312 route.add(srcSw);
313 route.add(sw.id());
314 routes.add(route);
315 }
316 }
317 }
sangho45b009c2015-05-07 13:30:57 -0700318 }
sangho20eff1d2015-04-13 15:15:58 -0700319
sangho45b009c2015-05-07 13:30:57 -0700320 for (ArrayList<DeviceId> link: routes) {
321 log.trace("Link changes - ");
322 if (link.size() == 1) {
323 log.trace(" : {} - all", link.get(0));
324 } else {
325 log.trace(" : {} - {}", link.get(0), link.get(1));
326 }
sangho20eff1d2015-04-13 15:15:58 -0700327 }
328
329 return routes;
330 }
331
332 private ArrayList<ArrayList<DeviceId>> getVia(HashMap<Integer, HashMap<DeviceId,
333 ArrayList<ArrayList<DeviceId>>>> switchVia, DeviceId srcSw) {
334 for (Integer itrIdx : switchVia.keySet()) {
335 HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>> swViaMap =
336 switchVia.get(itrIdx);
337 if (swViaMap.get(srcSw) == null) {
338 continue;
339 } else {
340 return swViaMap.get(srcSw);
341 }
342 }
343
344 return new ArrayList<>();
345 }
346
347 private Set<ArrayList<DeviceId>> computeLinks(DeviceId src,
348 DeviceId dst,
349 HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>> viaMap) {
350 Set<ArrayList<DeviceId>> subLinks = Sets.newHashSet();
351 for (ArrayList<DeviceId> via : viaMap.get(src)) {
352 DeviceId linkSrc = src;
353 DeviceId linkDst = dst;
354 for (DeviceId viaDevice: via) {
355 ArrayList<DeviceId> link = new ArrayList<>();
356 linkDst = viaDevice;
357 link.add(linkSrc);
358 link.add(linkDst);
359 subLinks.add(link);
360 linkSrc = viaDevice;
361 }
362 ArrayList<DeviceId> link = new ArrayList<>();
363 link.add(linkSrc);
364 link.add(dst);
365 subLinks.add(link);
366 }
367
368 return subLinks;
369 }
370
371 private boolean populateEcmpRoutingRules(DeviceId destSw,
sanghob35a6192015-04-01 13:05:26 -0700372 ECMPShortestPathGraph ecmpSPG) {
373
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700374 HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> switchVia = ecmpSPG
375 .getAllLearnedSwitchesAndVia();
sanghob35a6192015-04-01 13:05:26 -0700376 for (Integer itrIdx : switchVia.keySet()) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700377 HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>> swViaMap = switchVia
378 .get(itrIdx);
sanghob35a6192015-04-01 13:05:26 -0700379 for (DeviceId targetSw : swViaMap.keySet()) {
sanghob35a6192015-04-01 13:05:26 -0700380 Set<DeviceId> nextHops = new HashSet<>();
381
382 for (ArrayList<DeviceId> via : swViaMap.get(targetSw)) {
383 if (via.isEmpty()) {
384 nextHops.add(destSw);
385 } else {
386 nextHops.add(via.get(0));
387 }
388 }
389 if (!populateEcmpRoutingRulePartial(targetSw, destSw, nextHops)) {
390 return false;
391 }
392 }
393 }
394
395 return true;
396 }
397
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700398 private boolean populateEcmpRoutingRulePartial(DeviceId targetSw,
399 DeviceId destSw,
400 Set<DeviceId> nextHops) {
sanghob35a6192015-04-01 13:05:26 -0700401 boolean result;
402
403 if (nextHops.isEmpty()) {
404 nextHops.add(destSw);
405 }
406
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700407 // If both target switch and dest switch are edge routers, then set IP
sangho52abe3a2015-05-05 14:13:34 -0700408 // rule for both subnet and router IP.
sangho666cd6d2015-04-14 16:27:13 -0700409 if (config.isEdgeDevice(targetSw) && config.isEdgeDevice(destSw)) {
410 List<Ip4Prefix> subnets = config.getSubnets(destSw);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700411 log.debug("populateEcmpRoutingRulePartial in device {} towards {} for subnets {}",
412 targetSw, destSw, subnets);
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700413 result = rulePopulator.populateIpRuleForSubnet(targetSw,
414 subnets,
415 destSw,
416 nextHops);
sanghob35a6192015-04-01 13:05:26 -0700417 if (!result) {
418 return false;
419 }
420
sangho666cd6d2015-04-14 16:27:13 -0700421 Ip4Address routerIp = config.getRouterIp(destSw);
422 IpPrefix routerIpPrefix = IpPrefix.valueOf(routerIp, IpPrefix.MAX_INET_MASK_LENGTH);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700423 log.debug("populateEcmpRoutingRulePartial in device {} towards {} for router IP {}",
424 targetSw, destSw, routerIpPrefix);
sangho666cd6d2015-04-14 16:27:13 -0700425 result = rulePopulator.populateIpRuleForRouter(targetSw, routerIpPrefix, destSw, nextHops);
sanghob35a6192015-04-01 13:05:26 -0700426 if (!result) {
427 return false;
428 }
429
sangho52abe3a2015-05-05 14:13:34 -0700430 // If the target switch is an edge router, then set IP rules for the router IP.
sangho666cd6d2015-04-14 16:27:13 -0700431 } else if (config.isEdgeDevice(targetSw)) {
432 Ip4Address routerIp = config.getRouterIp(destSw);
433 IpPrefix routerIpPrefix = IpPrefix.valueOf(routerIp, IpPrefix.MAX_INET_MASK_LENGTH);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700434 log.debug("populateEcmpRoutingRulePartial in device {} towards {} for router IP {}",
435 targetSw, destSw, routerIpPrefix);
sangho666cd6d2015-04-14 16:27:13 -0700436 result = rulePopulator.populateIpRuleForRouter(targetSw, routerIpPrefix, destSw, nextHops);
sanghob35a6192015-04-01 13:05:26 -0700437 if (!result) {
438 return false;
439 }
sangho52abe3a2015-05-05 14:13:34 -0700440 }
sanghob35a6192015-04-01 13:05:26 -0700441
sangho52abe3a2015-05-05 14:13:34 -0700442 // Populates MPLS rules to all routers
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700443 log.debug("populateEcmpRoutingRulePartial in device{} towards {} for all MPLS rules",
444 targetSw, destSw);
sangho52abe3a2015-05-05 14:13:34 -0700445 result = rulePopulator.populateMplsRule(targetSw, destSw, nextHops);
446 if (!result) {
447 return false;
sanghob35a6192015-04-01 13:05:26 -0700448 }
449
450 return true;
451 }
452
453 /**
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700454 * Populates table miss entries for all tables, and pipeline rules for VLAN
455 * and TACM tables.
sanghob35a6192015-04-01 13:05:26 -0700456 *
457 * @param deviceId Switch ID to set the rules
458 */
459 public void populateTtpRules(DeviceId deviceId) {
sanghob35a6192015-04-01 13:05:26 -0700460 rulePopulator.populateTableVlan(deviceId);
461 rulePopulator.populateTableTMac(deviceId);
462 }
463
464 /**
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700465 * Start the flow rule population process if it was never started. The
466 * process finishes successfully when all flow rules are set and stops with
467 * ABORTED status when any groups required for flows is not set yet.
sanghob35a6192015-04-01 13:05:26 -0700468 */
469 public void startPopulationProcess() {
470 synchronized (populationStatus) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700471 if (populationStatus == Status.IDLE
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700472 || populationStatus == Status.SUCCEEDED
473 || populationStatus == Status.ABORTED) {
sanghob35a6192015-04-01 13:05:26 -0700474 populationStatus = Status.STARTED;
475 populateAllRoutingRules();
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700476 } else {
477 log.warn("Not initiating startPopulationProcess as populationStatus is {}",
478 populationStatus);
sanghob35a6192015-04-01 13:05:26 -0700479 }
480 }
481 }
482
483 /**
484 * Resume the flow rule population process if it was aborted for any reason.
485 * Mostly the process is aborted when the groups required are not set yet.
486 */
487 public void resumePopulationProcess() {
488 synchronized (populationStatus) {
489 if (populationStatus == Status.ABORTED) {
490 populationStatus = Status.STARTED;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700491 // TODO: we need to restart from the point aborted instead of
492 // restarting.
sanghob35a6192015-04-01 13:05:26 -0700493 populateAllRoutingRules();
494 }
495 }
496 }
497}