X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fstatistics%2Fservices%2FOpendaylightFlowTableStatisticsServiceImpl.java;h=874346766d8dd95b6dfb797767ad52582b85615a;hb=cfe3a97837951ebbedb337dc988027f10c49f714;hp=410c44f0348a1d2a8224d89927d2c11ee2e6c975;hpb=4364a002384b6767321799e38a091b109b4161da;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowTableStatisticsServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowTableStatisticsServiceImpl.java index 410c44f034..874346766d 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowTableStatisticsServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowTableStatisticsServiceImpl.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -7,60 +7,111 @@ */ package org.opendaylight.openflowplugin.impl.statistics.services; -import com.google.common.base.Function; import com.google.common.util.concurrent.ListenableFuture; -import java.util.concurrent.Future; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; -import org.opendaylight.openflowplugin.impl.services.CommonService; -import org.opendaylight.openflowplugin.impl.services.RequestInputUtils; -import org.opendaylight.openflowplugin.impl.util.StatisticsServiceUtil; +import org.opendaylight.openflowplugin.impl.services.util.RequestInputUtils; +import org.opendaylight.openflowplugin.impl.services.util.ServiceException; +import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId; import org.opendaylight.yangtools.yang.common.RpcResult; -/** - * @author joe - */ -public class OpendaylightFlowTableStatisticsServiceImpl extends CommonService implements +public final class OpendaylightFlowTableStatisticsServiceImpl extends + AbstractCompatibleStatService implements OpendaylightFlowTableStatisticsService { - public OpendaylightFlowTableStatisticsServiceImpl(final RequestContextStack requestContextStack, DeviceContext deviceContext) { - super(requestContextStack, deviceContext); + private final NotificationPublishService notificationPublishService; + + public OpendaylightFlowTableStatisticsServiceImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, + final AtomicLong compatibilityXidSeed, + final NotificationPublishService notificationPublishService) { + super(requestContextStack, deviceContext, compatibilityXidSeed); + this.notificationPublishService = notificationPublishService; } @Override - public Future> getFlowTablesStatistics( + public ListenableFuture> getFlowTablesStatistics( final GetFlowTablesStatisticsInput input) { + return handleAndNotify(input, notificationPublishService); + } + + @Override + protected OfHeader buildRequest(final Xid xid, final GetFlowTablesStatisticsInput input) throws ServiceException { + // Create multipart request body for fetch all the group stats + final MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = + new MultipartRequestTableCaseBuilder(); + final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder(); + multipartRequestTableBuilder.setEmpty(true); + multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build()); + + // Set request body to main multipart request + final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader( + MultipartType.OFPMPTABLE, xid.getValue(), getVersion()); + mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build()); - return this.handleServiceCall(new Function, ListenableFuture>>() { + return mprInput.build(); + } - @Override - public ListenableFuture> apply(final RequestContext requestContext) { + @Override + public GetFlowTablesStatisticsOutput buildTxCapableResult(TransactionId emulatedTxId) { + return new GetFlowTablesStatisticsOutputBuilder().setTransactionId(emulatedTxId).build(); + } - // Create multipart request body for fetch all the group stats - final MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder(); - final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder(); - multipartRequestTableBuilder.setEmpty(true); - multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build()); + @Override + public FlowTableStatisticsUpdate transformToNotification(List mpReplyList, + TransactionId emulatedTxId) { + FlowTableStatisticsUpdateBuilder notification = new FlowTableStatisticsUpdateBuilder(); + notification.setId(getDeviceInfo().getNodeId()); + notification.setMoreReplies(Boolean.FALSE); + notification.setTransactionId(emulatedTxId); - // Set request body to main multipart request - final Xid xid = requestContext.getXid(); - final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader( - MultipartType.OFPMPFLOW, xid.getValue(), getVersion()); + final List salFlowStats = new ArrayList<>(); + notification.setFlowTableAndStatisticsMap(salFlowStats); + for (MultipartReply mpReply : mpReplyList) { + MultipartReplyTableCase caseBody = (MultipartReplyTableCase) mpReply.getMultipartReplyBody(); + MultipartReplyTable replyBody = caseBody.getMultipartReplyTable(); + List swTablesStats = replyBody.getTableStats(); - mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build()); - return StatisticsServiceUtil.getRpcResultListenableFuture(xid, mprInput.build(), getDeviceContext()); + //TODO: Duplicate code: look at MultiReplyTranslatorUtil method translateTable + for (TableStats swTableStats : swTablesStats) { + FlowTableAndStatisticsMapBuilder statisticsBuilder = new FlowTableAndStatisticsMapBuilder(); + statisticsBuilder.setActiveFlows(new Counter32(swTableStats.getActiveCount())); + statisticsBuilder.setPacketsLookedUp(new Counter64(swTableStats.getLookupCount())); + statisticsBuilder.setPacketsMatched(new Counter64(swTableStats.getMatchedCount())); + statisticsBuilder.setTableId(new TableId(swTableStats.getTableId())); + salFlowStats.add(statisticsBuilder.build()); } - }); - } + } + return notification.build(); + } }