@Test public void groupModFailure() { TestOpenFlowGroupProviderService testProviderService = (TestOpenFlowGroupProviderService) providerService; GroupId groupId = new DefaultGroupId(1); List<GroupBucket> bucketList = Lists.newArrayList(); TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); builder.setOutput(PortNumber.portNumber(1)); GroupBucket bucket = DefaultGroupBucket.createSelectGroupBucket(builder.build()); bucketList.add(bucket); GroupBuckets buckets = new GroupBuckets(bucketList); List<GroupOperation> operationList = Lists.newArrayList(); GroupOperation operation = GroupOperation.createAddGroupOperation(groupId, GroupDescription.Type.SELECT, buckets); operationList.add(operation); GroupOperations operations = new GroupOperations(operationList); provider.performGroupOperation(deviceId, operations); OFGroupModFailedErrorMsg.Builder errorBuilder = OFFactories.getFactory(OFVersion.OF_13).errorMsgs().buildGroupModFailedErrorMsg(); OFGroupMod.Builder groupBuilder = OFFactories.getFactory(OFVersion.OF_13).buildGroupModify(); groupBuilder.setGroupType(OFGroupType.ALL); groupBuilder.setGroup(OFGroup.of(1)); errorBuilder.setCode(OFGroupModFailedCode.GROUP_EXISTS); errorBuilder.setXid(provider.getXidAndAdd(0) - 1); controller.processPacket(dpid1, errorBuilder.build()); assertNotNull("Operation failed should not be null", testProviderService.failedOperation); }
@Test public void groupModFailure() { TestOpenFlowGroupProviderService testProviderService = (TestOpenFlowGroupProviderService) providerService; GroupId groupId = new GroupId(1); List<GroupBucket> bucketList = Lists.newArrayList(); TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); builder.setOutput(PortNumber.portNumber(1)); GroupBucket bucket = DefaultGroupBucket.createSelectGroupBucket(builder.build()); bucketList.add(bucket); GroupBuckets buckets = new GroupBuckets(bucketList); List<GroupOperation> operationList = Lists.newArrayList(); GroupOperation operation = GroupOperation.createAddGroupOperation(groupId, GroupDescription.Type.SELECT, buckets); operationList.add(operation); GroupOperations operations = new GroupOperations(operationList); provider.performGroupOperation(deviceId, operations); OFGroupModFailedErrorMsg.Builder errorBuilder = OFFactories.getFactory(OFVersion.OF_13).errorMsgs().buildGroupModFailedErrorMsg(); OFGroupMod.Builder groupBuilder = OFFactories.getFactory(OFVersion.OF_13).buildGroupModify(); groupBuilder.setGroupType(OFGroupType.ALL); groupBuilder.setGroup(OFGroup.of(1)); errorBuilder.setCode(OFGroupModFailedCode.GROUP_EXISTS); errorBuilder.setXid(provider.getXidAndAdd(0) - 1); controller.processPacket(dpid1, errorBuilder.build()); assertNotNull("Operation failed should not be null", testProviderService.failedOperation); }
@Override public void handleMessage(Dpid dpid, OFMessage msg) { switch (msg.getType()) { case STATS_REPLY: pushGroupMetrics(dpid, (OFStatsReply) msg); break; case ERROR: OFErrorMsg errorMsg = (OFErrorMsg) msg; if (errorMsg.getErrType() == OFErrorType.GROUP_MOD_FAILED) { GroupId pendingGroupId = null; for (Map.Entry<GroupId, Long> entry: pendingXidMaps.entrySet()) { if (entry.getValue() == errorMsg.getXid()) { pendingGroupId = entry.getKey(); break; } } if (pendingGroupId == null) { log.warn("Error for unknown group operation: {}", errorMsg.getXid()); } else { GroupOperation operation = pendingGroupOperations.get(pendingGroupId); DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); if (operation != null) { OFGroupModFailedCode code = ((OFGroupModFailedErrorMsg) errorMsg).getCode(); GroupMsgErrorCode failureCode = GroupMsgErrorCode.values()[(code.ordinal())]; GroupOperation failedOperation = GroupOperation .createFailedGroupOperation(operation, failureCode); log.warn("Received a group mod error {}", msg); providerService.groupOperationFailed(deviceId, failedOperation); pendingGroupOperations.remove(pendingGroupId); pendingXidMaps.remove(pendingGroupId); } else { log.error("Cannot find pending group operation with group ID: {}", pendingGroupId); } } break; } default: break; } }