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 org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
19 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
29 import org.opendaylight.yangtools.yang.common.Uint16;
30 import org.opendaylight.yangtools.yang.common.Uint32;
31 import org.opendaylight.yangtools.yang.common.Uint8;
34 * Unit tests for OF10StatsRequestInputFlowFactory.
36 * @author giuseppex.petralia@intel.com
38 public class OF10StatsRequestInputFlowFactoryTest {
39 private OFDeserializer<MultipartRequestInput> factory;
42 public void startUp() {
43 DeserializerRegistry desRegistry = new DeserializerRegistryImpl();
46 .getDeserializer(new MessageCodeKey(EncodeConstants.OF_VERSION_1_0, 16, MultipartRequestInput.class));
51 ByteBuf bb = BufferHelper.buildBuffer("00 01 00 00 00 34 18 ff 00 33 00 01 02 03 04 "
52 + "05 05 04 03 02 01 00 00 34 35 00 00 36 37 38 00 00 0a 00 00 01 0a 00 00 02 "
53 + "00 39 00 3a 01 00 00 2a ");
55 MultipartRequestInput deserializedMessage = BufferHelper.deserialize(factory, bb);
56 BufferHelper.checkHeaderV10(deserializedMessage);
57 Assert.assertEquals("Wrong type", 1, deserializedMessage.getType().getIntValue());
58 Assert.assertEquals("Wrong flags", new MultipartRequestFlags(false), deserializedMessage.getFlags());
59 Assert.assertEquals("Wrong body", createMultipartRequestBody(), deserializedMessage.getMultipartRequestBody());
62 private static MultipartRequestBody createMultipartRequestBody() {
63 final MultipartRequestFlowCaseBuilder caseBuilder = new MultipartRequestFlowCaseBuilder();
64 final MultipartRequestFlowBuilder flowBuilder = new MultipartRequestFlowBuilder();
65 MatchV10Builder matchBuilder = new MatchV10Builder();
66 matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true));
67 matchBuilder.setNwSrcMask(Uint8.valueOf(8));
68 matchBuilder.setNwDstMask(Uint8.valueOf(16));
69 matchBuilder.setInPort(Uint16.valueOf(51));
70 matchBuilder.setDlSrc(new MacAddress("00:01:02:03:04:05"));
71 matchBuilder.setDlDst(new MacAddress("05:04:03:02:01:00"));
72 matchBuilder.setDlVlan(Uint16.valueOf(52));
73 matchBuilder.setDlVlanPcp(Uint8.valueOf(53));
74 matchBuilder.setDlType(Uint16.valueOf(54));
75 matchBuilder.setNwTos(Uint8.valueOf(55));
76 matchBuilder.setNwProto(Uint8.valueOf(56));
77 matchBuilder.setNwSrc(new Ipv4Address("10.0.0.1"));
78 matchBuilder.setNwDst(new Ipv4Address("10.0.0.2"));
79 matchBuilder.setTpSrc(Uint16.valueOf(57));
80 matchBuilder.setTpDst(Uint16.valueOf(58));
81 flowBuilder.setMatchV10(matchBuilder.build());
82 flowBuilder.setTableId(Uint8.ONE);
83 flowBuilder.setOutPort(Uint32.valueOf(42));
84 caseBuilder.setMultipartRequestFlow(flowBuilder.build());
85 return caseBuilder.build();