/** * Builds the GroupMod OF message. * * @return GroupMod OF message */ public OFGroupMod buildGroupMod() { List<OFBucket> ofBuckets = new ArrayList<OFBucket>(); for (GroupBucket bucket: buckets.buckets()) { List<OFAction> actions = buildActions(bucket.treatment()); OFBucket.Builder bucketBuilder = factory.buildBucket(); bucketBuilder.setActions(actions); if (type == GroupDescription.Type.SELECT) { bucketBuilder.setWeight(1); } bucketBuilder.setWatchGroup(OFGroup.ANY); bucketBuilder.setWatchPort(OFPort.ANY); OFBucket ofBucket = bucketBuilder.build(); ofBuckets.add(ofBucket); } OFGroupMod groupMsg = factory.buildGroupModify() .setGroup(OFGroup.of(groupId.id())) .setBuckets(ofBuckets) .setGroupType(getOFGroupType(type)) .setXid(xid) .build(); return groupMsg; }
@Override public void startDriverHandshake() { if (startDriverHandshakeCalled) { throw new SwitchDriverSubHandshakeAlreadyStarted(); } startDriverHandshakeCalled = true; OFFlowMod fm = factory().buildFlowDelete() .setTableId(TableId.ALL) .setOutGroup(OFGroup.ANY) .build(); sendMsg(ImmutableList.of(fm)); OFGroupMod gm = factory().buildGroupDelete() .setGroup(OFGroup.ALL) .setGroupType(OFGroupType.ALL) .build(); sendMsg(ImmutableList.of(gm)); handshakeComplete.set(true); log.info("Handshake with device {} ended", super.getStringId()); }
@Override public void startDriverHandshake() { if (startDriverHandshakeCalled) { throw new SwitchDriverSubHandshakeAlreadyStarted(); } startDriverHandshakeCalled = true; OFFlowMod fm = factory().buildFlowDelete() .setTableId(TableId.ALL) .setOutGroup(OFGroup.ANY) .build(); sendMsg(Collections.singletonList(fm)); OFGroupMod gm = factory().buildGroupDelete() .setGroup(OFGroup.ALL) .setGroupType(OFGroupType.ALL) .build(); sendMsg(Collections.singletonList(gm)); OFMeterMod mm = factory().buildMeterMod() .setMeterId(MeterId.ALL.id()) .build(); sendMsg(Collections.singletonList(mm)); barrierXid = getNextTransactionId(); OFBarrierRequest barrier = factory().buildBarrierRequest() .setXid(barrierXid).build(); sendHandshakeMessage(barrier); }
/** * Builds the GroupMod OF message. * * @return GroupMod OF message */ public OFGroupMod buildGroupMod() { List<OFBucket> ofBuckets = new ArrayList<OFBucket>(); for (GroupBucket bucket: buckets.buckets()) { List<OFAction> actions = buildActions(bucket.treatment()); OFBucket.Builder bucketBuilder = factory.buildBucket(); bucketBuilder.setActions(actions); if (type == GroupDescription.Type.SELECT) { bucketBuilder.setWeight(1); } if (type == GroupDescription.Type.FAILOVER && bucket.watchPort() != null) { bucketBuilder.setWatchPort(OFPort.of((int) bucket.watchPort().toLong())); } else { bucketBuilder.setWatchPort(OFPort.ANY); } if (type == GroupDescription.Type.FAILOVER && bucket.watchGroup() != null) { bucketBuilder.setWatchGroup(OFGroup.of(bucket.watchGroup().id())); } else { bucketBuilder.setWatchGroup(OFGroup.ANY); } OFBucket ofBucket = bucketBuilder.build(); ofBuckets.add(ofBucket); } OFGroupMod groupMsg = factory.buildGroupModify() .setGroup(OFGroup.of(groupId.id())) .setBuckets(ofBuckets) .setGroupType(getOFGroupType(type)) .setXid(xid) .build(); return groupMsg; }
@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); }
private void pushOFModifyGroup(IOFSwitch sw) { /* Creates group flow with set queue option */ OFFactory of13Factory = sw.getOFFactory(); OFGroupMod modGroup = of13Factory.buildGroupModify() .setGroup(OFGroup.of(multicastGroup.ofGroupId)) .setGroupType(OFGroupType.ALL) .setBuckets(multicastGroup.getMemberOFBucketList(sw.getId())) .build(); sw.write(modGroup); }
@Override public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) { Map<OFGroupMod, OpenFlowSwitch> mods = Maps.newIdentityHashMap(); final Dpid dpid = Dpid.dpid(deviceId.uri()); OpenFlowSwitch sw = controller.getSwitch(dpid); for (GroupOperation groupOperation: groupOps.operations()) { if (sw == null) { log.error("SW {} is not found", dpid); return; } final Long groupModXid = XID_COUNTER.getAndIncrement(); GroupModBuilder builder = GroupModBuilder.builder(groupOperation.buckets(), groupOperation.groupId(), groupOperation.groupType(), sw.factory(), Optional.of(groupModXid)); OFGroupMod groupMod = null; switch (groupOperation.opType()) { case ADD: groupMod = builder.buildGroupAdd(); break; case MODIFY: groupMod = builder.buildGroupMod(); break; case DELETE: groupMod = builder.buildGroupDel(); break; default: log.error("Unsupported Group operation"); } sw.sendMsg(groupMod); GroupId groudId = new DefaultGroupId(groupMod.getGroup().getGroupNumber()); pendingGroupOperations.put(groudId, groupOperation); pendingXidMaps.put(groudId, groupModXid); } }
/** * Builds the GroupMod OF message. * * @return GroupMod OF message */ public OFGroupMod buildGroupMod() { List<OFBucket> ofBuckets = new ArrayList<OFBucket>(); for (GroupBucket bucket: buckets.buckets()) { List<OFAction> actions = buildActions(bucket.treatment()); OFBucket.Builder bucketBuilder = factory.buildBucket(); bucketBuilder.setActions(actions); if (type == GroupDescription.Type.SELECT) { bucketBuilder.setWeight(bucket.weight()); } if (type == GroupDescription.Type.FAILOVER && bucket.watchPort() != null) { bucketBuilder.setWatchPort(OFPort.of((int) bucket.watchPort().toLong())); } else { bucketBuilder.setWatchPort(OFPort.ANY); } if (type == GroupDescription.Type.FAILOVER && bucket.watchGroup() != null) { bucketBuilder.setWatchGroup(OFGroup.of(bucket.watchGroup().id())); } else { bucketBuilder.setWatchGroup(OFGroup.ANY); } OFBucket ofBucket = bucketBuilder.build(); ofBuckets.add(ofBucket); } OFGroupMod groupMsg = factory.buildGroupModify() .setGroup(OFGroup.of(groupId.id())) .setBuckets(ofBuckets) .setGroupType(getOFGroupType(type)) .setXid(xid) .build(); return groupMsg; }
@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); }
private void processGroupMod(OFGroupMod groupMod) { log.debug("processing GROUP_MOD {} message", groupMod.getCommand()); ApplicationId appId = ofSwitchService.appId(); GroupKey appCookie = new DefaultGroupKey(networkId.toString().getBytes()); switch (groupMod.getCommand()) { case ADD: // TODO return OFGroupModFailedCode.GROUP_EXISTS if group already exists int groupId = groupMod.getGroup().getGroupNumber(); OFGroupAdd groupAdd = (OFGroupAdd) groupMod; GroupBuckets groupAddBuckets = new OFAgentVirtualGroupBucketEntryBuilder( Dpid.dpid(Dpid.uri(dpid().getLong())), groupAdd.getBuckets(), groupAdd.getGroupType(), driverService) .build(); GroupDescription groupDescription = new DefaultGroupDescription( deviceId, getGroupType(groupAdd.getGroupType()), groupAddBuckets, appCookie, groupId, appId); groupService.addGroup(groupDescription); break; case MODIFY: // TODO return OFGroupModFailedCode.INVALID_GROUP if group does not exist OFGroupModify groupModify = (OFGroupModify) groupMod; GroupBuckets groupModifyBuckets = new OFAgentVirtualGroupBucketEntryBuilder( Dpid.dpid(Dpid.uri(dpid().getLong())), groupModify.getBuckets(), groupModify.getGroupType(), driverService) .build(); groupService.setBucketsForGroup(deviceId, appCookie, groupModifyBuckets, appCookie, appId); break; case DELETE: groupService.removeGroup(deviceId, appCookie, appId); break; default: // INSERT_BUCKET, REMOVE_BUCKET are effective OF 1.5. OFAgent supports 1.3. log.warn("Unsupported GROUP_MOD {} message received for switch {}", groupMod.getCommand(), this); } }
@Override public void processControllerCommand(Channel channel, OFMessage msg) { OFControllerRole myRole = role(channel); if (OFControllerRole.ROLE_SLAVE.equals(myRole)) { OFBadRequestErrorMsg errorMsg = FACTORY.errorMsgs() .buildBadRequestErrorMsg() .setXid(msg.getXid()) .setCode(OFBadRequestCode.IS_SLAVE) .build(); channel.writeAndFlush(Collections.singletonList(errorMsg)); return; } switch (msg.getType()) { case PORT_MOD: OFPortMod portMod = (OFPortMod) msg; processPortMod(portMod); break; case FLOW_MOD: OFFlowMod flowMod = (OFFlowMod) msg; processFlowMod(flowMod); break; case GROUP_MOD: OFGroupMod groupMod = (OFGroupMod) msg; processGroupMod(groupMod); break; case METER_MOD: OFMeterMod meterMod = (OFMeterMod) msg; processMeterMod(meterMod, channel); break; case TABLE_MOD: log.debug("processControllerCommand: {} not yet supported for {}", msg.getType(), msg); break; default: log.warn("Unexpected message {} received for switch {}", msg.getType(), this); } }
@Override public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) { final Dpid dpid = Dpid.dpid(deviceId.uri()); OpenFlowSwitch sw = controller.getSwitch(dpid); for (GroupOperation groupOperation: groupOps.operations()) { if (sw == null) { log.error("SW {} is not found", dpid); return; } final Long groupModXid = XID_COUNTER.getAndIncrement(); GroupModBuilder builder = null; if (driverService == null) { builder = GroupModBuilder.builder(groupOperation.buckets(), groupOperation.groupId(), groupOperation.groupType(), sw.factory(), Optional.of(groupModXid)); } else { builder = GroupModBuilder.builder(groupOperation.buckets(), groupOperation.groupId(), groupOperation.groupType(), sw.factory(), Optional.of(groupModXid), Optional.of(driverService)); } OFGroupMod groupMod = null; switch (groupOperation.opType()) { case ADD: groupMod = builder.buildGroupAdd(); break; case MODIFY: groupMod = builder.buildGroupMod(); break; case DELETE: groupMod = builder.buildGroupDel(); break; default: log.error("Unsupported Group operation"); return; } sw.sendMsg(groupMod); GroupId groudId = new DefaultGroupId(groupMod.getGroup().getGroupNumber()); pendingGroupOperations.put(groudId, groupOperation); pendingXidMaps.put(groudId, groupModXid); } }
@Override public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) { final Dpid dpid = Dpid.dpid(deviceId.uri()); OpenFlowSwitch sw = controller.getSwitch(dpid); for (GroupOperation groupOperation: groupOps.operations()) { if (sw == null) { log.error("SW {} is not found", dpid); return; } final Long groupModXid = XID_COUNTER.getAndIncrement(); GroupModBuilder builder = null; if (driverService == null) { builder = GroupModBuilder.builder(groupOperation.buckets(), groupOperation.groupId(), groupOperation.groupType(), sw.factory(), Optional.of(groupModXid)); } else { builder = GroupModBuilder.builder(groupOperation.buckets(), groupOperation.groupId(), groupOperation.groupType(), sw.factory(), Optional.of(groupModXid), Optional.of(driverService)); } OFGroupMod groupMod = null; switch (groupOperation.opType()) { case ADD: groupMod = builder.buildGroupAdd(); break; case MODIFY: groupMod = builder.buildGroupMod(); break; case DELETE: groupMod = builder.buildGroupDel(); break; default: log.error("Unsupported Group operation"); return; } sw.sendMsg(groupMod); GroupId groudId = new GroupId(groupMod.getGroup().getGroupNumber()); pendingGroupOperations.put(groudId, groupOperation); pendingXidMaps.put(groudId, groupModXid); } }