Bug 2127: Fixed bugs in MatchConvertorImpl.fromOFMatchV10ToSALMatch(). 00/11700/1
authorShigeru Yasuda <s-yasuda@da.jp.nec.com>
Wed, 1 Oct 2014 13:13:52 +0000 (22:13 +0900)
committerShigeru Yasuda <s-yasuda@da.jp.nec.com>
Wed, 1 Oct 2014 13:13:52 +0000 (22:13 +0900)
  * TOS value in NW_TOS match field needs to be converted into
    IP DSCP value.
  * DSCP match field should be configured into a MD-SAL match unless
    NW_TOS wildcard bit is set in OF10 match.

Change-Id: Ie4d5dbf8a9db564a0e6785fea880b0d78cc1f499
Signed-off-by: Shigeru Yasuda <s-yasuda@da.jp.nec.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/FlowWildcardsV10Builder.java [new file with mode: 0644]
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImplTest.java

index 72d6eacd1ff203331c64db32df056d04945caab3..4a466c50ad7502f16eaf8fe33461da817406a07e 100644 (file)
@@ -20,6 +20,7 @@ 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;
@@ -575,12 +576,8 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
             }
         }
         if (!swMatch.getWildcards().isNWTOS().booleanValue() && swMatch.getNwTos() != null) {
-            // DSCP default value is 0 from the library but controller side it
-            // is null.
-            // look if there better solution
-            if (0 != swMatch.getNwTos()) {
-                ipMatchBuilder.setIpDscp(new Dscp(swMatch.getNwTos()));
-            }
+            Short dscp = ActionUtil.tosToDscp(swMatch.getNwTos().shortValue());
+            ipMatchBuilder.setIpDscp(new Dscp(dscp));
             matchBuilder.setIpMatch(ipMatchBuilder.build());
         }
 
diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/FlowWildcardsV10Builder.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/FlowWildcardsV10Builder.java
new file mode 100644 (file)
index 0000000..99879dd
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2014 NEC Corporation 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
+ */
+
+package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
+
+/**
+ * Builder class for {@link FlowWildcardsV10}.
+ */
+public class FlowWildcardsV10Builder {
+    private boolean  dlDst;
+    private boolean  dlSrc;
+    private boolean  dlType;
+    private boolean  dlVlan;
+    private boolean  dlVlanPcp;
+    private boolean  inPort;
+    private boolean  nwProto;
+    private boolean  nwTos;
+    private boolean  tpDst;
+    private boolean  tpSrc;
+
+    public FlowWildcardsV10 build() {
+        return new FlowWildcardsV10(dlDst, dlSrc, dlType, dlVlan, dlVlanPcp,
+                                    inPort, nwProto, nwTos, tpDst, tpSrc);
+    }
+
+    public FlowWildcardsV10Builder setAll(boolean b) {
+        dlDst = b;
+        dlSrc = b;
+        dlType = b;
+        dlVlan = b;
+        dlVlanPcp = b;
+        inPort = b;
+        nwProto = b;
+        nwTos = b;
+        tpDst = b;
+        tpSrc = b;
+        return this;
+    }
+
+    public FlowWildcardsV10Builder setDlDst(boolean b) {
+        dlDst = b;
+        return this;
+    }
+
+    public FlowWildcardsV10Builder setDlSrc(boolean b) {
+        dlSrc = b;
+        return this;
+    }
+
+    public FlowWildcardsV10Builder setDlType(boolean b) {
+        dlType = b;
+        return this;
+    }
+
+    public FlowWildcardsV10Builder setDlVlan(boolean b) {
+        dlVlan = b;
+        return this;
+    }
+
+    public FlowWildcardsV10Builder setDlVlanPcp(boolean b) {
+        dlVlanPcp = b;
+        return this;
+    }
+
+    public FlowWildcardsV10Builder setInPort(boolean b) {
+        inPort = b;
+        return this;
+    }
+
+    public FlowWildcardsV10Builder setNwProto(boolean b) {
+        nwProto = b;
+        return this;
+    }
+
+    public FlowWildcardsV10Builder setNwTos(boolean b) {
+        nwTos = b;
+        return this;
+    }
+
+    public FlowWildcardsV10Builder setTpDst(boolean b) {
+        tpDst = b;
+        return this;
+    }
+
+    public FlowWildcardsV10Builder setTpSrc(boolean b) {
+        tpSrc = b;
+        return this;
+    }
+}
index af5ab10fa9accb8a310841093ab7dc29e5076d43..152f69db76dfa481b9fb7402163ef3f11d59bd29 100644 (file)
@@ -20,11 +20,15 @@ import org.junit.Test;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
 
+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.yang.types.rev100924.MacAddress;
+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.match.EthernetMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
@@ -34,6 +38,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
@@ -43,6 +48,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Matc
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
 
