Bump upstreams
[openflowplugin.git] / openflowjava / 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 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
13 import org.opendaylight.openflowjava.util.ByteBufUtils;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
18
19 /**
20  * Translates PortMod messages.
21  *
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(IetfYangUtil.macAddressBytes(message.getHwAddress()));
34         outBuffer.writeInt(createPortConfigBitmask(message.getConfigV10()));
35         outBuffer.writeInt(createPortConfigBitmask(message.getMaskV10()));
36         outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10()));
37         outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE);
38         ByteBufUtils.updateOFHeaderLength(outBuffer);
39     }
40
41     private static int createPortConfigBitmask(final PortConfigV10 config) {
42         return ByteBufUtils.fillBitMask(0,
43                 config.getPortDown(),
44                 config.getNoStp(),
45                 config.getNoRecv(),
46                 config.getNoRecvStp(),
47                 config.getNoFlood(),
48                 config.getNoFwd(),
49                 config.getNoPacketIn());
50     }
51
52     private static int createPortFeaturesBitmask(final PortFeaturesV10 feature) {
53         return ByteBufUtils.fillBitMask(0,
54                 feature.get_10mbHd(),
55                 feature.get_10mbFd(),
56                 feature.get_100mbHd(),
57                 feature.get_100mbFd(),
58                 feature.get_1gbHd(),
59                 feature.get_1gbFd(),
60                 feature.get_10gbFd(),
61                 feature.getCopper(),
62                 feature.getFiber(),
63                 feature.getAutoneg(),
64                 feature.getPause(),
65                 feature.getPauseAsym());
66     }
67
68 }