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.deserialization.factories;
11 import io.netty.buffer.ByteBuf;
12 import java.math.BigInteger;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
25 * Translates FlowRemoved messages.
27 * @author michal.polkorab
28 * @author timotej.kubas
30 public class FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage>,
31 DeserializerRegistryInjector {
33 private DeserializerRegistry registry;
36 public FlowRemovedMessage deserialize(ByteBuf rawMessage) {
37 FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
38 builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
39 builder.setXid(rawMessage.readUnsignedInt());
40 byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
41 rawMessage.readBytes(cookie);
42 builder.setCookie(new BigInteger(1, cookie));
43 builder.setPriority(rawMessage.readUnsignedShort());
44 builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
45 builder.setTableId(new TableId((long)rawMessage.readUnsignedByte()));
46 builder.setDurationSec(rawMessage.readUnsignedInt());
47 builder.setDurationNsec(rawMessage.readUnsignedInt());
48 builder.setIdleTimeout(rawMessage.readUnsignedShort());
49 builder.setHardTimeout(rawMessage.readUnsignedShort());
50 byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
51 rawMessage.readBytes(packetCount);
52 builder.setPacketCount(new BigInteger(1, packetCount));
53 byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
54 rawMessage.readBytes(byteCount);
55 builder.setByteCount(new BigInteger(1, byteCount));
56 OFDeserializer<Match> matchDeserializer = registry.getDeserializer(new MessageCodeKey(
57 EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class));
58 builder.setMatch(matchDeserializer.deserialize(rawMessage));
59 return builder.build();
63 public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
64 registry = deserializerRegistry;