Java 类org.projectfloodlight.openflow.protocol.OFGroupAdd 实例源码

项目:athena    文件:GroupModBuilder.java   
/**
 * Builds the GroupAdd OF message.
 *
 * @return GroupAdd OF message
 */
public OFGroupAdd buildGroupAdd() {

    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);
    }

    OFGroupAdd groupMsg = factory.buildGroupAdd()
            .setGroup(OFGroup.of(groupId.id()))
            .setBuckets(ofBuckets)
            .setGroupType(getOFGroupType(type))
            .setXid(xid)
            .build();

    return groupMsg;
}
项目:SDN-Multicast    文件:MulticastTree.java   
private void pushOFCreateGroup(IOFSwitch sw) {

        /* Creates group flow with set queue option */
        OFFactory of13Factory = sw.getOFFactory();

        OFGroupAdd addGroup = of13Factory.buildGroupAdd()
                .setGroup(OFGroup.of(multicastGroup.ofGroupId))
                .setGroupType(OFGroupType.ALL)
                .setBuckets(multicastGroup.getMemberOFBucketList(sw.getId()))
                .build();
        sw.write(addGroup);
    }
项目:ravikumaran201504    文件:GroupModBuilder.java   
/**
 * Builds the GroupAdd OF message.
 *
 * @return GroupAdd OF message
 */
public OFGroupAdd buildGroupAdd() {

    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);
    }

    OFGroupAdd groupMsg = factory.buildGroupAdd()
            .setGroup(OFGroup.of(groupId.id()))
            .setBuckets(ofBuckets)
            .setGroupType(getOFGroupType(type))
            .setXid(xid)
            .build();

    return groupMsg;
}
项目:onos    文件:GroupModBuilder.java   
/**
 * Builds the GroupAdd OF message.
 *
 * @return GroupAdd OF message
 */
public OFGroupAdd buildGroupAdd() {

    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);
    }

    OFGroupAdd groupMsg = factory.buildGroupAdd()
            .setGroup(OFGroup.of(groupId.id()))
            .setBuckets(ofBuckets)
            .setGroupType(getOFGroupType(type))
            .setXid(xid)
            .build();

    return groupMsg;
}
项目:onos    文件:DefaultOFSwitch.java   
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);
    }
}
项目:floodlight    文件:ProtectionForwarding.java   
/**
 * ��������·��·����ȡԴĿ��������grouptable���bucket��Ȼ���·�OFGroupAdd��Ϣ����Ӧ������
 * @param firstRoute ����··��
 * @param secondRoute ����··��
 * @param isSrcSide Ϊtrueʱ��Ӧ·��·��Դ��Ͱ����Ϣ�·���������elseΪĿ�Ķ�
 * @author ZX Peng
 */
private void createGroupByRoute(Route firstRoute, Route secondRoute, boolean isSrcSide) {
    ArrayList<OFBucket> buckets = new ArrayList<OFBucket>(2);
    IOFSwitch sw;
    List<NodePortTuple> firstNptList = firstRoute.getPath();
    List<NodePortTuple> secondNptList = secondRoute.getPath();
    int firstIndex = 0, secondIndex = 0;
    if(isSrcSide == true) {
        firstIndex = 1;
        secondIndex = 1;
        sw = switchService.getSwitch(firstRoute.getId().getSrc());
    } else {
        firstIndex = firstNptList.size() - 2;
        secondIndex = secondNptList.size() - 2;
        sw = switchService.getSwitch(firstRoute.getId().getDst());
    }
    NodePortTuple firstWatchNpt =  firstNptList.get(firstIndex);
    NodePortTuple secondWatchNpt = secondNptList.get(secondIndex);

    buckets.add(sw.getOFFactory().buildBucket()
            .setWatchPort(firstWatchNpt.getPortId())
            .setWatchGroup(OFGroup.ZERO)
            .setActions(Collections.singletonList((OFAction) sw.getOFFactory().actions().buildOutput()
                    .setMaxLen(0x0fFFffFF)
                    .setPort(firstWatchNpt.getPortId())
                    .build()))
                    .build());
    buckets.add(sw.getOFFactory().buildBucket()
            .setWatchPort(secondWatchNpt.getPortId())
            .setWatchGroup(OFGroup.ZERO)
            .setActions(Collections.singletonList((OFAction) sw.getOFFactory().actions().buildOutput()
                    .setMaxLen(0x0fFFffFF)
                    .setPort(secondWatchNpt.getPortId())
                    .build()))
                    .build());

    //push OFGroupAdd message to the switch
    //TODO: group number has to be distinct from each other
    OFGroupAdd groupAdd = sw.getOFFactory().buildGroupAdd()
            .setGroup(OFGroup.of(GROUP_NUM))
            .setGroupType(OFGroupType.FF)
            .setBuckets(buckets)
            .build();

    sw.write(groupAdd);
}