Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -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 | */ |
Srikanth Vavilapalli | 4db76e3 | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 16 | package org.onosproject.segmentrouting.grouphandler; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 17 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 18 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | import org.onosproject.net.Link; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 21 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 22 | import org.onosproject.net.link.LinkService; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 23 | import org.onosproject.segmentrouting.SegmentRoutingManager; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 24 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 25 | import org.onosproject.segmentrouting.config.DeviceProperties; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 26 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 27 | import java.util.HashSet; |
| 28 | import java.util.Set; |
| 29 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 30 | /** |
| 31 | * Default ECMP group handler creation module for a transit device. |
| 32 | * This component creates a set of ECMP groups for every neighbor |
| 33 | * that this device is connected to. |
| 34 | * For example, consider a network of 4 devices: D0 (Segment ID: 100), |
| 35 | * D1 (Segment ID: 101), D2 (Segment ID: 102) and D3 (Segment ID: 103), |
| 36 | * where D0 and D3 are edge devices and D1 and D2 are transit devices. |
| 37 | * Assume transit device D1 is connected to 2 neighbors (D0 and D3 ). |
| 38 | * The following groups will be created in D1: |
| 39 | * 1) all ports to D0 + with no label push, |
| 40 | * 2) all ports to D3 + with no label push, |
| 41 | */ |
| 42 | public class DefaultTransitGroupHandler extends DefaultGroupHandler { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 43 | protected DefaultTransitGroupHandler(DeviceId deviceId, |
| 44 | ApplicationId appId, |
| 45 | DeviceProperties config, |
| 46 | LinkService linkService, |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 47 | FlowObjectiveService flowObjService, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 48 | SegmentRoutingManager srManager) { |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 49 | super(deviceId, appId, config, linkService, flowObjService, srManager); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public void createGroups() { |
| 54 | Set<DeviceId> neighbors = devicePortMap.keySet(); |
| 55 | if (neighbors == null || neighbors.isEmpty()) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | // Create all possible Neighbor sets from this router |
| 60 | // NOTE: Avoid any pairings of edge routers only |
| 61 | Set<Set<DeviceId>> sets = getPowerSetOfNeighbors(neighbors); |
| 62 | sets = filterEdgeRouterOnlyPairings(sets); |
| 63 | log.debug("createGroupsAtTransitRouter: The size of neighbor powerset " |
| 64 | + "for sw {} is {}", deviceId, sets.size()); |
Sho SHIMIZU | 6cfc02d | 2015-09-11 11:19:11 -0700 | [diff] [blame] | 65 | Set<NeighborSet> nsSet = new HashSet<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 66 | for (Set<DeviceId> combo : sets) { |
| 67 | if (combo.isEmpty()) { |
| 68 | continue; |
| 69 | } |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 70 | // For these NeighborSet isMpls is meaningless. |
| 71 | NeighborSet ns = new NeighborSet(combo, false); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 72 | log.debug("createGroupsAtTransitRouter: sw {} combo {} ns {}", |
| 73 | deviceId, combo, ns); |
| 74 | nsSet.add(ns); |
| 75 | } |
| 76 | log.debug("createGroupsAtTransitRouter: The neighborset with label " |
| 77 | + "for sw {} is {}", deviceId, nsSet); |
| 78 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 79 | //createGroupsFromNeighborsets(nsSet); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | protected void newNeighbor(Link newNeighborLink) { |
| 84 | log.debug("New Neighbor: Updating groups for " |
| 85 | + "transit device {}", deviceId); |
| 86 | // Recompute neighbor power set |
| 87 | addNeighborAtPort(newNeighborLink.dst().deviceId(), |
| 88 | newNeighborLink.src().port()); |
| 89 | // Compute new neighbor sets due to the addition of new neighbor |
| 90 | Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent( |
| 91 | newNeighborLink.dst().deviceId(), |
| 92 | devicePortMap.keySet()); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 93 | //createGroupsFromNeighborsets(nsSet); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
| 97 | protected void newPortToExistingNeighbor(Link newNeighborLink) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 98 | /*log.debug("New port to existing neighbor: Updating " |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 99 | + "groups for transit device {}", deviceId); |
| 100 | addNeighborAtPort(newNeighborLink.dst().deviceId(), |
| 101 | newNeighborLink.src().port()); |
| 102 | Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent( |
| 103 | newNeighborLink.dst().deviceId(), |
| 104 | devicePortMap.keySet()); |
| 105 | for (NeighborSet ns : nsSet) { |
| 106 | // Create the new bucket to be updated |
| 107 | TrafficTreatment.Builder tBuilder = |
| 108 | DefaultTrafficTreatment.builder(); |
| 109 | tBuilder.setOutput(newNeighborLink.src().port()) |
| 110 | .setEthDst(deviceConfig.getDeviceMac( |
| 111 | newNeighborLink.dst().deviceId())) |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 112 | .setEthSrc(nodeMacAddr); |
| 113 | if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { |
| 114 | tBuilder.pushMpls() |
| 115 | .setMpls(MplsLabel. |
| 116 | mplsLabel(ns.getEdgeLabel())); |
| 117 | } |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 118 | |
| 119 | |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 120 | Integer nextId = deviceNextObjectiveIds.get(ns); |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 121 | if (nextId != null) { |
| 122 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 123 | .builder().withId(nextId) |
| 124 | .withType(NextObjective.Type.HASHED).fromApp(appId); |
| 125 | |
| 126 | nextObjBuilder.addTreatment(tBuilder.build()); |
| 127 | |
| 128 | NextObjective nextObjective = nextObjBuilder.add(); |
| 129 | flowObjectiveService.next(deviceId, nextObjective); |
| 130 | } |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 131 | }*/ |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | @Override |
| 135 | protected Set<NeighborSet> computeImpactedNeighborsetForPortEvent( |
| 136 | DeviceId impactedNeighbor, |
| 137 | Set<DeviceId> updatedNeighbors) { |
| 138 | Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(updatedNeighbors); |
| 139 | |
Sho SHIMIZU | 6cfc02d | 2015-09-11 11:19:11 -0700 | [diff] [blame] | 140 | Set<DeviceId> tmp = new HashSet<>(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 141 | tmp.addAll(updatedNeighbors); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 142 | tmp.remove(impactedNeighbor); |
| 143 | Set<Set<DeviceId>> tmpPowerSet = getPowerSetOfNeighbors(tmp); |
| 144 | |
| 145 | // Compute the impacted neighbor sets |
| 146 | powerSet.removeAll(tmpPowerSet); |
| 147 | |
| 148 | powerSet = filterEdgeRouterOnlyPairings(powerSet); |
Sho SHIMIZU | 6cfc02d | 2015-09-11 11:19:11 -0700 | [diff] [blame] | 149 | Set<NeighborSet> nsSet = new HashSet<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 150 | for (Set<DeviceId> combo : powerSet) { |
| 151 | if (combo.isEmpty()) { |
| 152 | continue; |
| 153 | } |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 154 | // For these NeighborSet isMpls is meaningless. |
| 155 | NeighborSet ns = new NeighborSet(combo, false); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 156 | log.debug("createGroupsAtTransitRouter: sw {} combo {} ns {}", |
| 157 | deviceId, combo, ns); |
| 158 | nsSet.add(ns); |
| 159 | } |
| 160 | log.debug("computeImpactedNeighborsetForPortEvent: The neighborset with label " |
| 161 | + "for sw {} is {}", deviceId, nsSet); |
| 162 | |
| 163 | return nsSet; |
| 164 | } |
| 165 | |
| 166 | private Set<Set<DeviceId>> filterEdgeRouterOnlyPairings(Set<Set<DeviceId>> sets) { |
Sho SHIMIZU | 6cfc02d | 2015-09-11 11:19:11 -0700 | [diff] [blame] | 167 | Set<Set<DeviceId>> fiteredSets = new HashSet<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 168 | for (Set<DeviceId> deviceSubSet : sets) { |
| 169 | if (deviceSubSet.size() > 1) { |
| 170 | boolean avoidEdgeRouterPairing = true; |
| 171 | for (DeviceId device : deviceSubSet) { |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 172 | boolean isEdge; |
| 173 | try { |
| 174 | isEdge = deviceConfig.isEdgeDevice(device); |
| 175 | } catch (DeviceConfigNotFoundException e) { |
| 176 | log.warn(e.getMessage() + " Skipping filterEdgeRouterOnlyPairings on this device."); |
| 177 | continue; |
| 178 | } |
| 179 | |
| 180 | if (!isEdge) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 181 | avoidEdgeRouterPairing = false; |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | if (!avoidEdgeRouterPairing) { |
| 186 | fiteredSets.add(deviceSubSet); |
| 187 | } |
| 188 | } else { |
| 189 | fiteredSets.add(deviceSubSet); |
| 190 | } |
| 191 | } |
| 192 | return fiteredSets; |
| 193 | } |
| 194 | } |