5df1440ec25dbc89c66741d593d661ad94735c55
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / compatibility / GroupStatisticsToNotificationTransformer.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.openflow.md.core.sal.convertor.GroupStatsResponseConvertor;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdatedBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroup;
22
23 /**
24  * pulled out group stats to notification transformation
25  */
26 public class GroupStatisticsToNotificationTransformer {
27
28     private static GroupStatsResponseConvertor groupStatsConvertor = new GroupStatsResponseConvertor();
29
30     /**
31      * @param mpReplyList   raw multipart response from device
32      * @param deviceInfo   device state
33      * @param emulatedTxId
34      * @return notification containing flow stats
35      */
36     public static GroupStatisticsUpdated transformToNotification(final List<MultipartReply> mpReplyList,
37                                                                  final DeviceInfo deviceInfo,
38                                                                  final TransactionId emulatedTxId) {
39
40         GroupStatisticsUpdatedBuilder notification = new GroupStatisticsUpdatedBuilder();
41         notification.setId(deviceInfo.getNodeId());
42         notification.setMoreReplies(Boolean.FALSE);
43         notification.setTransactionId(emulatedTxId);
44
45         notification.setGroupStats(new ArrayList<GroupStats>());
46
47         for (MultipartReply mpReply : mpReplyList) {
48             MultipartReplyGroupCase caseBody = (MultipartReplyGroupCase) mpReply.getMultipartReplyBody();
49             MultipartReplyGroup replyBody = caseBody.getMultipartReplyGroup();
50             notification.getGroupStats().addAll(groupStatsConvertor.toSALGroupStatsList(replyBody.getGroupStats()));
51         }
52         return notification.build();
53     }
54 }