/**
- * Copyright (c) 2013-2014 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 static org.opendaylight.openflowjava.util.ByteBufUtils.macAddressToString;
+import com.google.common.base.Optional;
import java.math.BigInteger;
import java.nio.ByteBuffer;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-
/**
* Utility class for converting a MD-SAL Flow into the OF flow mod
*/
private static final byte[] VLAN_VID_MASK = new byte[]{16, 0};
private static final short PROTO_TCP = 6;
private static final short PROTO_UDP = 17;
- private static final String noIp = "0.0.0.0/0";
+ private static final short PROTO_ICMPV4 = 1;
+ 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());
- }
-
- 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());
- }
+ 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());
- 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;
}
matchEntryList.add(matchEntryBuilder.build());
}
- if (ipv6Match.getIpv6Destination() != null) {
- Ipv6Prefix ipv6Prefix = ipv6Match.getIpv6Destination();
+ if (ipv6Match.getIpv6Destination() != null) {
+ Ipv6Prefix ipv6Prefix = ipv6Match.getIpv6Destination();
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(Ipv6Dst.class);
+
+ Ipv6DstCaseBuilder ipv6DstCaseBuilder = new Ipv6DstCaseBuilder();
+ Ipv6DstBuilder ipv6DstBuilder = new Ipv6DstBuilder();
+ final Integer prefix = IpConversionUtil.extractIpv6Prefix(ipv6Prefix);
+ boolean hasMask = false;
+ if (null != prefix) {
+ ipv6DstBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix));
+ hasMask = true;
+ }
+ ipv6DstBuilder.setIpv6Address(IpConversionUtil.extractIpv6Address(ipv6Prefix));
+ ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build());
+ matchEntryBuilder.setHasMask(hasMask);
+ matchEntryBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build());
+ matchEntryList.add(matchEntryBuilder.build());
+ }
+
+ if (ipv6Match.getIpv6Label() != null) {
+ matchEntryList.add(toOfIpv6FlowLabel(ipv6Match.getIpv6Label()));
+ }
+
+ if (ipv6Match.getIpv6NdTarget() != null) {
+ matchEntryList.add(toOfIpv6NdTargetAddress(ipv6Match.getIpv6NdTarget()));
+ }
+
+ if (ipv6Match.getIpv6NdSll() != null) {
+ MacAddress ipv6NdSll = ipv6Match.getIpv6NdSll();
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(Ipv6NdSll.class);
+
+ Ipv6NdSllCaseBuilder ipv6NdSllCaseBuilder = new Ipv6NdSllCaseBuilder();
+ Ipv6NdSllBuilder ipv6NdSllBuilder = new Ipv6NdSllBuilder();
+ ipv6NdSllBuilder.setMacAddress(ipv6NdSll);
+ ipv6NdSllCaseBuilder.setIpv6NdSll(ipv6NdSllBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(ipv6NdSllCaseBuilder.build());
+ matchEntryBuilder.setHasMask(false);
+ matchEntryList.add(matchEntryBuilder.build());
+ }
+
+ if (ipv6Match.getIpv6NdTll() != null) {
+ MacAddress ipv6NdSll = ipv6Match.getIpv6NdTll();
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(Ipv6NdTll.class);
+
+ Ipv6NdTllCaseBuilder ipv6NdTllCaseBuilder = new Ipv6NdTllCaseBuilder();
+ Ipv6NdTllBuilder ipv6NdTllBuilder = new Ipv6NdTllBuilder();
+ ipv6NdTllBuilder.setMacAddress(ipv6NdSll);
+ ipv6NdTllCaseBuilder.setIpv6NdTll(ipv6NdTllBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(ipv6NdTllCaseBuilder.build());
+ matchEntryBuilder.setHasMask(false);
+ matchEntryList.add(matchEntryBuilder.build());
+
+ }
+
+ if (ipv6Match.getIpv6ExtHeader() != null) {
+ matchEntryList.add(toOfIpv6ExtHeader(ipv6Match.getIpv6ExtHeader()));
+ }
+ }
+ }
+ }
+
+
+ private void icmpv6Match(List<MatchEntry> matchEntryList,
+ Icmpv6Match icmpv6Match) {
+ if (icmpv6Match != null) {
+ if (icmpv6Match.getIcmpv6Type() != null) {
+ matchEntryList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
+ }
+
+ if (icmpv6Match.getIcmpv6Code() != null) {
+ matchEntryList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
+ }
+ }
+ }
+
+
+ private void icmpv4Match(List<MatchEntry> matchEntryList,
+ Icmpv4Match icmpv4Match) {
+ if (icmpv4Match != null) {
+ if (icmpv4Match.getIcmpv4Type() != null) {
+ matchEntryList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
+ }
+
+ if (icmpv4Match.getIcmpv4Code() != null) {
+ matchEntryList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
+ }
+ }
+ }
+
+
+ private void layer4Match(List<MatchEntry> matchEntryList,
+ Layer4Match layer4Match) {
+ 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(Ipv6Dst.class);
+ matchEntryBuilder.setOxmMatchField(UdpSrc.class);
- Ipv6DstCaseBuilder ipv6DstCaseBuilder = new Ipv6DstCaseBuilder();
- Ipv6DstBuilder ipv6DstBuilder = new Ipv6DstBuilder();
- final Integer prefix = IpConversionUtil.extractIpv6Prefix(ipv6Prefix);
+ UdpSrcCaseBuilder udpSrcCaseBuilder = new UdpSrcCaseBuilder();
+ UdpSrcBuilder udpSrcBuilder = new UdpSrcBuilder();
boolean hasMask = false;
- if (null != prefix) {
- ipv6DstBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix));
- hasMask = true;
- }
- ipv6DstBuilder.setIpv6Address(IpConversionUtil.extractIpv6Address(ipv6Prefix));
- ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build());
+ udpSrcBuilder.setPort(udpMatch.getUdpSourcePort());
+ udpSrcCaseBuilder.setUdpSrc(udpSrcBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(udpSrcCaseBuilder.build());
matchEntryBuilder.setHasMask(hasMask);
- matchEntryBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build());
matchEntryList.add(matchEntryBuilder.build());
}
- if (ipv6Match.getIpv6Label() != null) {
- matchEntryList.add(toOfIpv6FlowLabel(ipv6Match.getIpv6Label()));
- }
+ if (udpMatch.getUdpDestinationPort() != null) {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntryBuilder.setOxmMatchField(UdpDst.class);
- if (ipv6Match.getIpv6NdTarget() != null) {
- matchEntryList.add(toOfIpv6NdTargetAddress(ipv6Match.getIpv6NdTarget()));
+ 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());
}
-
- if (ipv6Match.getIpv6NdSll() != null) {
- MacAddress ipv6NdSll = ipv6Match.getIpv6NdSll();
+ } else if (layer4Match instanceof SctpMatch) {
+ SctpMatch sctpMatch = (SctpMatch) layer4Match;
+ if (sctpMatch.getSctpSourcePort() != null) {
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(Ipv6NdSll.class);
+ matchEntryBuilder.setOxmMatchField(SctpSrc.class);
- Ipv6NdSllCaseBuilder ipv6NdSllCaseBuilder = new Ipv6NdSllCaseBuilder();
- Ipv6NdSllBuilder ipv6NdSllBuilder = new Ipv6NdSllBuilder();
- ipv6NdSllBuilder.setMacAddress(ipv6NdSll);
- ipv6NdSllCaseBuilder.setIpv6NdSll(ipv6NdSllBuilder.build());
- matchEntryBuilder.setMatchEntryValue(ipv6NdSllCaseBuilder.build());
+ 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 (ipv6Match.getIpv6NdTll() != null) {
- MacAddress ipv6NdSll = ipv6Match.getIpv6NdTll();
+ if (sctpMatch.getSctpDestinationPort() != null) {
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
- matchEntryBuilder.setOxmMatchField(Ipv6NdTll.class);
+ matchEntryBuilder.setOxmMatchField(SctpDst.class);
- Ipv6NdTllCaseBuilder ipv6NdTllCaseBuilder = new Ipv6NdTllCaseBuilder();
- Ipv6NdTllBuilder ipv6NdTllBuilder = new Ipv6NdTllBuilder();
- ipv6NdTllBuilder.setMacAddress(ipv6NdSll);
- ipv6NdTllCaseBuilder.setIpv6NdTll(ipv6NdTllBuilder.build());
- matchEntryBuilder.setMatchEntryValue(ipv6NdTllCaseBuilder.build());
+ 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 (ipv6Match.getIpv6ExtHeader() != null) {
- matchEntryList.add(toOfIpv6ExtHeader(ipv6Match.getIpv6ExtHeader()));
}
}
}
+ }
- ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
- if (protocolMatchFields != null) {
- if (protocolMatchFields.getMplsLabel() != null) {
- matchEntryList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
- }
- if (protocolMatchFields.getMplsBos() != null) {
- matchEntryList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
+ private void ipMatch(List<MatchEntry> matchEntryList, IpMatch ipMatch) {
+ if (ipMatch != null) {
+ if (ipMatch.getIpDscp() != null) {
+ matchEntryList.add(toOfIpDscp(ipMatch.getIpDscp()));
}
- if (protocolMatchFields.getMplsTc() != null) {
- matchEntryList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
+ if (ipMatch.getIpEcn() != null) {
+ matchEntryList.add(toOfIpEcn(ipMatch.getIpEcn()));
}
- if (protocolMatchFields.getPbb() != null) {
- matchEntryList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
+ if (ipMatch.getIpProtocol() != null) {
+ matchEntryList.add(toOfIpProto(ipMatch.getIpProtocol()));
}
+
}
+ }
- org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
- .getTunnel();
- if (tunnel != null) {
+ 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);
- 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));
+ 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()));
}
- 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 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());
}
- }
- return matchEntryList;
+ 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());
}
}
if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() != null) {
- ipMatchBuilder.setIpProtocol(swMatch.getNwProto());
+ Short nwProto = swMatch.getNwProto();
+ ipMatchBuilder.setIpProtocol(nwProto);
matchBuilder.setIpMatch(ipMatchBuilder.build());
- }
- if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_TCP) {
- TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
- if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
- tcpMatchBuilder
- .setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
- swMatch.getTpSrc()));
- }
- if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
- tcpMatchBuilder
- .setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
- swMatch.getTpDst()));
- }
- if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
- matchBuilder.setLayer4Match(tcpMatchBuilder.build());
- }
- }
- if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_UDP) {
- UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
- if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
- udpMatchBuilder
- .setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
- swMatch.getTpSrc()));
- }
- if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
- udpMatchBuilder
- .setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
- swMatch.getTpDst()));
- }
+ int proto = nwProto.intValue();
+ if (proto == PROTO_TCP) {
+ TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
+ boolean hasTcp = false;
+ if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
+ tcpMatchBuilder
+ .setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
+ swMatch.getTpSrc()));
+ hasTcp = true;
+ }
+ if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
+ tcpMatchBuilder
+ .setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
+ swMatch.getTpDst()));
+ hasTcp = true;
+ }
- if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
- matchBuilder.setLayer4Match(udpMatchBuilder.build());
+ if (hasTcp) {
+ matchBuilder.setLayer4Match(tcpMatchBuilder.build());
+ }
+ } else if (proto == PROTO_UDP) {
+ UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
+ boolean hasUdp = false;
+ if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
+ udpMatchBuilder
+ .setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
+ swMatch.getTpSrc()));
+ hasUdp = true;
+ }
+ if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
+ udpMatchBuilder
+ .setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
+ swMatch.getTpDst()));
+ hasUdp = true;
+ }
+
+ if (hasUdp) {
+ matchBuilder.setLayer4Match(udpMatchBuilder.build());
+ }
+ } else if (proto == PROTO_ICMPV4) {
+ Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
+ boolean hasIcmpv4 = false;
+ if (!swMatch.getWildcards().isTPSRC().booleanValue()) {
+ Integer type = swMatch.getTpSrc();
+ if (type != null) {
+ icmpv4MatchBuilder.setIcmpv4Type(type.shortValue());
+ hasIcmpv4 = true;
+ }
+ }
+ if (!swMatch.getWildcards().isTPDST().booleanValue()) {
+ Integer code = swMatch.getTpDst();
+ if (code != null) {
+ icmpv4MatchBuilder.setIcmpv4Code(code.shortValue());
+ hasIcmpv4 = true;
+ }
+ }
+
+ if (hasIcmpv4) {
+ matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
+ }
}
}
if (!swMatch.getWildcards().isNWTOS().booleanValue() && swMatch.getNwTos() != null) {
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) {
MetadataBuilder metadataBuilder = new MetadataBuilder();
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.metadata._case.Metadata metadata = ((MetadataCase) ofMatch.getMatchEntryValue()).getMetadata();
if (metadata != null) {
- metadataBuilder.setMetadata(new BigInteger(1, metadata.getMetadata()));
+ metadataBuilder.setMetadata(new BigInteger(OFConstants.SIGNUM_UNSIGNED, metadata.getMetadata()));
byte[] metadataMask = metadata.getMask();
if (metadataMask != null) {
metadataBuilder.setMetadataMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, metadataMask));
} else if (ofMatch.getOxmMatchField().equals(ArpSpa.class)) {
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.spa._case.ArpSpa arpSpa = ((ArpSpaCase) ofMatch.getMatchEntryValue()).getArpSpa();
if (arpSpa != null) {
- String mask ="";
+ int mask = 32;
if (null != arpSpa.getMask()){
- mask = MatchConvertorUtil.getIpv4Mask(arpSpa.getMask());
+ mask = IpConversionUtil.countBits(arpSpa.getMask());
}
Ipv4Prefix ipv4Prefix = IpConversionUtil.createPrefix(arpSpa.getIpv4Address(), mask);
arpMatchBuilder.setArpSourceTransportAddress(ipv4Prefix);
} else if (ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.tpa._case.ArpTpa arpTpa = ((ArpTpaCase) ofMatch.getMatchEntryValue()).getArpTpa();
if (arpTpa != null) {
- String mask ="";
+ int mask = 32;
if (null != arpTpa.getMask()){
- mask = MatchConvertorUtil.getIpv4Mask(arpTpa.getMask());
+ mask = IpConversionUtil.countBits(arpTpa.getMask());
}
Ipv4Prefix ipv4Prefix = IpConversionUtil.createPrefix(arpTpa.getIpv4Address(), mask);
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tunnel.id._case.TunnelId tunnelId = ((TunnelIdCase) ofMatch.getMatchEntryValue()).getTunnelId();
TunnelBuilder tunnelBuilder = new TunnelBuilder();
if (tunnelId.getTunnelId()!= null) {
- tunnelBuilder.setTunnelId(new BigInteger(1, tunnelId.getTunnelId()));
+ tunnelBuilder.setTunnelId(new BigInteger(OFConstants.SIGNUM_UNSIGNED, tunnelId.getTunnelId()));
byte[] mask = tunnelId.getMask();
if (null != mask) {
tunnelBuilder.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, mask));
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) {
- ipv6PrefixStr += IpConversionUtil.PREFIX_SEPARATOR
- + MatchConvertorUtil.ipv6NetmaskArrayToCIDRValue(mask);
+ ipv6Prefix = IpConversionUtil.createPrefix(new Ipv6Address(ipv6PrefixStr), mask);
+ } else {
+ ipv6Prefix = IpConversionUtil.createPrefix(new Ipv6Address(ipv6PrefixStr));
}
if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)) {
- ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(ipv6PrefixStr));
+ ipv6MatchBuilder.setIpv6Source(ipv6Prefix);
}
if (ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
- ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix(ipv6PrefixStr));
+ ipv6MatchBuilder.setIpv6Destination(ipv6Prefix);
}
}
- 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) {
- ipv4PrefixStr += MatchConvertorUtil.getIpv4Mask(mask);
+ ipv4Prefix = IpConversionUtil.createPrefix(new Ipv4Address(ipv4PrefixStr), mask);
} else {
//Openflow Spec : 1.3.2
//An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
// So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
// statistics response.
-
- ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + "32";
+ ipv4Prefix = IpConversionUtil.createPrefix(new Ipv4Address(ipv4PrefixStr));
}
if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)) {
- ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
+ ipv4MatchBuilder.setIpv4Source(ipv4Prefix);
}
if (ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
- ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
+ ipv4MatchBuilder.setIpv4Destination(ipv4Prefix);
}
}
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();
-
+
SetFieldBuilder setField = new SetFieldBuilder();
MatchBuilder match = OfMatchToSALMatchConvertor(setFieldAction.getMatchEntry(), null, ofVersion);
setField.fieldsFrom(match.build());
return setField.build();
}
-
-
+
+
}