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
8 package org.opendaylight.openflowplugin.impl.protocol.deserialization.match;
10 import io.netty.buffer.ByteBuf;
11 import javax.annotation.Nullable;
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.openflow.md.core.sal.convertor.common.IpConversionUtil;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMask;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMaskBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
23 public class Ipv4DestinationEntryDeserializer extends AbstractMatchEntryDeserializer {
26 public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
27 final boolean hasMask = processHeader(message);
28 final Ipv4Address address = ByteBufUtils.readIetfIpv4Address(message);
31 final byte[] mask = OxmDeserializerHelper.convertMask(message, EncodeConstants.GROUPS_IN_IPV4_ADDRESS);
33 if (IpConversionUtil.isArbitraryBitMask(mask)) {
34 setArbitraryMatch(builder, address, mask);
36 setPrefixMatch(builder, address, mask);
39 setPrefixMatch(builder, address, null);
43 private static void setPrefixMatch(final MatchBuilder builder, final Ipv4Address address, @Nullable final byte[]
45 if (builder.getLayer3Match() == null) {
46 builder.setLayer3Match(new Ipv4MatchBuilder()
47 .setIpv4Destination(IpConversionUtil.createPrefix(address, mask))
49 } else if (builder.getLayer3Match() instanceof Ipv4Match
50 && ((Ipv4Match) builder.getLayer3Match()).getIpv4Destination() == null) {
51 builder.setLayer3Match(new Ipv4MatchBuilder((Ipv4Match) builder.getLayer3Match())
52 .setIpv4Destination(IpConversionUtil.createPrefix(address, mask))
55 throwErrorOnMalformed(builder, "layer3Match", "ipv4Destination");
59 private static void setArbitraryMatch(final MatchBuilder builder, final Ipv4Address address,
61 if (builder.getLayer3Match() == null) {
62 builder.setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder()
63 .setIpv4DestinationAddressNoMask(address)
64 .setIpv4DestinationArbitraryBitmask(IpConversionUtil.createArbitraryBitMask(mask))
66 } else if (builder.getLayer3Match() instanceof Ipv4MatchArbitraryBitMask
67 && ((Ipv4MatchArbitraryBitMask) builder.getLayer3Match()).getIpv4DestinationAddressNoMask() == null) {
68 builder.setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder((Ipv4MatchArbitraryBitMask) builder
70 .setIpv4DestinationAddressNoMask(address)
71 .setIpv4DestinationArbitraryBitmask(IpConversionUtil.createArbitraryBitMask(mask))
74 throwErrorOnMalformed(builder, "layer3Match", "ipv4DestinationAddressNoMask");