sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.provider.of.group.impl; |
| 18 | |
jiangrui | a6b4609 | 2015-11-11 16:28:51 +0800 | [diff] [blame] | 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
| 21 | import java.util.Collection; |
| 22 | import java.util.Map; |
| 23 | import java.util.Optional; |
| 24 | import java.util.concurrent.atomic.AtomicLong; |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 25 | |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 26 | import org.apache.felix.scr.annotations.Activate; |
| 27 | import org.apache.felix.scr.annotations.Component; |
| 28 | import org.apache.felix.scr.annotations.Deactivate; |
| 29 | import org.apache.felix.scr.annotations.Reference; |
| 30 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 31 | import org.onosproject.core.DefaultGroupId; |
| 32 | import org.onosproject.core.GroupId; |
| 33 | import org.onosproject.net.DeviceId; |
jiangrui | a6b4609 | 2015-11-11 16:28:51 +0800 | [diff] [blame] | 34 | import org.onosproject.net.driver.DriverService; |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 35 | import org.onosproject.net.group.DefaultGroup; |
| 36 | import org.onosproject.net.group.Group; |
| 37 | import org.onosproject.net.group.GroupBuckets; |
| 38 | import org.onosproject.net.group.GroupDescription; |
| 39 | import org.onosproject.net.group.GroupOperation; |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame] | 40 | import org.onosproject.net.group.GroupOperation.GroupMsgErrorCode; |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 41 | import org.onosproject.net.group.GroupOperations; |
| 42 | import org.onosproject.net.group.GroupProvider; |
| 43 | import org.onosproject.net.group.GroupProviderRegistry; |
| 44 | import org.onosproject.net.group.GroupProviderService; |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 45 | import org.onosproject.net.group.StoredGroupBucketEntry; |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 46 | import org.onosproject.net.provider.AbstractProvider; |
| 47 | import org.onosproject.net.provider.ProviderId; |
| 48 | import org.onosproject.openflow.controller.Dpid; |
| 49 | import org.onosproject.openflow.controller.OpenFlowController; |
| 50 | import org.onosproject.openflow.controller.OpenFlowEventListener; |
| 51 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
| 52 | import org.onosproject.openflow.controller.OpenFlowSwitchListener; |
| 53 | import org.onosproject.openflow.controller.RoleState; |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 54 | import org.projectfloodlight.openflow.protocol.OFBucketCounter; |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 55 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 56 | import org.projectfloodlight.openflow.protocol.OFErrorType; |
| 57 | import org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry; |
| 58 | import org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply; |
| 59 | import org.projectfloodlight.openflow.protocol.OFGroupMod; |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame] | 60 | import org.projectfloodlight.openflow.protocol.OFGroupModFailedCode; |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 61 | import org.projectfloodlight.openflow.protocol.OFGroupStatsEntry; |
| 62 | import org.projectfloodlight.openflow.protocol.OFGroupStatsReply; |
| 63 | import org.projectfloodlight.openflow.protocol.OFGroupType; |
| 64 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 65 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
| 66 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
| 67 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
sangho | 01a883c | 2015-02-23 11:01:50 -0800 | [diff] [blame] | 68 | import org.projectfloodlight.openflow.protocol.OFVersion; |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame] | 69 | import org.projectfloodlight.openflow.protocol.errormsg.OFGroupModFailedErrorMsg; |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 70 | import org.slf4j.Logger; |
| 71 | |
jiangrui | a6b4609 | 2015-11-11 16:28:51 +0800 | [diff] [blame] | 72 | import com.google.common.collect.Maps; |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Provider which uses an OpenFlow controller to handle Group. |
| 76 | */ |
| 77 | @Component(immediate = true) |
| 78 | public class OpenFlowGroupProvider extends AbstractProvider implements GroupProvider { |
| 79 | |
| 80 | private final Logger log = getLogger(getClass()); |
| 81 | |
| 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 83 | protected OpenFlowController controller; |
| 84 | |
| 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 86 | protected GroupProviderRegistry providerRegistry; |
| 87 | |
jiangrui | a6b4609 | 2015-11-11 16:28:51 +0800 | [diff] [blame] | 88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 89 | protected DriverService driverService; |
| 90 | |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 91 | private GroupProviderService providerService; |
| 92 | |
| 93 | static final int POLL_INTERVAL = 10; |
| 94 | |
| 95 | private final InternalGroupProvider listener = new InternalGroupProvider(); |
| 96 | |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 97 | private static final AtomicLong XID_COUNTER = new AtomicLong(1); |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 98 | private final Map<Dpid, GroupStatsCollector> collectors = Maps.newHashMap(); |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 99 | private final Map<Long, OFStatsReply> groupStats = Maps.newConcurrentMap(); |
sangho | 22a805d | 2015-02-13 09:45:43 -0800 | [diff] [blame] | 100 | private final Map<GroupId, GroupOperation> pendingGroupOperations = |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 101 | Maps.newConcurrentMap(); |
| 102 | |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 103 | /* Map<Group ID, Transaction ID> */ |
sangho | 22a805d | 2015-02-13 09:45:43 -0800 | [diff] [blame] | 104 | private final Map<GroupId, Long> pendingXidMaps = Maps.newConcurrentMap(); |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 105 | |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 106 | /** |
| 107 | * Creates a OpenFlow group provider. |
| 108 | */ |
| 109 | public OpenFlowGroupProvider() { |
| 110 | super(new ProviderId("of", "org.onosproject.provider.group")); |
| 111 | } |
| 112 | |
| 113 | @Activate |
| 114 | public void activate() { |
| 115 | providerService = providerRegistry.register(this); |
| 116 | controller.addListener(listener); |
| 117 | controller.addEventListener(listener); |
| 118 | |
| 119 | for (OpenFlowSwitch sw : controller.getSwitches()) { |
sangho | 01a883c | 2015-02-23 11:01:50 -0800 | [diff] [blame] | 120 | if (isGroupSupported(sw)) { |
| 121 | GroupStatsCollector gsc = new GroupStatsCollector(sw, POLL_INTERVAL); |
| 122 | gsc.start(); |
| 123 | collectors.put(new Dpid(sw.getId()), gsc); |
| 124 | } |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | log.info("Started"); |
| 128 | } |
| 129 | |
| 130 | @Deactivate |
| 131 | public void deactivate() { |
| 132 | providerRegistry.unregister(this); |
| 133 | providerService = null; |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 134 | collectors.values().forEach(GroupStatsCollector::stop); |
| 135 | collectors.clear(); |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 136 | log.info("Stopped"); |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) { |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 141 | final Dpid dpid = Dpid.dpid(deviceId.uri()); |
| 142 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 143 | for (GroupOperation groupOperation: groupOps.operations()) { |
| 144 | if (sw == null) { |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 145 | log.error("SW {} is not found", dpid); |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 146 | return; |
| 147 | } |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 148 | final Long groupModXid = XID_COUNTER.getAndIncrement(); |
jiangrui | a6b4609 | 2015-11-11 16:28:51 +0800 | [diff] [blame] | 149 | GroupModBuilder builder = null; |
| 150 | if (driverService == null) { |
| 151 | builder = GroupModBuilder.builder(groupOperation.buckets(), |
| 152 | groupOperation.groupId(), |
| 153 | groupOperation.groupType(), |
| 154 | sw.factory(), |
| 155 | Optional.of(groupModXid)); |
| 156 | } else { |
| 157 | builder = GroupModBuilder.builder(groupOperation.buckets(), |
| 158 | groupOperation.groupId(), |
| 159 | groupOperation.groupType(), |
| 160 | sw.factory(), |
| 161 | Optional.of(groupModXid), |
| 162 | Optional.of(driverService)); |
| 163 | } |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 164 | OFGroupMod groupMod = null; |
| 165 | switch (groupOperation.opType()) { |
| 166 | case ADD: |
| 167 | groupMod = builder.buildGroupAdd(); |
| 168 | break; |
| 169 | case MODIFY: |
| 170 | groupMod = builder.buildGroupMod(); |
| 171 | break; |
| 172 | case DELETE: |
| 173 | groupMod = builder.buildGroupDel(); |
| 174 | break; |
| 175 | default: |
| 176 | log.error("Unsupported Group operation"); |
Satish K | e6d91c5 | 2015-11-21 19:04:20 +0530 | [diff] [blame] | 177 | return; |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 178 | } |
| 179 | sw.sendMsg(groupMod); |
sangho | 22a805d | 2015-02-13 09:45:43 -0800 | [diff] [blame] | 180 | GroupId groudId = new DefaultGroupId(groupMod.getGroup().getGroupNumber()); |
| 181 | pendingGroupOperations.put(groudId, groupOperation); |
| 182 | pendingXidMaps.put(groudId, groupModXid); |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
| 186 | private void pushGroupMetrics(Dpid dpid, OFStatsReply statsReply) { |
| 187 | DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); |
| 188 | |
| 189 | OFGroupStatsReply groupStatsReply = null; |
| 190 | OFGroupDescStatsReply groupDescStatsReply = null; |
| 191 | |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 192 | synchronized (groupStats) { |
| 193 | if (statsReply.getStatsType() == OFStatsType.GROUP) { |
| 194 | OFStatsReply reply = groupStats.get(statsReply.getXid() + 1); |
| 195 | if (reply != null) { |
| 196 | groupStatsReply = (OFGroupStatsReply) statsReply; |
| 197 | groupDescStatsReply = (OFGroupDescStatsReply) reply; |
| 198 | groupStats.remove(statsReply.getXid() + 1); |
| 199 | } else { |
| 200 | groupStats.put(statsReply.getXid(), statsReply); |
| 201 | } |
| 202 | } else if (statsReply.getStatsType() == OFStatsType.GROUP_DESC) { |
| 203 | OFStatsReply reply = groupStats.get(statsReply.getXid() - 1); |
| 204 | if (reply != null) { |
| 205 | groupStatsReply = (OFGroupStatsReply) reply; |
| 206 | groupDescStatsReply = (OFGroupDescStatsReply) statsReply; |
| 207 | groupStats.remove(statsReply.getXid() - 1); |
| 208 | } else { |
| 209 | groupStats.put(statsReply.getXid(), statsReply); |
| 210 | } |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
Ray Milkey | 0ae473d | 2016-04-04 10:56:47 -0700 | [diff] [blame] | 214 | if (providerService != null && groupStatsReply != null) { |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 215 | Collection<Group> groups = buildGroupMetrics(deviceId, |
| 216 | groupStatsReply, groupDescStatsReply); |
| 217 | providerService.pushGroupMetrics(deviceId, groups); |
| 218 | for (Group group: groups) { |
| 219 | pendingGroupOperations.remove(group.id()); |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 220 | pendingXidMaps.remove(group.id()); |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | private Collection<Group> buildGroupMetrics(DeviceId deviceId, |
| 226 | OFGroupStatsReply groupStatsReply, |
| 227 | OFGroupDescStatsReply groupDescStatsReply) { |
| 228 | |
| 229 | Map<Integer, Group> groups = Maps.newHashMap(); |
Hyunsun Moon | a834c18 | 2015-12-16 03:01:56 -0800 | [diff] [blame] | 230 | Dpid dpid = Dpid.dpid(deviceId.uri()); |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 231 | |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 232 | for (OFGroupDescStatsEntry entry: groupDescStatsReply.getEntries()) { |
| 233 | int id = entry.getGroup().getGroupNumber(); |
| 234 | GroupId groupId = new DefaultGroupId(id); |
| 235 | GroupDescription.Type type = getGroupType(entry.getGroupType()); |
Hyunsun Moon | a834c18 | 2015-12-16 03:01:56 -0800 | [diff] [blame] | 236 | GroupBuckets buckets = new GroupBucketEntryBuilder(dpid, entry.getBuckets(), |
| 237 | entry.getGroupType(), driverService).build(); |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 238 | DefaultGroup group = new DefaultGroup(groupId, deviceId, type, buckets); |
| 239 | groups.put(id, group); |
| 240 | } |
| 241 | |
| 242 | for (OFGroupStatsEntry entry: groupStatsReply.getEntries()) { |
| 243 | int groupId = entry.getGroup().getGroupNumber(); |
| 244 | DefaultGroup group = (DefaultGroup) groups.get(groupId); |
| 245 | if (group != null) { |
| 246 | group.setBytes(entry.getByteCount().getValue()); |
| 247 | group.setLife(entry.getDurationSec()); |
| 248 | group.setPackets(entry.getPacketCount().getValue()); |
| 249 | group.setReferenceCount(entry.getRefCount()); |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 250 | int bucketIndex = 0; |
| 251 | for (OFBucketCounter bucketStats:entry.getBucketStats()) { |
| 252 | ((StoredGroupBucketEntry) group.buckets().buckets() |
| 253 | .get(bucketIndex)) |
| 254 | .setPackets(bucketStats |
| 255 | .getPacketCount().getValue()); |
| 256 | ((StoredGroupBucketEntry) group.buckets().buckets() |
| 257 | .get(bucketIndex)) |
| 258 | .setBytes(entry.getBucketStats() |
| 259 | .get(bucketIndex) |
| 260 | .getByteCount().getValue()); |
| 261 | bucketIndex++; |
| 262 | } |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
| 266 | return groups.values(); |
| 267 | } |
| 268 | |
| 269 | private GroupDescription.Type getGroupType(OFGroupType type) { |
| 270 | switch (type) { |
| 271 | case ALL: |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 272 | return GroupDescription.Type.ALL; |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 273 | case INDIRECT: |
| 274 | return GroupDescription.Type.INDIRECT; |
| 275 | case SELECT: |
| 276 | return GroupDescription.Type.SELECT; |
| 277 | case FF: |
| 278 | return GroupDescription.Type.FAILOVER; |
| 279 | default: |
| 280 | log.error("Unsupported OF group type : {}", type); |
| 281 | break; |
| 282 | } |
| 283 | return null; |
| 284 | } |
| 285 | |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 286 | /** |
| 287 | * Returns a transaction ID for entire group operations and increases |
| 288 | * the counter by the number given. |
| 289 | * |
| 290 | * @param increase the amount to increase the counter by |
| 291 | * @return a transaction ID |
| 292 | */ |
| 293 | public static long getXidAndAdd(int increase) { |
| 294 | return XID_COUNTER.getAndAdd(increase); |
| 295 | } |
| 296 | |
sangho | 01a883c | 2015-02-23 11:01:50 -0800 | [diff] [blame] | 297 | private boolean isGroupSupported(OpenFlowSwitch sw) { |
| 298 | if (sw.factory().getVersion() == OFVersion.OF_10 || |
| 299 | sw.factory().getVersion() == OFVersion.OF_11 || |
| 300 | sw.factory().getVersion() == OFVersion.OF_12) { |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | return true; |
| 305 | } |
| 306 | |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 307 | private class InternalGroupProvider |
| 308 | implements OpenFlowSwitchListener, OpenFlowEventListener { |
| 309 | |
| 310 | @Override |
| 311 | public void handleMessage(Dpid dpid, OFMessage msg) { |
| 312 | switch (msg.getType()) { |
| 313 | case STATS_REPLY: |
| 314 | pushGroupMetrics(dpid, (OFStatsReply) msg); |
| 315 | break; |
| 316 | case ERROR: |
| 317 | OFErrorMsg errorMsg = (OFErrorMsg) msg; |
| 318 | if (errorMsg.getErrType() == OFErrorType.GROUP_MOD_FAILED) { |
sangho | 22a805d | 2015-02-13 09:45:43 -0800 | [diff] [blame] | 319 | GroupId pendingGroupId = null; |
| 320 | for (Map.Entry<GroupId, Long> entry: pendingXidMaps.entrySet()) { |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 321 | if (entry.getValue() == errorMsg.getXid()) { |
| 322 | pendingGroupId = entry.getKey(); |
| 323 | break; |
| 324 | } |
| 325 | } |
sangho | 22a805d | 2015-02-13 09:45:43 -0800 | [diff] [blame] | 326 | if (pendingGroupId == null) { |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 327 | log.warn("Error for unknown group operation: {}", |
| 328 | errorMsg.getXid()); |
| 329 | } else { |
| 330 | GroupOperation operation = |
| 331 | pendingGroupOperations.get(pendingGroupId); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 332 | DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 333 | if (operation != null) { |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame] | 334 | OFGroupModFailedCode code = |
| 335 | ((OFGroupModFailedErrorMsg) errorMsg).getCode(); |
| 336 | GroupMsgErrorCode failureCode = |
| 337 | GroupMsgErrorCode.values()[(code.ordinal())]; |
| 338 | GroupOperation failedOperation = GroupOperation |
| 339 | .createFailedGroupOperation(operation, failureCode); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 340 | log.warn("Received a group mod error {}", msg); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 341 | providerService.groupOperationFailed(deviceId, |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame] | 342 | failedOperation); |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 343 | pendingGroupOperations.remove(pendingGroupId); |
| 344 | pendingXidMaps.remove(pendingGroupId); |
sangho | a09f274 | 2015-02-06 14:49:47 -0800 | [diff] [blame] | 345 | } else { |
| 346 | log.error("Cannot find pending group operation with group ID: {}", |
| 347 | pendingGroupId); |
| 348 | } |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 349 | } |
| 350 | break; |
| 351 | } |
| 352 | default: |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 353 | break; |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
| 357 | @Override |
| 358 | public void switchAdded(Dpid dpid) { |
sangho | 01a883c | 2015-02-23 11:01:50 -0800 | [diff] [blame] | 359 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 360 | if (sw == null) { |
| 361 | return; |
| 362 | } |
sangho | 01a883c | 2015-02-23 11:01:50 -0800 | [diff] [blame] | 363 | if (isGroupSupported(sw)) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 364 | GroupStatsCollector gsc = new GroupStatsCollector(sw, POLL_INTERVAL); |
sangho | 01a883c | 2015-02-23 11:01:50 -0800 | [diff] [blame] | 365 | gsc.start(); |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame^] | 366 | stopCollectorIfNeeded(collectors.put(dpid, gsc)); |
sangho | 01a883c | 2015-02-23 11:01:50 -0800 | [diff] [blame] | 367 | } |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 368 | |
| 369 | //figure out race condition |
| 370 | if (controller.getSwitch(dpid) == null) { |
| 371 | switchRemoved(dpid); |
| 372 | } |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public void switchRemoved(Dpid dpid) { |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame^] | 377 | stopCollectorIfNeeded(collectors.remove(dpid)); |
| 378 | } |
| 379 | |
| 380 | private void stopCollectorIfNeeded(GroupStatsCollector collector) { |
sangho | 5afd02a | 2015-02-03 20:07:35 -0800 | [diff] [blame] | 381 | if (collector != null) { |
| 382 | collector.stop(); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | @Override |
| 387 | public void switchChanged(Dpid dpid) { |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public void portChanged(Dpid dpid, OFPortStatus status) { |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public void receivedRoleReply(Dpid dpid, RoleState requested, RoleState response) { |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | } |