Search in sources :

Example 71 with GroupId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId in project netvirt by opendaylight.

the class NexthopManager method getBucketsForLocalNexthop.

private List<BucketInfo> getBucketsForLocalNexthop(Long vpnId, BigInteger dpnId, VrfEntry vrfEntry, Routes routes) {
    List<BucketInfo> listBucketInfo = new CopyOnWriteArrayList<>();
    routes.getNexthopIpList().parallelStream().forEach(nextHopIp -> {
        String localNextHopIP;
        if (isIpv4Address(nextHopIp)) {
            localNextHopIP = nextHopIp + NwConstants.IPV4PREFIX;
        } else {
            localNextHopIP = nextHopIp + NwConstants.IPV6PREFIX;
        }
        Prefixes localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, localNextHopIP);
        if (localNextHopInfo != null) {
            long groupId = getLocalNextHopGroup(vpnId, localNextHopIP);
            if (groupId == FibConstants.INVALID_GROUP_ID) {
                LOG.error("Unable to allocate groupId for vpnId {} , prefix {} , interface {}", vpnId, vrfEntry.getDestPrefix(), localNextHopInfo.getVpnInterfaceName());
                return;
            }
            List<ActionInfo> actionsInfos = Collections.singletonList(new ActionGroup(groupId));
            BucketInfo bucket = new BucketInfo(actionsInfos);
            bucket.setWeight(1);
            listBucketInfo.add(bucket);
        }
    });
    LOG.trace("LOCAL: listbucket {}, vpnId {}, dpnId {}, routes {}", listBucketInfo, vpnId, dpnId, routes);
    return listBucketInfo;
}
Also used : ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 72 with GroupId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId in project netvirt by opendaylight.

the class NexthopManager method createDcGwLoadBalancingGroup.

public void createDcGwLoadBalancingGroup(List<String> availableDcGws, BigInteger dpnId, String destinationIp) {
    Preconditions.checkNotNull(availableDcGws, "There are no dc-gws present");
    int noOfDcGws = availableDcGws.size();
    if (noOfDcGws == 1) {
        LOG.trace("There are no enough DC GateWays {} present to program LB group", availableDcGws);
        return;
    }
    // TODO : Place the logic to construct all possible DC-GW combination here.
    String groupIdKey = FibUtil.getGreLbGroupKey(availableDcGws);
    Long groupId = createNextHopPointer(groupIdKey);
    List<Bucket> listBucket = new ArrayList<>();
    for (int index = 0; index < noOfDcGws; index++) {
        if (isTunnelUp(availableDcGws.get(index), dpnId)) {
            listBucket.add(buildBucketForDcGwLbGroup(availableDcGws.get(index), dpnId, index));
        }
    }
    Group group = MDSALUtil.buildGroup(groupId, groupIdKey, GroupTypes.GroupSelect, MDSALUtil.buildBucketLists(listBucket));
    WriteTransaction configTx = dataBroker.newWriteOnlyTransaction();
    WriteTransaction operationalTx = dataBroker.newWriteOnlyTransaction();
    mdsalApiManager.addGroupToTx(dpnId, group, configTx);
    FibUtil.updateLbGroupInfo(dpnId, destinationIp, groupIdKey, groupId.toString(), operationalTx);
    configTx.submit();
    operationalTx.submit();
    LOG.trace("LB group {} towards DC-GW installed on dpn {}. Group - {}", groupIdKey, dpnId, group);
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 73 with GroupId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId in project netvirt by opendaylight.

the class PolicyServiceFlowUtil method updateInterfaceBucketToTx.

public void updateInterfaceBucketToTx(BigInteger dpId, long groupId, int bucketId, String interfaceName, int addOrRemove, WriteTransaction tx) {
    if (groupId == PolicyServiceConstants.INVALID_ID) {
        LOG.error("No valid group id found for interface {} DPN {}", interfaceName, dpId);
        return;
    }
    if (addOrRemove == NwConstants.DEL_FLOW) {
        LOG.debug("Remove bucket for interface {} from group {} DPN {}", interfaceName, groupId, dpId);
        mdsalManager.removeBucketToTx(dpId, groupId, bucketId, tx);
        return;
    }
    List<ActionInfo> egressActions = interfaceManager.getInterfaceEgressActions(interfaceName);
    if (egressActions == null || egressActions.isEmpty()) {
        LOG.error("Failed to get egress actions for interface {} DPN {}", interfaceName, dpId);
        return;
    }
    Long port = interfaceManager.getPortForInterface(interfaceName);
    if (port == null) {
        LOG.error("Failed to get port for interface {}", interfaceName);
        return;
    }
    Bucket bucket = MDSALUtil.buildBucket(MDSALUtil.buildActions(egressActions), MDSALUtil.GROUP_WEIGHT, bucketId, port, MDSALUtil.WATCH_GROUP);
    LOG.debug("Add bucket id {} for interface {} to group {} DPN {}", bucketId, interfaceName, groupId, dpId);
    mdsalManager.addBucketToTx(dpId, groupId, bucket, tx);
}
Also used : Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo)

