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.deserialization.match;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
13 import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmDeserializerHelper;
14 import org.opendaylight.openflowjava.util.ByteBufUtils;
15 import org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MatchEntryDeserializer;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
21 public abstract class AbstractMatchEntryDeserializer implements MatchEntryDeserializer {
24 * Processes match entry header and returns if it have mask, or not.
25 * @param in input buffer
26 * @return true if match entry has mask, false otherwise
28 protected static boolean processHeader(ByteBuf in) {
29 in.skipBytes(Short.BYTES); // skip oxm_class
30 boolean hasMask = (in.readUnsignedByte() & 1) != 0;
31 in.skipBytes(Byte.BYTES); // skip match entry length
36 * Read Ipv4Prefix from message.
37 * @param message buffered message
38 * @param hasMask determines if prefix has mask or not
41 protected static Ipv4Prefix readPrefix(ByteBuf message, boolean hasMask) {
42 final Ipv4Address address = ByteBufUtils.readIetfIpv4Address(message);
46 mask = IpConversionUtil.countBits(
47 OxmDeserializerHelper.convertMask(message, EncodeConstants.GROUPS_IN_IPV4_ADDRESS));
50 return IpConversionUtil.createPrefix(address, mask);
54 * Throw error on malformed match builder input.
55 * @param builder match builder
56 * @param propertyName name of property that already containsData
58 protected static void throwErrorOnMalformed(MatchBuilder builder, String propertyName) {
59 throw new IllegalArgumentException("Match: " + builder.toString() + " is malformed, "
60 + builder + "#" + propertyName + " contains invalid data.");
64 * Throw error on malformed match builder input.
65 * @param builder match builder
66 * @param propertyName name of property that already containsData
68 protected static void throwErrorOnMalformed(MatchBuilder builder, String propertyName, String fieldName) {
69 throw new IllegalArgumentException("Match: " + builder.toString() + " is malformed, "
70 + builder + "#" + propertyName + "#" + fieldName + " contains invalid data.");