2 * Copyright (c) 2016 Cisco Systems, Inc. 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.openflow.md.core.sal.convertor.match.cases;
11 import java.nio.ByteBuffer;
12 import java.util.Optional;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.openflowplugin.api.OFConstants;
15 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.data.MatchResponseConvertorData;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4DstCase;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.dst._case.Ipv4Dst;
27 public class OfToSalTunnelIpv4DstCase extends ConvertorCase<Ipv4DstCase, MatchBuilder, MatchResponseConvertorData> {
28 public OfToSalTunnelIpv4DstCase() {
29 super(Ipv4DstCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3);
33 public Optional<MatchBuilder> process(@Nonnull Ipv4DstCase source, MatchResponseConvertorData data, ConvertorExecutor convertorExecutor) {
34 final MatchBuilder matchBuilder = data.getMatchBuilder();
35 final Ipv4MatchBuilder ipv4MatchBuilder = data.getIpv4MatchBuilder();
36 final TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = data.getTunnelIpv4MatchBuilder();
38 Ipv4Dst tunnelIpv4Dst = source.getIpv4Dst();
39 if (tunnelIpv4Dst != null) {
40 String ipv4PrefixStr = tunnelIpv4Dst.getIpv4Address().getValue();
41 byte[] mask = tunnelIpv4Dst.getMask();
42 ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + ByteBuffer.wrap(tunnelIpv4Dst.getMask()).getInt();
43 final Ipv4Prefix ipv4Prefix;
46 ipv4Prefix = IpConversionUtil.createPrefix(new Ipv4Address(ipv4PrefixStr), mask);
48 //Openflow Spec : 1.3.2
49 //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
50 // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
51 // statistics response.
52 ipv4Prefix = IpConversionUtil.createPrefix(new Ipv4Address(ipv4PrefixStr));
55 ipv4MatchBuilder.setIpv4Destination(ipv4Prefix);
56 matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
59 return Optional.of(matchBuilder);