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