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