2 * Copyright (c) 2013 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.serialization.factories;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.UnpooledByteBufAllocator;
13 import junit.framework.Assert;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
17 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
18 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
27 * @author michal.polkorab
30 public class OF10PortModInputMessageFactoryTest {
33 * Testing of {@link OF10PortModInputMessageFactory} for correct translation from POJO
37 public void testPortModInput() throws Exception {
38 PortModInputBuilder builder = new PortModInputBuilder();
39 BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
40 builder.setPortNo(new PortNumber(6633L));
41 builder.setHwAddress(new MacAddress("08:00:27:00:B0:EB"));
42 builder.setConfigV10(new PortConfigV10(true, false, false, true, false, false, true));
43 builder.setMaskV10(new PortConfigV10(false, true, true, false, false, true, false));
44 builder.setAdvertiseV10(new PortFeaturesV10(true, true, false, false, false, false,
45 false, true, true, false, false, false));
46 PortModInput message = builder.build();
48 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
49 OF10PortModInputMessageFactory factory = OF10PortModInputMessageFactory.getInstance();
50 factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
52 BufferHelper.checkHeaderV10(out, (byte) 15, 32);
53 Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedShort());
54 byte[] address = new byte[6];
55 out.readBytes(address);
56 Assert.assertEquals("Wrong MacAddress", message.getHwAddress(),
57 new MacAddress(ByteBufUtils.macAddressToString(address)));
58 Assert.assertEquals("Wrong config", 21, out.readUnsignedInt());
59 Assert.assertEquals("Wrong mask", 98, out.readUnsignedInt());
60 Assert.assertEquals("Wrong advertise", 652, out.readUnsignedInt());