2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action;
10 import static org.mockito.Mockito.when;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.Mock;
17 import org.mockito.Mockito;
18 import org.mockito.runners.MockitoJUnitRunner;
19 import org.opendaylight.openflowjava.nx.codec.match.NiciraMatchCodecs;
20 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjNxHashFields;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjNxMpAlgorithm;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionMultipath;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.multipath.grouping.NxActionMultipath;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIdCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIdCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.get.flow.statistics.output.flow.and.statistics.map.list.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.get.flow.statistics.output.flow.and.statistics.map.list.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.group.desc.stats.updated.group.desc.stats.buckets.bucket.action.action.NxActionMultipathNotifGroupDescStatsUpdatedCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionMultipathNodesNodeTableFlowWriteActionsCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.multipath.grouping.NxMultipath;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.multipath.grouping.nx.multipath.Dst;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * Test for {@link MultipathConvertor}.
42 @RunWith(MockitoJUnitRunner.class)
43 public class MultipathConvertorTest {
45 private static final Logger LOG = LoggerFactory.getLogger(MultipathConvertorTest.class);
48 private NxActionMultipathNodesNodeTableFlowWriteActionsCase bucketActionsCase;
51 private Action action;
53 private MultipathConvertor multipathConvertor;
57 final NxMultipath nxMultipath = Mockito.mock(NxMultipath.class);
58 when(bucketActionsCase.getNxMultipath()).thenReturn(nxMultipath);
60 final Dst dst = Mockito.mock(Dst.class);
61 when(dst.getStart()).thenReturn(1);
62 when(dst.getEnd()).thenReturn(2);
64 final DstNxTunIdCase dstNxTunIdCase = new DstNxTunIdCaseBuilder().build();
65 when(dst.getDstChoice()).thenReturn(dstNxTunIdCase);
66 when(nxMultipath.getFields()).thenReturn(OfjNxHashFields.NXHASHFIELDSETHSRC);
67 when(nxMultipath.getBasis()).thenReturn(2);
68 when(nxMultipath.getAlgorithm()).thenReturn(OfjNxMpAlgorithm.NXMPALGHASHTHRESHOLD);
69 when(nxMultipath.getMaxLink()).thenReturn(2);
70 when(nxMultipath.getArg()).thenReturn(2L);
71 when(nxMultipath.getDst()).thenReturn(dst);
73 final ActionMultipath actionMultipath = Mockito.mock(ActionMultipath.class);
74 final NxActionMultipath nxActionMultipath = Mockito.mock(NxActionMultipath.class);
75 when(nxActionMultipath.getDst()).thenReturn(NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong());
76 when(nxActionMultipath.getBasis()).thenReturn(1);
77 when(nxActionMultipath.getAlgorithm()).thenReturn(OfjNxMpAlgorithm.NXMPALGHRW);
78 when(nxActionMultipath.getMaxLink()).thenReturn(2);
79 when(nxActionMultipath.getArg()).thenReturn(2L);
80 when(actionMultipath.getNxActionMultipath()).thenReturn(nxActionMultipath);
81 when(action.getActionChoice()).thenReturn(actionMultipath);
83 multipathConvertor = new MultipathConvertor();
87 public void testConvert() {
88 final ActionMultipath actionMultipath =
89 (ActionMultipath) multipathConvertor.convert(bucketActionsCase).getActionChoice();
90 Assert.assertEquals(OfjNxHashFields.NXHASHFIELDSETHSRC, actionMultipath.getNxActionMultipath().getFields());
91 Assert.assertEquals(Integer.valueOf(2), actionMultipath.getNxActionMultipath().getBasis());
92 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHASHTHRESHOLD,
93 actionMultipath.getNxActionMultipath().getAlgorithm());
94 Assert.assertEquals(Integer.valueOf(2), actionMultipath.getNxActionMultipath().getMaxLink());
95 Assert.assertEquals(Long.valueOf(2L), actionMultipath.getNxActionMultipath().getArg());
99 public void testConvert1() {
100 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult
101 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS);
102 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult1
103 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_UPDATE_WRITE_ACTIONS);
104 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult2
105 = multipathConvertor.convert(action, ActionPath.GROUP_DESC_STATS_UPDATED_BUCKET_ACTION);
106 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult3
107 = multipathConvertor.convert(action, ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS);
108 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult4
109 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_RPC_APPLY_ACTIONS);
110 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult5
111 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_RPC_WRITE_ACTIONS);
113 Assert.assertEquals(Integer.valueOf(1),
114 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
116 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
117 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
119 Assert.assertEquals(Long.valueOf(2L),
120 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath().getArg());
121 Assert.assertEquals(Integer.valueOf(2),
122 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
125 Assert.assertEquals(Integer.valueOf(1),
126 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
128 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
129 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
131 Assert.assertEquals(Long.valueOf(2L),
132 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
134 Assert.assertEquals(Integer.valueOf(2),
135 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
138 Assert.assertEquals(Integer.valueOf(1),
139 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getBasis());
140 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
141 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getAlgorithm());
142 Assert.assertEquals(Long.valueOf(2L),
143 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getArg());
144 Assert.assertEquals(Integer.valueOf(2),
145 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getMaxLink());
147 Assert.assertEquals(Integer.valueOf(1),
148 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getBasis());
149 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
150 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getAlgorithm());
151 Assert.assertEquals(Long.valueOf(2L),
152 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getArg());
153 Assert.assertEquals(Integer.valueOf(2),
154 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getMaxLink());
156 Assert.assertEquals(Integer.valueOf(1),
157 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
159 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
160 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
162 Assert.assertEquals(Long.valueOf(2L),
163 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
165 Assert.assertEquals(Integer.valueOf(2),
166 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
169 Assert.assertEquals(Integer.valueOf(1),
170 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
172 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
173 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
175 Assert.assertEquals(Long.valueOf(2L),
176 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
178 Assert.assertEquals(Integer.valueOf(2),
179 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()