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.junit.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.opendaylight.yangtools.yang.common.Uint16;
37 import org.opendaylight.yangtools.yang.common.Uint32;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * Test for {@link MultipathConvertor}.
44 @RunWith(MockitoJUnitRunner.class)
45 public class MultipathConvertorTest {
47 private static final Logger LOG = LoggerFactory.getLogger(MultipathConvertorTest.class);
50 private NxActionMultipathNodesNodeTableFlowWriteActionsCase bucketActionsCase;
53 private Action action;
55 private MultipathConvertor multipathConvertor;
59 final NxMultipath nxMultipath = Mockito.mock(NxMultipath.class);
60 when(bucketActionsCase.getNxMultipath()).thenReturn(nxMultipath);
62 final Dst dst = Mockito.mock(Dst.class);
63 when(dst.getStart()).thenReturn(Uint16.ONE);
64 when(dst.getEnd()).thenReturn(Uint16.valueOf(2));
66 final DstNxTunIdCase dstNxTunIdCase = new DstNxTunIdCaseBuilder().build();
67 when(dst.getDstChoice()).thenReturn(dstNxTunIdCase);
68 when(nxMultipath.getFields()).thenReturn(OfjNxHashFields.NXHASHFIELDSETHSRC);
69 when(nxMultipath.getBasis()).thenReturn(Uint16.valueOf(2));
70 when(nxMultipath.getAlgorithm()).thenReturn(OfjNxMpAlgorithm.NXMPALGHASHTHRESHOLD);
71 when(nxMultipath.getMaxLink()).thenReturn(Uint16.valueOf(2));
72 when(nxMultipath.getArg()).thenReturn(Uint32.valueOf(2));
73 when(nxMultipath.getDst()).thenReturn(dst);
75 final ActionMultipath actionMultipath = Mockito.mock(ActionMultipath.class);
76 final NxActionMultipath nxActionMultipath = Mockito.mock(NxActionMultipath.class);
77 when(nxActionMultipath.getDst()).thenReturn(
78 Uint32.valueOf(NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong()));
79 when(nxActionMultipath.getBasis()).thenReturn(Uint16.ONE);
80 when(nxActionMultipath.getAlgorithm()).thenReturn(OfjNxMpAlgorithm.NXMPALGHRW);
81 when(nxActionMultipath.getMaxLink()).thenReturn(Uint16.valueOf(2));
82 when(nxActionMultipath.getArg()).thenReturn(Uint32.valueOf(2));
83 when(nxActionMultipath.getOfsNbits()).thenReturn(Uint16.ZERO);
84 when(actionMultipath.getNxActionMultipath()).thenReturn(nxActionMultipath);
85 when(action.getActionChoice()).thenReturn(actionMultipath);
87 multipathConvertor = new MultipathConvertor();
91 public void testConvert() {
92 final ActionMultipath actionMultipath =
93 (ActionMultipath) multipathConvertor.convert(bucketActionsCase).getActionChoice();
94 Assert.assertEquals(OfjNxHashFields.NXHASHFIELDSETHSRC, actionMultipath.getNxActionMultipath().getFields());
95 Assert.assertEquals(Uint16.valueOf(2), actionMultipath.getNxActionMultipath().getBasis());
96 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHASHTHRESHOLD,
97 actionMultipath.getNxActionMultipath().getAlgorithm());
98 Assert.assertEquals(Uint16.valueOf(2), actionMultipath.getNxActionMultipath().getMaxLink());
99 Assert.assertEquals(Uint32.valueOf(2L), actionMultipath.getNxActionMultipath().getArg());
103 public void testConvert1() {
104 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult
105 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS);
106 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult1
107 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_UPDATE_WRITE_ACTIONS);
108 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult2
109 = multipathConvertor.convert(action, ActionPath.GROUP_DESC_STATS_UPDATED_BUCKET_ACTION);
110 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult3
111 = multipathConvertor.convert(action, ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS);
112 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult4
113 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_RPC_APPLY_ACTIONS);
114 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult5
115 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_RPC_WRITE_ACTIONS);
117 Assert.assertEquals(Uint16.ONE,
118 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
120 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
121 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
123 Assert.assertEquals(Uint32.valueOf(2L),
124 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath().getArg());
125 Assert.assertEquals(Uint16.valueOf(2),
126 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
129 Assert.assertEquals(Uint16.ONE,
130 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
132 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
133 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
135 Assert.assertEquals(Uint32.valueOf(2L),
136 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
138 Assert.assertEquals(Uint16.valueOf(2),
139 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
142 Assert.assertEquals(Uint16.ONE,
143 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getBasis());
144 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
145 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getAlgorithm());
146 Assert.assertEquals(Uint32.valueOf(2L),
147 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getArg());
148 Assert.assertEquals(Uint16.valueOf(2),
149 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getMaxLink());
151 Assert.assertEquals(Uint16.ONE,
152 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getBasis());
153 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
154 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getAlgorithm());
155 Assert.assertEquals(Uint32.valueOf(2L),
156 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getArg());
157 Assert.assertEquals(Uint16.valueOf(2),
158 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getMaxLink());
160 Assert.assertEquals(Uint16.ONE,
161 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
163 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
164 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
166 Assert.assertEquals(Uint32.valueOf(2L),
167 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
169 Assert.assertEquals(Uint16.valueOf(2),
170 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
173 Assert.assertEquals(Uint16.ONE,
174 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
176 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
177 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
179 Assert.assertEquals(Uint32.valueOf(2L),
180 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
182 Assert.assertEquals(Uint16.valueOf(2),
183 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()