1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
\r
2 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
\r
4 import io.netty.buffer.ByteBuf;
\r
5 import io.netty.buffer.UnpooledByteBufAllocator;
\r
6 import junit.framework.Assert;
\r
8 import org.junit.Test;
\r
9 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
\r
10 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
\r
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInputBuilder;
\r
17 * @author timotej.kubas
\r
18 * @author michal.polkorab
\r
20 public class TableModInputMessageFactoryTest {
\r
21 private static final byte MESSAGE_TYPE = 17;
\r
22 private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3;
\r
25 * Testing of {@link TableModInputMessageFactory} for correct translation from POJO
\r
26 * @throws Exception
\r
29 public void testTableModInput() throws Exception {
\r
30 TableModInputBuilder builder = new TableModInputBuilder();
\r
31 BufferHelper.setupHeader(builder);
\r
32 builder.setTableId(new TableId(9L));
\r
33 builder.setConfig(new PortConfig(true, false, true, false));
\r
34 TableModInput message = builder.build();
\r
36 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
37 TableModInputMessageFactory factory = TableModInputMessageFactory.getInstance();
\r
38 factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
\r
40 BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16);
\r
41 Assert.assertEquals("Wrong TableID", message.getTableId().getValue().intValue(), out.readByte());
\r
42 out.skipBytes(PADDING_IN_TABLE_MOD_MESSAGE);
\r
43 Assert.assertEquals("Wrong PortConfig", message.getConfig(), createPortConfig(out.readInt()));
\r
46 private static PortConfig createPortConfig(long input){
\r
47 final Boolean _portDown = ((input) & (1<<0)) > 0;
\r
48 final Boolean _noRecv = ((input) & (1<<2)) > 0;
\r
49 final Boolean _noFwd = ((input) & (1<<5)) > 0;
\r
50 final Boolean _noPacketIn = ((input) & (1<<6)) > 0;
\r
51 return new PortConfig(_noFwd, _noPacketIn, _noRecv, _portDown);
\r