@@ -59,6 +66,13 @@ public class MatchConvertorImplTest {
     private static final MacAddress MAC_DST =
         MacAddress.getDefaultInstance("fa:fb:fc:fd:fe:ff");
     private static final int  ETHTYPE_IPV4 = 0x800;
+    private static final short  VLAN_PCP = 7;
+    private static final Ipv4Address  IPV4_SRC =
+        Ipv4Address.getDefaultInstance("192.168.10.254");
+    private static final Ipv4Address  IPV4_DST =
+        Ipv4Address.getDefaultInstance("10.1.2.3");
+
+    private static final int  DL_VLAN_NONE = 0xffff;
 
     @BeforeClass
     public static void setUp() {
@@ -103,6 +117,59 @@ public class MatchConvertorImplTest {
         }
     }
 
+    /**
+     * Test method for {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}.
+     */
+    @Test
+    public void testFromOFMatchV10ToSALMatch() {
+        int[] vids = {
+            // Match untagged frame.
+            DL_VLAN_NONE,
+
+            // Match packet with VLAN tag and VID equals the specified value.
+            1, 20, 4095,
+        };
+        short[] dscps = {
+            0, 1, 20, 40, 62, 63,
+        };
+
+        FlowWildcardsV10Builder wcBuilder = new FlowWildcardsV10Builder();
+        for (int vid: vids) {
+            for (short dscp: dscps) {
+                short tos = (short)(dscp << 2);
+                MatchV10Builder builder = new MatchV10Builder();
+                builder.setDlSrc(MAC_SRC).setDlDst(MAC_DST).setDlVlan(vid).
+                    setDlVlanPcp(VLAN_PCP).setDlType(ETHTYPE_IPV4).
+                    setInPort(IN_PORT.intValue()).
+                    setNwSrc(IPV4_SRC).setNwDst(IPV4_DST).setNwTos(tos);
+                wcBuilder.setAll(false).setNwProto(true).setTpSrc(true).
+                    setTpDst(true);
+                if (vid == DL_VLAN_NONE) {
+                    wcBuilder.setDlVlanPcp(true);
+                }
+
+                FlowWildcardsV10 wc = wcBuilder.build();
+                MatchV10 ofMatch = builder.setWildcards(wc).build();
+                Match match = MatchConvertorImpl.fromOFMatchV10ToSALMatch(
+                    ofMatch, DPID, OpenflowVersion.OF10);
+                checkDefaultV10(match, wc, vid);
+
+                IpMatch ipMatch = match.getIpMatch();
+                assertEquals(null, ipMatch.getIpProtocol());
+                assertEquals(dscp, ipMatch.getIpDscp().getValue().shortValue());
+                assertEquals(null, ipMatch.getIpEcn());
+
+                // Set all wildcard bits.
+                wc = wcBuilder.setAll(true).build();
+                ofMatch = builder.setWildcards(wc).build();
+                match = MatchConvertorImpl.fromOFMatchV10ToSALMatch(
+                    ofMatch, DPID, OpenflowVersion.OF10);
+                checkDefaultV10(match, wc, vid);
+                assertEquals(null, match.getIpMatch());
+            }
+        }
+    }
+
     private void checkDefault(MatchBuilder builder) {
         EthernetMatch ethMatch = builder.getEthernetMatch();
         assertEquals(MAC_SRC, ethMatch.getEthernetSource().getAddress());
@@ -194,4 +261,65 @@ public class MatchConvertorImplTest {
         maskBuilder.setMask(mask);
         builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
     }
+
+    private void checkDefaultV10(Match match, FlowWildcardsV10 wc, int vid) {
+        EthernetMatch ethMatch = match.getEthernetMatch();
+        if (wc.isDLSRC().booleanValue()) {
+            if (ethMatch != null) {
+                assertEquals(null, ethMatch.getEthernetSource());
+            }
+        } else {
+            assertEquals(MAC_SRC, ethMatch.getEthernetSource().getAddress());
+        }
+
+        if (wc.isDLDST().booleanValue()) {
+            if (ethMatch != null) {
+                assertEquals(null, ethMatch.getEthernetDestination());
+            }
+        } else {
+            assertEquals(MAC_DST,
+                         ethMatch.getEthernetDestination().getAddress());
+        }
+
+        if (wc.isDLTYPE().booleanValue()) {
+            if (ethMatch != null) {
+                assertEquals(null, ethMatch.getEthernetType());
+            }
+            assertEquals(null, match.getLayer3Match());
+        } else {
+            assertEquals(ETHTYPE_IPV4, ethMatch.getEthernetType().getType().
+                         getValue().intValue());
+
+            Ipv4Match ipv4Match = (Ipv4Match)match.getLayer3Match();
+            assertEquals(IPV4_SRC.getValue(),
+                         ipv4Match.getIpv4Source().getValue());
+            assertEquals(IPV4_DST.getValue(),
+                         ipv4Match.getIpv4Destination().getValue());
+        }
+
+        VlanMatch vlanMatch = match.getVlanMatch();
+        if (wc.isDLVLAN().booleanValue()) {
+            assertEquals(null, vlanMatch);
+        } else {
+            int expectedVid;
+            Boolean expectedCfi;
+            if (vid == DL_VLAN_NONE) {
+                expectedVid = 0;
+                expectedCfi = Boolean.FALSE;
+            } else {
+                expectedVid = vid;
+                expectedCfi = Boolean.TRUE;
+            }
+            assertEquals(expectedVid, vlanMatch.getVlanId().getVlanId().
+                         getValue().intValue());
+            assertEquals(expectedCfi, vlanMatch.getVlanId().isVlanIdPresent());
+
+            if (wc.isDLVLANPCP().booleanValue()) {
+                assertEquals(null, vlanMatch.getVlanPcp());
+            } else {
+                assertEquals(VLAN_PCP,
+                             vlanMatch.getVlanPcp().getValue().shortValue());
+            }
+        }
+    }
 }