Rework bit-copying functions and re-enable tests
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / TcpSourcePortEntrySerializer.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.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
17
18 public class TcpSourcePortEntrySerializer extends AbstractMatchEntrySerializer {
19
20     @Override
21     public void serialize(Match match, ByteBuf outBuffer) {
22         super.serialize(match, outBuffer);
23         outBuffer.writeShort(TcpMatch.class.cast(match.getLayer4Match()).getTcpSourcePort().getValue());
24     }
25
26     @Override
27     public boolean matchTypeCheck(Match match) {
28         return Objects.nonNull(match.getLayer4Match())
29                 && TcpMatch.class.isInstance(match.getLayer4Match())
30                 && Objects.nonNull(TcpMatch.class.cast(match.getLayer4Match()).getTcpSourcePort());
31     }
32
33     @Override
34     protected boolean getHasMask(Match match) {
35         return false;
36     }
37
38     @Override
39     protected int getOxmFieldCode() {
40         return OxmMatchConstants.TCP_SRC;
41     }
42
43     @Override
44     protected int getOxmClassCode() {
45         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
46     }
47
48     @Override
49     protected int getValueLength() {
50         return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
51     }
52
53 }