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