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.keys.ActionSerializerKey;
14 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionSerializerKey;
15 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionSerializerKey;
16 import org.opendaylight.openflowjava.protocol.api.keys.InstructionSerializerKey;
17 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.experimenter.id._case.ExperimenterBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.ExperimenterActionSubType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCaseBuilder;
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.ExperimenterId;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ExperimenterClass;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
40 * @author michal.polkorab
43 public class TypeKeyMakerFactoryTest {
46 * Tests {@link TypeKeyMakerFactory#createActionKeyMaker(short)}
49 public void testActionKeyMaker() {
50 TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
51 Assert.assertNotNull("Null keyMaker", keyMaker);
53 ActionBuilder builder = new ActionBuilder();
54 builder.setActionChoice(new OutputActionCaseBuilder().build());
55 Action action = builder.build();
56 MessageTypeKey<?> key = keyMaker.make(action);
58 Assert.assertNotNull("Null key", key);
59 Assert.assertEquals("Wrong key", new ActionSerializerKey<>(EncodeConstants.OF13_VERSION_ID,
60 OutputActionCase.class, null), key);
64 * Tests {@link TypeKeyMakerFactory#createActionKeyMaker(short)}
67 public void testExperimenterActionKeyMaker() {
68 TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
69 Assert.assertNotNull("Null keyMaker", keyMaker);
71 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder builder = new ActionBuilder();
72 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.action.container.action.choice
73 .ExperimenterIdCaseBuilder caseBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments
74 .rev150225.action.container.action.choice.ExperimenterIdCaseBuilder();
75 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.action.container.action.choice
76 .experimenter.id._case.ExperimenterBuilder expIdBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight
77 .openflow.augments.rev150225.action.container.action.choice.experimenter.id._case.ExperimenterBuilder();
78 expIdBuilder.setExperimenter(new ExperimenterId(42L));
79 expIdBuilder.setSubType(ActionSubtypeClass.class);
80 caseBuilder.setExperimenter(expIdBuilder.build());
81 builder.setActionChoice(caseBuilder.build());
82 Action action = builder.build();
83 MessageTypeKey<?> key = keyMaker.make(action);
85 Assert.assertNotNull("Null key", key);
86 Assert.assertEquals("Wrong key", new ExperimenterActionSerializerKey(EncodeConstants.OF13_VERSION_ID, 42L,
87 ActionSubtypeClass.class), key);
91 * Tests {@link TypeKeyMakerFactory#createInstructionKeyMaker(short)}
94 public void testInstructionKeyMaker() {
95 TypeKeyMaker<Instruction> keyMaker = TypeKeyMakerFactory.createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
96 Assert.assertNotNull("Null keyMaker", keyMaker);
98 InstructionBuilder builder = new InstructionBuilder();
99 builder.setInstructionChoice(new GotoTableCaseBuilder().build());
100 Instruction instruction = builder.build();
101 MessageTypeKey<?> key = keyMaker.make(instruction);
103 Assert.assertNotNull("Null key", key);
104 Assert.assertEquals("Wrong key", new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID,
105 GotoTableCase.class, null), key);
109 * Tests {@link TypeKeyMakerFactory#createInstructionKeyMaker(short)}
112 public void testExperimenterInstructionKeyMaker() {
113 TypeKeyMaker<Instruction> keyMaker = TypeKeyMakerFactory.createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
114 Assert.assertNotNull("Null keyMaker", keyMaker);
116 InstructionBuilder builder = new InstructionBuilder();
117 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.instruction.container
118 .instruction.choice.ExperimenterIdCaseBuilder caseBuilder = new org.opendaylight.yang.gen.v1.urn
119 .opendaylight.openflow.augments.rev150225.instruction.container.instruction.choice.ExperimenterIdCaseBuilder();
120 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.instruction.container
121 .instruction.choice.experimenter.id._case.ExperimenterBuilder expIdBuilder = new org.opendaylight.yang.gen
122 .v1.urn.opendaylight.openflow.augments.rev150225.instruction.container.instruction.choice.experimenter.id
123 ._case.ExperimenterBuilder();
124 expIdBuilder.setExperimenterId(new ExperimenterId(42L));
125 caseBuilder.setExperimenter(expIdBuilder.build());
126 builder.setInstructionChoice(caseBuilder.build());
127 Instruction instruction = builder.build();
128 MessageTypeKey<?> key = keyMaker.make(instruction);
130 Assert.assertNotNull("Null key", key);
131 Assert.assertEquals("Wrong key", new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID,
136 * Tests {@link TypeKeyMakerFactory#createMatchEntriesKeyMaker(short)}
139 public void testMatchEntriesKeyMaker() {
140 TypeKeyMaker<MatchEntry> keyMaker = TypeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
141 Assert.assertNotNull("Null keyMaker", keyMaker);
143 MatchEntryBuilder builder = new MatchEntryBuilder();
144 builder.setOxmClass(OpenflowBasicClass.class);
145 builder.setOxmMatchField(InPort.class);
146 builder.setHasMask(true);
147 MatchEntry entry = builder.build();
148 MessageTypeKey<?> key = keyMaker.make(entry);
150 Assert.assertNotNull("Null key", key);
151 MatchEntrySerializerKey<?, ?> comparationKey = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
152 OpenflowBasicClass.class, InPort.class);
153 Assert.assertEquals("Wrong key", comparationKey, key);
157 * Tests {@link TypeKeyMakerFactory#createMatchEntriesKeyMaker(short)}
160 public void testExperimenterMatchEntriesKeyMaker() {
161 TypeKeyMaker<MatchEntry> keyMaker = TypeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
162 Assert.assertNotNull("Null keyMaker", keyMaker);
164 MatchEntryBuilder builder = new MatchEntryBuilder();
165 builder.setOxmClass(ExperimenterClass.class);
166 builder.setOxmMatchField(OxmMatchFieldClass.class);
167 builder.setHasMask(true);
168 ExperimenterIdCaseBuilder caseBuilder = new ExperimenterIdCaseBuilder();
169 ExperimenterBuilder expBuilder = new ExperimenterBuilder();
170 expBuilder.setExperimenter(new ExperimenterId(42L));
171 caseBuilder.setExperimenter(expBuilder.build());
172 builder.setMatchEntryValue(caseBuilder.build());
173 MatchEntry entry = builder.build();
174 MessageTypeKey<?> key = keyMaker.make(entry);
176 Assert.assertNotNull("Null key", key);
177 MatchEntrySerializerKey<?, ?> comparationKey = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
178 ExperimenterClass.class, OxmMatchFieldClass.class);
179 comparationKey.setExperimenterId(42L);
180 Assert.assertEquals("Wrong key", comparationKey, key);
183 private class ActionSubtypeClass extends ExperimenterActionSubType {
184 // only for testing purposes
187 private class OxmMatchFieldClass extends MatchField {
188 // only for testing purposes