2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories.multipart;
\r
11 import io.netty.buffer.ByteBuf;
\r
12 import io.netty.buffer.UnpooledByteBufAllocator;
\r
14 import org.junit.Assert;
\r
15 import org.junit.Before;
\r
16 import org.junit.Test;
\r
17 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
\r
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
\r
19 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
\r
20 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
\r
21 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
\r
22 import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactory;
\r
23 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
\r
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
\r
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
\r
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
\r
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
\r
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
\r
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
\r
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
\r
36 * @author michal.polkorab
\r
39 public class OF10StatsRequestAggregateTest {
\r
41 private SerializerRegistry registry;
\r
42 private OFSerializer<MultipartRequestInput> statsFactory;
\r
45 * Initializes serializer registry and stores correct factory in field
\r
48 public void startUp() {
\r
49 registry = new SerializerRegistryImpl();
\r
51 statsFactory = registry.getSerializer(
\r
52 new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MultipartRequestInput.class));
\r
56 * Tests {@link OF10StatsRequestInputFactory} for correct serialization
\r
57 * @throws Exception
\r
60 public void test() throws Exception {
\r
61 MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
\r
62 BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
\r
63 builder.setType(MultipartType.OFPMPAGGREGATE);
\r
64 builder.setFlags(new MultipartRequestFlags(false));
\r
65 MultipartRequestAggregateCaseBuilder caseBuilder = new MultipartRequestAggregateCaseBuilder();
\r
66 MultipartRequestAggregateBuilder aggBuilder = new MultipartRequestAggregateBuilder();
\r
67 MatchV10Builder matchBuilder = new MatchV10Builder();
\r
68 matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true,
\r
69 true, true, true, true));
\r
70 matchBuilder.setNwSrcMask((short) 8);
\r
71 matchBuilder.setNwDstMask((short) 16);
\r
72 matchBuilder.setInPort(51);
\r
73 matchBuilder.setDlSrc(new MacAddress("00:01:02:03:04:05"));
\r
74 matchBuilder.setDlDst(new MacAddress("05:04:03:02:01:00"));
\r
75 matchBuilder.setDlVlan(52);
\r
76 matchBuilder.setDlVlanPcp((short) 53);
\r
77 matchBuilder.setDlType(54);
\r
78 matchBuilder.setNwTos((short) 55);
\r
79 matchBuilder.setNwProto((short) 56);
\r
80 matchBuilder.setNwSrc(new Ipv4Address("10.0.0.1"));
\r
81 matchBuilder.setNwDst(new Ipv4Address("10.0.0.2"));
\r
82 matchBuilder.setTpSrc(57);
\r
83 matchBuilder.setTpDst(58);
\r
84 aggBuilder.setMatchV10(matchBuilder.build());
\r
85 aggBuilder.setTableId((short) 5);
\r
86 aggBuilder.setOutPort(42L);
\r
87 caseBuilder.setMultipartRequestAggregate(aggBuilder.build());
\r
88 builder.setMultipartRequestBody(caseBuilder.build());
\r
89 MultipartRequestInput message = builder.build();
\r
91 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
92 statsFactory.serialize(message, out);
\r
94 BufferHelper.checkHeaderV10(out, (byte) 16, 56);
\r
95 Assert.assertEquals("Wrong type", 2, out.readUnsignedShort());
\r
96 Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
\r
97 out.skipBytes(40); // skip match check
\r
98 Assert.assertEquals("Wrong table-id", 5, out.readUnsignedByte());
\r
100 Assert.assertEquals("Wrong out port", 42, out.readUnsignedShort());
\r