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.InstructionSerializerKey;
15 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.experimenter.id._case.ExperimenterBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.ExperimenterActionSubType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCaseBuilder;
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.ClearActionsCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ExperimenterClass;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
42 * @author michal.polkorab
45 public class TypeKeyMakerFactoryTest {
48 * Tests {@link TypeKeyMakerFactory#createActionKeyMaker(short)}
51 public void testActionKeyMaker() {
52 TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
53 Assert.assertNotNull("Null keyMaker", keyMaker);
55 ActionBuilder builder = new ActionBuilder();
56 builder.setActionChoice(new OutputActionCaseBuilder().build());
57 Action action = builder.build();
58 MessageTypeKey<?> key = keyMaker.make(action);
60 Assert.assertNotNull("Null key", key);
61 Assert.assertEquals("Wrong key", new ActionSerializerKey<>(EncodeConstants.OF13_VERSION_ID,
62 OutputActionCase.class, null), key);
66 * Tests {@link TypeKeyMakerFactory#createActionKeyMaker(short)}
69 public void testExperimenterActionKeyMaker() {
70 TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
71 Assert.assertNotNull("Null keyMaker", keyMaker);
73 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder builder = new ActionBuilder();
74 builder.setExperimenterId(new ExperimenterId(42L));
75 builder.setActionChoice(new CopyTtlInCaseBuilder().build());
76 Action action = builder.build();
77 MessageTypeKey<?> key = keyMaker.make(action);
79 Assert.assertNotNull("Null key", key);
80 Assert.assertEquals("Wrong key", new ActionSerializerKey(EncodeConstants.OF13_VERSION_ID,
81 CopyTtlInCase.class, 42L), key);
85 * Tests {@link TypeKeyMakerFactory#createInstructionKeyMaker(short)}
88 public void testInstructionKeyMaker() {
89 TypeKeyMaker<Instruction> keyMaker = TypeKeyMakerFactory.createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
90 Assert.assertNotNull("Null keyMaker", keyMaker);
92 InstructionBuilder builder = new InstructionBuilder();
93 builder.setInstructionChoice(new GotoTableCaseBuilder().build());
94 Instruction instruction = builder.build();
95 MessageTypeKey<?> key = keyMaker.make(instruction);
97 Assert.assertNotNull("Null key", key);
98 Assert.assertEquals("Wrong key", new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID,
99 GotoTableCase.class, null), key);
103 * Tests {@link TypeKeyMakerFactory#createInstructionKeyMaker(short)}
106 public void testExperimenterInstructionKeyMaker() {
107 TypeKeyMaker<Instruction> keyMaker = TypeKeyMakerFactory.createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
108 Assert.assertNotNull("Null keyMaker", keyMaker);
110 InstructionBuilder builder = new InstructionBuilder();
111 builder.setExperimenterId(new ExperimenterId(42L));
112 builder.setInstructionChoice(new ClearActionsCaseBuilder().build());
113 Instruction instruction = builder.build();
114 MessageTypeKey<?> key = keyMaker.make(instruction);
116 Assert.assertNotNull("Null key", key);
117 Assert.assertEquals("Wrong key", new InstructionSerializerKey(EncodeConstants.OF13_VERSION_ID,
118 ClearActionsCase.class, 42L), key);
122 * Tests {@link TypeKeyMakerFactory#createMatchEntriesKeyMaker(short)}
125 public void testMatchEntriesKeyMaker() {
126 TypeKeyMaker<MatchEntry> keyMaker = TypeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
127 Assert.assertNotNull("Null keyMaker", keyMaker);
129 MatchEntryBuilder builder = new MatchEntryBuilder();
130 builder.setOxmClass(OpenflowBasicClass.class);
131 builder.setOxmMatchField(InPort.class);
132 builder.setHasMask(true);
133 MatchEntry entry = builder.build();
134 MessageTypeKey<?> key = keyMaker.make(entry);
136 Assert.assertNotNull("Null key", key);
137 MatchEntrySerializerKey<?, ?> comparationKey = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
138 OpenflowBasicClass.class, InPort.class);
139 Assert.assertEquals("Wrong key", comparationKey, key);
143 * Tests {@link TypeKeyMakerFactory#createMatchEntriesKeyMaker(short)}
146 public void testExperimenterMatchEntriesKeyMaker() {
147 TypeKeyMaker<MatchEntry> keyMaker = TypeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
148 Assert.assertNotNull("Null keyMaker", keyMaker);
150 MatchEntryBuilder builder = new MatchEntryBuilder();
151 builder.setOxmClass(ExperimenterClass.class);
152 builder.setOxmMatchField(OxmMatchFieldClass.class);
153 builder.setHasMask(true);
154 ExperimenterIdCaseBuilder caseBuilder = new ExperimenterIdCaseBuilder();
155 ExperimenterBuilder expBuilder = new ExperimenterBuilder();
156 expBuilder.setExperimenter(new ExperimenterId(42L));
157 caseBuilder.setExperimenter(expBuilder.build());
158 builder.setMatchEntryValue(caseBuilder.build());
159 MatchEntry entry = builder.build();
160 MessageTypeKey<?> key = keyMaker.make(entry);
162 Assert.assertNotNull("Null key", key);
163 MatchEntrySerializerKey<?, ?> comparationKey = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
164 ExperimenterClass.class, OxmMatchFieldClass.class);
165 comparationKey.setExperimenterId(42L);
166 Assert.assertEquals("Wrong key", comparationKey, key);
169 private class ActionSubtypeClass extends ExperimenterActionSubType {
170 // only for testing purposes
173 private class OxmMatchFieldClass extends MatchField {
174 // only for testing purposes