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.util;
11 import io.netty.buffer.ByteBuf;
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.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder;
22 * Deserializes ofp_match (OpenFlow v1.3) and its oxm_fields structures
23 * @author timotej.kubas
24 * @author michal.polkorab
26 public class MatchDeserializer implements OFDeserializer<Match>,
27 DeserializerRegistryInjector {
29 private DeserializerRegistry registry;
32 public Match deserialize(ByteBuf input) {
33 if (input.readableBytes() > 0) {
34 MatchBuilder builder = new MatchBuilder();
35 int type = input.readUnsignedShort();
36 int length = input.readUnsignedShort();
39 builder.setType(StandardMatchType.class);
42 builder.setType(OxmMatchType.class);
47 builder.setMatchEntries(DecodingUtils.deserializeMatchEntries(
48 length - 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES, input, registry));
49 int paddingRemainder = length % EncodeConstants.PADDING;
50 if (paddingRemainder != 0) {
51 input.skipBytes(EncodeConstants.PADDING - paddingRemainder);
53 return builder.build();
59 public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
60 this.registry = deserializerRegistry;