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