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 / InPhyPortEntrySerializer.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 java.util.Objects;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
15 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
16 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
18
19 public class InPhyPortEntrySerializer extends AbstractMatchEntrySerializer {
20
21     @Override
22     public void serialize(Match match, ByteBuf outBuffer) {
23         super.serialize(match, outBuffer);
24         outBuffer.writeInt(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
25                 OpenflowVersion.OF13,
26                 match.getInPhyPort()).intValue());
27     }
28
29     @Override
30     public boolean matchTypeCheck(Match match) {
31         return Objects.nonNull(match.getInPhyPort());
32     }
33
34     @Override
35     protected boolean getHasMask(Match match) {
36         return false;
37     }
38
39     @Override
40     protected int getOxmFieldCode() {
41         return OxmMatchConstants.IN_PHY_PORT;
42     }
43
44     @Override
45     protected int getOxmClassCode() {
46         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
47     }
48
49     @Override
50     protected int getValueLength() {
51         return EncodeConstants.SIZE_OF_INT_IN_BYTES;
52     }
53
54 }