2 * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart;
11 import static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.UnpooledByteBufAllocator;
15 import java.math.BigInteger;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
20 import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowStats;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowStatsBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.multipart.request.flow.stats.FlowStatsBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
29 public class MultipartRequestFlowStatsSerializerTest extends AbstractSerializerTest {
30 private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3;
31 private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4;
32 private static final short TABLE_ID = 42;
33 private static final BigInteger OUT_PORT = BigInteger.ONE;
34 private static final long OUT_GROUP = 10;
35 private static final FlowCookie COOKIE = new FlowCookie(BigInteger.valueOf(8));
36 private static final FlowCookie COOKIE_MASK = new FlowCookie(BigInteger.TEN);
37 private static final Short IP_PROTOCOL_MATCH = (short) 17;
38 private static final Match MATCH = new MatchBuilder()
39 .setIpMatch(new IpMatchBuilder()
40 .setIpProtocol(IP_PROTOCOL_MATCH)
43 private static final MultipartRequestFlowStats BODY = new MultipartRequestFlowStatsBuilder()
44 .setFlowStats(new FlowStatsBuilder()
47 .setOutGroup(OUT_GROUP)
49 .setCookieMask(COOKIE_MASK)
53 private MultipartRequestFlowStatsSerializer serializer;
56 protected void init() {
57 serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID,
58 MultipartRequestFlowStats.class)) ;
62 public void testSerialize() throws Exception {
63 final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
64 serializer.serialize(BODY, out);
66 assertEquals(out.readUnsignedByte(), TABLE_ID);
67 out.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01);
68 assertEquals(out.readUnsignedInt(), OUT_PORT.longValue());
69 assertEquals(out.readUnsignedInt(), OUT_GROUP);
70 out.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02);
71 assertEquals(out.readLong(), COOKIE.getValue().longValue());
72 assertEquals(out.readLong(), COOKIE_MASK.getValue().longValue());
75 assertEquals(out.readShort(), 1); // OXM match type
76 assertEquals(out.readUnsignedShort(), matchLength); // OXM match length
78 assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS);
79 assertEquals(out.readUnsignedByte(), OxmMatchConstants.IP_PROTO << 1);
80 assertEquals(out.readUnsignedByte(), EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
81 assertEquals(out.readUnsignedByte(), IP_PROTOCOL_MATCH.shortValue());
83 int paddingRemainder = matchLength % EncodeConstants.PADDING;
84 if (paddingRemainder != 0) {
85 out.skipBytes(EncodeConstants.PADDING - paddingRemainder);
88 assertEquals(out.readableBytes(), 0);