Example 74 with GroupId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId in project openflowplugin by opendaylight.

the class GroupConvertorTest method testGroupModConvertorwithallParameters.

/**
 * test of {@link GroupConvertor#convert(Group, VersionDatapathIdConvertorData)} }.
 */
@Test
public void testGroupModConvertorwithallParameters() {
    final AddGroupInputBuilder addGroupBuilder = new AddGroupInputBuilder();
    addGroupBuilder.setGroupId(new GroupId(10L));
    addGroupBuilder.setGroupType(GroupTypes.GroupAll);
    final List<Bucket> bucketList = new ArrayList<>();
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionsList = new ArrayList<>();
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionsList1 = new ArrayList<>();
    int actionOrder = 0;
    // Action1
    final GroupActionBuilder groupActionBuilder = new GroupActionBuilder();
    groupActionBuilder.setGroup("005");
    final GroupAction groupIdaction = groupActionBuilder.build();
    final ActionBuilder actionsB = new ActionBuilder();
    actionsB.setOrder(actionOrder++).setAction(new GroupActionCaseBuilder().setGroupAction(groupIdaction).build());
    // Action2:
    final GroupActionBuilder groupActionBuilder1 = new GroupActionBuilder();
    groupActionBuilder1.setGroup("006");
    final GroupAction groupIdaction1 = groupActionBuilder.build();
    final ActionBuilder actionsB1 = new ActionBuilder();
    actionsB1.setOrder(actionOrder++).setAction(new GroupActionCaseBuilder().setGroupAction(groupIdaction1).build());
    actionsList.add(actionsB.build());
    actionsList.add(actionsB1.build());
    final BucketsBuilder bucketsB = new BucketsBuilder();
    final BucketBuilder bucketB = new BucketBuilder();
    bucketB.setWeight(10);
    bucketB.setWatchPort(20L);
    bucketB.setWatchGroup(22L);
    bucketB.setAction(actionsList);
    final Bucket bucket = bucketB.build();
    // List of bucket
    bucketList.add(bucket);
    final BucketBuilder bucketB1 = new BucketBuilder();
    bucketB1.setWeight(50);
    bucketB1.setWatchPort(60L);
    bucketB1.setWatchGroup(70L);
    // Action1
    final CopyTtlInBuilder copyTtlB = new CopyTtlInBuilder();
    final CopyTtlIn copyTtl = copyTtlB.build();
    final ActionBuilder actionsB2 = new ActionBuilder();
    actionsB2.setOrder(actionOrder++).setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(copyTtl).build());
    // Action2:
    final SetMplsTtlActionBuilder setMplsTtlActionBuilder = new SetMplsTtlActionBuilder();
    setMplsTtlActionBuilder.setMplsTtl((short) 0X1);
    final SetMplsTtlAction setMAction = setMplsTtlActionBuilder.build();
    final ActionBuilder actionsB3 = new ActionBuilder();
    actionsB3.setOrder(actionOrder++).setAction(new SetMplsTtlActionCaseBuilder().setSetMplsTtlAction(setMAction).build());
    actionsList1.add(actionsB2.build());
    actionsList1.add(actionsB3.build());
    bucketB1.setAction(actionsList);
    // second bucket
    final Bucket bucket1 = bucketB1.build();
    bucketList.add(bucket1);
    // List of bucket added to the Buckets
    bucketsB.setBucket(bucketList);
    final Buckets buckets = bucketsB.build();
    addGroupBuilder.setBuckets(buckets);
    VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData((short) 0X4);
    data.setDatapathId(BigInteger.valueOf(1));
    final GroupModInputBuilder outAddGroupInput = convert(addGroupBuilder.build(), data);
    assertEquals(GroupModCommand.OFPGCADD, outAddGroupInput.getCommand());
    assertEquals(GroupType.OFPGTALL, outAddGroupInput.getType());
    assertEquals(10L, (long) outAddGroupInput.getGroupId().getValue());
    assertEquals(10, (int) outAddGroupInput.getBucketsList().get(0).getWeight());
    assertEquals(20L, (long) outAddGroupInput.getBucketsList().get(0).getWatchPort().getValue());
    assertEquals((Long) 22L, outAddGroupInput.getBucketsList().get(0).getWatchGroup());
    final List<Action> outActionList = outAddGroupInput.getBucketsList().get(0).getAction();
    for (int outItem = 0; outItem < outActionList.size(); outItem++) {
        final Action action = outActionList.get(outItem);
        if (action.getActionChoice() instanceof GroupActionCase) {
            assertEquals((Long) 5L, ((GroupActionCase) action.getActionChoice()).getGroupAction().getGroupId());
        }
    // TODO:setMplsTTL :OF layer doesnt have get();
    }
    assertEquals((Integer) 50, outAddGroupInput.getBucketsList().get(1).getWeight());
    assertEquals((long) 60, (long) outAddGroupInput.getBucketsList().get(1).getWatchPort().getValue());
    assertEquals((Long) 70L, outAddGroupInput.getBucketsList().get(1).getWatchGroup());
    final List<Action> outActionList1 = outAddGroupInput.getBucketsList().get(1).getAction();
    for (int outItem = 0; outItem < outActionList1.size(); outItem++) {
        final Action action = outActionList1.get(outItem);
        if (action.getActionChoice() instanceof GroupActionCase) {
            assertEquals((Long) 6L, ((GroupActionCase) action.getActionChoice()).getGroupAction().getGroupId());
        }
    // TODO:setMplsTTL :OF layer doesnt have get();
    }
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) GroupAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupAction) SetMplsTtlAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlAction) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) SetMplsTtlActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder) GroupActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) ArrayList(java.util.ArrayList) CopyTtlIn(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlIn) BucketsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder) Buckets(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets) BucketBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder) SetMplsTtlActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder) GroupModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder) GroupActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase) CopyTtlInCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder) GroupActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder) AddGroupInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId) GroupAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupAction) CopyTtlInBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder) SetMplsTtlAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlAction) GroupActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder) SetMplsTtlActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) Test(org.junit.Test)

