Bug 2756 - Match model update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / match / OxmIcmpv4CodeDeserializer.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowjava.protocol.impl.deserialization.match;
9
10 import io.netty.buffer.ByteBuf;
11
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv4Code;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4CodeCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.code._case.Icmpv4CodeBuilder;
21
22 /**
23  * @author michal.polkorab
24  *
25  */
26 public class OxmIcmpv4CodeDeserializer extends AbstractOxmMatchEntryDeserializer
27         implements OFDeserializer<MatchEntry> {
28
29     @Override
30     public MatchEntry deserialize(ByteBuf input) {
31         MatchEntryBuilder builder = processHeader(getOxmClass(), getOxmField(), input);
32         addIcmpv4CodeValue(input, builder);
33         return builder.build();
34     }
35
36     private static void addIcmpv4CodeValue(ByteBuf input, MatchEntryBuilder builder) {
37         Icmpv4CodeCaseBuilder caseBuilder = new Icmpv4CodeCaseBuilder();
38         Icmpv4CodeBuilder icmpBuilder = new Icmpv4CodeBuilder();
39         icmpBuilder.setIcmpv4Code(input.readUnsignedByte());
40         caseBuilder.setIcmpv4Code(icmpBuilder.build());
41         builder.setMatchEntryValue(caseBuilder.build());
42     }
43
44     @Override
45     protected Class<? extends MatchField> getOxmField() {
46         return Icmpv4Code.class;
47     }
48
49     @Override
50     protected Class<? extends OxmClassBase> getOxmClass() {
51         return OpenflowBasicClass.class;
52     }
53
54 }