2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.openflowjava.protocol.impl.util;
\r
11 import org.junit.Assert;
\r
12 import org.junit.Test;
\r
13 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
\r
14 import org.opendaylight.openflowjava.protocol.api.keys.ActionSerializerKey;
\r
15 import org.opendaylight.openflowjava.protocol.api.keys.InstructionSerializerKey;
\r
16 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
\r
17 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterActionSerializerKey;
\r
18 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterInstructionSerializerKey;
\r
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdAction;
\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdActionBuilder;
\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdInstruction;
\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdInstructionBuilder;
\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdMatchEntry;
\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdMatchEntryBuilder;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;
\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.ExperimenterActionSubType;
\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;
\r
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
\r
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
\r
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable;
\r
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
\r
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
\r
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
\r
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass;
\r
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
\r
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
\r
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
\r
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
\r
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
\r
43 * @author michal.polkorab
\r
46 public class TypeKeyMakerFactoryTest {
\r
49 * Tests {@link TypeKeyMakerFactory#createActionKeyMaker(short)}
\r
52 public void testActionKeyMaker() {
\r
53 TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
\r
54 Assert.assertNotNull("Null keyMaker", keyMaker);
\r
56 ActionBuilder builder = new ActionBuilder();
\r
57 builder.setType(Output.class);
\r
58 Action action = builder.build();
\r
59 MessageTypeKey<?> key = keyMaker.make(action);
\r
61 Assert.assertNotNull("Null key", key);
\r
62 Assert.assertEquals("Wrong key", new ActionSerializerKey<>(EncodeConstants.OF13_VERSION_ID,
\r
63 Output.class, null), key);
\r
67 * Tests {@link TypeKeyMakerFactory#createActionKeyMaker(short)}
\r
70 public void testExperimenterActionKeyMaker() {
\r
71 TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
\r
72 Assert.assertNotNull("Null keyMaker", keyMaker);
\r
74 ActionBuilder builder = new ActionBuilder();
\r
75 builder.setType(Experimenter.class);
\r
76 ExperimenterIdActionBuilder expIdBuilder = new ExperimenterIdActionBuilder();
\r
77 expIdBuilder.setExperimenter(new ExperimenterId(42L));
\r
78 expIdBuilder.setSubType(ActionSubtypeClass.class);
\r
79 builder.addAugmentation(ExperimenterIdAction.class, expIdBuilder.build());
\r
80 Action action = builder.build();
\r
81 MessageTypeKey<?> key = keyMaker.make(action);
\r
83 Assert.assertNotNull("Null key", key);
\r
84 Assert.assertEquals("Wrong key", new ExperimenterActionSerializerKey(EncodeConstants.OF13_VERSION_ID, 42L,
\r
85 ActionSubtypeClass.class), key);
\r
89 * Tests {@link TypeKeyMakerFactory#createInstructionKeyMaker(short)}
\r
92 public void testInstructionKeyMaker() {
\r
93 TypeKeyMaker<Instruction> keyMaker = TypeKeyMakerFactory.createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
\r
94 Assert.assertNotNull("Null keyMaker", keyMaker);
\r
96 InstructionBuilder builder = new InstructionBuilder();
\r
97 builder.setType(GotoTable.class);
\r
98 Instruction instruction = builder.build();
\r
99 MessageTypeKey<?> key = keyMaker.make(instruction);
\r
101 Assert.assertNotNull("Null key", key);
\r
102 Assert.assertEquals("Wrong key", new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID,
\r
103 GotoTable.class, null), key);
\r
107 * Tests {@link TypeKeyMakerFactory#createInstructionKeyMaker(short)}
\r
110 public void testExperimenterInstructionKeyMaker() {
\r
111 TypeKeyMaker<Instruction> keyMaker = TypeKeyMakerFactory.createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
\r
112 Assert.assertNotNull("Null keyMaker", keyMaker);
\r
114 InstructionBuilder builder = new InstructionBuilder();
\r
115 builder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow
\r
116 .common.instruction.rev130731.Experimenter.class);
\r
117 ExperimenterIdInstructionBuilder expIdBuilder = new ExperimenterIdInstructionBuilder();
\r
118 expIdBuilder.setExperimenter(new ExperimenterId(42L));
\r
119 builder.addAugmentation(ExperimenterIdInstruction.class, expIdBuilder.build());
\r
120 Instruction instruction = builder.build();
\r
121 MessageTypeKey<?> key = keyMaker.make(instruction);
\r
123 Assert.assertNotNull("Null key", key);
\r
124 Assert.assertEquals("Wrong key", new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID,
\r
129 * Tests {@link TypeKeyMakerFactory#createMatchEntriesKeyMaker(short)}
\r
132 public void testMatchEntriesKeyMaker() {
\r
133 TypeKeyMaker<MatchEntries> keyMaker = TypeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
\r
134 Assert.assertNotNull("Null keyMaker", keyMaker);
\r
136 MatchEntriesBuilder builder = new MatchEntriesBuilder();
\r
137 builder.setOxmClass(OpenflowBasicClass.class);
\r
138 builder.setOxmMatchField(InPort.class);
\r
139 builder.setHasMask(true);
\r
140 MatchEntries entry = builder.build();
\r
141 MessageTypeKey<?> key = keyMaker.make(entry);
\r
143 Assert.assertNotNull("Null key", key);
\r
144 MatchEntrySerializerKey<?, ?> comparationKey = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
\r
145 OpenflowBasicClass.class, InPort.class);
\r
146 Assert.assertEquals("Wrong key", comparationKey, key);
\r
150 * Tests {@link TypeKeyMakerFactory#createMatchEntriesKeyMaker(short)}
\r
153 public void testExperimenterMatchEntriesKeyMaker() {
\r
154 TypeKeyMaker<MatchEntries> keyMaker = TypeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
\r
155 Assert.assertNotNull("Null keyMaker", keyMaker);
\r
157 MatchEntriesBuilder builder = new MatchEntriesBuilder();
\r
158 builder.setOxmClass(ExperimenterClass.class);
\r
159 builder.setOxmMatchField(OxmMatchFieldClass.class);
\r
160 builder.setHasMask(true);
\r
161 ExperimenterIdMatchEntryBuilder expIdBuilder = new ExperimenterIdMatchEntryBuilder();
\r
162 expIdBuilder.setExperimenter(new ExperimenterId(42L));
\r
163 builder.addAugmentation(ExperimenterIdMatchEntry.class, expIdBuilder.build());
\r
164 MatchEntries entry = builder.build();
\r
165 MessageTypeKey<?> key = keyMaker.make(entry);
\r
167 Assert.assertNotNull("Null key", key);
\r
168 MatchEntrySerializerKey<?, ?> comparationKey = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
\r
169 ExperimenterClass.class, OxmMatchFieldClass.class);
\r
170 comparationKey.setExperimenterId(42L);
\r
171 Assert.assertEquals("Wrong key", comparationKey, key);
\r
174 private class ActionSubtypeClass extends ExperimenterActionSubType {
\r
175 // only for testing purposes
\r
178 private class OxmMatchFieldClass extends MatchField {
\r
179 // only for testing purposes
\r