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.Before;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
20 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
23 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
32 * @author michal.polkorab
35 public class OF10PortModInputMessageFactoryTest {
37 private SerializerRegistry registry;
38 private OFSerializer<PortModInput> portModFactory;
41 * Initializes serializer registry and stores correct factory in field
44 public void startUp() {
45 registry = new SerializerRegistryImpl();
47 portModFactory = registry.getSerializer(
48 new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, PortModInput.class));
52 * Testing of {@link OF10PortModInputMessageFactory} for correct translation from POJO
56 public void testPortModInput() throws Exception {
57 PortModInputBuilder builder = new PortModInputBuilder();
58 BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
59 builder.setPortNo(new PortNumber(6633L));
60 builder.setHwAddress(new MacAddress("08:00:27:00:B0:EB"));
61 builder.setConfigV10(new PortConfigV10(true, false, false, true, false, false, true));
62 builder.setMaskV10(new PortConfigV10(false, true, true, false, false, true, false));
63 builder.setAdvertiseV10(new PortFeaturesV10(true, true, false, false, false, false,
64 false, true, true, false, false, false));
65 PortModInput message = builder.build();
67 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
68 portModFactory.serialize(message, out);
70 BufferHelper.checkHeaderV10(out, (byte) 15, 32);
71 Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedShort());
72 byte[] address = new byte[6];
73 out.readBytes(address);
74 Assert.assertEquals("Wrong MacAddress", message.getHwAddress(),
75 new MacAddress(ByteBufUtils.macAddressToString(address)));
76 Assert.assertEquals("Wrong config", 21, out.readUnsignedInt());
77 Assert.assertEquals("Wrong mask", 98, out.readUnsignedInt());
78 Assert.assertEquals("Wrong advertise", 652, out.readUnsignedInt());