Bug 5540 - PortConvertor, MatchConvertor
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / cases / OfToSalInPhyPortCase.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
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.cases;
10
11 import java.math.BigInteger;
12 import java.util.Optional;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.openflowplugin.api.OFConstants;
15 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.data.MatchResponseConvertorData;
18 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPhyPortCase;
22
23 public class OfToSalInPhyPortCase extends ConvertorCase<InPhyPortCase, MatchBuilder, MatchResponseConvertorData> {
24     public OfToSalInPhyPortCase() {
25         super(InPhyPortCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3);
26     }
27
28     @Override
29     public Optional<MatchBuilder> process(@Nonnull InPhyPortCase source, MatchResponseConvertorData data) {
30         final MatchBuilder matchBuilder = data.getMatchBuilder();
31         final OpenflowVersion ofVersion = OpenflowVersion.get(data.getVersion());
32         final BigInteger datapathId = data.getDatapathId();
33
34         final PortNumber portNumber = source.getInPhyPort().getPortNumber();
35
36         if (portNumber != null) {
37             matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathId, portNumber.getValue(), ofVersion));
38         }
39
40         return Optional.of(matchBuilder);
41     }
42 }