2 * Copyright (c) 2015 NetIDE Consortium 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
8 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
10 import io.netty.buffer.ByteBuf;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
20 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionRelatedTableFeaturePropertyBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.InstructionRelatedTableFeaturePropertyBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.NextTableRelatedTableFeaturePropertyBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.OxmRelatedTableFeaturePropertyBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.next.table.related.table.feature.property.NextTableIds;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.next.table.related.table.feature.property.NextTableIdsBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPhyPort;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeaturesBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeaturePropertiesBuilder;
52 import org.opendaylight.yangtools.yang.common.Uint32;
53 import org.opendaylight.yangtools.yang.common.Uint64;
54 import org.opendaylight.yangtools.yang.common.Uint8;
57 * Unit tests for MultipartRequestTableFeaturesInputMessageFactory.
59 * @author giuseppex.petralia@intel.com
61 public class MultipartRequestTableFeaturesInputMessageFactoryTest {
62 private OFDeserializer<MultipartRequestInput> factory;
65 public void startUp() {
66 DeserializerRegistry desRegistry = new DeserializerRegistryImpl();
69 .getDeserializer(new MessageCodeKey(EncodeConstants.OF_VERSION_1_3, 18, MultipartRequestInput.class));
74 ByteBuf bb = BufferHelper.buildBuffer("00 0c 00 01 00 00 00 00 00 68 01 00 00 00 00 00 4e 61 6d "
75 + "65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "
76 + "00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 10 00 01 "
77 + "00 04 00 02 00 04 00 04 00 04 00 02 00 05 01 00 00 00 00 04 00 08 00 00 00 04 00 08 00 08 80 00 02 04 ");
78 MultipartRequestInput deserializedMessage = BufferHelper.deserialize(factory, bb);
79 BufferHelper.checkHeaderV13(deserializedMessage);
80 Assert.assertEquals("Wrong type", MultipartType.forValue(12), deserializedMessage.getType());
81 Assert.assertEquals("Wrong flags", new MultipartRequestFlags(true), deserializedMessage.getFlags());
82 Assert.assertEquals("Wrong body", createTableFeatures(), deserializedMessage.getMultipartRequestBody());
85 public MultipartRequestTableFeaturesCase createTableFeatures() {
86 MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
87 MultipartRequestTableFeaturesBuilder builder = new MultipartRequestTableFeaturesBuilder();
88 builder.setTableFeatures(createTableFeaturesList());
89 caseBuilder.setMultipartRequestTableFeatures(builder.build());
90 return caseBuilder.build();
94 public List<TableFeatures> createTableFeaturesList() {
95 final List<TableFeatures> list = new ArrayList<>();
96 list.add(new TableFeaturesBuilder()
97 .setTableId(Uint8.ONE)
99 .setMetadataWrite(Uint64.ONE)
100 .setMetadataMatch(Uint64.ONE)
101 .setMaxEntries(Uint32.ONE)
102 .setConfig(new TableConfig(false))
103 .setTableFeatureProperties(createTableFeatureProperties())
108 public List<TableFeatureProperties> createTableFeatureProperties() {
109 final List<TableFeatureProperties> list = new ArrayList<>();
110 list.add(new TableFeaturePropertiesBuilder()
111 .setType(TableFeaturesPropType.forValue(0))
112 .addAugmentation(new InstructionRelatedTableFeaturePropertyBuilder()
113 .setInstruction(createInstructions())
117 list.add(new TableFeaturePropertiesBuilder()
118 .setType(TableFeaturesPropType.forValue(2))
119 .addAugmentation(new NextTableRelatedTableFeaturePropertyBuilder()
120 .setNextTableIds(createNextTableIds())
124 list.add(new TableFeaturePropertiesBuilder()
125 .setType(TableFeaturesPropType.forValue(4))
126 .addAugmentation(new ActionRelatedTableFeaturePropertyBuilder().setAction(createAction()).build())
129 list.add(new TableFeaturePropertiesBuilder()
130 .setType(TableFeaturesPropType.forValue(8))
131 .addAugmentation(new OxmRelatedTableFeaturePropertyBuilder().setMatchEntry(createMatchEntries()).build())
137 public List<MatchEntry> createMatchEntries() {
138 final List<MatchEntry> entries = new ArrayList<>();
139 MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
140 entriesBuilder.setOxmClass(OpenflowBasicClass.VALUE);
141 entriesBuilder.setOxmMatchField(InPhyPort.VALUE);
142 entriesBuilder.setHasMask(false);
143 entries.add(entriesBuilder.build());
147 public List<Action> createAction() {
148 List<Action> actions = new ArrayList<>();
149 ActionBuilder actionBuilder = new ActionBuilder();
150 OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
151 actionBuilder.setActionChoice(caseBuilder.build());
152 actions.add(actionBuilder.build());
156 public List<NextTableIds> createNextTableIds() {
157 List<NextTableIds> list = new ArrayList<>();
158 NextTableIdsBuilder builder = new NextTableIdsBuilder();
159 builder.setTableId(Uint8.ONE);
160 list.add(builder.build());
164 public List<Instruction> createInstructions() {
165 List<Instruction> instructions = new ArrayList<>();
166 InstructionBuilder insBuilder = new InstructionBuilder();
167 GotoTableCaseBuilder goToCaseBuilder = new GotoTableCaseBuilder();
168 insBuilder.setInstructionChoice(goToCaseBuilder.build());
169 instructions.add(insBuilder.build());
170 WriteMetadataCaseBuilder metadataCaseBuilder = new WriteMetadataCaseBuilder();
171 insBuilder.setInstructionChoice(metadataCaseBuilder.build());
172 instructions.add(insBuilder.build());
173 insBuilder = new InstructionBuilder();
174 ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder();
175 insBuilder.setInstructionChoice(applyActionsCaseBuilder.build());
176 instructions.add(insBuilder.build());