054a99ac36cd77121ac77774005f9c2895afeb7b
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / AllQueuesAllPortsService.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.impl.statistics.services;
9
10 import java.util.List;
11 import java.util.concurrent.atomic.AtomicLong;
12 import org.opendaylight.openflowplugin.api.OFConstants;
13 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
14 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
15 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
16 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
17 import org.opendaylight.openflowplugin.impl.services.ServiceException;
18 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
19 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.QueueStatisticsToNotificationTransformer;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCase;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
32
33 final class AllQueuesAllPortsService
34         extends AbstractCompatibleStatService<GetAllQueuesStatisticsFromAllPortsInput, GetAllQueuesStatisticsFromAllPortsOutput, QueueStatisticsUpdate> {
35
36     private static final MultipartRequestQueueCase QUEUE_CASE;
37
38     static {
39         MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
40         MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
41         // Select all ports
42         // Select all the ports
43         mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
44         mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
45         caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
46
47         QUEUE_CASE = caseBuilder.build();
48     }
49
50     public AllQueuesAllPortsService(RequestContextStack requestContextStack, DeviceContext deviceContext, AtomicLong compatibilityXidSeed) {
51         super(requestContextStack, deviceContext, compatibilityXidSeed);
52     }
53
54     @Override
55     protected OfHeader buildRequest(final Xid xid, final GetAllQueuesStatisticsFromAllPortsInput input) throws ServiceException {
56         // Set request body to main multipart request
57         MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
58                 MultipartType.OFPMPQUEUE, xid.getValue(), getVersion());
59         mprInput.setMultipartRequestBody(QUEUE_CASE);
60         return mprInput.build();
61     }
62
63     @Override
64     public GetAllQueuesStatisticsFromAllPortsOutput buildTxCapableResult(TransactionId emulatedTxId) {
65         return new GetAllQueuesStatisticsFromAllPortsOutputBuilder().setTransactionId(emulatedTxId).build();
66     }
67
68     @Override
69     public QueueStatisticsUpdate transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
70         return QueueStatisticsToNotificationTransformer.transformToNotification(result, getDeviceInfo(), getOfVersion(), emulatedTxId);
71     }
72 }