package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action;
import java.math.BigInteger;
-
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
* Utility class for converting a MD-SAL action subelement into the OF subelement
*/
public class ActionSetNwDstConvertorV10Impl implements Convertor<SetNwDstActionCase, Object> {
-
+
@Override
public Object convert(SetNwDstActionCase source, BigInteger datapathid) {
Address address = source.getSetNwDstAction().getAddress();
if (address instanceof Ipv4) {
- return new Ipv4Address(((Ipv4) address).getIpv4Address().getValue());
+ //FIXME use of substring should be removed and OF models should distinguish where
+ //FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask)
+
+ String ipAddress = ((Ipv4) address).getIpv4Address().getValue();
+ ipAddress = ipAddress.substring(0, ipAddress.indexOf("/"));
+ return new Ipv4Address(ipAddress);
} else {
- throw new IllegalArgumentException("Address is not supported by OF-1.0: "+address.getClass().getName());
+ throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName());
}
}
}
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action;
import java.math.BigInteger;
-
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
* Utility class for converting a MD-SAL action subelement into the OF subelement
*/
public class ActionSetNwSrcConvertorV10Impl implements Convertor<SetNwSrcActionCase, Object> {
-
+
@Override
public Object convert(SetNwSrcActionCase source, BigInteger datapathid) {
Address address = source.getSetNwSrcAction().getAddress();
if (address instanceof Ipv4) {
- return new Ipv4Address(((Ipv4) address).getIpv4Address().getValue());
+ //FIXME use of substring should be removed and OF models should distinguish where
+ //FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask)
+
+ String ipAddress = ((Ipv4) address).getIpv4Address().getValue();
+ ipAddress = ipAddress.substring(0, ipAddress.indexOf("/"));
+ return new Ipv4Address(ipAddress);
} else {
- throw new IllegalArgumentException("Address is not supported by OF-1.0: "+address.getClass().getName());
+ throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName());
}
}
}
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
+import com.google.common.base.Optional;
+import com.google.common.base.Splitter;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-
import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
-import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionResolvers;
import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil;
import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
-import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
-import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
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.inventory.rev130819.NodeConnectorId;
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.arp.match.fields.ArpTargetHardwareAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.base.Splitter;
-
/**
* Utility class for converting a MD-SAL Flow into the OF flow mod
*/
private static final Logger logger = LoggerFactory.getLogger(MatchConvertorImpl.class);
static final String PREFIX_SEPARATOR = "/";
static final Splitter PREFIX_SPLITTER = Splitter.on('/');
- private static final byte[] VLAN_VID_MASK = new byte[] { 16, 0 };
+ 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";
matchEntriesList.add(toOfMacAddress(ArpTha.class, arpTargetHardwareAddress.getAddress(),
arpTargetHardwareAddress.getMask()));
}
- }
-
- else if (layer3Match instanceof Ipv6Match) {
+ } else if (layer3Match instanceof Ipv6Match) {
Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
if (ipv6Match.getIpv6Source() != null) {
matchEntriesList.add(toOfIpv6Prefix(Ipv6Src.class, ipv6Match.getIpv6Source()));
if (tunnel != null) {
matchEntriesList.add(toOfMetadata(TunnelId.class, tunnel.getTunnelId(), tunnel.getTunnelMask()));
}
-
-
+
+
/**
* TODO: EXTENSION PROPOSAL (match, MD-SAL to OFJava)
* - we might need version for conversion and for key
for (ExtensionList extensionItem : extensionListOpt.get().getExtensionList()) {
// TODO: get real version
ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
- ConvertorToOFJava<MatchEntries> convertor =
+ ConvertorToOFJava<MatchEntries> convertor =
OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
MatchEntries ofMatch = convertor.convert(extensionItem.getExtension());
matchEntriesList.add(ofMatch);
* @return
* @author avishnoi@in.ibm.com
*/
- public static Match fromOFMatchV10ToSALMatch(final MatchV10 swMatch, final BigInteger datapathid, final OpenflowVersion ofVersion) {
+ public static Match fromOFMatchV10ToSALMatch(final MatchV10 swMatch, final BigInteger datapathid, final OpenflowVersion ofVersion) {
MatchBuilder matchBuilder = new MatchBuilder();
EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
int vlanId = (swMatch.getDlVlan() == ((int) 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);
+ vlanIdBuilder.setVlanIdPresent(vlanId == 0 ? false : true);
vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
matchBuilder.setVlanMatch(vlanMatchBuilder.build());
}
String ipv4PrefixStr = swMatch.getNwSrc().getValue();
if (swMatch.getNwSrcMask() != null) {
ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwSrcMask();
+ } 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 += PREFIX_SEPARATOR + "32";
}
if (!ipv4PrefixStr.equals(noIp)) {
ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
String ipv4PrefixStr = swMatch.getNwDst().getValue();
if (swMatch.getNwDstMask() != null) {
ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwDstMask();
+ } 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 += PREFIX_SEPARATOR + "32";
}
if (!ipv4PrefixStr.equals(noIp)) {
ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
* match
*
* @param match
- * @param swMatch
- * @param datapathid
- * @param ofVersion
+ * @param swMatch
+ * @param datapathid
+ * @param ofVersion
* @return md-sal match instance
* @author avishnoi@in.ibm.com
*/
return OfMatchToSALMatchConvertor(swMatch.getMatchEntries(), datapathid, ofVersion);
}
- private static MatchBuilder OfMatchToSALMatchConvertor(List<MatchEntries> swMatchList, final BigInteger datapathid,
- OpenflowVersion ofVersion){
-
+ private static MatchBuilder OfMatchToSALMatchConvertor(List<MatchEntries> swMatchList, final BigInteger datapathid,
+ OpenflowVersion ofVersion) {
+
MatchBuilder matchBuilder = new MatchBuilder();
EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
if (ofMatch.getOxmMatchField().equals(InPort.class)) {
PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
- if(portNumber != null){
+ if (portNumber != null) {
Long portNo = portNumber.getPortNumber().getValue();
matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, portNo, ofVersion));
}
VlanIdBuilder vlanBuilder = new VlanIdBuilder();
vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(
vlanVidMatchEntry.getVlanVid()))
- .setVlanIdPresent(vlanVidMatchEntry.isCfiBit());
+ .setVlanIdPresent(vlanVidMatchEntry.isCfiBit());
vlanMatchBuilder.setVlanId(vlanBuilder.build());
matchBuilder.setVlanMatch(vlanMatchBuilder.build());
}
String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
if (maskMatchEntry != null) {
- int receivedMask = ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
- int shiftCount=0;
- while(receivedMask != 0xffffffff){
- receivedMask = receivedMask >> 1;
- shiftCount++;
- }
- ipv4PrefixStr += PREFIX_SEPARATOR + (32-shiftCount);
- }else{
+ ipv4PrefixStr += MatchConvertorUtil.getIpv4Mask(maskMatchEntry);
+ } 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+=PREFIX_SEPARATOR + "32";
+ ipv4PrefixStr += PREFIX_SEPARATOR + "32";
}
if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)) {
ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
}
matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
}
- }
-
- else if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)
+ } else if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)
|| ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
if (ipv4AddressMatchEntry != null) {
MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
if (maskMatchEntry != null) {
ipv4PrefixStr += PREFIX_SEPARATOR + ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
+ } 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 += PREFIX_SEPARATOR + "32";
}
if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)) {
tunnelIpv4MatchBuilder.setTunnelIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
}
matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
}
- }
- else if (ofMatch.getOxmMatchField().equals(ArpOp.class)) {
+ } else if (ofMatch.getOxmMatchField().equals(ArpOp.class)) {
OpCodeMatchEntry opCodeMatchEntry = ofMatch.getAugmentation(OpCodeMatchEntry.class);
if (opCodeMatchEntry != null) {
arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
if (maskMatchEntry != null) {
- ipv4PrefixStr += PREFIX_SEPARATOR + ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
+ ipv4PrefixStr += MatchConvertorUtil.getIpv4Mask(maskMatchEntry);
+ } 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 += PREFIX_SEPARATOR + "32";
}
if (ofMatch.getOxmMatchField().equals(ArpSpa.class)) {
arpMatchBuilder.setArpSourceTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
if (ipv6AddressMatchEntry != null) {
String ipv6PrefixStr = ipv6AddressMatchEntry.getIpv6Address().getValue();
MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
- if(maskMatchEntry != null){
+ if (maskMatchEntry != null) {
ipv6PrefixStr += PREFIX_SEPARATOR
+ MatchConvertorUtil.ipv6NetmaskArrayToCIDRValue(maskMatchEntry.getMask());
}
-
+
if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)) {
ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(ipv6PrefixStr));
}
tcpFlagMatchBuilder.setTcpFlag(tcpFlagMatch.getTcpFlag());
matchBuilder.setTcpFlagMatch(tcpFlagMatchBuilder.build());
}
- }
+ }
}
return matchBuilder;
}
+
+
private static MatchEntries toOfMplsPbb(final Pbb pbb) {
MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
boolean hasmask = false;
}
private static MatchEntries toOfMetadata(final Class<? extends MatchField> field, final BigInteger metadata,
- final BigInteger metadataMask) {
+ final BigInteger metadataMask) {
MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
boolean hasmask = false;
matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
}
public static MatchEntries toOfMacAddress(final Class<? extends MatchField> field,
- final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress,
- final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress mask) {
+ final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress,
+ final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress mask) {
MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
boolean hasmask = false;
matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
}
private static MatchEntries toOfLayer3Port(final Class<? extends MatchField> field,
- final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) {
+ final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) {
MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
matchEntriesBuilder.setHasMask(false);
/**
* @return true if Ipv4Prefix contains prefix (and it is used in mask),
- * false otherwise
+ * false otherwise
*/
private static boolean addIpv4PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv4Prefix address) {
boolean hasMask = false;
final int prefix;
if (addressParts.hasNext()) {
- prefix = Integer.parseInt(addressParts.next());
+ int potentionalPrefix = Integer.parseInt(addressParts.next());
+ prefix = potentionalPrefix < 32 ? potentionalPrefix : 0;
} else {
prefix = 0;
}
builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
if (prefix != 0) {
int mask = 0xffffffff << (32 - prefix);
- byte[] maskBytes = new byte[] { (byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
- (byte) mask };
+ byte[] maskBytes = new byte[]{(byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
+ (byte) mask};
addMaskAugmentation(builder, maskBytes);
hasMask = true;
}
/**
* Copyright (c) 2013 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
import java.nio.ByteBuffer;
import java.util.Arrays;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
/**
*/
public abstract class MatchConvertorUtil {
+ private static final String PREFIX_SEPARATOR = "/";
+
+ /**
+ * @param maskMatchEntry
+ * @return subnetwork suffix in form of "/"+<mask value {0..32}>
+ */
+ public static String getIpv4Mask(MaskMatchEntry maskMatchEntry) {
+ int receivedMask = ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
+ int shiftCount = 0;
+
+ if (receivedMask == 0) {
+ shiftCount = 32;
+ } else {
+ while (receivedMask != 0xffffffff) {
+ receivedMask = receivedMask >> 1;
+ shiftCount++;
+ if (shiftCount >= 32) {
+ throw new IllegalArgumentException("given mask is invalid: "+Arrays.toString(maskMatchEntry.getMask()));
+ }
+ }
+ }
+ return PREFIX_SEPARATOR + (32 - shiftCount);
+ }
+
/**
* @param pField
* @return integer containing lower 9 bits filled with corresponding flags
public static Integer ipv6ExthdrFlagsToInt(Ipv6ExthdrFlags pField) {
Integer bitmap = 0;
bitmap |= pField.isNonext() ? (1 << 0) : 0;
- bitmap |= pField.isEsp() ? (1 << 1) : 0;
- bitmap |= pField.isAuth() ? (1 << 2) : 0;
- bitmap |= pField.isDest() ? (1 << 3) : 0;
- bitmap |= pField.isFrag() ? (1 << 4) : 0;
+ bitmap |= pField.isEsp() ? (1 << 1) : 0;
+ bitmap |= pField.isAuth() ? (1 << 2) : 0;
+ bitmap |= pField.isDest() ? (1 << 3) : 0;
+ bitmap |= pField.isFrag() ? (1 << 4) : 0;
bitmap |= pField.isRouter() ? (1 << 5) : 0;
- bitmap |= pField.isHop() ? (1 << 6) : 0;
- bitmap |= pField.isUnrep() ? (1 << 7) : 0;
- bitmap |= pField.isUnseq() ? (1 << 8) : 0;
+ bitmap |= pField.isHop() ? (1 << 6) : 0;
+ bitmap |= pField.isUnrep() ? (1 << 7) : 0;
+ bitmap |= pField.isUnseq() ? (1 << 8) : 0;
return bitmap;
}
-
- public static int ipv6NetmaskArrayToCIDRValue(byte[] rawMask){
+
+ public static int ipv6NetmaskArrayToCIDRValue(byte[] rawMask) {
/*
* Openflow Spec : 1.3.2+
if (rawMask != null) {
maskValue = 0;
- for(int subArrayCounter=0;subArrayCounter<4;subArrayCounter++){
+ for (int subArrayCounter = 0; subArrayCounter < 4; subArrayCounter++) {
int copyFrom = subArrayCounter * 4;
- byte[] subArray = Arrays.copyOfRange(rawMask, copyFrom, copyFrom+4);
+ byte[] subArray = Arrays.copyOfRange(rawMask, copyFrom, copyFrom + 4);
int receivedMask = ByteBuffer.wrap(subArray).getInt();
- int shiftCount=0;
+ int shiftCount = 0;
if (receivedMask == 0) {
break;
}
- while(receivedMask != 0xffffffff){
+ while (receivedMask != 0xffffffff) {
receivedMask = receivedMask >> 1;
shiftCount++;
}
- maskValue = maskValue+(32-shiftCount);
- if(shiftCount != 0) {
+ maskValue = maskValue + (32 - shiftCount);
+ if (shiftCount != 0) {
break;
}
}
*/
package org.opendaylight.openflowplugin.openflow.md.core.translator;
+import java.math.BigInteger;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
import org.opendaylight.openflowjava.util.ByteBufUtils;
-import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
-import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.md.core.IMDMessageTranslator;
import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
+import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
+import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
+import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
import org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
-import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
-import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.math.BigInteger;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CopyOnWriteArrayList;
-
public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
protected static final Logger LOG = LoggerFactory.getLogger(FlowRemovedTranslator.class);
FlowRemovedReason.OFPRRGROUPDELETE.equals(ofFlow.getReason()),
FlowRemovedReason.OFPRRHARDTIMEOUT.equals(ofFlow.getReason()),
FlowRemovedReason.OFPRRIDLETIMEOUT.equals(ofFlow.getReason())
- );
+ );
salFlowRemoved.setRemovedReason(removeReasonFlag);
.getMatch();
if (ofMatch != null) {
salFlowRemoved.setMatch(fromMatch(ofMatch, sc.getFeatures().getDatapathId(), ofVersion));
- }
- else if(ofFlow.getMatchV10() != null){
+ } else if (ofFlow.getMatchV10() != null) {
MatchBuilder matchBuilder = new MatchBuilder(MatchConvertorImpl.fromOFMatchV10ToSALMatch(ofFlow.getMatchV10(), sc.getFeatures().getDatapathId(), ofVersion));
salFlowRemoved.setMatch(matchBuilder.build());
}
public Match fromMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match ofMatch,
- BigInteger datapathid, OpenflowVersion ofVersion) {
+ BigInteger datapathid, OpenflowVersion ofVersion) {
MatchBuilder matchBuilder = new MatchBuilder();
EthernetMatchBuilder ethernetMatch = null;
VlanMatchBuilder vlanMatch = null;
EthernetDestinationBuilder ethDst = new EthernetDestinationBuilder();
ethDst.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
if (entry.isHasMask()) {
- ethDst.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
+ ethDst.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(), ":")));
}
ethernetMatch.setEthernetDestination(ethDst.build());
} else if (field.equals(EthSrc.class)) {
EthernetSourceBuilder ethSrc = new EthernetSourceBuilder();
ethSrc.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
if (entry.isHasMask()) {
- ethSrc.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
+ ethSrc.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(), ":")));
}
ethernetMatch.setEthernetSource(ethSrc.build());
} else if (field.equals(EthType.class)) {
ArpSourceHardwareAddressBuilder arpSha = new ArpSourceHardwareAddressBuilder();
arpSha.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
if (entry.isHasMask()) {
- arpSha.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
+ arpSha.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(), ":")));
}
arpMatch.setArpSourceHardwareAddress(arpSha.build());
} else if (field.equals(ArpTha.class)) {
ArpTargetHardwareAddressBuilder arpTha = new ArpTargetHardwareAddressBuilder();
arpTha.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
if (entry.isHasMask()) {
- arpTha.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
+ arpTha.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(), ":")));
}
arpMatch.setArpTargetHardwareAddress(arpTha.build());
}
ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
if (entry.isHasMask()) {
ipv6ExtHeaderBuilder.setIpv6ExthdrMask(
- ByteUtil.bytesToUnsignedShort(entry.getAugmentation(MaskMatchEntry.class).getMask()));
+ ByteUtil.bytesToUnsignedShort(entry.getAugmentation(MaskMatchEntry.class).getMask()));
}
ipv6Match.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
}
tunnel.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, entry.getAugmentation(MaskMatchEntry.class).getMask()));
}
matchBuilder.setTunnel(tunnel.build());
- }
+ }
}
-
- AugmentTuple<Match> matchExtensionWrap =
+
+ AugmentTuple<Match> matchExtensionWrap =
MatchExtensionHelper.processAllExtensions(
ofMatch.getMatchEntries(), ofVersion, MatchPath.SWITCHFLOWREMOVED_MATCH);
if (matchExtensionWrap != null) {
matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject());
}
-
-
+
+
if (ethernetMatch != null) {
matchBuilder.setEthernetMatch(ethernetMatch.build());
}
if (entry.isHasMask()) {
byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();
ipv4Prefix = ipv4Prefix + PREFIX_SEPARATOR + countBits(mask);
+ } else {
+ ipv4Prefix += PREFIX_SEPARATOR + "32";
}
return new Ipv4Prefix(ipv4Prefix);
}
short version = 1;
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder();
Address address;
- address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1")).build();
+ address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
SetNwDstActionCase action = provisionNwDstActionBuilder(address);
ActionConvertor.SalToOFSetNwDst(action, actionBuilder, version);
Assert.assertEquals(SetNwDst.class, actionBuilder.getType());
short version = 4;
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder();
Address address;
- address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1")).build();
+ address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
SetNwDstActionCase action = provisionNwDstActionBuilder(address);
ActionConvertor.SalToOFSetNwDst(action, actionBuilder, version);
Assert.assertEquals(SetField.class, actionBuilder.getType());
short version = 1;
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder();
Address address;
- address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1")).build();
+ address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
SetNwSrcActionCase action = provisionNwSrcActionBuilder(address);
ActionConvertor.SalToOFSetNwSrc(action, actionBuilder, version);
Assert.assertEquals(SetNwSrc.class, actionBuilder.getType());
short version = 4;
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder();
Address address;
- address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1")).build();
+ address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
SetNwSrcActionCase action = provisionNwSrcActionBuilder(address);
ActionConvertor.SalToOFSetNwSrc(action, actionBuilder, version);
Assert.assertEquals(SetField.class, actionBuilder.getType());
public class PortConvertorTest {
-
+ /** defautl mac address */
+ private static final String DEFAULT_MAC_ADDRESS = "01:02:03:04:05:06";
+
private PortFeatures features = new PortFeatures(true, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null);
portBld.setAdvertisedFeatures(features);
portBld.setConfiguration(config);
portBld.setPortNumber(new PortNumber(42L));
- portBld.setHardwareAddress(new MacAddress(""));
+ portBld.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
PortModInput portOut = PortConvertor.toPortModInput(portBld.build(), EncodeConstants.OF13_VERSION_ID);
portModInputBld.setMask(config31);
portModInputBld.setPortNo(
new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber(42L));
- portModInputBld.setHwAddress(new MacAddress(""));
+ portModInputBld.setHwAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
portModInputBld.setAdvertise(portf31);
portModInputBld.setConfigV10(portConfV10);
flowCapableNodeConnectorBuilder.setConfiguration(config);
flowCapableNodeConnectorBuilder.setCurrentFeature(features);
flowCapableNodeConnectorBuilder.setCurrentSpeed(null);
- flowCapableNodeConnectorBuilder.setHardwareAddress(new MacAddress(""));
+ flowCapableNodeConnectorBuilder.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
flowCapableNodeConnectorBuilder.setMaximumSpeed(null);
flowCapableNodeConnectorBuilder.setName("foo");
flowCapableNodeConnectorBuilder.setPeerFeatures(features);
portsB.setConfig(config31);
portsB.setCurrentFeatures(portf31);
portsB.setCurrSpeed(null);
- portsB.setHwAddr(new MacAddress(""));
+ portsB.setHwAddr(new MacAddress(DEFAULT_MAC_ADDRESS));
portsB.setMaxSpeed(null);
portsB.setName("foo");
portsB.setPeerFeatures(portf31);
import java.math.BigInteger;
-import junit.framework.Assert;
-
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.openflowplugin.api.OFConstants;
@Before
public void setUp() {
addresses = new Address[] {
- new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1")).build(),
+ new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1/32")).build(),
new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1/16")).build(),
new Ipv6Builder().setIpv6Address(new Ipv6Prefix("1234:5678:9abc:def1:2345:6789:abcd:ef12")).build(),
new Ipv6Builder().setIpv6Address(new Ipv6Prefix("1234:5678:9abc:def1:2345:6789:abcd:ef12/42")).build(),
import java.math.BigInteger;
-import junit.framework.Assert;
-
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.openflowplugin.api.OFConstants;
@Before
public void setUp() {
addresses = new Address[] {
- new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1")).build(),
+ new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1/32")).build(),
new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1/16")).build(),
new Ipv6Builder().setIpv6Address(new Ipv6Prefix("1234:5678:9abc:def1:2345:6789:abcd:ef12")).build(),
new Ipv6Builder().setIpv6Address(new Ipv6Prefix("1234:5678:9abc:def1:2345:6789:abcd:ef12/42")).build(),
tunnelBuilder.setTunnelId(new BigInteger("21"));\r
builder.setTunnel(tunnelBuilder.build());\r
Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();\r
- ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix("10.0.0.1"));\r
- ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix("10.0.0.2"));\r
+ ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix("10.0.0.1/32"));\r
+ ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix("10.0.0.2/32"));\r
builder.setLayer3Match(ipv4MatchBuilder.build());\r
Match match = builder.build();\r
\r
MatchBuilder builder = new MatchBuilder();\r
ArpMatchBuilder arpBuilder = new ArpMatchBuilder();\r
arpBuilder.setArpOp(5);\r
- arpBuilder.setArpSourceTransportAddress(new Ipv4Prefix("10.0.0.3"));\r
- arpBuilder.setArpTargetTransportAddress(new Ipv4Prefix("10.0.0.4"));\r
+ arpBuilder.setArpSourceTransportAddress(new Ipv4Prefix("10.0.0.3/32"));\r
+ arpBuilder.setArpTargetTransportAddress(new Ipv4Prefix("10.0.0.4/32"));\r
ArpSourceHardwareAddressBuilder srcHwBuilder = new ArpSourceHardwareAddressBuilder();\r
srcHwBuilder.setAddress(new MacAddress("00:00:00:00:00:05"));\r
arpBuilder.setArpSourceHardwareAddress(srcHwBuilder.build());\r
MatchBuilder builder = new MatchBuilder();\r
ArpMatchBuilder arpBuilder = new ArpMatchBuilder();\r
arpBuilder.setArpSourceTransportAddress(new Ipv4Prefix("10.0.0.3/8"));\r
- arpBuilder.setArpTargetTransportAddress(new Ipv4Prefix("10.0.0.4/32"));\r
+ arpBuilder.setArpTargetTransportAddress(new Ipv4Prefix("10.0.0.4/31"));\r
ArpSourceHardwareAddressBuilder srcHwBuilder = new ArpSourceHardwareAddressBuilder();\r
srcHwBuilder.setAddress(new MacAddress("00:00:00:00:00:05"));\r
srcHwBuilder.setMask(new MacAddress("00:00:00:00:00:08"));\r
checkEntryHeader(entry, ArpTpa.class, true);\r
Assert.assertEquals("Wrong arp tpa", "10.0.0.4", entry.getAugmentation(Ipv4AddressMatchEntry.class)\r
.getIpv4Address().getValue());\r
- Assert.assertArrayEquals("Wrong arp tpa mask", new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255},\r
+ Assert.assertArrayEquals("Wrong arp tpa mask", new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 254},\r
entry.getAugmentation(MaskMatchEntry.class).getMask());\r
entry = entries.get(2);\r
checkEntryHeader(entry, ArpSha.class, true);\r
getValue().intValue());
Ipv4Match ipv4Match = (Ipv4Match)match.getLayer3Match();
- assertEquals(IPV4_SRC.getValue(),
+ assertEquals(IPV4_SRC.getValue()+"/32",
ipv4Match.getIpv4Source().getValue());
- assertEquals(IPV4_DST.getValue(),
+ assertEquals(IPV4_DST.getValue()+"/32",
ipv4Match.getIpv4Destination().getValue());
}
\r
ArpMatch arpMatch = (ArpMatch) builtMatch.getLayer3Match();\r
Assert.assertEquals("Wrong arp op", 17, arpMatch.getArpOp().intValue());\r
- Assert.assertEquals("Wrong arp spa", "10.0.0.3", arpMatch.getArpSourceTransportAddress().getValue());\r
- Assert.assertEquals("Wrong arp tpa", "10.0.0.4", arpMatch.getArpTargetTransportAddress().getValue());\r
+ Assert.assertEquals("Wrong arp spa", "10.0.0.3/32", arpMatch.getArpSourceTransportAddress().getValue());\r
+ Assert.assertEquals("Wrong arp tpa", "10.0.0.4/32", arpMatch.getArpTargetTransportAddress().getValue());\r
Assert.assertEquals("Wrong arp sha", "00:00:00:00:00:03", arpMatch.getArpSourceHardwareAddress().getAddress().getValue());\r
Assert.assertEquals("Wrong arp tha", "00:00:00:00:00:04", arpMatch.getArpTargetHardwareAddress().getAddress().getValue());\r
}\r
import java.lang.reflect.Constructor;
import java.math.BigInteger;
+import java.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
maskSeed = maskSeed.clearBit(i);
}
}
+
+ /**
+ * Test method for {@link MatchConvertorUtil#getIpv4Mask(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry)}.
+ * @throws Exception
+ */
+ @Test
+ public void testGetIpv4Mask() {
+ MaskMatchEntryBuilder maskMatchEntry = new MaskMatchEntryBuilder();
+ byte[][] maskInputs = new byte[][] {
+ {(byte) 255, (byte) 255, (byte) 255, (byte) 255},
+ {(byte) 255, (byte) 255, (byte) 254, 0},
+ {(byte) 128, 0, 0, 0},
+ {0, 0, 0, 0},
+ };
+
+ String[] maskOutputs = new String[] {
+ "/32", "/23", "/1", "/0"
+ };
+
+ for (int i = 0; i < maskInputs.length; i++) {
+ MaskMatchEntry maskEntry = maskMatchEntry.setMask(maskInputs[i]).build();
+ String mask = MatchConvertorUtil.getIpv4Mask(maskEntry);
+ Assert.assertEquals(maskOutputs[i], mask);
+ }
+ }
+
+ /**
+ * Test method for {@link MatchConvertorUtil#getIpv4Mask(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry)}.
+ * @throws Exception
+ */
+ @Test
+ public void testGetIpv4MaskNegative() {
+ MaskMatchEntryBuilder maskMatchEntry = new MaskMatchEntryBuilder();
+ byte[][] maskInputs = new byte[][] {
+ {(byte) 127, 0, 0, 0},
+ {(byte) 127, 0, 0},
+ };
+
+ for (int i = 0; i < maskInputs.length; i++) {
+ MaskMatchEntry maskEntry = maskMatchEntry.setMask(maskInputs[i]).build();
+ try {
+ MatchConvertorUtil.getIpv4Mask(maskEntry);
+ Assert.fail("invalid mask should not have passed: " + Arrays.toString(maskInputs[i]));
+ } catch (Exception e) {
+ // expected
+ LOG.info("ipv4 mask excepted exception: {}", e.getMessage(), e);
+ }
+ }
+ }
}
private static final Integer TCP_FLAG = new Integer(42);
private static final Ipv4Prefix IPV_4_PREFIX = new Ipv4Prefix("10.0.0.1/24");
- private static final Ipv4Prefix IPV_4_PREFIX_NO_MASK = new Ipv4Prefix("10.0.0.1");
@Test
/**
*/
public void testAddNxmIpv4PrefixAugmentation() {
assertTrue(NxmExtensionsConvertor.addNxmIpv4PrefixAugmentation(new MatchEntriesBuilder(), IPV_4_PREFIX));
- assertFalse(NxmExtensionsConvertor.addNxmIpv4PrefixAugmentation(new MatchEntriesBuilder(), IPV_4_PREFIX_NO_MASK));
}
fieldClassesAndAugmentations.put(TunnelId.class, metadataMatchEntryBuilder.build());
Ipv4AddressMatchEntryBuilder ipv4AddressMatchEntryBuilder = new Ipv4AddressMatchEntryBuilder();
- ipv4AddressMatchEntryBuilder.setIpv4Address(new Ipv4Address("10.0.0.1/24"));
+ ipv4AddressMatchEntryBuilder.setIpv4Address(new Ipv4Address("10.0.0.1"));
fieldClassesAndAugmentations.put(ArpTpa.class, ipv4AddressMatchEntryBuilder.build());
fieldClassesAndAugmentations.put(ArpSpa.class, ipv4AddressMatchEntryBuilder.build());