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