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;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory;
16 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupTypes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeatures;
25 * @author michal.polkorab
28 public class MultipartReplyGroupFeaturesTest {
30 private MultipartReplyMessageFactory factory = new MultipartReplyMessageFactory();
33 * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
36 public void testMultipartReplyGroupFeatures() {
37 ByteBuf bb = BufferHelper.buildBuffer("00 08 00 01 00 00 00 00 "+
38 "00 00 00 0F "+// types
39 "00 00 00 0F "+// capabilities
40 "00 00 00 01 "+// max groups
41 "00 00 00 02 "+// max groups
42 "00 00 00 03 "+// max groups
43 "00 00 00 04 "+// max groups
44 "0F FF 98 01 "+// actions bitmap (all actions included)
45 "00 00 00 00 "+// actions bitmap (no actions included)
46 "00 00 00 00 "+// actions bitmap (no actions included)
47 "00 00 00 00"// actions bitmap (no actions included)
49 MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
51 BufferHelper.checkHeaderV13(builtByFactory);
52 Assert.assertEquals("Wrong type", 8, builtByFactory.getType().getIntValue());
53 Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
54 MultipartReplyGroupFeaturesCase messageCase =
55 (MultipartReplyGroupFeaturesCase) builtByFactory.getMultipartReplyBody();
56 MultipartReplyGroupFeatures message = messageCase.getMultipartReplyGroupFeatures();
57 Assert.assertEquals("Wrong group types", new GroupTypes(true, true, true, true), message.getTypes());
58 Assert.assertEquals("Wrong capabilities", new GroupCapabilities(true, true, true, true),
59 message.getCapabilities());
60 Assert.assertEquals("Wrong max groups", 1, message.getMaxGroups().get(0).intValue());
61 Assert.assertEquals("Wrong max groups", 2, message.getMaxGroups().get(1).intValue());
62 Assert.assertEquals("Wrong max groups", 3, message.getMaxGroups().get(2).intValue());
63 Assert.assertEquals("Wrong max groups", 4, message.getMaxGroups().get(3).intValue());
64 Assert.assertEquals("Wrong actions bitmap", new ActionType(true, true, true, true, false, true, true, true, true,
65 true, true, true, true, true, true, true, true), message.getActionsBitmap().get(0));
66 Assert.assertEquals("Wrong actions bitmap", new ActionType(false, false, false, false, false, false, false, false,
67 false, false, false, false, false, false, false, false, false), message.getActionsBitmap().get(1));
68 Assert.assertEquals("Wrong actions bitmap", new ActionType(false, false, false, false, false, false, false, false,
69 false, false, false, false, false, false, false, false, false), message.getActionsBitmap().get(2));
70 Assert.assertEquals("Wrong actions bitmap", new ActionType(false, false, false, false, false, false, false, false,
71 false, false, false, false, false, false, false, false, false), message.getActionsBitmap().get(3));
75 * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
76 * (with different group types and capabilities)
79 public void testMultipartReplyGroupFeatures2() {
80 ByteBuf bb = BufferHelper.buildBuffer("00 08 00 01 00 00 00 00 "+
81 "00 00 00 00 "+// types
82 "00 00 00 00 "+// capabilities
83 "00 00 00 01 "+// max groups
84 "00 00 00 02 "+// max groups
85 "00 00 00 03 "+// max groups
86 "00 00 00 04 "+// max groups
87 "00 00 00 00 "+// actions bitmap (all actions included)
88 "00 00 00 00 "+// actions bitmap (no actions included)
89 "00 00 00 00 "+// actions bitmap (no actions included)
90 "00 00 00 00"// actions bitmap (no actions included)
92 MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
94 BufferHelper.checkHeaderV13(builtByFactory);
95 Assert.assertEquals("Wrong type", 8, builtByFactory.getType().getIntValue());
96 Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
97 MultipartReplyGroupFeaturesCase messageCase =
98 (MultipartReplyGroupFeaturesCase) builtByFactory.getMultipartReplyBody();
99 MultipartReplyGroupFeatures message = messageCase.getMultipartReplyGroupFeatures();
100 Assert.assertEquals("Wrong group types", new GroupTypes(false, false, false, false), message.getTypes());
101 Assert.assertEquals("Wrong capabilities", new GroupCapabilities(false, false, false, false),
102 message.getCapabilities());