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