Search in sources :

Example 51 with PortNumber

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber in project openflowplugin by opendaylight.

the class DeviceContextImpl method handlePacketInMessage.

private void handlePacketInMessage(final PacketIn packetIn, final Class<?> implementedInterface, final Match match) {
    messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH);
    final ConnectionAdapter connectionAdapter = getPrimaryConnectionContext().getConnectionAdapter();
    if (packetIn == null) {
        LOG.debug("Received a null packet from switch {}", connectionAdapter.getRemoteAddress());
        messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_TRANSLATE_SRC_FAILURE);
        return;
    }
    final OpenflowVersion openflowVersion = OpenflowVersion.get(deviceInfo.getVersion());
    // Try to get ingress from match
    final NodeConnectorRef nodeConnectorRef = Objects.nonNull(packetIn.getIngress()) ? packetIn.getIngress() : Optional.ofNullable(match).map(Match::getInPort).map(nodeConnectorId -> InventoryDataServiceUtil.portNumberfromNodeConnectorId(openflowVersion, nodeConnectorId)).map(portNumber -> InventoryDataServiceUtil.nodeConnectorRefFromDatapathIdPortno(deviceInfo.getDatapathId(), portNumber, openflowVersion)).orElse(null);
    messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_TRANSLATE_OUT_SUCCESS);
    if (!packetInLimiter.acquirePermit()) {
        LOG.debug("Packet limited");
        // TODO: save packet into emergency slot if possible
        messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_PACKET_IN_LIMIT_REACHED_AND_DROPPED);
        return;
    }
    final ListenableFuture<?> offerNotification = notificationPublishService.offerNotification(new PacketReceivedBuilder(packetIn).setIngress(nodeConnectorRef).setMatch(MatchUtil.transformMatch(match, org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match.class)).build());
    if (NotificationPublishService.REJECTED.equals(offerNotification)) {
        LOG.debug("notification offer rejected");
        messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_NOTIFICATION_REJECTED);
        packetInLimiter.drainLowWaterMark();
        packetInLimiter.releasePermit();
        return;
    }
    Futures.addCallback(offerNotification, new FutureCallback<Object>() {

        @Override
        public void onSuccess(final Object result) {
            messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_SUCCESS);
            packetInLimiter.releasePermit();
        }

        @Override
        public void onFailure(final Throwable throwable) {
            messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_NOTIFICATION_REJECTED);
            LOG.debug("notification offer failed: {}", throwable.getMessage());
            LOG.trace("notification offer failed..", throwable);
            packetInLimiter.releasePermit();
        }
    }, MoreExecutors.directExecutor());
}
Also used : MultipartWriterProvider(org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider) FlowCapableNodeConnectorStatisticsData(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData) DeviceMeterRegistry(org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry) ServiceGroupIdentifier(org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier) Future(java.util.concurrent.Future) Error(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error) PacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey) ExtensionConverterProvider(org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) ContextChainState(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainState) PortStatusMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage) PortGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) FlowCapableNodeConnectorStatisticsDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder) ConnectionAdapter(org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter) PacketReceivedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder) AbstractDeviceInitializer(org.opendaylight.openflowplugin.impl.device.initialization.AbstractDeviceInitializer) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) MultiMsgCollectorImpl(org.opendaylight.openflowplugin.impl.device.listener.MultiMsgCollectorImpl) ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) TransactionChainManager(org.opendaylight.openflowplugin.common.txchain.TransactionChainManager) DeviceInitializerProvider(org.opendaylight.openflowplugin.impl.device.initialization.DeviceInitializerProvider) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) PacketIn(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketIn) Xid(org.opendaylight.openflowplugin.api.openflow.device.Xid) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) Nullable(javax.annotation.Nullable) ContextChainMastershipState(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipState) AbstractRequestContext(org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ExtensionConverterProviderKeeper(org.opendaylight.openflowplugin.extension.api.ExtensionConverterProviderKeeper) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) TranslatorKey(org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey) ConvertorMessageFromOFJava(org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava) ContextChainHolder(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainHolder) DeviceFlowRegistryImpl(org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl) NodeConnectorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder) DeviceFlowRegistry(org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry) NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) NotificationPublishService(org.opendaylight.controller.md.sal.binding.api.NotificationPublishService) ContextChainMastershipWatcher(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipWatcher) ExperimenterMessageFromDevBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.ExperimenterMessageFromDevBuilder) MessagePath(org.opendaylight.openflowplugin.extension.api.path.MessagePath) MessageTranslator(org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator) DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Collection(java.util.Collection) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice) Objects(java.util.Objects) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) List(java.util.List) ContextChain(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain) ExperimenterMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage) MessageSpy(org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy) HashedWheelTimer(io.netty.util.HashedWheelTimer) MultiMsgCollector(org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector) Optional(java.util.Optional) DeviceMeterRegistryImpl(org.opendaylight.openflowplugin.impl.registry.meter.DeviceMeterRegistryImpl) InventoryDataServiceUtil(org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil) FlowRemoved(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConvertorExecutor(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MultipartWriterProviderFactory(org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory) DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) HashSet(java.util.HashSet) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) RequestContextUtil(org.opendaylight.openflowplugin.impl.services.util.RequestContextUtil) PortReason(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason) Nonnull(javax.annotation.Nonnull) PortStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) DeviceGroupRegistryImpl(org.opendaylight.openflowplugin.impl.registry.group.DeviceGroupRegistryImpl) Logger(org.slf4j.Logger) OFConstants(org.opendaylight.openflowplugin.api.OFConstants) TimeUnit(java.util.concurrent.TimeUnit) DeviceGroupRegistry(org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) RequestContext(org.opendaylight.openflowplugin.api.openflow.device.RequestContext) TranslatorLibrary(org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) MatchUtil(org.opendaylight.openflowplugin.impl.util.MatchUtil) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) PacketReceivedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder) ConnectionAdapter(org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter) DataObject(org.opendaylight.yangtools.yang.binding.DataObject)