Example 75 with GroupId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId in project openflowplugin by opendaylight.

the class GroupConvertorTest method testGroupModConvertorBucketwithNOWieghtValuesForGroupTypeAll.

/**
 * test of {@link GroupConvertor#convert(Group, VersionDatapathIdConvertorData)} }.
 */
@Test
public void testGroupModConvertorBucketwithNOWieghtValuesForGroupTypeAll() {
    int actionOrder = 0;
    final AddGroupInputBuilder addGroupBuilder = new AddGroupInputBuilder();
    addGroupBuilder.setGroupId(new GroupId(10L));
    addGroupBuilder.setGroupType(GroupTypes.GroupAll);
    final List<Bucket> bucketList = new ArrayList<>();
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionsList = new ArrayList<>();
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionsList1 = new ArrayList<>();
    // Action1
    actionsList.add(assembleActionBuilder("005", actionOrder++).build());
    // Action2:
    actionsList.add(assembleActionBuilder("006", actionOrder++).build());
    final BucketsBuilder bucketsB = new BucketsBuilder();
    final BucketBuilder bucketB = new BucketBuilder();
    bucketB.setAction(actionsList);
    final Bucket bucket = bucketB.build();
    // List of bucket
    bucketList.add(bucket);
    final BucketBuilder bucketB1 = new BucketBuilder();
    // Action1
    actionsList1.add(assembleCopyTtlInBuilder(actionOrder++).build());
    // Action2:
    actionsList1.add(assembleSetMplsTtlActionBuilder(actionOrder++).build());
    bucketB1.setAction(actionsList);
    // second bucket
    final Bucket bucket1 = bucketB1.build();
    bucketList.add(bucket1);
    // List of bucket added to the Buckets
    bucketsB.setBucket(bucketList);
    final Buckets buckets = bucketsB.build();
    addGroupBuilder.setBuckets(buckets);
    VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData((short) 0X4);
    data.setDatapathId(BigInteger.valueOf(1));
    final GroupModInputBuilder outAddGroupInput = convert(addGroupBuilder.build(), data);
    assertEquals(GroupModCommand.OFPGCADD, outAddGroupInput.getCommand());
    assertEquals(GroupType.OFPGTALL, outAddGroupInput.getType());
    assertEquals(10L, outAddGroupInput.getGroupId().getValue().longValue());
    final List<Action> outActionList = outAddGroupInput.getBucketsList().get(0).getAction();
    for (int outItem = 0; outItem < outActionList.size(); outItem++) {
        final Action action = outActionList.get(outItem);
        if (action.getActionChoice() instanceof GroupActionCase) {
            assertEquals((Long) 5L, ((GroupActionCase) action.getActionChoice()).getGroupAction().getGroupId());
        }
    }
    final List<Action> outActionList1 = outAddGroupInput.getBucketsList().get(1).getAction();
    for (int outItem = 0; outItem < outActionList1.size(); outItem++) {
        final Action action = outActionList1.get(outItem);
        if (action.getActionChoice() instanceof GroupActionCase) {
            assertEquals((Long) 6L, ((GroupActionCase) action.getActionChoice()).getGroupAction().getGroupId());
        }
    }
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) GroupAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupAction) SetMplsTtlAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlAction) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) ArrayList(java.util.ArrayList) BucketsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder) Buckets(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets) AddGroupInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder) 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) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) GroupModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder) GroupActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)41 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId)36 Test (org.junit.Test)28 Bucket (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket)27 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId)22 Group (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group)21 BigInteger (java.math.BigInteger)19 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)18 GroupBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder)12 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)11 BucketsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder)10 BucketBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder)10 ByteBuf (io.netty.buffer.ByteBuf)9 GroupKey (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey)9 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)8 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)8 AddGroupInput (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput)8 AddGroupInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder)8 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)7 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)6