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.List; |
| 20 | import java.util.Set; |
| 21 | |
| 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.Link; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 25 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 26 | import org.onosproject.net.link.LinkService; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 27 | import org.onosproject.segmentrouting.SegmentRoutingManager; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 28 | import org.onosproject.segmentrouting.config.DeviceProperties; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Default ECMP group handler creation module for an edge 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 device D0 is connected to 2 neighbors (D1 and D2 ). |
| 38 | * The following groups will be created in D0: |
Saurav Das | a07f203 | 2015-10-19 14:37:36 -0700 | [diff] [blame] | 39 | * 1) all ports to D1 + with no label push, // direct attach case, seen |
| 40 | * 2) all ports to D1 + with label 102 pushed, // this is not needed |
| 41 | * 3) all ports to D1 + with label 103 pushed, // maybe needed, sometimes seen |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 42 | * 4) all ports to D2 + with no label push, |
| 43 | * 5) all ports to D2 + with label 101 pushed, |
| 44 | * 6) all ports to D2 + with label 103 pushed, |
Saurav Das | a07f203 | 2015-10-19 14:37:36 -0700 | [diff] [blame] | 45 | * 7) all ports to D1 and D2 + with label 103 pushed // ecmp case |
| 46 | * 8) what about ecmp no label case |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 47 | */ |
| 48 | public class DefaultEdgeGroupHandler extends DefaultGroupHandler { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 49 | protected DefaultEdgeGroupHandler(DeviceId deviceId, |
| 50 | ApplicationId appId, |
| 51 | DeviceProperties config, |
| 52 | LinkService linkService, |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 53 | FlowObjectiveService flowObjService, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 54 | SegmentRoutingManager srManager) { |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame^] | 55 | super(deviceId, appId, config, linkService, flowObjService, srManager); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void createGroups() { |
| 60 | log.debug("Creating default groups " |
| 61 | + "for edge device {}", deviceId); |
| 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 | Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(neighbors); |
| 69 | log.trace("createGroupsAtEdgeRouter: The size of neighbor powerset " |
| 70 | + "for sw {} is {}", deviceId, powerSet.size()); |
Sho SHIMIZU | 6cfc02d | 2015-09-11 11:19:11 -0700 | [diff] [blame] | 71 | Set<NeighborSet> nsSet = new HashSet<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 72 | for (Set<DeviceId> combo : powerSet) { |
| 73 | if (combo.isEmpty()) { |
| 74 | continue; |
| 75 | } |
| 76 | List<Integer> groupSegmentIds = |
| 77 | getSegmentIdsTobePairedWithNeighborSet(combo); |
| 78 | for (Integer sId : groupSegmentIds) { |
| 79 | NeighborSet ns = new NeighborSet(combo, sId); |
| 80 | log.trace("createGroupsAtEdgeRouter: sw {} " |
| 81 | + "combo {} sId {} ns {}", |
| 82 | deviceId, combo, sId, ns); |
| 83 | nsSet.add(ns); |
| 84 | } |
| 85 | } |
| 86 | log.trace("createGroupsAtEdgeRouter: The neighborset " |
| 87 | + "with label for sw {} is {}", |
| 88 | deviceId, nsSet); |
| 89 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 90 | //createGroupsFromNeighborsets(nsSet); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Override |
| 94 | protected void newNeighbor(Link newNeighborLink) { |
| 95 | log.debug("New Neighbor: Updating groups " |
| 96 | + "for edge device {}", deviceId); |
| 97 | // Recompute neighbor power set |
| 98 | addNeighborAtPort(newNeighborLink.dst().deviceId(), |
| 99 | newNeighborLink.src().port()); |
| 100 | // Compute new neighbor sets due to the addition of new neighbor |
| 101 | Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent( |
| 102 | newNeighborLink.dst().deviceId(), |
| 103 | devicePortMap.keySet()); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 104 | //createGroupsFromNeighborsets(nsSet); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @Override |
| 108 | protected void newPortToExistingNeighbor(Link newNeighborLink) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 109 | /*log.debug("New port to existing neighbor: Updating " |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 110 | + "groups for edge device {}", deviceId); |
| 111 | addNeighborAtPort(newNeighborLink.dst().deviceId(), |
| 112 | newNeighborLink.src().port()); |
| 113 | Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent( |
| 114 | newNeighborLink.dst().deviceId(), |
| 115 | devicePortMap.keySet()); |
| 116 | for (NeighborSet ns : nsSet) { |
| 117 | // Create the new bucket to be updated |
| 118 | TrafficTreatment.Builder tBuilder = |
| 119 | DefaultTrafficTreatment.builder(); |
| 120 | tBuilder.setOutput(newNeighborLink.src().port()) |
| 121 | .setEthDst(deviceConfig.getDeviceMac( |
| 122 | newNeighborLink.dst().deviceId())) |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 123 | .setEthSrc(nodeMacAddr); |
| 124 | if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { |
| 125 | tBuilder.pushMpls() |
| 126 | .setMpls(MplsLabel. |
| 127 | mplsLabel(ns.getEdgeLabel())); |
| 128 | } |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 129 | |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 130 | Integer nextId = deviceNextObjectiveIds.get(ns); |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 131 | if (nextId != null) { |
| 132 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 133 | .builder().withId(nextId) |
| 134 | .withType(NextObjective.Type.HASHED).fromApp(appId); |
| 135 | |
| 136 | nextObjBuilder.addTreatment(tBuilder.build()); |
| 137 | |
| 138 | NextObjective nextObjective = nextObjBuilder.add(); |
| 139 | flowObjectiveService.next(deviceId, nextObjective); |
| 140 | } |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 141 | }*/ |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | @Override |
| 145 | protected Set<NeighborSet> computeImpactedNeighborsetForPortEvent( |
| 146 | DeviceId impactedNeighbor, |
| 147 | Set<DeviceId> updatedNeighbors) { |
| 148 | Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(updatedNeighbors); |
| 149 | |
Sho SHIMIZU | 6cfc02d | 2015-09-11 11:19:11 -0700 | [diff] [blame] | 150 | Set<DeviceId> tmp = new HashSet<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 151 | tmp.addAll(updatedNeighbors); |
| 152 | tmp.remove(impactedNeighbor); |
| 153 | Set<Set<DeviceId>> tmpPowerSet = getPowerSetOfNeighbors(tmp); |
| 154 | |
| 155 | // Compute the impacted neighbor sets |
| 156 | powerSet.removeAll(tmpPowerSet); |
| 157 | |
Sho SHIMIZU | 6cfc02d | 2015-09-11 11:19:11 -0700 | [diff] [blame] | 158 | Set<NeighborSet> nsSet = new HashSet<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 159 | for (Set<DeviceId> combo : powerSet) { |
| 160 | if (combo.isEmpty()) { |
| 161 | continue; |
| 162 | } |
| 163 | List<Integer> groupSegmentIds = |
| 164 | getSegmentIdsTobePairedWithNeighborSet(combo); |
| 165 | for (Integer sId : groupSegmentIds) { |
| 166 | NeighborSet ns = new NeighborSet(combo, sId); |
| 167 | log.trace("computeImpactedNeighborsetForPortEvent: sw {} " |
| 168 | + "combo {} sId {} ns {}", |
| 169 | deviceId, combo, sId, ns); |
| 170 | nsSet.add(ns); |
| 171 | } |
| 172 | } |
| 173 | log.trace("computeImpactedNeighborsetForPortEvent: The neighborset " |
| 174 | + "with label for sw {} is {}", |
| 175 | deviceId, nsSet); |
| 176 | return nsSet; |
| 177 | } |
| 178 | |
| 179 | } |