Example 52 with PortNumber

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber in project openflowplugin by opendaylight.

the class OxmUdpSrcSerializerTest method prepareMatchEntry.

private static MatchEntryBuilder prepareMatchEntry(int value) {
    MatchEntryBuilder builder = prepareHeader(false);
    UdpSrcCaseBuilder casebuilder = new UdpSrcCaseBuilder();
    UdpSrcBuilder valueBuilder = new UdpSrcBuilder();
    valueBuilder.setPort(new PortNumber(value));
    casebuilder.setUdpSrc(valueBuilder.build());
    builder.setMatchEntryValue(casebuilder.build());
    return builder;
}
Also used : MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) UdpSrcBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.src._case.UdpSrcBuilder) UdpSrcCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpSrcCaseBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)

Example 53 with PortNumber

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber in project openflowplugin by opendaylight.

the class OxmTcpDstSerializerTest method prepareMatchEntry.

private static MatchEntryBuilder prepareMatchEntry(int value) {
    MatchEntryBuilder builder = prepareHeader(false);
    TcpDstCaseBuilder casebuilder = new TcpDstCaseBuilder();
    TcpDstBuilder valueBuilder = new TcpDstBuilder();
    valueBuilder.setPort(new PortNumber(value));
    casebuilder.setTcpDst(valueBuilder.build());
    builder.setMatchEntryValue(casebuilder.build());
    return builder;
}
Also used : TcpDstBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.dst._case.TcpDstBuilder) MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) TcpDstCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpDstCaseBuilder)

Example 54 with PortNumber

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber in project openflowplugin by opendaylight.

the class MatchResponseConvertor2Test method testLayer4MatchSctp.

/**
 * Test {@link MatchResponseConvertor#convert(MatchEntriesGrouping, VersionDatapathIdConvertorData)}.
 */
