Use ByteBuf.readRetainedSlice()
[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.statistics.services.compatibility.AbstractCompatibleStatService;
18 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.QueueStatisticsToNotificationTransformer;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCase;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
31
32 final class AllQueuesAllPortsService extends AbstractCompatibleStatService<GetAllQueuesStatisticsFromAllPortsInput,
33                                                                            GetAllQueuesStatisticsFromAllPortsOutput,
34                                                                            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     AllQueuesAllPortsService(RequestContextStack requestContextStack,
51                                     DeviceContext deviceContext,
52                                     AtomicLong compatibilityXidSeed) {
53         super(requestContextStack, deviceContext, compatibilityXidSeed);
54     }
55
56     @Override
57     protected OfHeader buildRequest(final Xid xid,
58                                     final GetAllQueuesStatisticsFromAllPortsInput input) {
59         // Set request body to main multipart request
60         MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
61                 MultipartType.OFPMPQUEUE, xid.getValue(), getVersion());
62         mprInput.setMultipartRequestBody(QUEUE_CASE);
63         return mprInput.build();
64     }
65
66     @Override
67     public GetAllQueuesStatisticsFromAllPortsOutput buildTxCapableResult(TransactionId emulatedTxId) {
68         return new GetAllQueuesStatisticsFromAllPortsOutputBuilder().setTransactionId(emulatedTxId).build();
69     }
70
71     @Override
72     public QueueStatisticsUpdate transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
73         return QueueStatisticsToNotificationTransformer.transformToNotification(result,
74                                                                                 getDeviceInfo(),
75                                                                                 getOfVersion(),
76                                                                                 emulatedTxId);
77     }
78 }