Merge "Bug 7481 - Flows with nicira actions get corrupted after cluster failure"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / AbstractExperimenterMatchEntrySerializer.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
10
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
14
15 public abstract class AbstractExperimenterMatchEntrySerializer extends AbstractMatchEntrySerializer {
16
17     @Override
18     public void serialize(Match match, ByteBuf outBuffer) {
19         super.serialize(match, outBuffer);
20         outBuffer.writeInt(Long.valueOf(getExperimenterId()).intValue());
21     }
22
23     @Override
24     public void serializeHeader(Match match, ByteBuf outBuffer) {
25         outBuffer.writeShort(getOxmClassCode());
26
27         int fieldAndMask = getOxmFieldCode() << 1;
28         int length = getValueLength();
29
30         if (getHasMask(match)) {
31             fieldAndMask |= 1;
32             length *= 2;
33         }
34
35         outBuffer.writeByte(fieldAndMask);
36
37         // Add length of experimenter ID to total length
38         outBuffer.writeByte(length + EncodeConstants.SIZE_OF_INT_IN_BYTES);
39     }
40
41     /**
42      * @return experimenter match entry id
43      */
44     protected abstract long getExperimenterId();
45 }