Fixup Augmentable and Identifiable methods changing
[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 final class FlowConvertorUtil {
22     private FlowConvertorUtil() {
23     }
24
25     /**
26      * Method wrapping all the actions
27      * org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action
28      * in org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action, to set
29      * appropriate keys for actions.
30      *
31      * @param actionList the action list
32      * @return the list
33      */
34     public static List<Action> wrapActionList(List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types
35             .rev131112.action.Action> actionList) {
36         List<Action> actions = new ArrayList<>();
37
38         int actionKey = 0;
39         for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action : actionList) {
40             ActionBuilder wrappedAction = new ActionBuilder();
41             wrappedAction.setAction(action);
42             wrappedAction.withKey(new ActionKey(actionKey));
43             wrappedAction.setOrder(actionKey);
44             actions.add(wrappedAction.build());
45             actionKey++;
46         }
47
48         return actions;
49     }
50
51     /**
52      * Safely gets ip protocol from flow.
53      *
54      * @param flow the flow
55      * @return the ip protocol from flow
56      */
57     public static Short getIpProtocolFromFlow(Flow flow) {
58         Short ipProtocol = null;
59
60         if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) {
61             ipProtocol = flow.getMatch().getIpMatch().getIpProtocol();
62         }
63
64         return ipProtocol;
65     }
66 }