2 * Copyright (c) 2014 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.openflow.md.core.sal.convertor;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstructionBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstructionBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase;
34 * Created by Martin Bobak mbobak@cisco.com on 9/18/14.
36 public class OFToMDSalFlowConvertorTest {
38 private static final int PRESET_COUNT = 7;
42 * Test method for {@link OFToMDSalFlowConvertor#wrapOF10ActionsToInstruction(java.util.List, org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion)}
44 public void testWrapOF10ActionsToInstruction() {
45 ActionBuilder actionBuilder = new ActionBuilder();
46 List<Action> actions = new ArrayList<>();
47 for (int j = 0; j < PRESET_COUNT; j++) {
48 actionBuilder.setType(MockActionBase.class);
49 actions.add(actionBuilder.build());
51 Instructions instructions = OFToMDSalFlowConvertor.wrapOF10ActionsToInstruction(actions, OpenflowVersion.OF13);
52 assertNotNull(instructions);
56 * Test method for {@link OFToMDSalFlowConvertor#toSALInstruction(java.util.List, org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion)}
58 public void testToSALInstruction() {
59 List<Instruction> instructionsList = new ArrayList<>();
60 InstructionBuilder instructionBuilder = new InstructionBuilder();
61 for (int i = 0; i < PRESET_COUNT; i++) {
62 instructionBuilder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class);
63 ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
64 ActionBuilder actionBuilder = new ActionBuilder();
65 List<Action> actions = new ArrayList<>();
66 for (int j = 0; j < PRESET_COUNT; j++) {
67 actionBuilder.setType(MockActionBase.class);
68 actions.add(actionBuilder.build());
70 actionsInstructionBuilder.setAction(actions);
71 instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
72 instructionsList.add(instructionBuilder.build());
75 Instructions instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13);
76 assertNotNull(instructions);
77 assertEquals(PRESET_COUNT, instructions.getInstruction().size());
79 instructionsList = new ArrayList<>();
80 for (int i = 0; i < PRESET_COUNT; i++) {
81 instructionBuilder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class);
82 TableIdInstructionBuilder tableIdInstructionBuilder = new TableIdInstructionBuilder();
83 tableIdInstructionBuilder.setTableId((short) i);
84 instructionBuilder.addAugmentation(TableIdInstruction.class, tableIdInstructionBuilder.build());
85 instructionsList.add(instructionBuilder.build());
88 instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13);
89 assertNotNull(instructions);
90 assertEquals(PRESET_COUNT, instructions.getInstruction().size());
92 instructionsList = new ArrayList<>();
93 for (int i = 0; i < PRESET_COUNT; i++) {
94 instructionBuilder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class);
95 MeterIdInstructionBuilder meterIdInstructionBuilder = new MeterIdInstructionBuilder();
96 meterIdInstructionBuilder.setMeterId(Long.valueOf(i));
97 instructionBuilder.addAugmentation(MeterIdInstruction.class, meterIdInstructionBuilder.build());
98 instructionsList.add(instructionBuilder.build());
101 instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13);
102 assertNotNull(instructions);
103 assertEquals(PRESET_COUNT, instructions.getInstruction().size());
106 instructionsList = new ArrayList<>();
107 for (int i = 0; i < PRESET_COUNT; i++) {
108 instructionBuilder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class);
109 ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
110 ActionBuilder actionBuilder = new ActionBuilder();
111 List<Action> actions = new ArrayList<>();
112 for (int j = 0; j < PRESET_COUNT; j++) {
113 actionBuilder.setType(MockActionBase.class);
114 actions.add(actionBuilder.build());
116 actionsInstructionBuilder.setAction(actions);
117 instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
118 instructionsList.add(instructionBuilder.build());
121 instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13);
122 assertNotNull(instructions);
123 assertEquals(PRESET_COUNT, instructions.getInstruction().size());
126 instructionsList = new ArrayList<>();
127 for (int i = 0; i < PRESET_COUNT; i++) {
128 instructionBuilder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class);
129 MetadataInstructionBuilder metadataInstructionBuilder = new MetadataInstructionBuilder();
130 metadataInstructionBuilder.setMetadata(new byte[i]);
131 metadataInstructionBuilder.setMetadataMask(new byte[i]);
132 instructionBuilder.addAugmentation(MetadataInstruction.class, metadataInstructionBuilder.build());
133 instructionsList.add(instructionBuilder.build());
136 instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13);
137 assertNotNull(instructions);
138 assertEquals(PRESET_COUNT, instructions.getInstruction().size());
143 private static final class MockActionBase extends ActionBase {