/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder; /** * Translates PortStatus messages * @author michal.polkorab * @author timotej.kubas */ public class PortStatusMessageFactory implements OFDeserializer { private static PortStatusMessageFactory instance; private static final byte PADDING_IN_PORT_STATUS_HEADER = 7; private static final byte PADDING_IN_OFP_PORT_HEADER_1 = 4; private static final byte PADDING_IN_OFP_PORT_HEADER_2 = 2; private static final int macAddressLength = 6; private PortStatusMessageFactory() { // Singleton } /** * @return singleton factory */ public static synchronized PortStatusMessageFactory getInstance(){ if(instance == null){ instance = new PortStatusMessageFactory(); } return instance; } @Override public PortStatusMessage bufferToMessage(ByteBuf rawMessage, short version) { PortStatusMessageBuilder builder = new PortStatusMessageBuilder(); builder.setVersion(version); builder.setXid(rawMessage.readUnsignedInt()); builder.setReason(PortReason.forValue(rawMessage.readUnsignedByte())); rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER); builder.setPortNo(rawMessage.readUnsignedInt()); rawMessage.skipBytes(PADDING_IN_OFP_PORT_HEADER_1); StringBuffer macToString = new StringBuffer(); for(int i=0; i