Bug 5895 - Support of Ext109 openflow tcp flag matching
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / match / ext / OnfOxmTcpFlagsSerializer.java
1 /*
2  * Copyright (c) 2016 Brocade Communications 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 package org.opendaylight.openflowjava.protocol.impl.serialization.match.ext;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
12 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.TcpFlagsContainer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.oxm.container.match.entry.value.experimenter.id._case.TcpFlags;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
17
18 /**
19  * Created by Anil Vishnoi (avishnoi@Brocade.com) on 7/25/16.
20  */
21 public class OnfOxmTcpFlagsSerializer extends AbstractOxmExperimenterMatchEntrySerializer {
22
23     @Override
24     public void serialize(MatchEntry entry, ByteBuf outBuffer) {
25         super.serialize(entry, outBuffer);
26         ExperimenterIdCase expCase = serializeExperimenterId(entry, outBuffer);
27         TcpFlags tcpFlags = expCase.getAugmentation(TcpFlagsContainer.class).getTcpFlags();
28         outBuffer.writeShort(tcpFlags.getFlags());
29         if (entry.isHasMask()) {
30             outBuffer.writeBytes(tcpFlags.getMask());
31         }
32     }
33
34     /**
35      * @return Experimenter match entry ID
36      */
37     @Override
38     protected long getExperimenterId() {
39         return OxmMatchConstants.ONFOXM_ET_TCP_FLAGS_EXP_ID;
40     }
41
42     /**
43      * @return numeric representation of oxm_field
44      */
45     @Override
46     protected int getOxmFieldCode() {
47         return OxmMatchConstants.ONFOXM_ET_TCP_FLAGS;
48     }
49
50     /**
51      * @return numeric representation of oxm_class
52      */
53     @Override
54     protected int getOxmClassCode() {
55         return OxmMatchConstants.EXPERIMENTER_CLASS;
56     }
57
58     /**
59      * @return match entry value length (without mask length)
60      */
61     @Override
62     protected int getValueLength() {
63         return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
64     }
65 }