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 | */ |
| 16 | package org.onosproject.grouphandler; |
| 17 | |
| 18 | import java.util.Arrays; |
| 19 | import java.util.HashSet; |
| 20 | import java.util.List; |
| 21 | import java.util.Set; |
| 22 | |
sangho | 32a5932 | 2015-02-17 12:07:41 -0800 | [diff] [blame] | 23 | import org.onlab.packet.MplsLabel; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 24 | import org.onosproject.core.ApplicationId; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.Link; |
| 27 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 28 | import org.onosproject.net.flow.TrafficTreatment; |
| 29 | import org.onosproject.net.group.DefaultGroupBucket; |
| 30 | import org.onosproject.net.group.GroupBucket; |
| 31 | import org.onosproject.net.group.GroupBuckets; |
| 32 | import org.onosproject.net.group.GroupService; |
| 33 | import org.onosproject.net.link.LinkService; |
| 34 | |
| 35 | /** |
| 36 | * Default ECMP group handler creation module for an edge device. |
| 37 | * This component creates a set of ECMP groups for every neighbor |
| 38 | * that this device is connected to. |
| 39 | * For example, consider a network of 4 devices: D0 (Segment ID: 100), |
| 40 | * D1 (Segment ID: 101), D2 (Segment ID: 102) and D3 (Segment ID: 103), |
| 41 | * where D0 and D3 are edge devices and D1 and D2 are transit devices. |
| 42 | * Assume device D0 is connected to 2 neighbors (D1 and D2 ). |
| 43 | * The following groups will be created in D0: |
| 44 | * 1) all ports to D1 + with no label push, |
| 45 | * 2) all ports to D1 + with label 102 pushed, |
| 46 | * 3) all ports to D1 + with label 103 pushed, |
| 47 | * 4) all ports to D2 + with no label push, |
| 48 | * 5) all ports to D2 + with label 101 pushed, |
| 49 | * 6) all ports to D2 + with label 103 pushed, |
| 50 | * 7) all ports to D1 and D2 + with label 103 pushed |
| 51 | */ |
| 52 | public class DefaultEdgeGroupHandler extends DefaultGroupHandler { |
| 53 | |
| 54 | protected DefaultEdgeGroupHandler(DeviceId deviceId, |
| 55 | ApplicationId appId, |
| 56 | DeviceProperties config, |
| 57 | LinkService linkService, |
| 58 | GroupService groupService) { |
| 59 | super(deviceId, appId, config, linkService, groupService); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public void createGroups() { |
| 64 | log.debug("Creating default groups " |
| 65 | + "for edge device {}", deviceId); |
| 66 | Set<DeviceId> neighbors = devicePortMap.keySet(); |
| 67 | if (neighbors == null || neighbors.isEmpty()) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | // Create all possible Neighbor sets from this router |
| 72 | Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(neighbors); |
| 73 | log.trace("createGroupsAtEdgeRouter: The size of neighbor powerset " |
| 74 | + "for sw {} is {}", deviceId, powerSet.size()); |
| 75 | Set<NeighborSet> nsSet = new HashSet<NeighborSet>(); |
| 76 | for (Set<DeviceId> combo : powerSet) { |
| 77 | if (combo.isEmpty()) { |
| 78 | continue; |
| 79 | } |
| 80 | List<Integer> groupSegmentIds = |
| 81 | getSegmentIdsTobePairedWithNeighborSet(combo); |
| 82 | for (Integer sId : groupSegmentIds) { |
| 83 | NeighborSet ns = new NeighborSet(combo, sId); |
| 84 | log.trace("createGroupsAtEdgeRouter: sw {} " |
| 85 | + "combo {} sId {} ns {}", |
| 86 | deviceId, combo, sId, ns); |
| 87 | nsSet.add(ns); |
| 88 | } |
| 89 | } |
| 90 | log.trace("createGroupsAtEdgeRouter: The neighborset " |
| 91 | + "with label for sw {} is {}", |
| 92 | deviceId, nsSet); |
| 93 | |
| 94 | createGroupsFromNeighborsets(nsSet); |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | protected void newNeighbor(Link newNeighborLink) { |
| 99 | log.debug("New Neighbor: Updating groups " |
| 100 | + "for edge device {}", deviceId); |
| 101 | // Recompute neighbor power set |
| 102 | addNeighborAtPort(newNeighborLink.dst().deviceId(), |
| 103 | newNeighborLink.src().port()); |
| 104 | // Compute new neighbor sets due to the addition of new neighbor |
| 105 | Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent( |
| 106 | newNeighborLink.dst().deviceId(), |
| 107 | devicePortMap.keySet()); |
| 108 | createGroupsFromNeighborsets(nsSet); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | protected void newPortToExistingNeighbor(Link newNeighborLink) { |
| 113 | log.debug("New port to existing neighbor: Updating " |
| 114 | + "groups for edge device {}", deviceId); |
| 115 | addNeighborAtPort(newNeighborLink.dst().deviceId(), |
| 116 | newNeighborLink.src().port()); |
| 117 | Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent( |
| 118 | newNeighborLink.dst().deviceId(), |
| 119 | devicePortMap.keySet()); |
| 120 | for (NeighborSet ns : nsSet) { |
| 121 | // Create the new bucket to be updated |
| 122 | TrafficTreatment.Builder tBuilder = |
| 123 | DefaultTrafficTreatment.builder(); |
| 124 | tBuilder.setOutput(newNeighborLink.src().port()) |
| 125 | .setEthDst(deviceConfig.getDeviceMac( |
| 126 | newNeighborLink.dst().deviceId())) |
| 127 | .setEthSrc(nodeMacAddr) |
| 128 | .pushMpls() |
sangho | 32a5932 | 2015-02-17 12:07:41 -0800 | [diff] [blame] | 129 | .setMpls(MplsLabel.mplsLabel(ns.getEdgeLabel())); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 130 | GroupBucket updatedBucket = DefaultGroupBucket. |
| 131 | createSelectGroupBucket(tBuilder.build()); |
| 132 | GroupBuckets updatedBuckets = new GroupBuckets( |
| 133 | Arrays.asList(updatedBucket)); |
| 134 | log.debug("newPortToExistingNeighborAtEdgeRouter: " |
| 135 | + "groupService.addBucketsToGroup for neighborset{}", ns); |
| 136 | groupService.addBucketsToGroup(deviceId, ns, updatedBuckets, ns, appId); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | protected Set<NeighborSet> computeImpactedNeighborsetForPortEvent( |
| 142 | DeviceId impactedNeighbor, |
| 143 | Set<DeviceId> updatedNeighbors) { |
| 144 | Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(updatedNeighbors); |
| 145 | |
| 146 | Set<DeviceId> tmp = new HashSet<DeviceId>(); |
| 147 | tmp.addAll(updatedNeighbors); |
| 148 | tmp.remove(impactedNeighbor); |
| 149 | Set<Set<DeviceId>> tmpPowerSet = getPowerSetOfNeighbors(tmp); |
| 150 | |
| 151 | // Compute the impacted neighbor sets |
| 152 | powerSet.removeAll(tmpPowerSet); |
| 153 | |
| 154 | Set<NeighborSet> nsSet = new HashSet<NeighborSet>(); |
| 155 | for (Set<DeviceId> combo : powerSet) { |
| 156 | if (combo.isEmpty()) { |
| 157 | continue; |
| 158 | } |
| 159 | List<Integer> groupSegmentIds = |
| 160 | getSegmentIdsTobePairedWithNeighborSet(combo); |
| 161 | for (Integer sId : groupSegmentIds) { |
| 162 | NeighborSet ns = new NeighborSet(combo, sId); |
| 163 | log.trace("computeImpactedNeighborsetForPortEvent: sw {} " |
| 164 | + "combo {} sId {} ns {}", |
| 165 | deviceId, combo, sId, ns); |
| 166 | nsSet.add(ns); |
| 167 | } |
| 168 | } |
| 169 | log.trace("computeImpactedNeighborsetForPortEvent: The neighborset " |
| 170 | + "with label for sw {} is {}", |
| 171 | deviceId, nsSet); |
| 172 | return nsSet; |
| 173 | } |
| 174 | |
| 175 | } |