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.common.ConvertorCase;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpDst;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpSrc;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpDstCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpSrcCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.dst._case.TcpDstBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.src._case.TcpSrcBuilder;
28 public class SalToOfTcpMatchCase extends ConvertorCase<TcpMatch, List<MatchEntry>, VersionConvertorData> {
29 public SalToOfTcpMatchCase() {
30 super(TcpMatch.class, true);
34 public Optional<List<MatchEntry>> process(@Nonnull TcpMatch source, VersionConvertorData data) {
35 List<MatchEntry> result = new ArrayList<>();
37 if (source.getTcpSourcePort() != null) {
38 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
39 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
40 matchEntryBuilder.setOxmMatchField(TcpSrc.class);
42 TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder();
43 TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder();
44 tcpSrcBuilder.setPort(source.getTcpSourcePort());
45 tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build());
47 matchEntryBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build());
48 matchEntryBuilder.setHasMask(false);
49 result.add(matchEntryBuilder.build());
52 if (source.getTcpDestinationPort() != null) {
53 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
54 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
55 matchEntryBuilder.setOxmMatchField(TcpDst.class);
57 TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder();
58 TcpDstBuilder tcpDstBuilder = new TcpDstBuilder();
59 tcpDstBuilder.setPort(source.getTcpDestinationPort());
60 tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build());
61 matchEntryBuilder.setMatchEntryValue(tcpDstCaseBuilder.build());
62 matchEntryBuilder.setHasMask(false);
63 result.add(matchEntryBuilder.build());
66 return Optional.of(result);