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