Bug 5540 - FlowConvertor, FlowStatsResponseConvertor, FlowInstructionResponseConvertor
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / flow / FlowConvertorUtil.java
1 /*
2  * Copyright (c) 2016 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.openflow.md.core.sal.convertor.flow;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
17
18 /**
19  * Flow related utils
20  */
21 public abstract class FlowConvertorUtil {
22
23     /**
24      * Method wrapping all the actions org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action
25      * in org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action, to set appropriate keys
26      * for actions.
27      *
28      * @param actionList the action list
29      * @return the list
30      */
31     public static List<Action> wrapActionList(List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> actionList) {
32         List<Action> actions = new ArrayList<>();
33
34         int actionKey = 0;
35         for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action : actionList) {
36             ActionBuilder wrappedAction = new ActionBuilder();
37             wrappedAction.setAction(action);
38             wrappedAction.setKey(new ActionKey(actionKey));
39             wrappedAction.setOrder(actionKey);
40             actions.add(wrappedAction.build());
41             actionKey++;
42         }
43
44         return actions;
45     }
46
47     /**
48      * Safely gets ip protocol from flow.
49      *
50      * @param flow the flow
51      * @return the ip protocol from flow
52      */
53     public static Short getIpProtocolFromFlow(Flow flow) {
54         Short ipProtocol = null;
55
56         if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) {
57             ipProtocol = flow.getMatch().getIpMatch().getIpProtocol();
58         }
59
60         return ipProtocol;
61     }
62 }