import java.util.List;
import java.util.Map;
import java.util.Optional;
-import org.opendaylight.openflowjava.protocol.api.util.BinContent;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*
* @param version Openflow version
* @return default empty group mod input builder
+ * @deprecated Use {@link #defaultResult(Uint8)} instead.
*/
+ @Deprecated
public static GroupModInputBuilder defaultResult(final short version) {
- return new GroupModInputBuilder()
- .setVersion(version);
+ return defaultResult(Uint8.valueOf(version));
}
+ /**
+ * Create default empty group mod input builder
+ * Use this method, if result from convertor is empty.
+ *
+ * @param version Openflow version
+ * @return default empty group mod input builder
+ * @throws NullPointerException if version is null
+ */
+ public static GroupModInputBuilder defaultResult(final Uint8 version) {
+ return new GroupModInputBuilder().setVersion(version);
+ }
+
+
private static final Logger LOG = LoggerFactory.getLogger(GroupConvertor.class);
- private static final Integer DEFAULT_WEIGHT = 0;
- private static final Long OFPP_ANY = Long.parseLong("ffffffff", 16);
- private static final Long DEFAULT_WATCH_PORT = OFPP_ANY;
- private static final Long OFPG_ANY = Long.parseLong("ffffffff", 16);
- private static final Long DEFAULT_WATCH_GROUP = OFPG_ANY;
+ private static final Uint16 DEFAULT_WEIGHT = Uint16.ZERO;
+ private static final PortNumber DEFAULT_WATCH_PORT = new PortNumber(Uint32.MAX_VALUE);
+ private static final Uint32 DEFAULT_WATCH_GROUP = Uint32.MAX_VALUE;
private static final Comparator<Bucket> COMPARATOR = (bucket1, bucket2) -> {
if (bucket1.getBucketId() == null || bucket2.getBucketId() == null) {
return 0;
if (null != groupBucket.getWatchPort()) {
bucketBuilder.setWatchPort(new PortNumber(groupBucket.getWatchPort()));
} else {
- bucketBuilder.setWatchPort(new PortNumber(BinContent.intToUnsignedLong(DEFAULT_WATCH_PORT.intValue())));
+ bucketBuilder.setWatchPort(DEFAULT_WATCH_PORT);
if (groupType == GroupType.OFPGTFF.getIntValue()) {
LOG.error("WatchPort required for this OFPGT_FF");
}
if (null != groupBucket.getWatchGroup()) {
bucketBuilder.setWatchGroup(groupBucket.getWatchGroup());
} else {
- bucketBuilder.setWatchGroup(BinContent.intToUnsignedLong(DEFAULT_WATCH_GROUP.intValue()));
+ bucketBuilder.setWatchGroup(DEFAULT_WATCH_GROUP);
if (groupType == GroupType.OFPGTFF.getIntValue()) {
LOG.error("WatchGroup required for this OFPGT_FF");
}
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
+import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStats;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Converts group related statistics messages coming from switch to MD-SAL messages.
.reply.group.GroupStats.class);
private static Buckets toSALBuckets(List<BucketStats> bucketStats) {
- BucketsBuilder salBuckets = new BucketsBuilder();
+ final ImmutableMap.Builder<BucketCounterKey, BucketCounter> allBucketStats =
+ ImmutableMap.builderWithExpectedSize(bucketStats.size());
- List<BucketCounter> allBucketStats = new ArrayList<>();
int bucketKey = 0;
-
for (BucketStats bucketStat : bucketStats) {
- BucketCounterBuilder bucketCounter = new BucketCounterBuilder();
- bucketCounter.setByteCount(new Counter64(bucketStat.getByteCount()));
- bucketCounter.setPacketCount(new Counter64(bucketStat.getPacketCount()));
- BucketId bucketId = new BucketId((long) bucketKey);
- bucketCounter.withKey(new BucketCounterKey(bucketId));
- bucketCounter.setBucketId(bucketId);
- bucketKey++;
- allBucketStats.add(bucketCounter.build());
+ final BucketCounterKey key = new BucketCounterKey(new BucketId(Uint32.valueOf(bucketKey++)));
+ allBucketStats.put(key, new BucketCounterBuilder()
+ .withKey(key)
+ .setByteCount(new Counter64(bucketStat.getByteCount()))
+ .setPacketCount(new Counter64(bucketStat.getPacketCount()))
+ .build());
}
- salBuckets.setBucketCounter(allBucketStats);
- return salBuckets.build();
+ return new BucketsBuilder().setBucketCounter(allBucketStats.build()).build();
}
@Override
for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply
.body.multipart.reply.group._case.multipart.reply.group.GroupStats groupStats : source) {
- GroupStatsBuilder salGroupStats = new GroupStatsBuilder();
-
- salGroupStats.setBuckets(toSALBuckets(groupStats.nonnullBucketStats()));
- salGroupStats.setByteCount(new Counter64(groupStats.getByteCount()));
-
- DurationBuilder time = new DurationBuilder();
- time.setSecond(new Counter32(groupStats.getDurationSec()));
- time.setNanosecond(new Counter32(groupStats.getDurationNsec()));
-
- salGroupStats.setDuration(time.build());
- salGroupStats.setGroupId(new GroupId(groupStats.getGroupId().getValue()));
- salGroupStats.setPacketCount(new Counter64(groupStats.getPacketCount()));
- salGroupStats.setRefCount(new Counter32(groupStats.getRefCount()));
- salGroupStats.withKey(new GroupStatsKey(salGroupStats.getGroupId()));
- convertedSALGroups.add(salGroupStats.build());
+ convertedSALGroups.add(new GroupStatsBuilder()
+ .withKey(new GroupStatsKey(new GroupId(groupStats.getGroupId().getValue())))
+ .setBuckets(toSALBuckets(groupStats.nonnullBucketStats()))
+ .setByteCount(new Counter64(groupStats.getByteCount()))
+ .setDuration(new DurationBuilder()
+ .setSecond(new Counter32(groupStats.getDurationSec()))
+ .setNanosecond(new Counter32(groupStats.getDurationNsec()))
+ .build())
+ .setPacketCount(new Counter64(groupStats.getPacketCount()))
+ .setRefCount(new Counter32(groupStats.getRefCount()))
+ .build());
}
return convertedSALGroups;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.meter.config.Bands;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Converts list of OF library config meter stats to MD-SAL config meter stats.
meterBandHeaderBuilder.setBandBurstSize(dropBand.getBurstSize());
meterBandHeaderBuilder.setBandRate(dropBand.getRate());
- BandId bandId = new BandId((long) bandKey);
+ BandId bandId = new BandId(Uint32.valueOf(bandKey));
meterBandHeaderBuilder.withKey(new MeterBandHeaderKey(bandId));
meterBandHeaderBuilder.setBandId(bandId);
meterBandHeaderBuilder.setBandBurstSize(dscpRemarkBand.getBurstSize());
meterBandHeaderBuilder.setBandRate(dscpRemarkBand.getRate());
- BandId bandId = new BandId((long) bandKey);
+ BandId bandId = new BandId(Uint32.valueOf(bandKey));
meterBandHeaderBuilder.withKey(new MeterBandHeaderKey(bandId));
meterBandHeaderBuilder.setBandId(bandId);
meterBandHeaderBuilder.setBandBurstSize(experimenterBand.getBurstSize());
meterBandHeaderBuilder.setBandRate(experimenterBand.getRate());
- BandId bandId = new BandId((long) bandKey);
+ BandId bandId = new BandId(Uint32.valueOf(bandKey));
meterBandHeaderBuilder.withKey(new MeterBandHeaderKey(bandId));
meterBandHeaderBuilder.setBandId(bandId);
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Converts list of OF library meter stats to MD-SAL meter stats.
BandStatBuilder bandStatBuilder = new BandStatBuilder();
bandStatBuilder.setByteBandCount(new Counter64(meterBandStats.getByteBandCount()));
bandStatBuilder.setPacketBandCount(new Counter64(meterBandStats.getPacketBandCount()));
- BandId bandId = new BandId((long) bandKey);
+ BandId bandId = new BandId(Uint32.valueOf(bandKey));
bandStatBuilder.withKey(new BandStatKey(bandId));
bandStatBuilder.setBandId(bandId);
bandKey++;
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases;
import java.util.Optional;
SetTpSrcAction settpsrcaction = source.getSetTpSrcAction();
SetTpSrcCaseBuilder setTpSrcCaseBuilder = new SetTpSrcCaseBuilder();
SetTpSrcActionBuilder setTpSrcActionBuilder = new SetTpSrcActionBuilder();
- setTpSrcActionBuilder.setPort(new PortNumber(settpsrcaction.getPort()
- .getValue()
- .longValue()));
+ setTpSrcActionBuilder.setPort(new PortNumber(settpsrcaction.getPort().getValue().toUint32()));
setTpSrcCaseBuilder.setSetTpSrcAction(setTpSrcActionBuilder.build());
return Optional.of(new ActionBuilder()
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases;
import java.util.ArrayList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanVidCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.vid._case.VlanVidBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
public class SalToOfStripVlanActionCase extends ConvertorCase<StripVlanActionCase, Action, ActionConvertorData> {
public SalToOfStripVlanActionCase() {
VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
VlanVidBuilder vlanVidBuilder = new VlanVidBuilder();
vlanVidBuilder.setCfiBit(true);
- vlanVidBuilder.setVlanVid(0x0000);
+ vlanVidBuilder.setVlanVid(Uint16.ZERO);
vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
matchBuilder.setMatchEntryValue(vlanVidCaseBuilder.build());
matchBuilder.setHasMask(false);
private static void salToOFFlowTableId(final Flow flow, final FlowModInputBuilder flowMod) {
if (flow.getTableId() != null) {
- flowMod.setTableId(new TableId(flow.getTableId().longValue()));
+ flowMod.setTableId(new TableId(flow.getTableId().toUint32()));
} else {
flowMod.setTableId(DEFAULT_TABLE_ID);
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.cases;
import java.util.Optional;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MplsBosCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.bos._case.MplsBos;
+import org.opendaylight.yangtools.yang.common.Uint8;
public class OfToSalMplsBosCase extends ConvertorCase<MplsBosCase, MatchBuilder, MatchResponseConvertorData> {
public OfToSalMplsBosCase() {
MplsBos mplsBos = source.getMplsBos();
if (mplsBos != null) {
- protocolMatchFieldsBuilder.setMplsBos(mplsBos.isBos() ? (short) 1 : (short) 0);
+ protocolMatchFieldsBuilder.setMplsBos(mplsBos.isBos() ? Uint8.ONE : Uint8.ZERO);
matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
}
* @param bytes an array of 4 unsigned bytes
* @return a long representing the unsigned int
*/
- public static long bytesToUnsignedInt(final byte[] bytes) {
+ public static Uint32 bytesToUnsignedInt(final byte[] bytes) {
Preconditions.checkArgument(bytes.length == 4, "Input byte array must be exactly four bytes long.");
- long unsignedInt = 0;
+ int unsignedInt = 0;
unsignedInt |= bytes[0] & 0xFF;
unsignedInt <<= 8;
unsignedInt |= bytes[1] & 0xFF;
unsignedInt |= bytes[2] & 0xFF;
unsignedInt <<= 8;
unsignedInt |= bytes[3] & 0xFF;
- return unsignedInt;
+ return Uint32.fromIntBits(unsignedInt);
}
/**
import java.math.BigInteger;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.common.Uint64;
/**
@Test
public void testBytesToUnsignedInt() {
- long unsigned = ByteUtil.bytesToUnsignedInt(TEST_BYTES);
- assertEquals(BIG_INTEGER.longValue(), unsigned);
+ Uint32 unsigned = ByteUtil.bytesToUnsignedInt(TEST_BYTES);
+ assertEquals(BIG_INTEGER.longValue(), unsigned.toJava());
unsigned = ByteUtil.bytesToUnsignedInt(TEST_BYTES00);
- assertEquals(0, unsigned);
+ assertEquals(Uint32.ZERO, unsigned);
unsigned = ByteUtil.bytesToUnsignedInt(TEST_BYTESFF);
- assertEquals(BIG_INTFF.longValue(), unsigned);
+ assertEquals(BIG_INTFF.longValue(), unsigned.toJava());
}
@Test