2 * Copyright (c) 2015 NetIDE Consortium 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
8 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import io.netty.buffer.ByteBuf;
12 import java.math.BigInteger;
13 import java.util.List;
14 import java.util.Objects;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
20 import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker;
21 import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactory;
22 import org.opendaylight.openflowjava.protocol.impl.util.ListDeserializer;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
32 * Translates FlowModInput messages.
34 * @author giuseppex.petralia@intel.com
36 public class OF10FlowModInputMessageFactory implements OFDeserializer<FlowModInput>, DeserializerRegistryInjector {
38 private DeserializerRegistry registry;
41 public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
42 registry = deserializerRegistry;
46 @SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") // FB doesn't recognize Objects.requireNonNull
47 public FlowModInput deserialize(ByteBuf rawMessage) {
48 Objects.requireNonNull(registry);
50 FlowModInputBuilder builder = new FlowModInputBuilder();
51 builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
52 builder.setXid(rawMessage.readUnsignedInt());
53 OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(
54 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
55 builder.setMatchV10(matchDeserializer.deserialize(rawMessage));
56 byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
57 rawMessage.readBytes(cookie);
58 builder.setCookie(new BigInteger(1, cookie));
59 builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedShort()));
60 builder.setIdleTimeout(rawMessage.readUnsignedShort());
61 builder.setHardTimeout(rawMessage.readUnsignedShort());
62 builder.setPriority(rawMessage.readUnsignedShort());
63 builder.setBufferId(rawMessage.readUnsignedInt());
64 builder.setOutPort(new PortNumber((long) rawMessage.readUnsignedShort()));
65 builder.setFlagsV10(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort()));
66 CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);
68 List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID,
69 rawMessage.readableBytes(), rawMessage, keyMaker, registry);
70 builder.setAction(actions);
71 return builder.build();
74 @SuppressWarnings("checkstyle:AbbreviationAsWordInName")
75 private static FlowModFlagsV10 createFlowModFlagsFromBitmap(int input) {
76 final Boolean _oFPFFSENDFLOWREM = (input & 1 << 0) != 0;
77 final Boolean _oFPFFCHECKOVERLAP = (input & 1 << 1) != 0;
78 final Boolean _oFPFFEMERG = (input & 1 << 2) != 0;
79 return new FlowModFlagsV10(_oFPFFCHECKOVERLAP, _oFPFFEMERG, _oFPFFSENDFLOWREM);