/* * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.cases; import java.util.ArrayList; import java.util.List; import java.util.Optional; import javax.annotation.Nonnull; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpDst; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpSrc; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpDstCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpSrcCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.dst._case.TcpDstBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.src._case.TcpSrcBuilder; public class SalToOfTcpMatchCase extends ConvertorCase<TcpMatch, List<MatchEntry>, VersionConvertorData> { public SalToOfTcpMatchCase() { super(TcpMatch.class, true); } @Override public Optional<List<MatchEntry>> process(@Nonnull TcpMatch source, VersionConvertorData data, ConvertorExecutor convertorExecutor) { List<MatchEntry> result = new ArrayList<>(); if (source.getTcpSourcePort() != null) { MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder(); matchEntryBuilder.setOxmClass(OpenflowBasicClass.class); matchEntryBuilder.setOxmMatchField(TcpSrc.class); TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder(); TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder(); tcpSrcBuilder.setPort(source.getTcpSourcePort()); tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build()); matchEntryBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build()); matchEntryBuilder.setHasMask(false); result.add(matchEntryBuilder.build()); } if (source.getTcpDestinationPort() != null) { MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder(); matchEntryBuilder.setOxmClass(OpenflowBasicClass.class); matchEntryBuilder.setOxmMatchField(TcpDst.class); TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder(); TcpDstBuilder tcpDstBuilder = new TcpDstBuilder(); tcpDstBuilder.setPort(source.getTcpDestinationPort()); tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build()); matchEntryBuilder.setMatchEntryValue(tcpDstCaseBuilder.build()); matchEntryBuilder.setHasMask(false); result.add(matchEntryBuilder.build()); } return Optional.of(result); } }