Updated experimenter model
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF10PortModInputMessageFactory.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
14 import org.opendaylight.openflowjava.util.ByteBufUtils;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
19
20 /**
21  * Translates PortMod messages
22  * @author michal.polkorab
23  */
24 public class OF10PortModInputMessageFactory implements OFSerializer<PortModInput> {
25
26     private static final byte MESSAGE_TYPE = 15;
27     private static final byte PADDING_IN_PORT_MOD_MESSAGE = 4;
28
29     @Override
30     public void serialize(final PortModInput message, final ByteBuf outBuffer) {
31         ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
32         outBuffer.writeShort(message.getPortNo().getValue().intValue());
33         outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue()));
34         outBuffer.writeInt(createPortConfigBitmask(message.getConfigV10()));
35         outBuffer.writeInt(createPortConfigBitmask(message.getMaskV10()));
36         outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10()));
37         ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE, outBuffer);
38         ByteBufUtils.updateOFHeaderLength(outBuffer);
39     }
40
41     /**
42      * @param config
43      * @return port config bitmask
44      */
45     private static int createPortConfigBitmask(final PortConfigV10 config) {
46         return ByteBufUtils.fillBitMask(0,
47                 config.isPortDown(),
48                 config.isNoStp(),
49                 config.isNoRecv(),
50                 config.isNoRecvStp(),
51                 config.isNoFlood(),
52                 config.isNoFwd(),
53                 config.isNoPacketIn());
54     }
55
56     private static int createPortFeaturesBitmask(final PortFeaturesV10 feature) {
57         return ByteBufUtils.fillBitMask(0,
58                 feature.is_10mbHd(),
59                 feature.is_10mbFd(),
60                 feature.is_100mbHd(),
61                 feature.is_100mbFd(),
62                 feature.is_1gbHd(),
63                 feature.is_1gbFd(),
64                 feature.is_10gbFd(),
65                 feature.isCopper(),
66                 feature.isFiber(),
67                 feature.isAutoneg(),
68                 feature.isPause(),
69                 feature.isPauseAsym());
70     }
71
72 }