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
8 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories.multipart;
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.deserialization.factories.MultipartReplyMessageFactory;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmMatchType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
27 import org.opendaylight.yangtools.yang.common.Uint64;
30 * Unit tests for MultipartReplyFlow.
32 * @author michal.polkorab
34 public class MultipartReplyFlowTest {
36 private OFDeserializer<MultipartReplyMessage> factory;
39 * Initializes deserializer registry and lookups correct deserializer.
42 public void startUp() {
43 DeserializerRegistry registry = new DeserializerRegistryImpl();
45 factory = registry.getDeserializer(
46 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 19, MultipartReplyMessage.class));
50 * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
53 public void testEmptyMultipartReplyFlowBody() {
54 ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00");
55 MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
57 BufferHelper.checkHeaderV13(builtByFactory);
58 Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());
59 Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
60 MultipartReplyFlowCase messageCase = (MultipartReplyFlowCase) builtByFactory.getMultipartReplyBody();
61 MultipartReplyFlow message = messageCase.getMultipartReplyFlow();
62 Assert.assertEquals("Wrong flow stats size", 0, message.nonnullFlowStats().size());
66 * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
69 public void testMultipartReplyFlowBody() {
70 ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00 " + //
72 "00 48 08 00 " + // length, tableId, padding
73 "00 00 00 09 " + //durationSec
74 "00 00 00 07 " + //durationNsec
75 "00 0C 00 0E 00 0F 00 1F " + //priority, idleTimeout, hardTimeout, flags
76 "00 00 00 00 " + //pad_02
77 "FF 01 01 01 01 01 01 01 " + //cookie
78 "EF 01 01 01 01 01 01 01 " + //packetCount
79 "7F 01 01 01 01 01 01 01 " + //byteCount
80 "00 01 00 04 00 00 00 00 " + //empty match
81 "00 01 00 08 06 00 00 00 " + //
82 "00 01 00 08 06 00 00 00 " + //
84 "00 48 08 00 " + // length, tableId, padding
85 "00 00 00 09 " + //durationSec
86 "00 00 00 07 " + //durationNsec
87 "00 0C 00 0E 00 0F 00 00 " + // priority, idleTimeout, hardTimeout, flags
88 "00 00 00 00 " + //pad_02
89 "FF 01 01 01 01 01 01 01 " + //cookie
90 "EF 01 01 01 01 01 01 01 " + //packetCount
91 "7F 01 01 01 01 01 01 01 " + //byteCount
92 "00 01 00 04 00 00 00 00 " + //empty match
93 "00 01 00 08 06 00 00 00 " + //
94 "00 01 00 08 06 00 00 00");
95 MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
97 BufferHelper.checkHeaderV13(builtByFactory);
98 Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());
99 Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
100 MultipartReplyFlowCase messageCase = (MultipartReplyFlowCase) builtByFactory.getMultipartReplyBody();
101 MultipartReplyFlow message = messageCase.getMultipartReplyFlow();
102 Assert.assertEquals("Wrong flow stats size", 2, message.getFlowStats().size());
103 FlowStats flowStats1 = message.getFlowStats().get(0);
104 Assert.assertEquals("Wrong tableId", 8, flowStats1.getTableId().intValue());
105 Assert.assertEquals("Wrong durationSec", 9, flowStats1.getDurationSec().intValue());
106 Assert.assertEquals("Wrong durationNsec", 7, flowStats1.getDurationNsec().intValue());
107 Assert.assertEquals("Wrong priority", 12, flowStats1.getPriority().intValue());
108 Assert.assertEquals("Wrong idleTimeOut", 14, flowStats1.getIdleTimeout().intValue());
109 Assert.assertEquals("Wrong hardTimeOut", 15, flowStats1.getHardTimeout().intValue());
110 Assert.assertEquals("Wrong flags", new FlowModFlags(true, true, true, true, true), flowStats1.getFlags());
111 Assert.assertEquals("Wrong cookie", Uint64.valueOf("FF01010101010101", 16), flowStats1.getCookie());
112 Assert.assertEquals("Wrong packetCount", Uint64.valueOf("EF01010101010101", 16), flowStats1.getPacketCount());
113 Assert.assertEquals("Wrong byteCount", Uint64.valueOf("7F01010101010101", 16), flowStats1.getByteCount());
114 Assert.assertEquals("Wrong match type", OxmMatchType.class, flowStats1.getMatch().getType());
115 flowStats1 = message.getFlowStats().get(1);
116 Assert.assertEquals("Wrong tableId", 8, flowStats1.getTableId().intValue());
117 Assert.assertEquals("Wrong durationSec", 9, flowStats1.getDurationSec().intValue());
118 Assert.assertEquals("Wrong durationNsec", 7, flowStats1.getDurationNsec().intValue());
119 Assert.assertEquals("Wrong priority", 12, flowStats1.getPriority().intValue());
120 Assert.assertEquals("Wrong idleTimeOut", 14, flowStats1.getIdleTimeout().intValue());
121 Assert.assertEquals("Wrong hardTimeOut", 15, flowStats1.getHardTimeout().intValue());
122 Assert.assertEquals("Wrong flags", new FlowModFlags(false, false, false, false, false), flowStats1.getFlags());
123 Assert.assertEquals("Wrong cookie", Uint64.valueOf("FF01010101010101", 16), flowStats1.getCookie());
124 Assert.assertEquals("Wrong packetCount", Uint64.valueOf("EF01010101010101", 16), flowStats1.getPacketCount());
125 Assert.assertEquals("Wrong byteCount", Uint64.valueOf("7F01010101010101", 16), flowStats1.getByteCount());
126 Assert.assertEquals("Wrong match type", OxmMatchType.class, flowStats1.getMatch().getType());