Mark potentially-static methods as static
[genius.git] / mdsalutil / mdsalutil-api / src / test / java / org / opendaylight / genius / mdsalutil / actions / ActionLearnTest.java
1 /*
2  * Copyright © 2016 Red Hat, Inc. and others.
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 package org.opendaylight.genius.mdsalutil.actions;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12
13 import java.util.Arrays;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Action;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModAddMatchFromFieldCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModAddMatchFromValueCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModCopyFieldIntoFieldCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModCopyValueIntoFieldCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModOutputToPortCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.flow.mod.add.match.from.field._case.FlowModAddMatchFromField;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.flow.mod.add.match.from.value._case.FlowModAddMatchFromValue;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.flow.mod.copy.field.into.field._case.FlowModCopyFieldIntoField;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.flow.mod.copy.value.into.field._case.FlowModCopyValueIntoField;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.flow.mod.output.to.port._case.FlowModOutputToPort;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionLearnNodesNodeTableFlowApplyActionsCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.learn.grouping.NxLearn;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.learn.grouping.nx.learn.FlowMods;
29 import org.opendaylight.yangtools.yang.common.Uint64;
30
31 /**
32  * Test class for {@link ActionRegLoad}.
33  */
34 public class ActionLearnTest {
35     private static final int IDLE_TIMEOUT = 2;
36     private static final int HARD_TIMEOUT = 3;
37     private static final int PRIORITY = 4;
38     private static final Uint64 COOKIE = Uint64.valueOf(5);
39     private static final int FLAGS = 6;
40     private static final short TABLE_ID = (short) 7;
41     private static final int FIN_IDLE_TIMEOUT = 8;
42     private static final int FIN_HARD_TIMEOUT = 9;
43
44     private static void verifyAction(Action action) {
45         assertTrue(action.getAction() instanceof NxActionLearnNodesNodeTableFlowApplyActionsCase);
46         NxActionLearnNodesNodeTableFlowApplyActionsCase nxAction =
47             (NxActionLearnNodesNodeTableFlowApplyActionsCase) action.getAction();
48         NxLearn nxLearn = nxAction.getNxLearn();
49         assertEquals(IDLE_TIMEOUT, nxLearn.getIdleTimeout().intValue());
50         assertEquals(HARD_TIMEOUT, nxLearn.getHardTimeout().intValue());
51         assertEquals(PRIORITY, nxLearn.getPriority().intValue());
52         assertEquals(COOKIE, nxLearn.getCookie());
53         assertEquals(FLAGS, nxLearn.getFlags().intValue());
54         assertEquals(TABLE_ID, nxLearn.getTableId().shortValue());
55         assertEquals(FIN_IDLE_TIMEOUT, nxLearn.getFinIdleTimeout().intValue());
56         assertEquals(FIN_HARD_TIMEOUT, nxLearn.getFinHardTimeout().intValue());
57
58         assertEquals(5, nxLearn.getFlowMods().size());
59
60         int nbChecked = 0;
61         for (FlowMods flowMods : nxLearn.getFlowMods()) {
62             if (flowMods.getFlowModSpec() instanceof FlowModAddMatchFromFieldCase) {
63                 FlowModAddMatchFromFieldCase flowModAddMatchFromFieldCase =
64                     (FlowModAddMatchFromFieldCase) flowMods.getFlowModSpec();
65                 FlowModAddMatchFromField flowModAddMatchFromField =
66                     flowModAddMatchFromFieldCase.getFlowModAddMatchFromField();
67                 assertEquals(0, flowModAddMatchFromField.getSrcOfs().intValue());
68                 assertEquals(1, flowModAddMatchFromField.getSrcField().longValue());
69                 assertEquals(0, flowModAddMatchFromField.getDstOfs().intValue());
70                 assertEquals(2, flowModAddMatchFromField.getDstField().longValue());
71                 assertEquals(3, flowModAddMatchFromField.getFlowModNumBits().intValue());
72                 nbChecked++;
73             } else if (flowMods.getFlowModSpec() instanceof FlowModAddMatchFromValueCase) {
74                 FlowModAddMatchFromValueCase flowModAddMatchFromValueCase =
75                     (FlowModAddMatchFromValueCase) flowMods.getFlowModSpec();
76                 FlowModAddMatchFromValue flowModAddMatchFromValue =
77                     flowModAddMatchFromValueCase.getFlowModAddMatchFromValue();
78                 assertEquals(4, flowModAddMatchFromValue.getValue().intValue());
79                 assertEquals(0, flowModAddMatchFromValue.getSrcOfs().intValue());
80                 assertEquals(5, flowModAddMatchFromValue.getSrcField().longValue());
81                 assertEquals(6, flowModAddMatchFromValue.getFlowModNumBits().intValue());
82                 nbChecked++;
83             } else if (flowMods.getFlowModSpec() instanceof FlowModCopyFieldIntoFieldCase) {
84                 FlowModCopyFieldIntoFieldCase flowModCopyFieldIntoFieldCase =
85                     (FlowModCopyFieldIntoFieldCase) flowMods.getFlowModSpec();
86                 FlowModCopyFieldIntoField flowModCopyFieldIntoField =
87                     flowModCopyFieldIntoFieldCase.getFlowModCopyFieldIntoField();
88                 assertEquals(0, flowModCopyFieldIntoField.getSrcOfs().intValue());
89                 assertEquals(7, flowModCopyFieldIntoField.getSrcField().longValue());
90                 assertEquals(0, flowModCopyFieldIntoField.getDstOfs().intValue());
91                 assertEquals(8, flowModCopyFieldIntoField.getDstField().longValue());
92                 assertEquals(9, flowModCopyFieldIntoField.getFlowModNumBits().intValue());
93                 nbChecked++;
94             } else if (flowMods.getFlowModSpec() instanceof FlowModCopyValueIntoFieldCase) {
95                 FlowModCopyValueIntoFieldCase flowModCopyValueIntoFieldCase =
96                     (FlowModCopyValueIntoFieldCase) flowMods.getFlowModSpec();
97                 FlowModCopyValueIntoField flowModCopyValueIntoField =
98                     flowModCopyValueIntoFieldCase.getFlowModCopyValueIntoField();
99                 assertEquals(10, flowModCopyValueIntoField.getValue().intValue());
100                 assertEquals(0, flowModCopyValueIntoField.getDstOfs().intValue());
101                 assertEquals(11, flowModCopyValueIntoField.getDstField().longValue());
102                 assertEquals(12, flowModCopyValueIntoField.getFlowModNumBits().intValue());
103                 nbChecked++;
104             } else if (flowMods.getFlowModSpec() instanceof FlowModOutputToPortCase) {
105                 FlowModOutputToPortCase flowModOutputToPortCase = (FlowModOutputToPortCase) flowMods.getFlowModSpec();
106                 FlowModOutputToPort flowModCopyFieldIntoField = flowModOutputToPortCase.getFlowModOutputToPort();
107                 assertEquals(0, flowModCopyFieldIntoField.getSrcOfs().intValue());
108                 assertEquals(13, flowModCopyFieldIntoField.getSrcField().longValue());
109                 assertEquals(14, flowModCopyFieldIntoField.getFlowModNumBits().intValue());
110                 nbChecked++;
111             }
112         }
113         assertEquals(5, nbChecked);
114     }
115
116     @Test
117     public void actionInfoTestForLearnAction() {
118         verifyAction(buildActionLearn().buildAction());
119     }
120
121     private static ActionLearn buildActionLearn() {
122         return new ActionLearn(IDLE_TIMEOUT, HARD_TIMEOUT, PRIORITY, COOKIE, FLAGS, TABLE_ID, FIN_IDLE_TIMEOUT,
123             FIN_HARD_TIMEOUT,
124             Arrays.asList(
125                 new ActionLearn.MatchFromField(1, 2, 3),
126                 new ActionLearn.MatchFromValue(4, 5, 6),
127                 new ActionLearn.CopyFromField(7, 8, 9),
128                 new ActionLearn.CopyFromValue(10, 11, 12),
129                 new ActionLearn.OutputToPort(13, 14)
130                 ));
131     }
132 }