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.ExperimenterIdInstruction;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdInstructionBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.experimenter.id._case.ExperimenterBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.ExperimenterActionSubType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ExperimenterClass;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
41 * @author michal.polkorab
44 public class TypeKeyMakerFactoryTest {
47 * Tests {@link TypeKeyMakerFactory#createActionKeyMaker(short)}
50 public void testActionKeyMaker() {
51 TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
52 Assert.assertNotNull("Null keyMaker", keyMaker);
54 ActionBuilder builder = new ActionBuilder();
55 builder.setActionChoice(new OutputActionCaseBuilder().build());
56 Action action = builder.build();
57 MessageTypeKey<?> key = keyMaker.make(action);
59 Assert.assertNotNull("Null key", key);
60 Assert.assertEquals("Wrong key", new ActionSerializerKey<>(EncodeConstants.OF13_VERSION_ID,
61 OutputActionCase.class, null), key);
65 * Tests {@link TypeKeyMakerFactory#createActionKeyMaker(short)}
68 public void testExperimenterActionKeyMaker() {
69 TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
70 Assert.assertNotNull("Null keyMaker", keyMaker);
72 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder builder = new ActionBuilder();
73 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.action.container.action.choice
74 .ExperimenterIdCaseBuilder caseBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments
75 .rev150225.action.container.action.choice.ExperimenterIdCaseBuilder();
76 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.action.container.action.choice
77 .experimenter.id._case.ExperimenterBuilder expIdBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight
78 .openflow.augments.rev150225.action.container.action.choice.experimenter.id._case.ExperimenterBuilder();
79 expIdBuilder.setExperimenter(new ExperimenterId(42L));
80 expIdBuilder.setSubType(ActionSubtypeClass.class);
81 caseBuilder.setExperimenter(expIdBuilder.build());
82 builder.setActionChoice(caseBuilder.build());
83 Action action = builder.build();
84 MessageTypeKey<?> key = keyMaker.make(action);
86 Assert.assertNotNull("Null key", key);
87 Assert.assertEquals("Wrong key", new ExperimenterActionSerializerKey(EncodeConstants.OF13_VERSION_ID, 42L,
88 ActionSubtypeClass.class), key);
92 * Tests {@link TypeKeyMakerFactory#createInstructionKeyMaker(short)}
95 public void testInstructionKeyMaker() {
96 TypeKeyMaker<Instruction> keyMaker = TypeKeyMakerFactory.createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
97 Assert.assertNotNull("Null keyMaker", keyMaker);
99 InstructionBuilder builder = new InstructionBuilder();
100 builder.setType(GotoTable.class);
101 Instruction instruction = builder.build();
102 MessageTypeKey<?> key = keyMaker.make(instruction);
104 Assert.assertNotNull("Null key", key);
105 Assert.assertEquals("Wrong key", new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID,
106 GotoTable.class, null), key);
110 * Tests {@link TypeKeyMakerFactory#createInstructionKeyMaker(short)}
113 public void testExperimenterInstructionKeyMaker() {
114 TypeKeyMaker<Instruction> keyMaker = TypeKeyMakerFactory.createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
115 Assert.assertNotNull("Null keyMaker", keyMaker);
117 InstructionBuilder builder = new InstructionBuilder();
118 builder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow
119 .common.instruction.rev130731.Experimenter.class);
120 ExperimenterIdInstructionBuilder expIdBuilder = new ExperimenterIdInstructionBuilder();
121 expIdBuilder.setExperimenter(new ExperimenterId(42L));
122 builder.addAugmentation(ExperimenterIdInstruction.class, expIdBuilder.build());
123 Instruction instruction = builder.build();
124 MessageTypeKey<?> key = keyMaker.make(instruction);
126 Assert.assertNotNull("Null key", key);
127 Assert.assertEquals("Wrong key", new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID,
132 * Tests {@link TypeKeyMakerFactory#createMatchEntriesKeyMaker(short)}
135 public void testMatchEntriesKeyMaker() {
136 TypeKeyMaker<MatchEntry> keyMaker = TypeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
137 Assert.assertNotNull("Null keyMaker", keyMaker);
139 MatchEntryBuilder builder = new MatchEntryBuilder();
140 builder.setOxmClass(OpenflowBasicClass.class);
141 builder.setOxmMatchField(InPort.class);
142 builder.setHasMask(true);
143 MatchEntry entry = builder.build();
144 MessageTypeKey<?> key = keyMaker.make(entry);
146 Assert.assertNotNull("Null key", key);
147 MatchEntrySerializerKey<?, ?> comparationKey = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
148 OpenflowBasicClass.class, InPort.class);
149 Assert.assertEquals("Wrong key", comparationKey, key);
153 * Tests {@link TypeKeyMakerFactory#createMatchEntriesKeyMaker(short)}
156 public void testExperimenterMatchEntriesKeyMaker() {
157 TypeKeyMaker<MatchEntry> keyMaker = TypeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
158 Assert.assertNotNull("Null keyMaker", keyMaker);
160 MatchEntryBuilder builder = new MatchEntryBuilder();
161 builder.setOxmClass(ExperimenterClass.class);
162 builder.setOxmMatchField(OxmMatchFieldClass.class);
163 builder.setHasMask(true);
164 ExperimenterIdCaseBuilder caseBuilder = new ExperimenterIdCaseBuilder();
165 ExperimenterBuilder expBuilder = new ExperimenterBuilder();
166 expBuilder.setExperimenter(new ExperimenterId(42L));
167 caseBuilder.setExperimenter(expBuilder.build());
168 builder.setMatchEntryValue(caseBuilder.build());
169 MatchEntry entry = builder.build();
170 MessageTypeKey<?> key = keyMaker.make(entry);
172 Assert.assertNotNull("Null key", key);
173 MatchEntrySerializerKey<?, ?> comparationKey = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
174 ExperimenterClass.class, OxmMatchFieldClass.class);
175 comparationKey.setExperimenterId(42L);
176 Assert.assertEquals("Wrong key", comparationKey, key);
179 private class ActionSubtypeClass extends ExperimenterActionSubType {
180 // only for testing purposes
183 private class OxmMatchFieldClass extends MatchField {
184 // only for testing purposes