Bump upstreams
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / cases / OfToSalEthDstCase.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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
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.ethernet.match.fields.EthernetDestinationBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthDstCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.dst._case.EthDst;
22
23 public class OfToSalEthDstCase extends ConvertorCase<EthDstCase, MatchBuilder, MatchResponseConvertorData> {
24     public OfToSalEthDstCase() {
25         super(EthDstCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3);
26     }
27
28     @Override
29     public Optional<MatchBuilder> process(@NonNull EthDstCase source, MatchResponseConvertorData data,
30             ConvertorExecutor convertorExecutor) {
31         final MatchBuilder matchBuilder = data.getMatchBuilder();
32         final EthernetMatchBuilder ethMatchBuilder = data.getEthernetMatchBuilder();
33
34         final EthDst ethDstCase = source.getEthDst();
35
36         if (ethDstCase != null) {
37             EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
38             ethDestinationBuilder.setAddress(ethDstCase.getMacAddress());
39             byte[] destinationMask = ethDstCase.getMask();
40
41             if (destinationMask != null) {
42                 ethDestinationBuilder.setMask(IetfYangUtil.macAddressFor(destinationMask));
43             }
44
45             ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
46             matchBuilder.setEthernetMatch(ethMatchBuilder.build());
47         }
48
49         return Optional.of(matchBuilder);
50     }
51 }