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.util.ArrayList;
12 import java.util.List;
13 import java.util.Optional;
14 import javax.annotation.Nonnull;
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.data.VersionConvertorData;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpDst;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpSrc;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpDstCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpSrcCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.dst._case.TcpDstBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.src._case.TcpSrcBuilder;
29 public class SalToOfTcpMatchCase extends ConvertorCase<TcpMatch, List<MatchEntry>, VersionConvertorData> {
30 public SalToOfTcpMatchCase() {
31 super(TcpMatch.class, true);
35 public Optional<List<MatchEntry>> process(@Nonnull TcpMatch source, VersionConvertorData data, ConvertorExecutor convertorExecutor) {
36 List<MatchEntry> result = new ArrayList<>();
38 if (source.getTcpSourcePort() != null) {
39 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
40 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
41 matchEntryBuilder.setOxmMatchField(TcpSrc.class);
43 TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder();
44 TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder();
45 tcpSrcBuilder.setPort(source.getTcpSourcePort());
46 tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build());
48 matchEntryBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build());
49 matchEntryBuilder.setHasMask(false);
50 result.add(matchEntryBuilder.build());
53 if (source.getTcpDestinationPort() != null) {
54 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
55 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
56 matchEntryBuilder.setOxmMatchField(TcpDst.class);
58 TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder();
59 TcpDstBuilder tcpDstBuilder = new TcpDstBuilder();
60 tcpDstBuilder.setPort(source.getTcpDestinationPort());
61 tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build());
62 matchEntryBuilder.setMatchEntryValue(tcpDstCaseBuilder.build());
63 matchEntryBuilder.setHasMask(false);
64 result.add(matchEntryBuilder.build());
67 return Optional.of(result);