2 * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
11 import io.netty.buffer.ByteBuf;
12 import java.util.Iterator;
13 import java.util.Objects;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4Match;
20 public class TunnelIpv4SourceEntrySerializer extends AbstractMatchEntrySerializer {
23 public void serialize(Match match, ByteBuf outBuffer) {
24 super.serialize(match, outBuffer);
25 // TODO: Why is this serialization exactly same as in Ipv4SourceEntrySerializer?
26 writeIpv4Prefix(TunnelIpv4Match.class.cast(match.getLayer3Match()).getTunnelIpv4Source(), outBuffer);
30 public boolean matchTypeCheck(Match match) {
31 return Objects.nonNull(match.getLayer3Match()) &&
32 TunnelIpv4Match.class.isInstance(match.getLayer3Match()) &&
33 Objects.nonNull(TunnelIpv4Match.class.cast(match.getLayer3Match()).getTunnelIpv4Source());
37 protected boolean getHasMask(Match match) {
38 // Split address to IP and mask
39 final Iterator<String> addressParts = IpConversionUtil.splitToParts(
40 TunnelIpv4Match.class.cast(match.getLayer3Match()).getTunnelIpv4Source());
43 // Check if we have mask
44 return addressParts.hasNext() && Integer.parseInt(addressParts.next()) < 32;
48 protected int getOxmFieldCode() {
49 return OxmMatchConstants.IPV4_SRC;
53 protected int getOxmClassCode() {
54 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
58 protected int getValueLength() {
59 return EncodeConstants.SIZE_OF_INT_IN_BYTES;