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;
13 import java.math.BigInteger;
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.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
26 * Translates FlowRemoved messages (OpenFlow v1.0)
27 * @author michal.polkorab
29 public class OF10FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage>,
30 DeserializerRegistryInjector {
32 private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE = 1;
33 private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE_2 = 2;
34 private DeserializerRegistry registry;
37 public FlowRemovedMessage deserialize(ByteBuf rawMessage) {
38 FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
39 builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
40 builder.setXid(rawMessage.readUnsignedInt());
41 OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(
42 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
43 builder.setMatchV10(matchDeserializer.deserialize(rawMessage));
44 byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
45 rawMessage.readBytes(cookie);
46 builder.setCookie(new BigInteger(1, cookie));
47 builder.setPriority(rawMessage.readUnsignedShort());
48 builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
49 rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE);
50 builder.setDurationSec(rawMessage.readUnsignedInt());
51 builder.setDurationNsec(rawMessage.readUnsignedInt());
52 builder.setIdleTimeout(rawMessage.readUnsignedShort());
53 rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE_2);
54 byte[] packet_count = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
55 rawMessage.readBytes(packet_count);
56 builder.setPacketCount(new BigInteger(1, packet_count));
57 byte[] byte_count = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
58 rawMessage.readBytes(byte_count);
59 builder.setByteCount(new BigInteger(1, byte_count));
60 return builder.build();
64 public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
65 registry = deserializerRegistry;