/**
- * Copyright (c) 2013-2015 Ericsson. and others. All rights reserved.
+ * Copyright (c) 2013, 2015 Ericsson. 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,
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import javax.annotation.Nonnull;
import org.opendaylight.openflowjava.util.ByteBufUtils;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
private static final short PROTO_TCP = 6;
private static final short PROTO_UDP = 17;
private static final short PROTO_ICMPV4 = 1;
- private static final String noIp = "0.0.0.0/0";
+ private static final String NO_IP = "0.0.0.0/0";
@Override
public List<MatchEntry> convert(
final org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match, final BigInteger datapathid) {
List<MatchEntry> matchEntryList = new ArrayList<>();
- if (match == null) return matchEntryList;
+ if (match == null) {
+ return matchEntryList;
+ }
if (match.getInPort() != null) {
//TODO: currently this matchconverter is mapped to OF1.3 in MatchReactorMappingFactory. Will need to revisit during 1.4+
matchEntryList.add(toOfPort(InPort.class,
matchEntryList.add(toOfMetadata(Metadata.class, metadata.getMetadata(), metadata.getMetadataMask()));
}
- EthernetMatch ethernetMatch = match.getEthernetMatch();
- if (ethernetMatch != null) {
- EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
- if (ethernetDestination != null) {
- MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
- matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(EthDst.class);
- EthDstCaseBuilder ethDstCaseBuilder = new EthDstCaseBuilder();
- EthDstBuilder ethDstBuilder = new EthDstBuilder();
- ethDstBuilder.setMacAddress(ethernetDestination.getAddress());
- boolean hasMask = false;
- if (null != ethernetDestination.getMask()) {
- ethDstBuilder.setMask(ByteBufUtils.macAddressToBytes(ethernetDestination.getMask().getValue()));
- hasMask = true;
- }
- ethDstCaseBuilder.setEthDst(ethDstBuilder.build());
- matchEntryBuilder.setMatchEntryValue(ethDstCaseBuilder.build());
- matchEntryBuilder.setHasMask(hasMask);
- matchEntryList.add(matchEntryBuilder.build());
- }
+ ethernetMatch(matchEntryList, match.getEthernetMatch());
+ vlanMatch(matchEntryList, match.getVlanMatch());
+ ipMatch(matchEntryList, match.getIpMatch());
+ layer4Match(matchEntryList, match.getLayer4Match());
+ icmpv4Match(matchEntryList, match.getIcmpv4Match());
+ icmpv6Match(matchEntryList, match.getIcmpv6Match());
+ layer3Match(matchEntryList, match.getLayer3Match());
+ protocolMatchFields(matchEntryList, match.getProtocolMatchFields());
- EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
- if (ethernetSource != null) {
- MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
- matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(EthSrc.class);
-
- EthSrcCaseBuilder ethSrcCaseBuilder = new EthSrcCaseBuilder();
- EthSrcBuilder ethDstBuilder = new EthSrcBuilder();
- ethDstBuilder.setMacAddress(ethernetSource.getAddress());
- boolean hasMask = false;
- if (null != ethernetSource.getMask()) {
- ethDstBuilder.setMask(ByteBufUtils.macAddressToBytes(ethernetSource.getMask().getValue()));
- hasMask = true;
- }
- ethSrcCaseBuilder.setEthSrc(ethDstBuilder.build());
- matchEntryBuilder.setMatchEntryValue(ethSrcCaseBuilder.build());
- matchEntryBuilder.setHasMask(hasMask);
- matchEntryList.add(matchEntryBuilder.build());
- }
-
- if (ethernetMatch.getEthernetType() != null) {
- matchEntryList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
+ org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
+ .getTunnel();
+ if (tunnel != null) {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ TunnelIdCaseBuilder tunnelIdCaseBuilder = new TunnelIdCaseBuilder();
+ TunnelIdBuilder tunnelIdBuilder = new TunnelIdBuilder();
+ boolean hasMask = false;
+ if (null != tunnel.getTunnelMask()) {
+ hasMask = true;
+ tunnelIdBuilder.setMask(ByteUtil.convertBigIntegerToNBytes(tunnel.getTunnelMask(), OFConstants.SIZE_OF_LONG_IN_BYTES));
}
+ tunnelIdBuilder.setTunnelId(ByteUtil.convertBigIntegerToNBytes(tunnel.getTunnelId(), OFConstants.SIZE_OF_LONG_IN_BYTES));
+ tunnelIdCaseBuilder.setTunnelId(tunnelIdBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(tunnelIdCaseBuilder.build());
+ matchEntryBuilder.setHasMask(hasMask);
+ matchEntryBuilder.setOxmMatchField(TunnelId.class);
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryList.add(matchEntryBuilder.build());
}
- VlanMatch vlanMatch = match.getVlanMatch();
- if (vlanMatch != null) {
- if (vlanMatch.getVlanId() != null) {
- VlanId vlanId = vlanMatch.getVlanId();
- MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
- matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(VlanVid.class);
-
- VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
- VlanVidBuilder vlanVidBuilder = new VlanVidBuilder();
- boolean setCfiBit = false;
- Integer vidEntryValue = new Integer(0);
- boolean hasmask = false;
- if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
- setCfiBit = true;
- if (vlanId.getVlanId() != null) {
- vidEntryValue = vlanId.getVlanId().getValue();
- }
- hasmask = (vidEntryValue == 0);
- if (hasmask) {
- vlanVidBuilder.setMask(VLAN_VID_MASK);
- }
- }
- vlanVidBuilder.setCfiBit(setCfiBit);
- vlanVidBuilder.setVlanVid(vidEntryValue);
- vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
- matchEntryBuilder.setMatchEntryValue(vlanVidCaseBuilder.build());
- matchEntryBuilder.setHasMask(hasmask);
- matchEntryList.add(matchEntryBuilder.build());
- }
-
- if (vlanMatch.getVlanPcp() != null) {
- matchEntryList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
+ /**
+ * TODO: EXTENSION PROPOSAL (match, MD-SAL to OFJava)
+ * - we might need version for conversion and for key
+ * - sanitize NPE
+ */
+ Optional<GeneralExtensionListGrouping> extensionListOpt = ExtensionResolvers.getMatchExtensionResolver().getExtension(match);
+ if (extensionListOpt.isPresent()) {
+ for (ExtensionList extensionItem : extensionListOpt.get().getExtensionList()) {
+ // TODO: get real version
+ ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
+ ConvertorToOFJava<MatchEntry> convertor =
+ OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
+ MatchEntry ofMatch = convertor.convert(extensionItem.getExtension());
+ matchEntryList.add(ofMatch);
}
}
- IpMatch ipMatch = match.getIpMatch();
- if (ipMatch != null) {
- if (ipMatch.getIpDscp() != null) {
- matchEntryList.add(toOfIpDscp(ipMatch.getIpDscp()));
- }
+ return matchEntryList;
+ }
- if (ipMatch.getIpEcn() != null) {
- matchEntryList.add(toOfIpEcn(ipMatch.getIpEcn()));
- }
- if (ipMatch.getIpProtocol() != null) {
- matchEntryList.add(toOfIpProto(ipMatch.getIpProtocol()));
+ private void protocolMatchFields(List<MatchEntry> matchEntryList,
+ ProtocolMatchFields protocolMatchFields) {
+ if (protocolMatchFields != null) {
+ if (protocolMatchFields.getMplsLabel() != null) {
+ matchEntryList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
}
- }
-
- Layer4Match layer4Match = match.getLayer4Match();
- if (layer4Match != null) {
- if (layer4Match instanceof TcpMatch) {
- TcpMatch tcpMatch = (TcpMatch) layer4Match;
-
- if (tcpMatch.getTcpSourcePort() != null) {
- MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
- matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(TcpSrc.class);
-
- TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder();
- TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder();
- tcpSrcBuilder.setPort(tcpMatch.getTcpSourcePort());
- tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build());
-
- matchEntryBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build());
- matchEntryBuilder.setHasMask(false);
- matchEntryList.add(matchEntryBuilder.build());
- }
- if (tcpMatch.getTcpDestinationPort() != null) {
- MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
- matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(TcpDst.class);
-
- TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder();
- TcpDstBuilder tcpDstBuilder = new TcpDstBuilder();
- tcpDstBuilder.setPort(tcpMatch.getTcpDestinationPort());
- tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build());
- matchEntryBuilder.setMatchEntryValue(tcpDstCaseBuilder.build());
- matchEntryBuilder.setHasMask(false);
- matchEntryList.add(matchEntryBuilder.build());
- }
- } else if (layer4Match instanceof UdpMatch) {
- UdpMatch udpMatch = (UdpMatch) layer4Match;
- if (udpMatch.getUdpSourcePort() != null) {
- MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
- matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(UdpSrc.class);
-
- UdpSrcCaseBuilder udpSrcCaseBuilder = new UdpSrcCaseBuilder();
- UdpSrcBuilder udpSrcBuilder = new UdpSrcBuilder();
- boolean hasMask = false;
- udpSrcBuilder.setPort(udpMatch.getUdpSourcePort());
- udpSrcCaseBuilder.setUdpSrc(udpSrcBuilder.build());
- matchEntryBuilder.setMatchEntryValue(udpSrcCaseBuilder.build());
- matchEntryBuilder.setHasMask(hasMask);
- matchEntryList.add(matchEntryBuilder.build());
- }
-
- if (udpMatch.getUdpDestinationPort() != null) {
- MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
- matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(UdpDst.class);
-
- UdpDstCaseBuilder udpDstCaseBuilder = new UdpDstCaseBuilder();
- UdpDstBuilder udpDstBuilder = new UdpDstBuilder();
- udpDstBuilder.setPort(udpMatch.getUdpDestinationPort());
- udpDstCaseBuilder.setUdpDst(udpDstBuilder.build());
- matchEntryBuilder.setMatchEntryValue(udpDstCaseBuilder.build());
- matchEntryBuilder.setHasMask(false);
- matchEntryList.add(matchEntryBuilder.build());
- }
- } else if (layer4Match instanceof SctpMatch) {
- SctpMatch sctpMatch = (SctpMatch) layer4Match;
- if (sctpMatch.getSctpSourcePort() != null) {
- MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
- matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(SctpSrc.class);
-
- SctpSrcCaseBuilder sctpSrcCaseBuilder = new SctpSrcCaseBuilder();
- SctpSrcBuilder sctpSrcBuilder = new SctpSrcBuilder();
- sctpSrcBuilder.setPort(sctpMatch.getSctpSourcePort());
- sctpSrcCaseBuilder.setSctpSrc(sctpSrcBuilder.build());
- matchEntryBuilder.setMatchEntryValue(sctpSrcCaseBuilder.build());
- matchEntryBuilder.setHasMask(false);
- matchEntryList.add(matchEntryBuilder.build());
- }
-
- if (sctpMatch.getSctpDestinationPort() != null) {
- MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
- matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(SctpDst.class);
-
- SctpDstCaseBuilder sctpDstCaseBuilder = new SctpDstCaseBuilder();
- SctpDstBuilder sctpDstBuilder = new SctpDstBuilder();
- sctpDstBuilder.setPort(sctpMatch.getSctpDestinationPort());
- sctpDstCaseBuilder.setSctpDst(sctpDstBuilder.build());
- matchEntryBuilder.setMatchEntryValue(sctpDstCaseBuilder.build());
- matchEntryBuilder.setHasMask(false);
- matchEntryList.add(matchEntryBuilder.build());
- }
+ if (protocolMatchFields.getMplsBos() != null) {
+ matchEntryList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
}
- }
- Icmpv4Match icmpv4Match = match.getIcmpv4Match();
- if (icmpv4Match != null) {
- if (icmpv4Match.getIcmpv4Type() != null) {
- matchEntryList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
+ if (protocolMatchFields.getMplsTc() != null) {
+ matchEntryList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
}
- if (icmpv4Match.getIcmpv4Code() != null) {
- matchEntryList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
+ if (protocolMatchFields.getPbb() != null) {
+ matchEntryList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
}
}
+ }
- Icmpv6Match icmpv6Match = match.getIcmpv6Match();
- if (icmpv6Match != null) {
- if (icmpv6Match.getIcmpv6Type() != null) {
- matchEntryList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
- }
-
- if (icmpv6Match.getIcmpv6Code() != null) {
- matchEntryList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
- }
- }
- Layer3Match layer3Match = match.getLayer3Match();
+ private void layer3Match(List<MatchEntry> matchEntryList,
+ Layer3Match layer3Match) {
if (layer3Match != null) {
if (layer3Match instanceof Ipv4Match) {
Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
ArpThaBuilder arpThaBuilder = new ArpThaBuilder();
arpThaBuilder.setMacAddress(arpTargetHardwareAddress.getAddress());
boolean hasMask = false;
- if (null != arpSourceHardwareAddress.getMask()) {
+ if (null != arpTargetHardwareAddress.getMask()) {
arpThaBuilder.setMask(ByteBufUtils.macAddressToBytes(arpTargetHardwareAddress.getMask().getValue()));
hasMask = true;
}
}
}
}
+ }
- ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
- if (protocolMatchFields != null) {
- if (protocolMatchFields.getMplsLabel() != null) {
- matchEntryList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
+
+ private void icmpv6Match(List<MatchEntry> matchEntryList,
+ Icmpv6Match icmpv6Match) {
+ if (icmpv6Match != null) {
+ if (icmpv6Match.getIcmpv6Type() != null) {
+ matchEntryList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
}
- if (protocolMatchFields.getMplsBos() != null) {
- matchEntryList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
+ if (icmpv6Match.getIcmpv6Code() != null) {
+ matchEntryList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
}
+ }
+ }
- if (protocolMatchFields.getMplsTc() != null) {
- matchEntryList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
+
+ private void icmpv4Match(List<MatchEntry> matchEntryList,
+ Icmpv4Match icmpv4Match) {
+ if (icmpv4Match != null) {
+ if (icmpv4Match.getIcmpv4Type() != null) {
+ matchEntryList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
}
- if (protocolMatchFields.getPbb() != null) {
- matchEntryList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
+ if (icmpv4Match.getIcmpv4Code() != null) {
+ matchEntryList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
}
}
+ }
- org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
- .getTunnel();
- if (tunnel != null) {
+ private void layer4Match(List<MatchEntry> matchEntryList,
+ Layer4Match layer4Match) {
+ if (layer4Match != null) {
+ if (layer4Match instanceof TcpMatch) {
+ TcpMatch tcpMatch = (TcpMatch) layer4Match;
- MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
- TunnelIdCaseBuilder tunnelIdCaseBuilder = new TunnelIdCaseBuilder();
- TunnelIdBuilder tunnelIdBuilder = new TunnelIdBuilder();
- boolean hasMask = false;
- if (null != tunnel.getTunnelMask()) {
- hasMask = true;
- tunnelIdBuilder.setMask(ByteUtil.convertBigIntegerToNBytes(tunnel.getTunnelMask(), OFConstants.SIZE_OF_LONG_IN_BYTES));
+ if (tcpMatch.getTcpSourcePort() != null) {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(TcpSrc.class);
+
+ TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder();
+ TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder();
+ tcpSrcBuilder.setPort(tcpMatch.getTcpSourcePort());
+ tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build());
+
+ matchEntryBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build());
+ matchEntryBuilder.setHasMask(false);
+ matchEntryList.add(matchEntryBuilder.build());
+ }
+ if (tcpMatch.getTcpDestinationPort() != null) {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(TcpDst.class);
+
+ TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder();
+ TcpDstBuilder tcpDstBuilder = new TcpDstBuilder();
+ tcpDstBuilder.setPort(tcpMatch.getTcpDestinationPort());
+ tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(tcpDstCaseBuilder.build());
+ matchEntryBuilder.setHasMask(false);
+ matchEntryList.add(matchEntryBuilder.build());
+ }
+ } else if (layer4Match instanceof UdpMatch) {
+ UdpMatch udpMatch = (UdpMatch) layer4Match;
+ if (udpMatch.getUdpSourcePort() != null) {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(UdpSrc.class);
+
+ UdpSrcCaseBuilder udpSrcCaseBuilder = new UdpSrcCaseBuilder();
+ UdpSrcBuilder udpSrcBuilder = new UdpSrcBuilder();
+ boolean hasMask = false;
+ udpSrcBuilder.setPort(udpMatch.getUdpSourcePort());
+ udpSrcCaseBuilder.setUdpSrc(udpSrcBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(udpSrcCaseBuilder.build());
+ matchEntryBuilder.setHasMask(hasMask);
+ matchEntryList.add(matchEntryBuilder.build());
+ }
+
+ if (udpMatch.getUdpDestinationPort() != null) {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(UdpDst.class);
+
+ UdpDstCaseBuilder udpDstCaseBuilder = new UdpDstCaseBuilder();
+ UdpDstBuilder udpDstBuilder = new UdpDstBuilder();
+ udpDstBuilder.setPort(udpMatch.getUdpDestinationPort());
+ udpDstCaseBuilder.setUdpDst(udpDstBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(udpDstCaseBuilder.build());
+ matchEntryBuilder.setHasMask(false);
+ matchEntryList.add(matchEntryBuilder.build());
+ }
+ } else if (layer4Match instanceof SctpMatch) {
+ SctpMatch sctpMatch = (SctpMatch) layer4Match;
+ if (sctpMatch.getSctpSourcePort() != null) {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(SctpSrc.class);
+
+ SctpSrcCaseBuilder sctpSrcCaseBuilder = new SctpSrcCaseBuilder();
+ SctpSrcBuilder sctpSrcBuilder = new SctpSrcBuilder();
+ sctpSrcBuilder.setPort(sctpMatch.getSctpSourcePort());
+ sctpSrcCaseBuilder.setSctpSrc(sctpSrcBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(sctpSrcCaseBuilder.build());
+ matchEntryBuilder.setHasMask(false);
+ matchEntryList.add(matchEntryBuilder.build());
+ }
+
+ if (sctpMatch.getSctpDestinationPort() != null) {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(SctpDst.class);
+
+ SctpDstCaseBuilder sctpDstCaseBuilder = new SctpDstCaseBuilder();
+ SctpDstBuilder sctpDstBuilder = new SctpDstBuilder();
+ sctpDstBuilder.setPort(sctpMatch.getSctpDestinationPort());
+ sctpDstCaseBuilder.setSctpDst(sctpDstBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(sctpDstCaseBuilder.build());
+ matchEntryBuilder.setHasMask(false);
+ matchEntryList.add(matchEntryBuilder.build());
+ }
}
- tunnelIdBuilder.setTunnelId(ByteUtil.convertBigIntegerToNBytes(tunnel.getTunnelId(), OFConstants.SIZE_OF_LONG_IN_BYTES));
- tunnelIdCaseBuilder.setTunnelId(tunnelIdBuilder.build());
- matchEntryBuilder.setMatchEntryValue(tunnelIdCaseBuilder.build());
- matchEntryBuilder.setHasMask(hasMask);
- matchEntryBuilder.setOxmMatchField(TunnelId.class);
- matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryList.add(matchEntryBuilder.build());
}
+ }
- /**
- * TODO: EXTENSION PROPOSAL (match, MD-SAL to OFJava)
- * - we might need version for conversion and for key
- * - sanitize NPE
- */
- Optional<GeneralExtensionListGrouping> extensionListOpt = ExtensionResolvers.getMatchExtensionResolver().getExtension(match);
- if (extensionListOpt.isPresent()) {
- for (ExtensionList extensionItem : extensionListOpt.get().getExtensionList()) {
- // TODO: get real version
- ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
- ConvertorToOFJava<MatchEntry> convertor =
- OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
- MatchEntry ofMatch = convertor.convert(extensionItem.getExtension());
- matchEntryList.add(ofMatch);
+ private void ipMatch(List<MatchEntry> matchEntryList, IpMatch ipMatch) {
+ if (ipMatch != null) {
+ if (ipMatch.getIpDscp() != null) {
+ matchEntryList.add(toOfIpDscp(ipMatch.getIpDscp()));
+ }
+
+ if (ipMatch.getIpEcn() != null) {
+ matchEntryList.add(toOfIpEcn(ipMatch.getIpEcn()));
}
+
+ if (ipMatch.getIpProtocol() != null) {
+ matchEntryList.add(toOfIpProto(ipMatch.getIpProtocol()));
+ }
+
}
+ }
- return matchEntryList;
+
+ private void vlanMatch(List<MatchEntry> matchEntryList,
+ VlanMatch vlanMatch) {
+ if (vlanMatch != null) {
+ if (vlanMatch.getVlanId() != null) {
+ VlanId vlanId = vlanMatch.getVlanId();
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(VlanVid.class);
+
+ VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
+ VlanVidBuilder vlanVidBuilder = new VlanVidBuilder();
+ boolean setCfiBit = false;
+ Integer vidEntryValue = 0;
+ boolean hasmask = false;
+ if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
+ setCfiBit = true;
+ if (vlanId.getVlanId() != null) {
+ vidEntryValue = vlanId.getVlanId().getValue();
+ }
+ hasmask = (vidEntryValue == 0);
+ if (hasmask) {
+ vlanVidBuilder.setMask(VLAN_VID_MASK);
+ }
+ }
+
+ vlanVidBuilder.setCfiBit(setCfiBit);
+ vlanVidBuilder.setVlanVid(vidEntryValue);
+ vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(vlanVidCaseBuilder.build());
+ matchEntryBuilder.setHasMask(hasmask);
+ matchEntryList.add(matchEntryBuilder.build());
+ }
+
+ if (vlanMatch.getVlanPcp() != null) {
+ matchEntryList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
+ }
+ }
+ }
+
+
+ private void ethernetMatch(List<MatchEntry> matchEntryList,
+ EthernetMatch ethernetMatch) {
+ if (ethernetMatch != null) {
+ EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
+ if (ethernetDestination != null) {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(EthDst.class);
+ EthDstCaseBuilder ethDstCaseBuilder = new EthDstCaseBuilder();
+ EthDstBuilder ethDstBuilder = new EthDstBuilder();
+ ethDstBuilder.setMacAddress(ethernetDestination.getAddress());
+ boolean hasMask = false;
+ if (null != ethernetDestination.getMask()) {
+ ethDstBuilder.setMask(ByteBufUtils.macAddressToBytes(ethernetDestination.getMask().getValue()));
+ hasMask = true;
+ }
+ ethDstCaseBuilder.setEthDst(ethDstBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(ethDstCaseBuilder.build());
+ matchEntryBuilder.setHasMask(hasMask);
+ matchEntryList.add(matchEntryBuilder.build());
+ }
+
+ EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
+ if (ethernetSource != null) {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(EthSrc.class);
+
+ EthSrcCaseBuilder ethSrcCaseBuilder = new EthSrcCaseBuilder();
+ EthSrcBuilder ethDstBuilder = new EthSrcBuilder();
+ ethDstBuilder.setMacAddress(ethernetSource.getAddress());
+ boolean hasMask = false;
+ if (null != ethernetSource.getMask()) {
+ ethDstBuilder.setMask(ByteBufUtils.macAddressToBytes(ethernetSource.getMask().getValue()));
+ hasMask = true;
+ }
+ ethSrcCaseBuilder.setEthSrc(ethDstBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(ethSrcCaseBuilder.build());
+ matchEntryBuilder.setHasMask(hasMask);
+ matchEntryList.add(matchEntryBuilder.build());
+ }
+
+ if (ethernetMatch.getEthernetType() != null) {
+ matchEntryList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
+ }
+ }
}
- private byte[] extractIpv4Mask(boolean hasMask, final Iterator<String> addressParts) {
+ private static byte[] extractIpv4Mask(boolean hasMask, final Iterator<String> addressParts) {
final int prefix;
if (addressParts.hasNext()) {
int potentionalPrefix = Integer.parseInt(addressParts.next());
* @return
* @author avishnoi@in.ibm.com
*/
- public static Match fromOFMatchV10ToSALMatch(final MatchV10 swMatch, final BigInteger datapathid, final OpenflowVersion ofVersion) {
+ public static MatchBuilder fromOFMatchV10ToSALMatch(@Nonnull final MatchV10 swMatch, @Nonnull final BigInteger datapathid, @Nonnull final OpenflowVersion ofVersion) {
MatchBuilder matchBuilder = new MatchBuilder();
EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
}
if (!swMatch.getWildcards().isDLVLAN().booleanValue() && swMatch.getDlVlan() != null) {
VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
- int vlanId = (swMatch.getDlVlan() == ((int) 0xffff)) ? 0 : swMatch.getDlVlan();
+ int vlanId = (swMatch.getDlVlan() == (0xffff)) ? 0 : swMatch.getDlVlan();
vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
vlanIdBuilder.setVlanIdPresent(vlanId == 0 ? false : true);
vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + "32";
}
- if (!ipv4PrefixStr.equals(noIp)) {
+ if (!NO_IP.equals(ipv4PrefixStr)) {
ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
}
ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + "32";
}
- if (!ipv4PrefixStr.equals(noIp)) {
+ if (!NO_IP.equals(ipv4PrefixStr)) {
ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
}
matchBuilder.setIpMatch(ipMatchBuilder.build());
}
- return matchBuilder.build();
+ return matchBuilder;
}
/**
* @author avishnoi@in.ibm.com
*/
public static MatchBuilder fromOFMatchToSALMatch(
- final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match swMatch,
- final BigInteger datapathid, final OpenflowVersion ofVersion) {
+ @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match swMatch,
+ @Nonnull final BigInteger datapathid, @Nonnull final OpenflowVersion ofVersion) {
return OfMatchToSALMatchConvertor(swMatch.getMatchEntry(), datapathid, ofVersion);
}
- private static MatchBuilder OfMatchToSALMatchConvertor(List<MatchEntry> swMatchList, final BigInteger datapathid,
- OpenflowVersion ofVersion) {
+ private static MatchBuilder OfMatchToSALMatchConvertor(final List<MatchEntry> swMatchList, final BigInteger datapathid,
+ final OpenflowVersion ofVersion) {
MatchBuilder matchBuilder = new MatchBuilder();
EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
- TcpFlagMatchBuilder tcpFlagMatchBuilder = new TcpFlagMatchBuilder();
TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
for (MatchEntry ofMatch : swMatchList) {
return matchBuilder;
}
- private static void setIpv6MatchBuilderFields(final Ipv6MatchBuilder ipv6MatchBuilder, final MatchEntry ofMatch, String ipv6PrefixStr, final byte[] mask) {
+ private static void setIpv6MatchBuilderFields(final Ipv6MatchBuilder ipv6MatchBuilder, final MatchEntry ofMatch, final String ipv6PrefixStr, final byte[] mask) {
Ipv6Prefix ipv6Prefix;
if (mask != null) {
}
}
- private static void setIpv4MatchBuilderFields(final Ipv4MatchBuilder ipv4MatchBuilder, final MatchEntry ofMatch, final byte[] mask, String ipv4PrefixStr) {
+ private static void setIpv4MatchBuilderFields(final Ipv4MatchBuilder ipv4MatchBuilder, final MatchEntry ofMatch, final byte[] mask, final String ipv4PrefixStr) {
Ipv4Prefix ipv4Prefix;
if (mask != null) {
ipv4Prefix = IpConversionUtil.createPrefix(new Ipv4Address(ipv4PrefixStr), mask);
if (mplsBos.shortValue() != 0) {
isBos = true;
}
- mplsBosBuilder.setBos(new Boolean(isBos));
+ mplsBosBuilder.setBos(isBos);
mplsBosCaseBuilder.setMplsBos(mplsBosBuilder.build());
matchEntryBuilder.setMatchEntryValue(mplsBosCaseBuilder.build());
return matchEntryBuilder.build();
}
- private static MatchEntry toOfVlanVid(final VlanId vlanId) {
- // TODO: verify
- boolean hasmask = false;
- boolean setCfiBit = false;
- Integer vidEntryValue = 0;
- MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
- matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(VlanVid.class);
- VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
- VlanVidBuilder vlanVidBuilder = new VlanVidBuilder();
- if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
- setCfiBit = true;
- if (vlanId.getVlanId() != null) {
- vidEntryValue = vlanId.getVlanId().getValue();
- }
- hasmask = (vidEntryValue == 0);
- }
- vlanVidBuilder.setCfiBit(setCfiBit);
- vlanVidBuilder.setVlanVid(vidEntryValue);
- if (hasmask) {
- vlanVidBuilder.setMask(VLAN_VID_MASK);
- }
- vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
- matchEntryBuilder.setMatchEntryValue(vlanVidCaseBuilder.build());
- matchEntryBuilder.setHasMask(hasmask);
- return matchEntryBuilder.build();
- }
private static MatchEntry toOfIpProto(final Short ipProtocol) {
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
}
-// /**
-// * Method converts OF SetField action to SAL SetFiled action.
-// *
-// * @param action
-// * @param ofVersion current ofp version
-// * @return
-// */
-// public static SetField fromOFSetFieldToSALSetFieldAction(
-// final Action action, OpenflowVersion ofVersion) {
-// logger.debug("Converting OF SetField action to SAL SetField action");
-// SetFieldBuilder setField = new SetFieldBuilder();
-// OxmFieldsAction oxmFields = action.getAugmentation(OxmFieldsAction.class);
-// MatchBuilder match = OfMatchToSALMatchConvertor(oxmFields.getMatchEntry(), null, ofVersion);
-// setField.fieldsFrom(match.build());
-// return setField.build();
-// }
+
/**
* Method converts OF SetField action to SAL SetFiled action.
* @return
*/
public static SetField fromOFSetFieldToSALSetFieldAction(
- final Action action, OpenflowVersion ofVersion) {
+ final Action action, final OpenflowVersion ofVersion) {
logger.debug("Converting OF SetField action to SAL SetField action");
SetFieldCase setFieldCase = (SetFieldCase) action.getActionChoice();
SetFieldAction setFieldAction = setFieldCase.getSetFieldAction();