Merge remote-tracking branch 'liblldp/master'
[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.util.RequestInputUtils;
17 import org.opendaylight.openflowplugin.impl.services.util.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 extends AbstractCompatibleStatService<GetAllQueuesStatisticsFromAllPortsInput,
34                                                                            GetAllQueuesStatisticsFromAllPortsOutput,
35                                                                            QueueStatisticsUpdate> {
36
37     private static final MultipartRequestQueueCase QUEUE_CASE;
38
39     static {
40         MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
41         MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
42         // Select all ports
43         // Select all the ports
44         mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
45         mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
46         caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
47
48         QUEUE_CASE = caseBuilder.build();
49     }
50
51     AllQueuesAllPortsService(RequestContextStack requestContextStack,
52                                     DeviceContext deviceContext,
53                                     AtomicLong compatibilityXidSeed) {
54         super(requestContextStack, deviceContext, compatibilityXidSeed);
55     }
56
57     @Override
58     protected OfHeader buildRequest(final Xid xid,
59                                     final GetAllQueuesStatisticsFromAllPortsInput input) throws ServiceException {
60         // Set request body to main multipart request
61         MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
62                 MultipartType.OFPMPQUEUE, xid.getValue(), getVersion());
63         mprInput.setMultipartRequestBody(QUEUE_CASE);
64         return mprInput.build();
65     }
66
67     @Override
68     public GetAllQueuesStatisticsFromAllPortsOutput buildTxCapableResult(TransactionId emulatedTxId) {
69         return new GetAllQueuesStatisticsFromAllPortsOutputBuilder().setTransactionId(emulatedTxId).build();
70     }
71
72     @Override
73     public QueueStatisticsUpdate transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
74         return QueueStatisticsToNotificationTransformer.transformToNotification(result,
75                                                                                 getDeviceInfo(),
76                                                                                 getOfVersion(),
77                                                                                 emulatedTxId);
78     }
79 }