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 | |
Sho SHIMIZU | 24deb90 | 2015-05-11 18:40:48 -0700 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkArgument; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
| 21 | import java.util.ArrayList; |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 22 | import java.util.Collections; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 23 | import java.util.HashMap; |
| 24 | import java.util.Iterator; |
| 25 | import java.util.List; |
| 26 | |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame^] | 27 | import org.onlab.packet.MacAddress; |
sangho | 32a5932 | 2015-02-17 12:07:41 -0800 | [diff] [blame] | 28 | import org.onlab.packet.MplsLabel; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 29 | import org.onosproject.core.ApplicationId; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame^] | 30 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 31 | import org.onosproject.segmentrouting.config.DeviceProperties; |
Srikanth Vavilapalli | 4db76e3 | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 32 | import org.onosproject.segmentrouting.grouphandler.GroupBucketIdentifier.BucketOutputType; |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 33 | import org.onosproject.store.service.EventuallyConsistentMap; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 34 | import org.onosproject.net.DeviceId; |
| 35 | import org.onosproject.net.PortNumber; |
| 36 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 37 | import org.onosproject.net.flow.TrafficTreatment; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 38 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 39 | import org.onosproject.net.group.GroupBucket; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 40 | import org.onosproject.net.link.LinkService; |
| 41 | import org.slf4j.Logger; |
| 42 | |
| 43 | /** |
| 44 | * A module to create group chains based on the specified device |
| 45 | * ports and label stack to be applied on each port. |
| 46 | */ |
| 47 | public class PolicyGroupHandler extends DefaultGroupHandler { |
| 48 | |
| 49 | private final Logger log = getLogger(getClass()); |
Sho SHIMIZU | 8b4b9f0 | 2015-05-11 18:37:27 -0700 | [diff] [blame] | 50 | private HashMap<PolicyGroupIdentifier, PolicyGroupIdentifier> dependentGroups = new HashMap<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 51 | |
| 52 | /** |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 53 | * Policy group handler constructor. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 54 | * |
| 55 | * @param deviceId device identifier |
| 56 | * @param appId application identifier |
| 57 | * @param config interface to retrieve the device properties |
| 58 | * @param linkService link service object |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 59 | * @param flowObjService flow objective service object |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 60 | * @param nsNextObjStore NeighborSet next objective store map |
| 61 | * @param subnetNextObjStore subnet next objective store map |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 62 | */ |
| 63 | public PolicyGroupHandler(DeviceId deviceId, |
| 64 | ApplicationId appId, |
| 65 | DeviceProperties config, |
| 66 | LinkService linkService, |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 67 | FlowObjectiveService flowObjService, |
Thomas Vachuska | 6cdbdd8 | 2015-05-15 09:10:58 -0700 | [diff] [blame] | 68 | EventuallyConsistentMap<NeighborSetNextObjectiveStoreKey, |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 69 | Integer> nsNextObjStore, |
| 70 | EventuallyConsistentMap<SubnetNextObjectiveStoreKey, |
| 71 | Integer> subnetNextObjStore) { |
| 72 | super(deviceId, appId, config, linkService, flowObjService, |
| 73 | nsNextObjStore, subnetNextObjStore); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | public PolicyGroupIdentifier createPolicyGroupChain(String id, |
| 77 | List<PolicyGroupParams> params) { |
Sho SHIMIZU | 8b4b9f0 | 2015-05-11 18:37:27 -0700 | [diff] [blame] | 78 | List<GroupBucketIdentifier> bucketIds = new ArrayList<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 79 | for (PolicyGroupParams param: params) { |
| 80 | List<PortNumber> ports = param.getPorts(); |
| 81 | if (ports == null) { |
| 82 | log.warn("createPolicyGroupChain in sw {} with wrong " |
| 83 | + "input parameters", deviceId); |
| 84 | return null; |
| 85 | } |
| 86 | |
| 87 | int labelStackSize = (param.getLabelStack() != null) ? |
| 88 | param.getLabelStack().size() : 0; |
| 89 | |
| 90 | if (labelStackSize > 1) { |
| 91 | for (PortNumber sp : ports) { |
| 92 | PolicyGroupIdentifier previousGroupkey = null; |
| 93 | DeviceId neighbor = portDeviceMap.get(sp); |
| 94 | for (int idx = 0; idx < param.getLabelStack().size(); idx++) { |
Sho SHIMIZU | baddcbe | 2015-05-11 18:42:18 -0700 | [diff] [blame] | 95 | int label = param.getLabelStack().get(idx); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 96 | if (idx == (labelStackSize - 1)) { |
| 97 | // Innermost Group |
| 98 | GroupBucketIdentifier bucketId = |
| 99 | new GroupBucketIdentifier(label, |
| 100 | previousGroupkey); |
| 101 | bucketIds.add(bucketId); |
| 102 | } else if (idx == 0) { |
| 103 | // Outermost Group |
Sho SHIMIZU | 8b4b9f0 | 2015-05-11 18:37:27 -0700 | [diff] [blame] | 104 | List<GroupBucket> outBuckets = new ArrayList<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 105 | GroupBucketIdentifier bucketId = |
| 106 | new GroupBucketIdentifier(label, sp); |
| 107 | PolicyGroupIdentifier key = new |
| 108 | PolicyGroupIdentifier(id, |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 109 | Collections.singletonList(param), |
| 110 | Collections.singletonList(bucketId)); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame^] | 111 | MacAddress neighborEthDst; |
| 112 | try { |
| 113 | neighborEthDst = deviceConfig.getDeviceMac(neighbor); |
| 114 | } catch (DeviceConfigNotFoundException e) { |
| 115 | log.warn(e.getMessage() |
| 116 | + " Skipping createPolicyGroupChain for this label."); |
| 117 | continue; |
| 118 | } |
| 119 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 120 | TrafficTreatment.Builder tBuilder = |
| 121 | DefaultTrafficTreatment.builder(); |
| 122 | tBuilder.setOutput(sp) |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame^] | 123 | .setEthDst(neighborEthDst) |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 124 | .setEthSrc(nodeMacAddr) |
| 125 | .pushMpls() |
sangho | 32a5932 | 2015-02-17 12:07:41 -0800 | [diff] [blame] | 126 | .setMpls(MplsLabel.mplsLabel(label)); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 127 | /*outBuckets.add(DefaultGroupBucket. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 128 | createSelectGroupBucket(tBuilder.build())); |
| 129 | GroupDescription desc = new |
| 130 | DefaultGroupDescription(deviceId, |
| 131 | GroupDescription.Type.INDIRECT, |
| 132 | new GroupBuckets(outBuckets)); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 133 | //TODO: BoS*/ |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 134 | previousGroupkey = key; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 135 | //groupService.addGroup(desc); |
| 136 | //TODO: Use nextObjective APIs here |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 137 | } else { |
| 138 | // Intermediate Groups |
| 139 | GroupBucketIdentifier bucketId = |
| 140 | new GroupBucketIdentifier(label, |
| 141 | previousGroupkey); |
| 142 | PolicyGroupIdentifier key = new |
| 143 | PolicyGroupIdentifier(id, |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 144 | Collections.singletonList(param), |
| 145 | Collections.singletonList(bucketId)); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 146 | // Add to group dependency list |
| 147 | dependentGroups.put(previousGroupkey, key); |
| 148 | previousGroupkey = key; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } else { |
| 153 | int label = -1; |
| 154 | if (labelStackSize == 1) { |
Sho SHIMIZU | baddcbe | 2015-05-11 18:42:18 -0700 | [diff] [blame] | 155 | label = param.getLabelStack().get(0); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 156 | } |
| 157 | for (PortNumber sp : ports) { |
| 158 | GroupBucketIdentifier bucketId = |
| 159 | new GroupBucketIdentifier(label, sp); |
| 160 | bucketIds.add(bucketId); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | PolicyGroupIdentifier innermostGroupkey = null; |
| 165 | if (!bucketIds.isEmpty()) { |
| 166 | innermostGroupkey = new |
| 167 | PolicyGroupIdentifier(id, |
| 168 | params, |
| 169 | bucketIds); |
| 170 | // Add to group dependency list |
| 171 | boolean fullyResolved = true; |
| 172 | for (GroupBucketIdentifier bucketId:bucketIds) { |
| 173 | if (bucketId.type() == BucketOutputType.GROUP) { |
| 174 | dependentGroups.put(bucketId.outGroup(), |
| 175 | innermostGroupkey); |
| 176 | fullyResolved = false; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | if (fullyResolved) { |
Sho SHIMIZU | 8b4b9f0 | 2015-05-11 18:37:27 -0700 | [diff] [blame] | 181 | List<GroupBucket> outBuckets = new ArrayList<>(); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame^] | 182 | for (GroupBucketIdentifier bucketId : bucketIds) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 183 | DeviceId neighbor = portDeviceMap. |
| 184 | get(bucketId.outPort()); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame^] | 185 | |
| 186 | MacAddress neighborEthDst; |
| 187 | try { |
| 188 | neighborEthDst = deviceConfig.getDeviceMac(neighbor); |
| 189 | } catch (DeviceConfigNotFoundException e) { |
| 190 | log.warn(e.getMessage() |
| 191 | + " Skipping createPolicyGroupChain for this bucketId."); |
| 192 | continue; |
| 193 | } |
| 194 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 195 | TrafficTreatment.Builder tBuilder = |
| 196 | DefaultTrafficTreatment.builder(); |
| 197 | tBuilder.setOutput(bucketId.outPort()) |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame^] | 198 | .setEthDst(neighborEthDst) |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 199 | .setEthSrc(nodeMacAddr); |
| 200 | if (bucketId.label() != NeighborSet.NO_EDGE_LABEL) { |
| 201 | tBuilder.pushMpls() |
sangho | 32a5932 | 2015-02-17 12:07:41 -0800 | [diff] [blame] | 202 | .setMpls(MplsLabel.mplsLabel(bucketId.label())); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 203 | } |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 204 | //TODO: BoS |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 205 | /*outBuckets.add(DefaultGroupBucket. |
| 206 | createSelectGroupBucket(tBuilder.build()));*/ |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 207 | } |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 208 | /*GroupDescription desc = new |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 209 | DefaultGroupDescription(deviceId, |
| 210 | GroupDescription.Type.SELECT, |
| 211 | new GroupBuckets(outBuckets)); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 212 | groupService.addGroup(desc);*/ |
| 213 | //TODO: Use nextObjective APIs here |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | return innermostGroupkey; |
| 217 | } |
| 218 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 219 | //TODO: Use nextObjective APIs to handle the group chains |
| 220 | /*@Override |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 221 | protected void handleGroupEvent(GroupEvent event) { |
| 222 | if (event.type() == GroupEvent.Type.GROUP_ADDED) { |
| 223 | if (dependentGroups.get(event.subject().appCookie()) != null) { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 224 | PolicyGroupIdentifier dependentGroupKey = dependentGroups.get(event.subject().appCookie()); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 225 | dependentGroups.remove(event.subject().appCookie()); |
| 226 | boolean fullyResolved = true; |
| 227 | for (GroupBucketIdentifier bucketId: |
| 228 | dependentGroupKey.bucketIds()) { |
| 229 | if (bucketId.type() != BucketOutputType.GROUP) { |
| 230 | continue; |
| 231 | } |
| 232 | if (dependentGroups.containsKey(bucketId.outGroup())) { |
| 233 | fullyResolved = false; |
| 234 | break; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | if (fullyResolved) { |
| 239 | List<GroupBucket> outBuckets = new ArrayList<GroupBucket>(); |
| 240 | for (GroupBucketIdentifier bucketId: |
| 241 | dependentGroupKey.bucketIds()) { |
| 242 | TrafficTreatment.Builder tBuilder = |
| 243 | DefaultTrafficTreatment.builder(); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 244 | if (bucketId.label() != NeighborSet.NO_EDGE_LABEL) { |
| 245 | tBuilder.pushMpls() |
| 246 | .setMpls(MplsLabel. |
| 247 | mplsLabel(bucketId.label())); |
| 248 | } |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 249 | //TODO: BoS |
| 250 | if (bucketId.type() == BucketOutputType.PORT) { |
| 251 | DeviceId neighbor = portDeviceMap. |
| 252 | get(bucketId.outPort()); |
| 253 | tBuilder.setOutput(bucketId.outPort()) |
| 254 | .setEthDst(deviceConfig. |
| 255 | getDeviceMac(neighbor)) |
| 256 | .setEthSrc(nodeMacAddr); |
| 257 | } else { |
| 258 | if (groupService. |
| 259 | getGroup(deviceId, |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 260 | getGroupKey(bucketId. |
| 261 | outGroup())) == null) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 262 | throw new IllegalStateException(); |
| 263 | } |
| 264 | GroupId indirectGroupId = groupService. |
| 265 | getGroup(deviceId, |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 266 | getGroupKey(bucketId. |
| 267 | outGroup())).id(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 268 | tBuilder.group(indirectGroupId); |
| 269 | } |
| 270 | outBuckets.add(DefaultGroupBucket. |
| 271 | createSelectGroupBucket(tBuilder.build())); |
| 272 | } |
| 273 | GroupDescription desc = new |
| 274 | DefaultGroupDescription(deviceId, |
| 275 | GroupDescription.Type.SELECT, |
| 276 | new GroupBuckets(outBuckets)); |
| 277 | groupService.addGroup(desc); |
| 278 | } |
| 279 | } |
| 280 | } |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 281 | }*/ |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 282 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 283 | public PolicyGroupIdentifier generatePolicyGroupKey(String id, |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 284 | List<PolicyGroupParams> params) { |
Sho SHIMIZU | 8b4b9f0 | 2015-05-11 18:37:27 -0700 | [diff] [blame] | 285 | List<GroupBucketIdentifier> bucketIds = new ArrayList<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 286 | for (PolicyGroupParams param: params) { |
| 287 | List<PortNumber> ports = param.getPorts(); |
| 288 | if (ports == null) { |
| 289 | log.warn("generateGroupKey in sw {} with wrong " |
| 290 | + "input parameters", deviceId); |
| 291 | return null; |
| 292 | } |
| 293 | |
| 294 | int labelStackSize = (param.getLabelStack() != null) |
| 295 | ? param.getLabelStack().size() : 0; |
| 296 | |
| 297 | if (labelStackSize > 1) { |
| 298 | for (PortNumber sp : ports) { |
| 299 | PolicyGroupIdentifier previousGroupkey = null; |
| 300 | for (int idx = 0; idx < param.getLabelStack().size(); idx++) { |
Sho SHIMIZU | baddcbe | 2015-05-11 18:42:18 -0700 | [diff] [blame] | 301 | int label = param.getLabelStack().get(idx); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 302 | if (idx == (labelStackSize - 1)) { |
| 303 | // Innermost Group |
| 304 | GroupBucketIdentifier bucketId = |
| 305 | new GroupBucketIdentifier(label, |
| 306 | previousGroupkey); |
| 307 | bucketIds.add(bucketId); |
| 308 | } else if (idx == 0) { |
| 309 | // Outermost Group |
| 310 | GroupBucketIdentifier bucketId = |
| 311 | new GroupBucketIdentifier(label, sp); |
| 312 | PolicyGroupIdentifier key = new |
| 313 | PolicyGroupIdentifier(id, |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 314 | Collections.singletonList(param), |
| 315 | Collections.singletonList(bucketId)); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 316 | previousGroupkey = key; |
| 317 | } else { |
| 318 | // Intermediate Groups |
| 319 | GroupBucketIdentifier bucketId = |
| 320 | new GroupBucketIdentifier(label, |
| 321 | previousGroupkey); |
| 322 | PolicyGroupIdentifier key = new |
| 323 | PolicyGroupIdentifier(id, |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 324 | Collections.singletonList(param), |
| 325 | Collections.singletonList(bucketId)); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 326 | previousGroupkey = key; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | } else { |
| 331 | int label = -1; |
| 332 | if (labelStackSize == 1) { |
Sho SHIMIZU | baddcbe | 2015-05-11 18:42:18 -0700 | [diff] [blame] | 333 | label = param.getLabelStack().get(0); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 334 | } |
| 335 | for (PortNumber sp : ports) { |
| 336 | GroupBucketIdentifier bucketId = |
| 337 | new GroupBucketIdentifier(label, sp); |
| 338 | bucketIds.add(bucketId); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | PolicyGroupIdentifier innermostGroupkey = null; |
| 343 | if (!bucketIds.isEmpty()) { |
| 344 | innermostGroupkey = new |
| 345 | PolicyGroupIdentifier(id, |
| 346 | params, |
| 347 | bucketIds); |
| 348 | } |
| 349 | return innermostGroupkey; |
| 350 | } |
| 351 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 352 | public void removeGroupChain(PolicyGroupIdentifier key) { |
Sho SHIMIZU | 24deb90 | 2015-05-11 18:40:48 -0700 | [diff] [blame] | 353 | checkArgument(key != null); |
Sho SHIMIZU | 8b4b9f0 | 2015-05-11 18:37:27 -0700 | [diff] [blame] | 354 | List<PolicyGroupIdentifier> groupsToBeDeleted = new ArrayList<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 355 | groupsToBeDeleted.add(key); |
| 356 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 357 | Iterator<PolicyGroupIdentifier> it = |
| 358 | groupsToBeDeleted.iterator(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 359 | |
| 360 | while (it.hasNext()) { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 361 | PolicyGroupIdentifier innerMostGroupKey = it.next(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 362 | for (GroupBucketIdentifier bucketId: |
| 363 | innerMostGroupKey.bucketIds()) { |
| 364 | if (bucketId.type() != BucketOutputType.GROUP) { |
| 365 | groupsToBeDeleted.add(bucketId.outGroup()); |
| 366 | } |
| 367 | } |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 368 | /*groupService.removeGroup(deviceId, |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 369 | getGroupKey(innerMostGroupKey), |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 370 | appId);*/ |
| 371 | //TODO: Use nextObjective APIs here |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 372 | it.remove(); |
| 373 | } |
| 374 | } |
| 375 | |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 376 | } |