Merge "Turn extension/pom.xml into an aggregator"
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / cases / OfToSalIcmpv4CodeCase.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.cases;
9
10 import java.util.Optional;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.openflowplugin.api.OFConstants;
13 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
14 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase;
15 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.data.MatchResponseConvertorData;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4CodeCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.code._case.Icmpv4Code;
20 import org.opendaylight.yangtools.yang.common.Uint8;
21
22 public class OfToSalIcmpv4CodeCase extends ConvertorCase<Icmpv4CodeCase, MatchBuilder, MatchResponseConvertorData> {
23     public OfToSalIcmpv4CodeCase() {
24         super(Icmpv4CodeCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3);
25     }
26
27     @Override
28     public Optional<MatchBuilder> process(@NonNull final Icmpv4CodeCase source, final MatchResponseConvertorData data,
29             final ConvertorExecutor convertorExecutor) {
30         final MatchBuilder matchBuilder = data.getMatchBuilder();
31         final Icmpv4MatchBuilder icmpv4MatchBuilder = data.getIcmpv4MatchBuilder();
32
33         Icmpv4Code icmpv4Code = source.getIcmpv4Code();
34         Uint8 v4code = icmpv4Code.getIcmpv4Code();
35
36         if (v4code != null) {
37             icmpv4MatchBuilder.setIcmpv4Code(v4code);
38             matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
39         }
40
41         return Optional.of(matchBuilder);
42     }
43 }