use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId in project netvirt by opendaylight.
the class NexthopManager method updateDcGwLoadBalancingGroup.
/**
* This method is invoked when the tunnel status is updated.
* The bucket is directly removed/added based on the operational status of the tunnel.
*/
public void updateDcGwLoadBalancingGroup(List<String> availableDcGws, BigInteger dpnId, String destinationIp, boolean isTunnelUp) {
Preconditions.checkNotNull(availableDcGws, "There are no dc-gws present");
WriteTransaction configTx = dataBroker.newWriteOnlyTransaction();
// TODO : Place the logic to construct all possible DC-GW combination here.
int bucketId = availableDcGws.indexOf(destinationIp);
Optional<DpnLbNexthops> dpnLbNextHops = fibUtil.getDpnLbNexthops(dpnId, destinationIp);
if (!dpnLbNextHops.isPresent()) {
return;
}
List<String> nextHopKeys = dpnLbNextHops.get().getNexthopKey();
nextHopKeys.forEach(nextHopKey -> {
Optional<Nexthops> optionalNextHops = fibUtil.getNexthops(nextHopKey);
if (!optionalNextHops.isPresent()) {
return;
}
Nexthops nexthops = optionalNextHops.get();
final String groupId = nexthops.getGroupId();
final long groupIdValue = Long.parseLong(groupId);
if (isTunnelUp) {
Bucket bucket = buildBucketForDcGwLbGroup(destinationIp, dpnId, bucketId);
LOG.trace("Added bucket {} to group {} on dpn {}.", bucket, groupId, dpnId);
mdsalApiManager.addBucketToTx(dpnId, groupIdValue, bucket, configTx);
} else {
LOG.trace("Removed bucketId {} from group {} on dpn {}.", bucketId, groupId, dpnId);
mdsalApiManager.removeBucketToTx(dpnId, groupIdValue, bucketId, configTx);
}
});
configTx.submit();
return;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId 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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId in project netvirt by opendaylight.
the class PolicyRouteGroupProgrammer method programPolicyClassifierGroupBuckets.
public void programPolicyClassifierGroupBuckets(String policyClassifier, List<String> underlayNetworks, int addOrRemove) {
if (underlayNetworks == null) {
return;
}
coordinator.enqueueJob(policyClassifier, () -> {
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
for (int idx = 0; idx < underlayNetworks.size(); idx++) {
final int bucketId = idx;
String underlayNetwork = underlayNetworks.get(idx);
List<DpnToInterface> dpnToInterfaceList = policyServiceUtil.getUnderlayNetworkDpnToInterfaces(underlayNetwork);
dpnToInterfaceList.forEach(dpnToInterface -> {
BigInteger dpId = dpnToInterface.getDpId();
List<TunnelInterface> tunnelInterfaces = dpnToInterface.getTunnelInterface();
programPolicyClassifierGroupBuckets(policyClassifier, tunnelInterfaces, dpId, bucketId, addOrRemove, tx);
});
}
return Collections.singletonList(tx.submit());
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId in project openflowplugin by opendaylight.
the class GroupConvertorTest method testGroupModConvertSortedBuckets.
/**
* test of {@link GroupConvertor#convert(Group, VersionDatapathIdConvertorData)} }.
*/
@Test
public void testGroupModConvertSortedBuckets() {
final int actionOrder = 0;
final ArrayList<Bucket> bucket = new ArrayList<>();
bucket.add(new BucketBuilder().setBucketId(new BucketId((long) 4)).setWatchPort((long) 2).setWatchGroup((long) 1).setAction(ImmutableList.of(new ActionBuilder().setOrder(0).setAction(new OutputActionCaseBuilder().setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri("openflow:1:2")).build()).build()).build())).build());
bucket.add(new BucketBuilder().setBucketId(new BucketId((long) 3)).setWatchPort((long) 6).setWatchGroup((long) 1).setAction(ImmutableList.of(new ActionBuilder().setOrder(0).setAction(new OutputActionCaseBuilder().setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri("openflow:1:6")).build()).build()).build())).build());
bucket.add(new BucketBuilder().setBucketId(new BucketId((long) 2)).setWatchPort((long) 5).setWatchGroup((long) 1).setAction(ImmutableList.of(new ActionBuilder().setOrder(0).setAction(new OutputActionCaseBuilder().setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri("openflow:1:5")).build()).build()).build())).build());
bucket.add(new BucketBuilder().setBucketId(new BucketId((long) 1)).setWatchPort((long) 4).setWatchGroup((long) 1).setAction(ImmutableList.of(new ActionBuilder().setOrder(0).setAction(new OutputActionCaseBuilder().setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri("openflow:1:4")).build()).build()).build())).build());
bucket.add(new BucketBuilder().setBucketId(new BucketId((long) 0)).setWatchPort((long) 3).setWatchGroup((long) 1).setAction(ImmutableList.of(new ActionBuilder().setOrder(0).setAction(new OutputActionCaseBuilder().setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri("openflow:1:3")).build()).build()).build())).build());
final AddGroupInput input = new AddGroupInputBuilder().setGroupId(new GroupId((long) 1)).setGroupName("Foo").setGroupType(GroupTypes.GroupFf).setBuckets(new BucketsBuilder().setBucket(bucket).build()).build();
VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData((short) 0X4);
data.setDatapathId(BigInteger.valueOf(1));
final GroupModInputBuilder outAddGroupInput = convert(input, data);
final List<BucketsList> bucketList = outAddGroupInput.getBucketsList();
assertEquals(Long.valueOf(1), bucketList.get(0).getWatchGroup());
assertEquals(Long.valueOf(3), bucketList.get(0).getWatchPort().getValue());
assertEquals(Long.valueOf(1), bucketList.get(1).getWatchGroup());
assertEquals(Long.valueOf(4), bucketList.get(1).getWatchPort().getValue());
assertEquals(Long.valueOf(1), bucketList.get(2).getWatchGroup());
assertEquals(Long.valueOf(5), bucketList.get(2).getWatchPort().getValue());
assertEquals(Long.valueOf(1), bucketList.get(3).getWatchGroup());
assertEquals(Long.valueOf(6), bucketList.get(3).getWatchPort().getValue());
assertEquals(Long.valueOf(1), bucketList.get(4).getWatchGroup());
assertEquals(Long.valueOf(2), bucketList.get(4).getWatchPort().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId in project openflowplugin by opendaylight.
the class MultipartReplyGroupStatsDeserializer method deserialize.
@Override
public MultipartReplyBody deserialize(ByteBuf message) {
final MultipartReplyGroupStatsBuilder builder = new MultipartReplyGroupStatsBuilder();
final List<GroupStats> items = new ArrayList<>();
while (message.readableBytes() > 0) {
final int itemLength = message.readUnsignedShort();
message.skipBytes(PADDING_IN_GROUP_HEADER_01);
final GroupStatsBuilder itemBuilder = new GroupStatsBuilder().setGroupId(new GroupId(message.readUnsignedInt())).setRefCount(new Counter32(message.readUnsignedInt()));
message.skipBytes(PADDING_IN_GROUP_HEADER_02);
final byte[] packetCountg = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
message.readBytes(packetCountg);
final byte[] byteCountg = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
message.readBytes(byteCountg);
itemBuilder.setKey(new GroupStatsKey(itemBuilder.getGroupId())).setPacketCount(new Counter64(new BigInteger(1, packetCountg))).setByteCount(new Counter64(new BigInteger(1, byteCountg))).setDuration(new DurationBuilder().setSecond(new Counter32(message.readUnsignedInt())).setNanosecond(new Counter32(message.readUnsignedInt())).build());
final List<BucketCounter> subItems = new ArrayList<>();
int actualLength = GROUP_BODY_LENGTH;
long bucketKey = 0;
while (actualLength < itemLength) {
final byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
message.readBytes(packetCount);
final byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
message.readBytes(byteCount);
subItems.add(new BucketCounterBuilder().setBucketId(new BucketId(bucketKey)).setKey(new BucketCounterKey(new BucketId(bucketKey))).setPacketCount(new Counter64(new BigInteger(1, packetCount))).setByteCount(new Counter64(new BigInteger(1, byteCount))).build());
bucketKey++;
actualLength += BUCKET_COUNTER_LENGTH;
}
items.add(itemBuilder.setBuckets(new BucketsBuilder().setBucketCounter(subItems).build()).build());
}
return builder.setGroupStats(items).build();
}
Aggregations