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