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
9 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action;
11 import static org.mockito.Mockito.when;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.openflowjava.nx.codec.match.NiciraMatchCodecs;
21 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjNxHashFields;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjNxMpAlgorithm;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionMultipath;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.multipath.grouping.NxActionMultipath;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIdCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIdCaseBuilder;
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.apply.actions._case.apply.actions.action.action.NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase;
30 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;
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.apply.actions._case.apply.actions.action.action.NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase;
32 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;
33 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;
34 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;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.multipath.grouping.NxMultipath;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.multipath.grouping.nx.multipath.Dst;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
41 * Test for {@link MultipathConvertor}.
43 @RunWith(MockitoJUnitRunner.class)
44 public class MultipathConvertorTest {
46 private static final Logger LOG = LoggerFactory.getLogger(MultipathConvertorTest.class);
49 private NxActionMultipathNodesNodeTableFlowWriteActionsCase bucketActionsCase;
52 private Action action;
54 private MultipathConvertor multipathConvertor;
58 final NxMultipath nxMultipath = Mockito.mock(NxMultipath.class);
59 when(bucketActionsCase.getNxMultipath()).thenReturn(nxMultipath);
61 final Dst dst = Mockito.mock(Dst.class);
62 when(dst.getStart()).thenReturn(1);
63 when(dst.getEnd()).thenReturn(2);
65 final DstNxTunIdCase dstNxTunIdCase = new DstNxTunIdCaseBuilder().build();
66 when(dst.getDstChoice()).thenReturn(dstNxTunIdCase);
67 when(nxMultipath.getFields()).thenReturn(OfjNxHashFields.NXHASHFIELDSETHSRC);
68 when(nxMultipath.getBasis()).thenReturn(2);
69 when(nxMultipath.getAlgorithm()).thenReturn(OfjNxMpAlgorithm.NXMPALGHASHTHRESHOLD);
70 when(nxMultipath.getMaxLink()).thenReturn(2);
71 when(nxMultipath.getArg()).thenReturn(2L);
72 when(nxMultipath.getDst()).thenReturn(dst);
74 final ActionMultipath actionMultipath = Mockito.mock(ActionMultipath.class);
75 final NxActionMultipath nxActionMultipath = Mockito.mock(NxActionMultipath.class);
76 when(nxActionMultipath.getDst()).thenReturn(NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong());
77 when(nxActionMultipath.getBasis()).thenReturn(1);
78 when(nxActionMultipath.getAlgorithm()).thenReturn(OfjNxMpAlgorithm.NXMPALGHRW);
79 when(nxActionMultipath.getMaxLink()).thenReturn(2);
80 when(nxActionMultipath.getArg()).thenReturn(2L);
81 when(actionMultipath.getNxActionMultipath()).thenReturn(nxActionMultipath);
82 when(action.getActionChoice()).thenReturn(actionMultipath);
84 multipathConvertor = new MultipathConvertor();
88 public void testConvert() {
89 final ActionMultipath actionMultipath =
90 (ActionMultipath) multipathConvertor.convert(bucketActionsCase).getActionChoice();
91 Assert.assertEquals(OfjNxHashFields.NXHASHFIELDSETHSRC, actionMultipath.getNxActionMultipath().getFields());
92 Assert.assertEquals(Integer.valueOf(2), actionMultipath.getNxActionMultipath().getBasis());
93 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHASHTHRESHOLD,
94 actionMultipath.getNxActionMultipath().getAlgorithm());
95 Assert.assertEquals(Integer.valueOf(2), actionMultipath.getNxActionMultipath().getMaxLink());
96 Assert.assertEquals(Long.valueOf(2L), actionMultipath.getNxActionMultipath().getArg());
100 public void testConvert1() {
101 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult
102 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS);
103 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult1
104 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_UPDATE_WRITE_ACTIONS);
105 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult2
106 = multipathConvertor.convert(action, ActionPath.GROUP_DESC_STATS_UPDATED_BUCKET_ACTION);
107 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult3
108 = multipathConvertor.convert(action, ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS);
109 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult4
110 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_RPC_APPLY_ACTIONS);
111 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult5
112 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_RPC_WRITE_ACTIONS);
114 Assert.assertEquals(Integer.valueOf(1),
115 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
117 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
118 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
120 Assert.assertEquals(Long.valueOf(2L),
121 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath().getArg());
122 Assert.assertEquals(Integer.valueOf(2),
123 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
126 Assert.assertEquals(Integer.valueOf(1),
127 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
129 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
130 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
132 Assert.assertEquals(Long.valueOf(2L),
133 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
135 Assert.assertEquals(Integer.valueOf(2),
136 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
139 Assert.assertEquals(Integer.valueOf(1),
140 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getBasis());
141 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
142 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getAlgorithm());
143 Assert.assertEquals(Long.valueOf(2L),
144 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getArg());
145 Assert.assertEquals(Integer.valueOf(2),
146 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getMaxLink());
148 Assert.assertEquals(Integer.valueOf(1),
149 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getBasis());
150 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
151 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getAlgorithm());
152 Assert.assertEquals(Long.valueOf(2L),
153 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getArg());
154 Assert.assertEquals(Integer.valueOf(2),
155 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getMaxLink());
157 Assert.assertEquals(Integer.valueOf(1),
158 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
160 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
161 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
163 Assert.assertEquals(Long.valueOf(2L),
164 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
166 Assert.assertEquals(Integer.valueOf(2),
167 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
170 Assert.assertEquals(Integer.valueOf(1),
171 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
173 Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
174 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
176 Assert.assertEquals(Long.valueOf(2L),
177 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
179 Assert.assertEquals(Integer.valueOf(2),
180 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()