Bug 1953 - fix of this bugs impact on OFP 47/13147/2
authorMartin Bobak <mbobak@cisco.com>
Wed, 26 Nov 2014 14:59:14 +0000 (15:59 +0100)
committerMichal Rehak <mirehak@cisco.com>
Wed, 26 Nov 2014 17:14:11 +0000 (18:14 +0100)
- fixed errors where Ipv4Prefix was instantiated without mask
- fixed errors where Ipv4Address was instantiated using mask
- fixed failing tests

Change-Id: I3a9270fc75128ab5fa7ee12bf92ad9a1cb324fc0
Signed-off-by: Martin Bobak <mbobak@cisco.com>
Signed-off-by: Michal Rehak <mirehak@cisco.com>
15 files changed:
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorV10Impl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorV10Impl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorUtil.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslator.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertorTest.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PortConvertorTest.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorTest.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorTest.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl2Test.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImplTest.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImplV13Test.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorUtilTest.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/NxmExtensionsConvertorTest.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslatorTest.java

index f3a0f95c17a6b37bf73d9288653730d2b688f7a5..fb6beeffab87f26bf36fd15b28a2acf8e899b2bb 100644 (file)
@@ -9,7 +9,6 @@
 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;
@@ -20,14 +19,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.addr
  * 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());
         }
     }
 }
index 796c092de8fda735274930bcf91d4f77ca5b7e3f..e19daf3c7676c5976b6fdcc32151cac274d3c671 100644 (file)
@@ -9,7 +9,6 @@
 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;
@@ -20,14 +19,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.addr
  * 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());
         }
     }
 }
index 4a466c50ad7502f16eaf8fe33461da817406a07e..3b73311e9a9b0b1ecd5450c55a36cd1bf3039f37 100644 (file)
@@ -8,23 +8,23 @@
 
 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;
@@ -36,7 +36,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti
 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;
@@ -195,9 +194,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ge
 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
  */
@@ -205,7 +201,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
     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";
@@ -377,9 +373,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                     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()));
@@ -444,8 +438,8 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         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
@@ -456,7 +450,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
             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);
@@ -474,7 +468,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
      * @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();
@@ -508,7 +502,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
             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());
         }
@@ -521,6 +515,13 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
             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));
@@ -531,6 +532,13 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
             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));
@@ -589,9 +597,9 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
      * 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
      */
@@ -601,9 +609,9 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         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();
@@ -624,7 +632,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
 
             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));
                 }
@@ -676,7 +684,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                     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());
                 }
@@ -774,20 +782,14 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                     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));
@@ -797,9 +799,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                     }
                     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) {
@@ -807,6 +807,13 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                     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));
@@ -816,8 +823,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                     }
                     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());
@@ -830,7 +836,14 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                     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));
@@ -873,11 +886,11 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                 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));
                     }
@@ -982,10 +995,12 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                     tcpFlagMatchBuilder.setTcpFlag(tcpFlagMatch.getTcpFlag());
                     matchBuilder.setTcpFlagMatch(tcpFlagMatchBuilder.build());
                 }
-            } 
+            }
         }
         return matchBuilder;
     }
+
+
     private static MatchEntries toOfMplsPbb(final Pbb pbb) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         boolean hasmask = false;
@@ -1093,7 +1108,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
     }
 
     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);
@@ -1109,8 +1124,8 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
     }
 
     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);
@@ -1136,7 +1151,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
     }
 
     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);
@@ -1355,7 +1370,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
 
     /**
      * @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;
@@ -1364,7 +1379,8 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
 
         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;
         }
@@ -1374,8 +1390,8 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         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;
         }
index d3ef62894746aca8d1099ae46debc0e761a50010..dfe901cd20756e59b7810f75da2bdcd8465718e1 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -10,6 +10,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
 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;
 
 /**
@@ -17,6 +18,30 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13
  */
 public abstract class MatchConvertorUtil {
 
+    private static final String PREFIX_SEPARATOR = "/";
+
+    /**
+     * @param maskMatchEntry
+     * @return subnetwork suffix in form of "/"+&lt;mask value {0..32}&gt;
+     */
+    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
@@ -24,18 +49,18 @@ public abstract class MatchConvertorUtil {
     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+
@@ -48,26 +73,26 @@ public abstract class MatchConvertorUtil {
 
         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;
                 }
             }
index 8f3a29d585b5cc7f357187325087cf490ad89807..de4fa585f83505f01af97af9637b24b29fa7d177 100644 (file)
@@ -9,18 +9,24 @@
  */
 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;
@@ -133,13 +139,6 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 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);
@@ -175,7 +174,7 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
                     FlowRemovedReason.OFPRRGROUPDELETE.equals(ofFlow.getReason()),
                     FlowRemovedReason.OFPRRHARDTIMEOUT.equals(ofFlow.getReason()),
                     FlowRemovedReason.OFPRRIDLETIMEOUT.equals(ofFlow.getReason())
