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