2 * Copyright (c) 2014 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.openflowjava.protocol.impl.deserialization.factories.multipart;
11 import io.netty.buffer.ByteBuf;
12 import java.math.BigInteger;
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.deserialization.factories.MultipartReplyMessageFactory;
22 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmMatchType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
31 * Unit tests for MultipartReplyFlow.
33 * @author michal.polkorab
35 public class MultipartReplyFlowTest {
37 private OFDeserializer<MultipartReplyMessage> factory;
40 * Initializes deserializer registry and lookups correct deserializer.
43 public void startUp() {
44 DeserializerRegistry registry = new DeserializerRegistryImpl();
46 factory = registry.getDeserializer(
47 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 19, MultipartReplyMessage.class));
51 * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
54 public void testEmptyMultipartReplyFlowBody() {
55 ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00");
56 MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
58 BufferHelper.checkHeaderV13(builtByFactory);
59 Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());
60 Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
61 MultipartReplyFlowCase messageCase = (MultipartReplyFlowCase) builtByFactory.getMultipartReplyBody();
62 MultipartReplyFlow message = messageCase.getMultipartReplyFlow();
63 Assert.assertEquals("Wrong flow stats size", 0, message.getFlowStats().size());
67 * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
70 public void testMultipartReplyFlowBody() {
71 ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00 " + //
73 "00 48 08 00 " + // length, tableId, padding
74 "00 00 00 09 " + //durationSec
75 "00 00 00 07 " + //durationNsec
76 "00 0C 00 0E 00 0F 00 1F " + //priority, idleTimeout, hardTimeout, flags
77 "00 00 00 00 " + //pad_02
78 "FF 01 01 01 01 01 01 01 " + //cookie
79 "EF 01 01 01 01 01 01 01 " + //packetCount
80 "7F 01 01 01 01 01 01 01 " + //byteCount
81 "00 01 00 04 00 00 00 00 " + //empty match
82 "00 01 00 08 06 00 00 00 " + //
83 "00 01 00 08 06 00 00 00 " + //
85 "00 48 08 00 " + // length, tableId, padding
86 "00 00 00 09 " + //durationSec
87 "00 00 00 07 " + //durationNsec
88 "00 0C 00 0E 00 0F 00 00 " + // priority, idleTimeout, hardTimeout, flags
89 "00 00 00 00 " + //pad_02
90 "FF 01 01 01 01 01 01 01 " + //cookie
91 "EF 01 01 01 01 01 01 01 " + //packetCount
92 "7F 01 01 01 01 01 01 01 " + //byteCount
93 "00 01 00 04 00 00 00 00 " + //empty match
94 "00 01 00 08 06 00 00 00 " + //
95 "00 01 00 08 06 00 00 00");
96 MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
98 BufferHelper.checkHeaderV13(builtByFactory);
99 Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());
100 Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
101 MultipartReplyFlowCase messageCase = (MultipartReplyFlowCase) builtByFactory.getMultipartReplyBody();
102 MultipartReplyFlow message = messageCase.getMultipartReplyFlow();
103 Assert.assertEquals("Wrong flow stats size", 2, message.getFlowStats().size());
104 FlowStats flowStats1 = message.getFlowStats().get(0);
105 Assert.assertEquals("Wrong tableId", 8, flowStats1.getTableId().intValue());
106 Assert.assertEquals("Wrong durationSec", 9, flowStats1.getDurationSec().intValue());
107 Assert.assertEquals("Wrong durationNsec", 7, flowStats1.getDurationNsec().intValue());
108 Assert.assertEquals("Wrong priority", 12, flowStats1.getPriority().intValue());
109 Assert.assertEquals("Wrong idleTimeOut", 14, flowStats1.getIdleTimeout().intValue());
110 Assert.assertEquals("Wrong hardTimeOut", 15, flowStats1.getHardTimeout().intValue());
111 Assert.assertEquals("Wrong flags", new FlowModFlags(true, true, true, true, true), flowStats1.getFlags());
112 Assert.assertEquals("Wrong cookie", new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01,
113 0x01, 0x01, 0x01}), flowStats1.getCookie());
114 Assert.assertEquals("Wrong packetCount", new BigInteger(1, new byte[]{(byte) 0xEF, 0x01, 0x01, 0x01,
115 0x01, 0x01, 0x01, 0x01}), flowStats1.getPacketCount());
116 Assert.assertEquals("Wrong byteCount", new BigInteger(1, new byte[]{(byte) 0x7F, 0x01, 0x01, 0x01,
117 0x01, 0x01, 0x01, 0x01}), flowStats1.getByteCount());
118 Assert.assertEquals("Wrong match type", OxmMatchType.class, flowStats1.getMatch().getType());
119 flowStats1 = message.getFlowStats().get(1);
120 Assert.assertEquals("Wrong tableId", 8, flowStats1.getTableId().intValue());
121 Assert.assertEquals("Wrong durationSec", 9, flowStats1.getDurationSec().intValue());
122 Assert.assertEquals("Wrong durationNsec", 7, flowStats1.getDurationNsec().intValue());
123 Assert.assertEquals("Wrong priority", 12, flowStats1.getPriority().intValue());
124 Assert.assertEquals("Wrong idleTimeOut", 14, flowStats1.getIdleTimeout().intValue());
125 Assert.assertEquals("Wrong hardTimeOut", 15, flowStats1.getHardTimeout().intValue());
126 Assert.assertEquals("Wrong flags", new FlowModFlags(false, false, false, false, false), flowStats1.getFlags());
127 Assert.assertEquals("Wrong cookie", new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01,
128 0x01, 0x01, 0x01}), flowStats1.getCookie());
129 Assert.assertEquals("Wrong packetCount", new BigInteger(1, new byte[]{(byte) 0xEF, 0x01, 0x01, 0x01,
130 0x01, 0x01, 0x01, 0x01}), flowStats1.getPacketCount());
131 Assert.assertEquals("Wrong byteCount", new BigInteger(1, new byte[]{(byte) 0x7F, 0x01, 0x01, 0x01,
132 0x01, 0x01, 0x01, 0x01}), flowStats1.getByteCount());
133 Assert.assertEquals("Wrong match type", OxmMatchType.class, flowStats1.getMatch().getType());