d0c776e0aac564a5e783e641f40ee38fc6658fd2
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / TunIpv4SrcCodec.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.openflowjava.nx.codec.match;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
14 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxTunIpv4Src;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.ipv4.src.grouping.TunIpv4SrcValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4SrcCaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4SrcCaseValueBuilder;
26
27 public class TunIpv4SrcCodec extends AbstractMatchCodec {
28
29     private static final int VALUE_LENGTH = 4;
30     private static final int NXM_FIELD_CODE = 31;
31     public static final MatchEntrySerializerKey<Nxm1Class, NxmNxTunIpv4Src> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
32             EncodeConstants.OF13_VERSION_ID, Nxm1Class.class, NxmNxTunIpv4Src.class);
33     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
34             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
35
36     @Override
37     public void serialize(MatchEntry input, ByteBuf outBuffer) {
38         serializeHeader(input, outBuffer);
39         TunIpv4SrcCaseValue caseValue = (TunIpv4SrcCaseValue) input.getMatchEntryValue();
40         outBuffer.writeInt(caseValue.getTunIpv4SrcValues().getValue().intValue());
41     }
42
43     @Override
44     public MatchEntry deserialize(ByteBuf message) {
45         MatchEntryBuilder matchEntriesBuilder = deserializeHeaderToBuilder(message);
46         TunIpv4SrcCaseValueBuilder caseBuilder = new TunIpv4SrcCaseValueBuilder();
47         TunIpv4SrcValuesBuilder valuesBuilder = new TunIpv4SrcValuesBuilder();
48         valuesBuilder.setValue(message.readUnsignedInt());
49         caseBuilder.setTunIpv4SrcValues(valuesBuilder.build());
50         matchEntriesBuilder.setMatchEntryValue(caseBuilder.build());
51         return matchEntriesBuilder.build();
52     }
53
54     @Override
55     public int getNxmFieldCode() {
56         return NXM_FIELD_CODE;
57     }
58
59     @Override
60     public int getOxmClassCode() {
61         return OxmMatchConstants.NXM_1_CLASS;
62     }
63
64     @Override
65     public int getValueLength() {
66         return VALUE_LENGTH;
67     }
68
69     @Override
70     public Class<? extends MatchField> getNxmField() {
71         return NxmNxTunIpv4Src.class;
72     }
73
74     @Override
75     public Class<? extends OxmClassBase> getOxmClass() {
76         return Nxm1Class.class;
77     }
78
79 }