2 * Copyright (c) 2017 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.openflowplugin.impl.protocol.deserialization.multipart;
11 import io.netty.buffer.ByteBuf;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.util.ByteBufUtils;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.StateBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.multipart.reply.multipart.reply.body.MultipartReplyPortDescBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.multipart.reply.multipart.reply.body.multipart.reply.port.desc.Ports;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.multipart.reply.multipart.reply.body.multipart.reply.port.desc.PortsBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.multipart.reply.MultipartReplyBody;
27 public class MultipartReplyPortDescDeserializer implements OFDeserializer<MultipartReplyBody> {
29 private static final byte PADDING_IN_PORT_DESC_HEADER_01 = 4;
30 private static final byte PADDING_IN_PORT_DESC_HEADER_02 = 2;
33 public MultipartReplyBody deserialize(ByteBuf message) {
34 final MultipartReplyPortDescBuilder builder = new MultipartReplyPortDescBuilder();
35 final List<Ports> items = new ArrayList<>();
37 while (message.readableBytes() > 0) {
38 final PortsBuilder itemBuilder = new PortsBuilder();
39 itemBuilder.setPortNumber(new PortNumberUni(message.readUnsignedInt()));
40 message.skipBytes(PADDING_IN_PORT_DESC_HEADER_01);
41 itemBuilder.setHardwareAddress(ByteBufUtils.readIetfMacAddress(message));
42 message.skipBytes(PADDING_IN_PORT_DESC_HEADER_02);
45 .setName(ByteBufUtils.decodeNullTerminatedString(message, EncodeConstants.MAX_PORT_NAME_LENGTH))
46 .setConfiguration(readPortConfig(message))
47 .setState(readPortState(message))
48 .setCurrentFeature(readPortFeatures(message))
49 .setAdvertisedFeatures(readPortFeatures(message))
50 .setSupported(readPortFeatures(message))
51 .setPeerFeatures(readPortFeatures(message))
52 .setCurrentSpeed(message.readUnsignedInt())
53 .setMaximumSpeed(message.readUnsignedInt())
63 private static PortConfig readPortConfig(final ByteBuf message) {
64 final long input = message.readUnsignedInt();
65 final Boolean pcPortDown = ((input) & (1)) != 0;
66 final Boolean pcNRecv = ((input) & (1 << 2)) != 0;
67 final Boolean pcNFwd = ((input) & (1 << 5)) != 0;
68 final Boolean pcNPacketIn = ((input) & (1 << 6)) != 0;
69 return new PortConfig(pcNFwd, pcNPacketIn, pcNRecv, pcPortDown);
72 private static State readPortState(final ByteBuf message) {
73 final long input = message.readUnsignedInt();
74 final Boolean psLinkDown = ((input) & (1)) != 0;
75 final Boolean psBlocked = ((input) & (1 << 1)) != 0;
76 final Boolean psLive = ((input) & (1 << 2)) != 0;
77 return new StateBuilder()
78 .setBlocked(psBlocked)
79 .setLinkDown(psLinkDown)
84 private static PortFeatures readPortFeatures(ByteBuf message) {
85 final long input = message.readUnsignedInt();
86 final Boolean pf10mbHd = ((input) & (1)) != 0;
87 final Boolean pf10mbFd = ((input) & (1 << 1)) != 0;
88 final Boolean pf100mbHd = ((input) & (1 << 2)) != 0;
89 final Boolean pf100mbFd = ((input) & (1 << 3)) != 0;
90 final Boolean pf1gbHd = ((input) & (1 << 4)) != 0;
91 final Boolean pf1gbFd = ((input) & (1 << 5)) != 0;
92 final Boolean pf10gbFd = ((input) & (1 << 6)) != 0;
93 final Boolean pf40gbFd = ((input) & (1 << 7)) != 0;
94 final Boolean pf100gbFd = ((input) & (1 << 8)) != 0;
95 final Boolean pf1tbFd = ((input) & (1 << 9)) != 0;
96 final Boolean pfOther = ((input) & (1 << 10)) != 0;
97 final Boolean pfCopper = ((input) & (1 << 11)) != 0;
98 final Boolean pfFiber = ((input) & (1 << 12)) != 0;
99 final Boolean pfAutoneg = ((input) & (1 << 13)) != 0;
100 final Boolean pfPause = ((input) & (1 << 14)) != 0;
101 final Boolean pfPauseAsym = ((input) & (1 << 15)) != 0;
102 return new PortFeatures(pfAutoneg, pfCopper, pfFiber, pf40gbFd,
103 pf100gbFd, pf100mbFd, pf100mbHd, pf1gbFd, pf1gbHd, pf1tbFd,
104 pfOther, pfPause, pfPauseAsym, pf10gbFd, pf10mbFd, pf10mbHd);