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