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 java.util.List;
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.util.EncodeConstants;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
26 * Deserializes ofp_match (OpenFlow v1.3) and its oxm_fields structures
27 * @author timotej.kubas
28 * @author michal.polkorab
30 public class MatchDeserializer implements OFDeserializer<Match>,
31 DeserializerRegistryInjector {
33 private DeserializerRegistry registry;
36 public Match deserialize(ByteBuf input) {
37 if (input.readableBytes() > 0) {
38 MatchBuilder builder = new MatchBuilder();
39 int type = input.readUnsignedShort();
40 int length = input.readUnsignedShort();
43 builder.setType(StandardMatchType.class);
46 builder.setType(OxmMatchType.class);
51 CodeKeyMaker keyMaker = CodeKeyMakerFactory
52 .createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
53 List<MatchEntries> entries = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID,
54 length - 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES, input, keyMaker, registry);
55 builder.setMatchEntries(entries);
56 int paddingRemainder = length % EncodeConstants.PADDING;
57 if (paddingRemainder != 0) {
58 input.skipBytes(EncodeConstants.PADDING - paddingRemainder);
60 return builder.build();
66 public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
67 this.registry = deserializerRegistry;