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 / AbstractOxmExperimenterMatchEntrySerializer.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.openflowjava.protocol.impl.serialization.match.AbstractOxmMatchEntrySerializer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
16
17 /**
18  * Created by Anil Vishnoi (avishnoi@Brocade.com) on 7/25/16.
19  */
20 public abstract class AbstractOxmExperimenterMatchEntrySerializer extends AbstractOxmMatchEntrySerializer {
21
22     @Override
23     public void serialize(MatchEntry entry, ByteBuf outBuffer) {
24         serializeHeader(entry, outBuffer);
25     }
26
27     @Override
28     public void serializeHeader(MatchEntry entry, ByteBuf outBuffer) {
29         outBuffer.writeShort(getOxmClassCode());
30         writeOxmFieldAndLength(outBuffer, getOxmFieldCode(), entry.isHasMask(),
31                 getValueLength());
32     }
33
34     protected static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, boolean hasMask, int lengthArg) {
35         int fieldAndMask = fieldValue << 1;
36         int length = lengthArg;
37         if (hasMask) {
38             fieldAndMask |= 1;
39             length *= 2;
40         }
41
42         //Add experimenter-id lenge
43         length = length + EncodeConstants.SIZE_OF_INT_IN_BYTES;
44         out.writeByte(fieldAndMask);
45         out.writeByte(length);
46     }
47
48     protected ExperimenterIdCase serializeExperimenterId(MatchEntry matchEntry, ByteBuf out) {
49         ExperimenterIdCase expCase = (ExperimenterIdCase) matchEntry.getMatchEntryValue();
50         out.writeInt(expCase.getExperimenter().getExperimenter().getValue().intValue());
51         return expCase;
52     }
53
54     /**
55      * @return Experimenter match entry ID
56      */
57     protected abstract long getExperimenterId();
58 }
59