Merge "Remove Optional.ofNullable() antipatterns"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / InPortEntrySerializer.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 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
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.openflowplugin.api.openflow.md.util.OpenflowVersion;
14 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
16
17 public class InPortEntrySerializer extends AbstractMatchEntrySerializer {
18
19     @Override
20     public void serialize(Match match, ByteBuf outBuffer) {
21         super.serialize(match, outBuffer);
22         Long value = InventoryDataServiceUtil.portNumberfromNodeConnectorId(
23                 OpenflowVersion.OF13,
24                 match.getInPort().getValue());
25         if (value == null) {
26             throw new IllegalArgumentException("Not a valid port number: " + match.getInPort().getValue());
27         }
28         outBuffer.writeInt(value.intValue());
29     }
30
31     @Override
32     public boolean matchTypeCheck(Match match) {
33         return match.getInPort() != null;
34     }
35
36     @Override
37     protected boolean getHasMask(Match match) {
38         return false;
39     }
40
41     @Override
42     protected int getOxmFieldCode() {
43         return OxmMatchConstants.IN_PORT;
44     }
45
46     @Override
47     protected int getOxmClassCode() {
48         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
49     }
50
51     @Override
52     protected int getValueLength() {
53         return EncodeConstants.SIZE_OF_INT_IN_BYTES;
54     }
55 }