-                    );
+            );
 
             salFlowRemoved.setRemovedReason(removeReasonFlag);
 
@@ -184,8 +183,7 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
                     .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());
             }
@@ -201,7 +199,7 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
 
 
     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;
@@ -239,14 +237,14 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
                     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)) {
@@ -363,14 +361,14 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
                     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());
                 }
@@ -424,7 +422,7 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
                     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());
                 }
@@ -455,17 +453,17 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
                     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());
         }
@@ -508,6 +506,8 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
         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);
     }
index c9d4f09690e6e3330e22d05ed581a0dcc20ca65d..4a146f338d7f1b189dbf9f05e82958db9c12b2af 100644 (file)
@@ -470,7 +470,7 @@ public class ActionConvertorTest {
         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());
@@ -502,7 +502,7 @@ public class ActionConvertorTest {
         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());
@@ -541,7 +541,7 @@ public class ActionConvertorTest {
         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());
@@ -572,7 +572,7 @@ public class ActionConvertorTest {
         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());
index 98555e5fcb9cd945e44dd137cca37e884ced68f1..f2438d8ec0e3cb0279c6cad51921f8616c63726e 100644 (file)
@@ -30,7 +30,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 
 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);
     
@@ -55,7 +57,7 @@ public class PortConvertorTest {
         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);
         
@@ -67,7 +69,7 @@ public class PortConvertorTest {
         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);
@@ -95,7 +97,7 @@ public class PortConvertorTest {
         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);
@@ -111,7 +113,7 @@ public class PortConvertorTest {
         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);
index 305bdd9162145ee766d0d5e27dda27a9080503b1..31ef0d26f8f6ce7cc85839bff4a0bb2caffd1100 100644 (file)
@@ -9,8 +9,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action;
 
 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;
@@ -44,7 +43,7 @@ public class ActionSetNwDstReactorTest {
     @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(),
index 3b29b9ee7b170085c80e9ccc466bbaf58d214d51..6045aae4ee13ddd460eae14e6638abd315ef4393 100644 (file)
@@ -9,8 +9,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action;
 
 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;
@@ -44,7 +43,7 @@ public class ActionSetNwSrcReactorTest {
     @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(),
index 8b0172b603e6a3d33cff2801272deed1195779a3..d7692f0dd408b9523f427795db9986e98e1c6731 100644 (file)
@@ -208,8 +208,8 @@ public class MatchConvertorImpl2Test {
         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
@@ -376,8 +376,8 @@ public class MatchConvertorImpl2Test {
         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
@@ -419,7 +419,7 @@ public class MatchConvertorImpl2Test {
         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
@@ -444,7 +444,7 @@ public class MatchConvertorImpl2Test {
         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
index 152f69db76dfa481b9fb7402163ef3f11d59bd29..13c16051808fa62bc6d6675164da6fc8aaa77e06 100644 (file)
@@ -291,9 +291,9 @@ public class MatchConvertorImplTest {
                          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());
         }
 
index 46814fdf7ed417c4f2be054ede4512ab13a7cf4e..65622c485fd79c082459c0c9699f476d674cd4ea 100644 (file)
@@ -788,8 +788,8 @@ public class MatchConvertorImplV13Test {
         \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
index f947a00dbc95c13eeb03067e100f33d55520f6d2..f2d621fac91c6b2db0eabed42587a7a7dbb7f13e 100644 (file)
@@ -9,10 +9,13 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
 
 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;
@@ -85,4 +88,53 @@ public class MatchConvertorUtilTest {
             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);
+            }
+        }
+    }
 }
index b2c64283c7f8d4e4d8bd470a77681c61ceeeb2d8..f9445f1457320ae057f1862b62dfcda1264a0031 100644 (file)
@@ -32,7 +32,6 @@ public class NxmExtensionsConvertorTest {
 
     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
     /**
@@ -65,7 +64,6 @@ public class NxmExtensionsConvertorTest {
      */
     public void testAddNxmIpv4PrefixAugmentation() {
         assertTrue(NxmExtensionsConvertor.addNxmIpv4PrefixAugmentation(new MatchEntriesBuilder(), IPV_4_PREFIX));
-        assertFalse(NxmExtensionsConvertor.addNxmIpv4PrefixAugmentation(new MatchEntriesBuilder(), IPV_4_PREFIX_NO_MASK));
     }
 
 
index 9e5773821ae2791d107a79c528085bc0b9b94908..7eb573074fbf3481aabb9ac606879e2ae7573800 100644 (file)
@@ -264,7 +264,7 @@ public class FlowRemovedTranslatorTest extends FlowRemovedTranslator {
         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());