Added JSON and XML payloads tabs with RFC 8040 URL
[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
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowjava.util.ByteBufUtils;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
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  *
23  * @author michal.polkorab
24  */
25 public class OF10PortModInputMessageFactory implements OFSerializer<PortModInput> {
26
27     private static final byte MESSAGE_TYPE = 15;
28     private static final byte PADDING_IN_PORT_MOD_MESSAGE = 4;
29
30     @Override
31     public void serialize(final PortModInput message, final ByteBuf outBuffer) {
32         ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
33         outBuffer.writeShort(message.getPortNo().getValue().intValue());
34         outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(message.getHwAddress()));
35         outBuffer.writeInt(createPortConfigBitmask(message.getConfigV10()));
36         outBuffer.writeInt(createPortConfigBitmask(message.getMaskV10()));
37         outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10()));
38         outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE);
39         ByteBufUtils.updateOFHeaderLength(outBuffer);
40     }
41
42     private static int createPortConfigBitmask(final PortConfigV10 config) {
43         return ByteBufUtils.fillBitMask(0,
44                 config.isPortDown(),
45                 config.isNoStp(),
46                 config.isNoRecv(),
47                 config.isNoRecvStp(),
48                 config.isNoFlood(),
49                 config.isNoFwd(),
50                 config.isNoPacketIn());
51     }
52
53     private static int createPortFeaturesBitmask(final PortFeaturesV10 feature) {
54         return ByteBufUtils.fillBitMask(0,
55                 feature.is_10mbHd(),
56                 feature.is_10mbFd(),
57                 feature.is_100mbHd(),
58                 feature.is_100mbFd(),
59                 feature.is_1gbHd(),
60                 feature.is_1gbFd(),
61                 feature.is_10gbFd(),
62                 feature.isCopper(),
63                 feature.isFiber(),
64                 feature.isAutoneg(),
65                 feature.isPause(),
66                 feature.isPauseAsym());
67     }
68
69 }