Search in sources :

Example 1 with NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.group.buckets.bucket.action.action.NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase in project netvirt by opendaylight.

the class ElanUtils method syncUpdateGroup.

public void syncUpdateGroup(Uint64 dpnId, Group newGroup, long delayTime, TypedWriteTransaction<Datastore.Configuration> confTx) {
    Node nodeDpn = buildDpnNode(dpnId);
    long groupIdInfo = newGroup.getGroupId().getValue().longValue();
    GroupKey groupKey = new GroupKey(new GroupId(groupIdInfo));
    InstanceIdentifier<Group> groupInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.key()).augmentation(FlowCapableNode.class).child(Group.class, groupKey).build();
    LOG.trace("Performing merge operation for remote BC group for node {} with group {}", nodeDpn, newGroup);
    Optional<Group> existingGroupOpt = ElanUtils.read(broker, LogicalDatastoreType.CONFIGURATION, groupInstanceId);
    if (!existingGroupOpt.isPresent()) {
        LOG.debug("Group {} doesn't exist. Performing syncInstall", groupIdInfo);
        mdsalManager.addGroup(confTx, dpnId, newGroup);
        return;
    }
    Buckets existingGroup = existingGroupOpt.get().getBuckets();
    if (existingGroup == null) {
        LOG.debug("Bucket doesn't exist for group {}. Performing syncInstall", groupIdInfo);
        mdsalManager.addGroup(confTx, dpnId, newGroup);
        return;
    }
    if (newGroup.getBuckets() == null) {
        LOG.debug("Buckets are not sent for group {}. Skipping merge operation", groupIdInfo);
        return;
    }
    List<Bucket> newBuckets = new ArrayList<>(newGroup.getBuckets().nonnullBucket().values());
    List<Bucket> existingBuckets = new ArrayList<>(existingGroup.nonnullBucket().values());
    LOG.debug("New Buckets {} and Existing Buckets {}", newBuckets, existingBuckets);
    List<Bucket> combinedBuckets = new ArrayList<>(existingBuckets);
    Map<String, Bucket> ncBucketMap = new HashMap<>();
    Map<String, Bucket> reg6ActionBucketMap = new HashMap<>();
    // Add all buckets in the new group to a map with node connector/reg6 value as key
    newBuckets.forEach(bucket -> {
        List<Action> actionList = new ArrayList<>(bucket.getAction().values());
        if (actionList != null && !actionList.isEmpty()) {
            actionList.forEach(action -> {
                if (action.getAction() instanceof OutputActionCase) {
                    OutputActionCase outputAction = (OutputActionCase) action.getAction();
                    String nc = outputAction.getOutputAction().getOutputNodeConnector().getValue();
                    ncBucketMap.put(nc, bucket);
                }
                if (action.getAction() instanceof NxActionRegLoadNodesNodeTableFlowApplyActionsCase) {
                    NxActionRegLoadNodesNodeTableFlowApplyActionsCase regLoad = (NxActionRegLoadNodesNodeTableFlowApplyActionsCase) action.getAction();
                    String regValue = regLoad.getNxRegLoad().getValue().toString();
                    reg6ActionBucketMap.put(regValue, bucket);
                }
            });
        }
    });
    // Replace existing bucket if action has same node connector/reg6 value as stored in map
    // First, remove buckets with same nc id/reg6 value as in hashmap from combinedBuckets
    // Next, add all the buckets in hashmap to combined buckets
    existingBuckets.forEach(existingBucket -> {
        List<Action> actionList = new ArrayList<>(existingBucket.getAction().values());
        if (actionList != null && !actionList.isEmpty()) {
            actionList.forEach(action -> {
                if (action.getAction() instanceof OutputActionCase) {
                    OutputActionCase outputAction = (OutputActionCase) action.getAction();
                    String nc = outputAction.getOutputAction().getOutputNodeConnector().getValue();
                    Bucket storedBucket = ncBucketMap.get(nc);
                    if (storedBucket != null) {
                        combinedBuckets.remove(existingBucket);
                    }
                }
                if (action.getAction() instanceof NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase) {
                    NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase regLoad = (NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase) action.getAction();
                    String regValue = regLoad.getNxRegLoad().getValue().toString();
                    Bucket storedBucket = reg6ActionBucketMap.get(regValue);
                    if (storedBucket != null) {
                        combinedBuckets.remove(existingBucket);
                    }
                }
            });
        }
    });
    AtomicLong bucketIdValue = new AtomicLong(-1);
    // Change the bucket id of existing buckets
    List<Bucket> bucketsToBeAdded = new ArrayList<>();
    bucketsToBeAdded.addAll(combinedBuckets.stream().map(bucket -> {
        BucketId bucketId = new BucketId(bucketIdValue.incrementAndGet());
        return new BucketBuilder(bucket).withKey(new BucketKey(bucketId)).setBucketId(bucketId).build();
    }).collect(Collectors.toList()));
    // Change the bucket id of remaining to be added to the combined buckets
    bucketsToBeAdded.addAll(ncBucketMap.values().stream().map(bucket -> {
        BucketId bucketId = new BucketId(bucketIdValue.incrementAndGet());
        return new BucketBuilder(bucket).withKey(new BucketKey(bucketId)).setBucketId(bucketId).build();
    }).collect(Collectors.toList()));
    bucketsToBeAdded.addAll(reg6ActionBucketMap.values().stream().map(bucket -> {
        BucketId bucketId = new BucketId(bucketIdValue.incrementAndGet());
        return new BucketBuilder(bucket).withKey(new BucketKey(bucketId)).setBucketId(bucketId).build();
    }).collect(Collectors.toList()));
    Group group = MDSALUtil.buildGroup(newGroup.getGroupId().getValue().longValue(), newGroup.getGroupName(), GroupTypes.GroupAll, MDSALUtil.buildBucketLists(bucketsToBeAdded));
    mdsalManager.addGroup(confTx, dpnId, group);
    LOG.trace("Installed remote BC group for node {} with group {}", nodeDpn.key().getId().getValue(), group);
}
Also used : Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) HashMap(java.util.HashMap) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NxActionRegLoadNodesNodeTableFlowApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegLoadNodesNodeTableFlowApplyActionsCase) BucketKey(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketKey) GroupKey(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey) ArrayList(java.util.ArrayList) BucketId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId) Buckets(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId) BucketBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder) AtomicLong(java.util.concurrent.atomic.AtomicLong) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) OutputActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase) NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.group.buckets.bucket.action.action.NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 OutputActionCase (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase)1 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)1 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)1 BucketId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId)1 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId)1 Buckets (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets)1 Bucket (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket)1 BucketBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder)1 BucketKey (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketKey)1 Group (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group)1 GroupKey (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey)1 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)1 NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.group.buckets.bucket.action.action.NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase)1 NxActionRegLoadNodesNodeTableFlowApplyActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegLoadNodesNodeTableFlowApplyActionsCase)1