@Test
public void testLayer4MatchSctp() {
    final MatchBuilder builder = new MatchBuilder();
    builder.setType(OxmMatchType.class);
    final List<MatchEntry> entries = new ArrayList<>();
    MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(SctpSrc.class);
    entriesBuilder.setHasMask(false);
    final SctpSrcCaseBuilder sctpSrcCaseBuilder = new SctpSrcCaseBuilder();
    final SctpSrcBuilder portBuilder = new SctpSrcBuilder();
    portBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(13));
    sctpSrcCaseBuilder.setSctpSrc(portBuilder.build());
    entriesBuilder.setMatchEntryValue(sctpSrcCaseBuilder.build());
    entries.add(entriesBuilder.build());
    entriesBuilder = new MatchEntryBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(SctpDst.class);
    entriesBuilder.setHasMask(false);
    final SctpDstCaseBuilder sctpDstCaseBuilder = new SctpDstCaseBuilder();
    final SctpDstBuilder sctpDstBuilder = new SctpDstBuilder();
    sctpDstBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(14));
    sctpDstCaseBuilder.setSctpDst(sctpDstBuilder.build());
    entriesBuilder.setMatchEntryValue(sctpDstCaseBuilder.build());
    entries.add(entriesBuilder.build());
    builder.setMatchEntry(entries);
    final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);
    datapathIdConvertorData.setDatapathId(new BigInteger("42"));
    final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder salMatchBuilder = convert(builder.build(), datapathIdConvertorData);
    final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match builtMatch = salMatchBuilder.build();
    final SctpMatch udpMatch = (SctpMatch) builtMatch.getLayer4Match();
    Assert.assertEquals("Wrong sctp src port", 13, udpMatch.getSctpSourcePort().getValue().intValue());
    Assert.assertEquals("Wrong sctp dst port", 14, udpMatch.getSctpDestinationPort().getValue().intValue());
}
Also used : MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) SctpDstBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.sctp.dst._case.SctpDstBuilder) ArrayList(java.util.ArrayList) SctpDstCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.SctpDstCaseBuilder) MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) SctpSrcBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.sctp.src._case.SctpSrcBuilder) SctpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch) SctpSrcCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.SctpSrcCaseBuilder) BigInteger(java.math.BigInteger) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder) Test(org.junit.Test)

Example 55 with PortNumber

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber in project openflowplugin by opendaylight.

the class GroupDescStatsResponseConvertorTest method testGroupDescStats.

/**
 * Test single GroupDescStats conversion.
 */
