f4f09234fb4b7a08e311145e5cd151a76b18af1d
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / compatibility / MeterStatisticsToNotificationTransformer.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
9 package org.opendaylight.openflowplugin.impl.statistics.services.compatibility;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
14 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
15 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterStatsResponseConvertor;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdatedBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeter;
23
24 /**
25  * pulled out meter stats to notification transformation
26  */
27 public class MeterStatisticsToNotificationTransformer {
28
29     private static MeterStatsResponseConvertor meterStatsConvertor = new MeterStatsResponseConvertor();
30
31     /**
32      * @param mpReplyList   raw multipart response from device
33      * @param deviceInfo   device state
34      * @param ofVersion     device version
35      * @param emulatedTxId
36      * @return notification containing flow stats
37      */
38     public static MeterStatisticsUpdated transformToNotification(final List<MultipartReply> mpReplyList,
39                                                                  final DeviceInfo deviceInfo,
40                                                                  final OpenflowVersion ofVersion,
41                                                                  final TransactionId emulatedTxId) {
42
43         MeterStatisticsUpdatedBuilder notification = new MeterStatisticsUpdatedBuilder();
44         notification.setId(deviceInfo.getNodeId());
45         notification.setMoreReplies(Boolean.FALSE);
46         notification.setTransactionId(emulatedTxId);
47
48         notification.setMeterStats(new ArrayList<MeterStats>());
49         for (MultipartReply mpReply : mpReplyList) {
50             MultipartReplyMeterCase caseBody = (MultipartReplyMeterCase) mpReply.getMultipartReplyBody();
51             MultipartReplyMeter replyBody = caseBody.getMultipartReplyMeter();
52             notification.getMeterStats().addAll(meterStatsConvertor.toSALMeterStatsList(replyBody.getMeterStats()));
53         }
54
55         return notification.build();
56     }
57 }