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;
13 import java.util.HashMap;
16 import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
17 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
23 * Translates PortMod messages
24 * @author michal.polkorab
26 public class OF10PortModInputMessageFactory implements OFSerializer<PortModInput> {
28 private static final byte MESSAGE_TYPE = 15;
29 private static final byte PADDING_IN_PORT_MOD_MESSAGE = 4;
30 private static final int MESSAGE_LENGTH = 32;
32 private static OF10PortModInputMessageFactory instance;
34 private OF10PortModInputMessageFactory() {
39 * @return singleton factory
41 public static synchronized OF10PortModInputMessageFactory getInstance() {
42 if (instance == null) {
43 instance = new OF10PortModInputMessageFactory();
49 public void messageToBuffer(short version, ByteBuf out, PortModInput message) {
50 ByteBufUtils.writeOFHeader(instance, message, out);
51 out.writeShort(message.getPortNo().getValue().intValue());
52 out.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue()));
53 out.writeInt(createPortConfigBitmask(message.getConfigV10()));
54 out.writeInt(createPortConfigBitmask(message.getMaskV10()));
55 out.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10()));
56 ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE, out);
60 public int computeLength(PortModInput message) {
61 return MESSAGE_LENGTH;
65 public byte getMessageType() {
72 * @return port config bitmask
74 private static int createPortConfigBitmask(PortConfigV10 config) {
75 int configBitmask = 0;
76 Map<Integer, Boolean> portConfigMap = new HashMap<>();
77 portConfigMap.put(0, config.isPortDown());
78 portConfigMap.put(1, config.isNoStp());
79 portConfigMap.put(2, config.isNoRecv());
80 portConfigMap.put(3, config.isNoRecvStp());
81 portConfigMap.put(4, config.isNoFlood());
82 portConfigMap.put(5, config.isNoFwd());
83 portConfigMap.put(6, config.isNoPacketIn());
85 configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap);
89 private static int createPortFeaturesBitmask(PortFeaturesV10 feature) {
90 int configBitmask = 0;
91 Map<Integer, Boolean> portFeaturesMap = new HashMap<>();
92 portFeaturesMap.put(0, feature.is_10mbHd());
93 portFeaturesMap.put(1, feature.is_10mbFd());
94 portFeaturesMap.put(2, feature.is_100mbHd());
95 portFeaturesMap.put(3, feature.is_100mbFd());
96 portFeaturesMap.put(4, feature.is_1gbHd());
97 portFeaturesMap.put(5, feature.is_1gbFd());
98 portFeaturesMap.put(6, feature.is_10gbFd());
99 portFeaturesMap.put(7, feature.isCopper());
100 portFeaturesMap.put(8, feature.isFiber());
101 portFeaturesMap.put(9, feature.isAutoneg());
102 portFeaturesMap.put(10, feature.isPause());
103 portFeaturesMap.put(11, feature.isPauseAsym());
104 configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap);
105 return configBitmask;