@Test
public void testGroupDescStats() {
    // **********************************************
    // First group desc
    // **********************************************
    GroupDescBuilder builder = new GroupDescBuilder();
    builder.setType(GroupType.OFPGTFF);
    builder.setGroupId(new GroupId(42L));
    // Buckets for first group desc
    BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
    bucketsBuilder.setWeight(16);
    bucketsBuilder.setWatchPort(new PortNumber(84L));
    bucketsBuilder.setWatchGroup(168L);
    // Actions for buckets for first group desc
    List<Action> actions = new ArrayList<>();
    ActionBuilder actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new CopyTtlInCaseBuilder().build());
    actions.add(actionBuilder.build());
    // Build bucket with actions
    bucketsBuilder.setAction(actions);
    List<BucketsList> bucketsList = new ArrayList<>();
    bucketsList.add(bucketsBuilder.build());
    // Build first group desc
    builder.setBucketsList(bucketsList);
    List<GroupDesc> groupDescStats = new ArrayList<>();
    groupDescStats.add(builder.build());
    // **********************************************
    // Second group desc
    // **********************************************
    builder = new GroupDescBuilder();
    builder.setType(GroupType.OFPGTINDIRECT);
    builder.setGroupId(new GroupId(50L));
    // First buckets for second group desc
    bucketsList = new ArrayList<>();
    bucketsBuilder = new BucketsListBuilder();
    bucketsBuilder.setWeight(100);
    bucketsBuilder.setWatchPort(new PortNumber(200L));
    bucketsBuilder.setWatchGroup(400L);
    // Actions for first buckets for second group desc
    actions = new ArrayList<>();
    actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new CopyTtlOutCaseBuilder().build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new DecNwTtlCaseBuilder().build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new PopPbbCaseBuilder().build());
    actions.add(actionBuilder.build());
    // Build first bucket with actions
    bucketsBuilder.setAction(actions);
    bucketsList.add(bucketsBuilder.build());
    // Second buckets for second group desc
    bucketsBuilder = new BucketsListBuilder();
    bucketsBuilder.setWeight(5);
    bucketsBuilder.setWatchPort(new PortNumber(10L));
    bucketsBuilder.setWatchGroup(15L);
    // Actions for second buckets for second group desc
    actions = new ArrayList<>();
    // Build second bucket with actions
    bucketsBuilder.setAction(actions);
    bucketsList.add(bucketsBuilder.build());
    // Build second group desc
    builder.setBucketsList(bucketsList);
    groupDescStats.add(builder.build());
    VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
    List<GroupDescStats> statsList = convert(groupDescStats, data);
    Assert.assertEquals("Wrong groupDesc stats size", 2, statsList.size());
    // **********************************************
    // Test first group desc
    // **********************************************
    GroupDescStats stat = statsList.get(0);
    Assert.assertEquals("Wrong type", GroupTypes.GroupFf, stat.getGroupType());
    Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong buckets size", 1, stat.getBuckets().getBucket().size());
    // Test first bucket for first group desc
    Bucket bucket = stat.getBuckets().getBucket().get(0);
    Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 16, bucket.getWeight().intValue());
    Assert.assertEquals("Wrong type", 168, bucket.getWatchGroup().intValue());
    Assert.assertEquals("Wrong type", 84, bucket.getWatchPort().intValue());
    Assert.assertEquals("Wrong type", 1, bucket.getAction().size());
    // Test first action for first bucket for first group desc
    org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action = bucket.getAction().get(0);
    Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.CopyTtlInCase", action.getAction().getImplementedInterface().getName());
    // **********************************************
    // Test second group desc
    // **********************************************
    stat = statsList.get(1);
    Assert.assertEquals("Wrong type", GroupTypes.GroupIndirect, stat.getGroupType());
    Assert.assertEquals("Wrong group-id", 50, stat.getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong key", 50, stat.getKey().getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong buckets size", 2, stat.getBuckets().getBucket().size());
    // Test first bucket for second group desc
    bucket = stat.getBuckets().getBucket().get(0);
    Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 100, bucket.getWeight().intValue());
    Assert.assertEquals("Wrong type", 400, bucket.getWatchGroup().intValue());
    Assert.assertEquals("Wrong type", 200, bucket.getWatchPort().intValue());
    Assert.assertEquals("Wrong type", 3, bucket.getAction().size());
    // Test first action for first bucket of second group desc
    action = bucket.getAction().get(0);
    Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.CopyTtlOutCase", action.getAction().getImplementedInterface().getName());
    // Test second action for first bucket of second group desc
    action = bucket.getAction().get(1);
    Assert.assertEquals("Wrong type", 1, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.DecNwTtlCase", action.getAction().getImplementedInterface().getName());
    // Test third action for first bucket of second group desc
    action = bucket.getAction().get(2);
    Assert.assertEquals("Wrong type", 2, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.PopPbbActionCase", action.getAction().getImplementedInterface().getName());
    // Test second bucket for second group desc
    bucket = stat.getBuckets().getBucket().get(1);
    Assert.assertEquals("Wrong type", 1, bucket.getKey().getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 1, bucket.getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 5, bucket.getWeight().intValue());
    Assert.assertEquals("Wrong type", 15, bucket.getWatchGroup().intValue());
    Assert.assertEquals("Wrong type", 10, bucket.getWatchPort().intValue());
    Assert.assertEquals("Wrong type", 0, bucket.getAction().size());
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) PopPbbCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCaseBuilder) ArrayList(java.util.ArrayList) GroupDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDesc) GroupDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDescBuilder) GroupDescStats(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats) BucketsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder) CopyTtlInCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCaseBuilder) DecNwTtlCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCaseBuilder) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId) VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) BucketsList(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList) CopyTtlOutCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCaseBuilder) Test(org.junit.Test)

Aggregations

PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)98 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)81 Test (org.junit.Test)72 ArrayList (java.util.ArrayList)50 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)33 ByteBuf (io.netty.buffer.ByteBuf)29 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder)29 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)26 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)23 BigInteger (java.math.BigInteger)21 OutputActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder)19 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)18 TransportAddressBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder)17 TcpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder)17 OutputActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder)17 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)16 UdpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder)16 SctpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder)14 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)13 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)12