@Test public void addGroup() { 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); final Dpid dpid = Dpid.dpid(deviceId.uri()); TestOpenFlowSwitch sw = (TestOpenFlowSwitch) controller.getSwitch(dpid); assertNotNull("Switch should not be nul", sw); assertNotNull("OFGroupMsg should not be null", sw.msg); }
@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); } }
OpenFlowGroupProvider extends AbstractProvider implements GroupProvider { @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); } } }
OpenFlowGroupProvider extends AbstractProvider implements GroupProvider { @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); } } OpenFlowGroupProvider(); }
OpenFlowGroupProvider extends AbstractProvider implements GroupProvider { @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); } } OpenFlowGroupProvider(); @Activate void activate(); @Deactivate void deactivate(); @Override void performGroupOperation(DeviceId deviceId, GroupOperations groupOps); static long getXidAndAdd(int increase); }
OpenFlowGroupProvider extends AbstractProvider implements GroupProvider { @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); } } OpenFlowGroupProvider(); @Activate void activate(); @Deactivate void deactivate(); @Override void performGroupOperation(DeviceId deviceId, GroupOperations groupOps); static long getXidAndAdd(int increase);  }