From SAL conversion test. 52/1452/3
authorJozef Gloncak <jgloncak@cisco.com>
Fri, 27 Sep 2013 09:35:36 +0000 (11:35 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 30 Sep 2013 10:34:03 +0000 (10:34 +0000)
The test was added.

Change-Id: Ic1931aef40418b1b48849be4c6f6518548d9f8cf
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/FromSalConversionsUtils.java
opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ProtocolConstants.java [new file with mode: 0644]
opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ToSalConversionsUtils.java
opendaylight/md-sal/sal-compability/src/test/java/org/opendaylight/controller/sal/compability/TestFromSalConversionsUtils.java [new file with mode: 0644]
opendaylight/md-sal/sal-compability/src/test/java/org/opendaylight/controller/sal/compability/TestToSalConversionsUtils.java

index 1d4f42c7999ebb4269fa9a047f0261715f4aedb4..18c47246290b0207a56be128e0df02ebb87f780a 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.controller.sal.flowprogrammer.Flow;
 import org.opendaylight.controller.sal.match.Match;
 import org.opendaylight.controller.sal.match.MatchField;
 import org.opendaylight.controller.sal.match.MatchType;
+import org.opendaylight.controller.sal.utils.NetUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.*;
 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.service.rev130819.FlowAdded;
@@ -46,15 +47,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._4.match.UdpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.vlan.match.fields.VlanIdBuilder;
 
-public class FromSalConversionsUtils {
+import com.google.common.net.InetAddresses;
 
-    // source: http://en.wikipedia.org/wiki/Ethertype
-    private static final Short ETHERNET_ARP = new Short((short) 0x0806);
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.ETHERNET_ARP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.SCTP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.TCP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.UDP;
 
-    // source: http://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
-    private static final short TCP = (short) 0x06;
-    private static final short UDP = (short) 0x11;
-    private static final short SCTP = (short) 0x84;
+public class FromSalConversionsUtils {
 
     private FromSalConversionsUtils() {
 
@@ -122,13 +122,13 @@ public class FromSalConversionsUtils {
             SetDlDst setDlDst = (SetDlDst) sourceAction;
             SetDlDstActionBuilder setDlDstActionBuilder = new SetDlDstActionBuilder();
 
-            setDlDstActionBuilder.setAddress(new MacAddress(Arrays.toString(setDlDst.getDlAddress())));
+            setDlDstActionBuilder.setAddress(new MacAddress(new String(setDlDst.getDlAddress())));
             targetAction = setDlDstActionBuilder.build();
         } else if (sourceAction instanceof SetDlSrc) {
             SetDlSrc setDlSrc = (SetDlSrc) sourceAction;
             SetDlSrcActionBuilder setDlSrcActionBuilder = new SetDlSrcActionBuilder();
 
-            setDlSrcActionBuilder.setAddress(new MacAddress(Arrays.toString(setDlSrc.getDlAddress())));
+            setDlSrcActionBuilder.setAddress(new MacAddress(new String(setDlSrc.getDlAddress())));
             targetAction = setDlSrcActionBuilder.build();
         } else if (sourceAction instanceof SetDlType) {
             SetDlType setDlType = (SetDlType) sourceAction;
@@ -211,14 +211,14 @@ public class FromSalConversionsUtils {
     }
 
     private static Address addressFromAction(InetAddress inetAddress) {
-        byte[] byteInetAddresss = inetAddress.getAddress();
+        String strInetAddresss = InetAddresses.toAddrString(inetAddress);
         if (inetAddress instanceof Inet4Address) {
             Ipv4Builder ipv4Builder = new Ipv4Builder();
-            ipv4Builder.setIpv4Address(new Ipv4Prefix(Arrays.toString(byteInetAddresss)));
+            ipv4Builder.setIpv4Address(new Ipv4Prefix(strInetAddresss));
             return ipv4Builder.build();
         } else if (inetAddress instanceof Inet6Address) {
             Ipv6Builder ipv6Builder = new Ipv6Builder();
-            ipv6Builder.setIpv6Address(new Ipv6Prefix(Arrays.toString(byteInetAddresss)));
+            ipv6Builder.setIpv6Address(new Ipv6Prefix(strInetAddresss));
             return ipv6Builder.build();
         }
         return null;
@@ -250,16 +250,15 @@ public class FromSalConversionsUtils {
         MatchField nwProto = sourceMatch.getField(MatchType.NW_PROTO);
         Short nwProtocolSource = null;
         if (nwProto != null && nwProto.getValue() != null) {
-            nwProtocolSource = (Short) (nwProto.getValue());
-        }
-
-        switch (nwProtocolSource) {
-        case TCP:
-            return Layer4MatchAsTcp(sourceMatch);
-        case UDP:
-            return Layer4MatchAsUdp(sourceMatch);
-        case SCTP:
-            return Layer4MatchAsSctp(sourceMatch);
+            nwProtocolSource = (short) ((byte) nwProto.getValue());
+            switch (nwProtocolSource) {
+            case TCP:
+                return Layer4MatchAsTcp(sourceMatch);
+            case UDP:
+                return Layer4MatchAsUdp(sourceMatch);
+            case SCTP:
+                return Layer4MatchAsSctp(sourceMatch);
+            }
         }
         return null;
     }
@@ -315,8 +314,9 @@ public class FromSalConversionsUtils {
 
     private static Integer transportPortFrom(final Match sourceMatch, final MatchType matchType) {
         MatchField transportPort = sourceMatch.getField(matchType);
-        if (transportPort != null && transportPort.getValue() != null) {
-            return (Integer) (transportPort.getValue());
+        if (transportPort != null && transportPort.getValue() != null
+                && transportPort.getValue().getClass().equals(Short.class)) {
+            return new Integer(NetUtils.getUnsignedShort((short) transportPort.getValue()));
         }
         return null;
     }
@@ -327,13 +327,13 @@ public class FromSalConversionsUtils {
         MatchField vlan = sourceMatch.getField(MatchType.DL_VLAN);
         if (vlan != null && vlan.getValue() != null) {
             VlanIdBuilder vlanIDBuilder = new VlanIdBuilder();
-            vlanIDBuilder.setVlanId(new VlanId((Integer) (vlan.getValue())));
+            vlanIDBuilder.setVlanId(new VlanId((int) (NetUtils.getUnsignedShort((short) vlan.getValue()))));
             vlanMatchBuild.setVlanId(vlanIDBuilder.build());
         }
 
         MatchField vlanPriority = sourceMatch.getField(MatchType.DL_VLAN_PR);
         if (vlanPriority != null && vlanPriority.getValue() != null) {
-            vlanMatchBuild.setVlanPcp(new VlanPcp((Short) (vlanPriority.getValue())));
+            vlanMatchBuild.setVlanPcp(new VlanPcp((short) ((byte) vlanPriority.getValue())));
         }
 
         return vlanMatchBuild.build();
@@ -343,13 +343,13 @@ public class FromSalConversionsUtils {
         IpMatchBuilder targetIpMatchBuild = new IpMatchBuilder();
         MatchField networkTos = sourceMatch.getField(MatchType.NW_TOS);
         if (networkTos != null && networkTos.getValue() != null) {
-            Dscp dscp = new Dscp((Short) (networkTos.getValue()));
+            Dscp dscp = new Dscp((short) (NetUtils.getUnsignedByte((Byte) networkTos.getValue())));
             targetIpMatchBuild.setIpDscp(dscp);
         }
 
         MatchField protocol = sourceMatch.getField(MatchType.NW_PROTO);
         if (protocol != null && protocol.getValue() != null) {
-            targetIpMatchBuild.setIpProtocol((Short) (protocol.getValue()));
+            targetIpMatchBuild.setIpProtocol((short) ((byte) protocol.getValue()));
         }
 
         return targetIpMatchBuild.build();
@@ -369,7 +369,7 @@ public class FromSalConversionsUtils {
 
         final MatchField dataLinkType = sourceMatch.getField(MatchType.DL_TYPE);
         if (dataLinkType != null && dataLinkType.getValue() != null) {
-            EtherType etherType = new EtherType((Long) (dataLinkType.getValue()));
+            EtherType etherType = new EtherType(new Long(NetUtils.getUnsignedShort((Short) dataLinkType.getValue())));
             EthernetTypeBuilder ethType = new EthernetTypeBuilder().setType(etherType);
             targetEthMatchBuild.setEthernetType(ethType.build());
         }
@@ -379,7 +379,7 @@ public class FromSalConversionsUtils {
     private static MacAddress ethernetSourceAddressFrom(final Match sourceMatch) {
         final MatchField dataLinkSource = sourceMatch.getField(DL_SRC);
         if (dataLinkSource != null && dataLinkSource.getValue() != null) {
-            return new MacAddress(new MacAddress((String) (dataLinkSource.getValue())));
+            return new MacAddress(new MacAddress(new String((byte[]) dataLinkSource.getValue())));
         }
         return null;
 
@@ -404,7 +404,7 @@ public class FromSalConversionsUtils {
             if (dataLinkType != null && dataLinkType.getValue() != null) {
                 dLType = (Short) (dataLinkType.getValue());
             }
-            if (dLType.equals(ETHERNET_ARP)) {
+            if (dLType != null && dLType.equals(ETHERNET_ARP)) {
                 return setLayer3MatchAsArp(sourceMatch, (Inet4Address) inetSourceAddress,
                         (Inet4Address) inetDestAddress);
             } else {
@@ -420,16 +420,16 @@ public class FromSalConversionsUtils {
 
     private static Layer3Match setLayer3MatchAsArp(final Match sourceMatch, final Inet4Address inetSourceAddress,
             final Inet4Address inetDestAddress) {
-        byte[] inetSourceAddressValue = inetSourceAddress.getAddress();
-        Ipv4Prefix ipv4SourcePrefix = new Ipv4Prefix(Arrays.toString(inetSourceAddressValue));
+        String inetSourceAddressStr = InetAddresses.toAddrString(inetSourceAddress);
+        Ipv4Prefix ipv4SourcePrefix = new Ipv4Prefix(inetSourceAddressStr);
 
-        byte[] inetDestAddressValue = inetDestAddress.getAddress();
-        Ipv4Prefix ipv4DestPrefix = new Ipv4Prefix(Arrays.toString(inetDestAddressValue));
+        String inetDestAddressValue = InetAddresses.toAddrString(inetDestAddress);
+        Ipv4Prefix ipv4DestPrefix = new Ipv4Prefix(inetDestAddressValue);
 
         ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
 
         arpMatchBuilder.setArpSourceTransportAddress(ipv4SourcePrefix);
-        arpMatchBuilder.setArpSourceTransportAddress(ipv4DestPrefix);
+        arpMatchBuilder.setArpTargetTransportAddress(ipv4DestPrefix);
 
         ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
         arpSourceHardwareAddressBuilder.setAddress(ethernetSourceAddressFrom(sourceMatch));
@@ -446,27 +446,31 @@ public class FromSalConversionsUtils {
     private static MacAddress ethernetDestAddressFrom(final Match sourceMatch) {
         final MatchField dataLinkDest = sourceMatch.getField(DL_DST);
         if (dataLinkDest != null && dataLinkDest.getValue() != null) {
-            return new MacAddress((String) (dataLinkDest.getValue()));
+            return new MacAddress(new String((byte[]) (dataLinkDest.getValue())));
         }
         return null;
     }
 
     private static Layer3Match setLayer3MatchAsIpv4(final Inet4Address inetSourceAddress,
             final Inet4Address inetDestAddress) {
-        byte[] inetAddressValue = inetSourceAddress.getAddress();
+        String inetSrcAddressString = InetAddresses.toAddrString(inetSourceAddress);
+        String inetDstAddressString = InetAddresses.toAddrString(inetDestAddress);
 
         Ipv4MatchBuilder layer4MatchBuild = new Ipv4MatchBuilder();
-        layer4MatchBuild.setIpv4Source(new Ipv4Prefix(Arrays.toString(inetAddressValue)));
+        layer4MatchBuild.setIpv4Source(new Ipv4Prefix(inetSrcAddressString));
+        layer4MatchBuild.setIpv4Destination(new Ipv4Prefix(inetDstAddressString));
         return layer4MatchBuild.build();
 
     }
 
     private static Layer3Match setLayer3MatchAsIpv6(final Inet6Address inetSourceAddress,
             final Inet6Address inetDestAddress) {
-        byte[] inetAddressValue = inetSourceAddress.getAddress();
+        String inetSrcAddressString = InetAddresses.toAddrString(inetSourceAddress);
+        String inetDstAddressString = InetAddresses.toAddrString(inetDestAddress);
         Ipv6MatchBuilder layer6MatchBuild = new Ipv6MatchBuilder();
 
-        layer6MatchBuild.setIpv6Source(new Ipv6Prefix(Arrays.toString(inetAddressValue)));
+        layer6MatchBuild.setIpv6Source(new Ipv6Prefix(inetSrcAddressString));
+        layer6MatchBuild.setIpv6Destination(new Ipv6Prefix(inetDstAddressString));
         return layer6MatchBuild.build();
     }
 
diff --git a/opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ProtocolConstants.java b/opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ProtocolConstants.java
new file mode 100644 (file)
index 0000000..1828dac
--- /dev/null
@@ -0,0 +1,15 @@
+package org.opendaylight.controller.sal.compability;
+
+public class ProtocolConstants {
+    // source: http://en.wikipedia.org/wiki/Ethertype
+    public static final short ETHERNET_ARP = (short) 0x0806;
+
+    // source: http://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
+    public static final byte TCP = (byte) 0x06;
+    public static final byte UDP = (byte) 0x11;
+    public static final byte SCTP = (byte) 0x84;
+
+    private ProtocolConstants() {
+
+    }
+}
index 793ac4988842e817292418db3b1d3a6237e5520a..0534a5ccaeeefbda058fc3358d3a53c7bc7201b4 100644 (file)
@@ -1,5 +1,9 @@
 package org.opendaylight.controller.sal.compability;
 
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.ETHERNET_ARP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.SCTP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.TCP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.UDP;
 import static org.opendaylight.controller.sal.match.MatchType.DL_DST;
 import static org.opendaylight.controller.sal.match.MatchType.DL_SRC;
 import static org.opendaylight.controller.sal.match.MatchType.DL_TYPE;
@@ -14,9 +18,7 @@ import static org.opendaylight.controller.sal.match.MatchType.TP_SRC;
 
 import java.net.InetAddress;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 import org.opendaylight.controller.sal.action.*;
 import org.opendaylight.controller.sal.core.NodeConnector;
@@ -34,6 +36,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.A
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.MacAddressFilter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.arp.match.fields.ArpSourceHardwareAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.arp.match.fields.ArpTargetHardwareAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.ethernet.match.fields.EthernetType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.*;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._3.match.ArpMatch;
@@ -311,7 +315,8 @@ public class ToSalConversionsUtils {
     private static void fillFrom(Match target, IpMatch ipMatch) {
         if (ipMatch != null) {
             Short ipProtocol = ipMatch.getIpProtocol();
-            if (ipProtocol != null) {
+
+            if (ipProtocol != null && target.getField(NW_PROTO) == null) {
                 target.setField(NW_PROTO, ipProtocol.byteValue());
             }
             Dscp dscp = ipMatch.getIpDscp();
@@ -353,6 +358,8 @@ public class ToSalConversionsUtils {
                 target.setField(TP_DST, udpDestPortValue.shortValue());
             }
         }
+
+        target.setField(NW_PROTO, UDP);
     }
 
     private static void fillTransportLayer(Match target, TcpMatch source) {
@@ -371,6 +378,8 @@ public class ToSalConversionsUtils {
                 target.setField(TP_DST, tcpDestPortValue.shortValue());
             }
         }
+
+        target.setField(NW_PROTO, TCP);
     }
 
     private static void fillTransportLayer(Match target, SctpMatch source) {
@@ -388,6 +397,9 @@ public class ToSalConversionsUtils {
                 target.setField(TP_DST, sctpDestPortValue.shortValue());
             }
         }
+
+        target.setField(NW_PROTO, SCTP);
+
     }
 
     private static void fillFrom(Match target, Layer3Match source) {
@@ -407,10 +419,21 @@ public class ToSalConversionsUtils {
         if (sourceAddress != null) {
             target.setField(NW_SRC, (InetAddress) inetAddressFrom(sourceAddress), null);
         }
-        Ipv4Prefix destAddress = source.getArpSourceTransportAddress();
+        Ipv4Prefix destAddress = source.getArpTargetTransportAddress();
         if (destAddress != null) {
             target.setField(NW_DST, (InetAddress) inetAddressFrom(destAddress), null);
         }
+        ArpSourceHardwareAddress sourceHwAddress = source.getArpSourceHardwareAddress();
+        if (sourceHwAddress != null) {
+            target.setField(DL_SRC, sourceHwAddress.getAddress().getValue().getBytes());
+        }
+        ArpTargetHardwareAddress targetHwAddress = source.getArpTargetHardwareAddress();
+        if (targetHwAddress != null) {
+            target.setField(DL_DST, targetHwAddress.getAddress().getValue().getBytes());
+        }
+
+        target.setField(DL_TYPE, new Short(ETHERNET_ARP));
+
     }
 
     private static void fillFromIpv6(Match target, Ipv6Match source) {
@@ -418,7 +441,7 @@ public class ToSalConversionsUtils {
         if (sourceAddress != null) {
             target.setField(NW_SRC, (InetAddress) inetAddressFrom(sourceAddress), null);
         }
-        Ipv6Prefix destAddress = source.getIpv6Source();
+        Ipv6Prefix destAddress = source.getIpv6Destination();
         if (destAddress != null) {
             target.setField(NW_DST, (InetAddress) inetAddressFrom(destAddress), null);
         }
@@ -429,7 +452,7 @@ public class ToSalConversionsUtils {
         if (sourceAddress != null) {
             target.setField(NW_SRC, (InetAddress) inetAddressFrom(sourceAddress), null);
         }
-        Ipv4Prefix destAddress = source.getIpv4Source();
+        Ipv4Prefix destAddress = source.getIpv4Destination();
         if (destAddress != null) {
             target.setField(NW_DST, (InetAddress) inetAddressFrom(destAddress), null);
         }
@@ -457,7 +480,7 @@ public class ToSalConversionsUtils {
         EthernetType ethType = source.getEthernetType();
         if (ethType != null) {
             EtherType ethInnerType = ethType.getType();
-            if (ethInnerType != null) {
+            if (ethInnerType != null && target.getField(DL_TYPE) == null) {
                 Long value = ethInnerType.getValue();
                 target.setField(DL_TYPE, value.shortValue());
             }
diff --git a/opendaylight/md-sal/sal-compability/src/test/java/org/opendaylight/controller/sal/compability/TestFromSalConversionsUtils.java b/opendaylight/md-sal/sal-compability/src/test/java/org/opendaylight/controller/sal/compability/TestFromSalConversionsUtils.java
new file mode 100644 (file)
index 0000000..aa3950d
--- /dev/null
@@ -0,0 +1,368 @@
+package org.opendaylight.controller.sal.compability;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.ETHERNET_ARP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.SCTP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.TCP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.UDP;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.controller.sal.action.*;
+import org.opendaylight.controller.sal.flowprogrammer.Flow;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.action.action.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.address.Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.address.address.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.Layer3Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.Layer4Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._3.match.ArpMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._3.match.Ipv4Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._3.match.Ipv6Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._4.match.SctpMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._4.match.TcpMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._4.match.UdpMatch;
+
+import com.google.common.net.InetAddresses;
+
+public class TestFromSalConversionsUtils {
+    private enum MtchType {
+        other, ipv4, ipv6, arp, sctp, tcp, udp
+    }
+
+    @Test
+    public void testFromSalConversion() {
+
+        Flow salFlow = prepareSalFlowCommon();
+        NodeFlow odNodeFlow = FromSalConversionsUtils.flowFrom(salFlow);
+
+        checkOdFlow(odNodeFlow);
+
+        odNodeFlow = FromSalConversionsUtils.flowFrom(prepareSalMatch(salFlow, MtchType.other));
+        checkOdMatch(odNodeFlow.getMatch(), MtchType.other);
+
+        odNodeFlow = FromSalConversionsUtils.flowFrom(prepareSalMatch(salFlow, MtchType.arp));
+        checkOdMatch(odNodeFlow.getMatch(), MtchType.arp);
+
+        odNodeFlow = FromSalConversionsUtils.flowFrom(prepareSalMatch(salFlow, MtchType.ipv4));
+        checkOdMatch(odNodeFlow.getMatch(), MtchType.ipv4);
+
+        odNodeFlow = FromSalConversionsUtils.flowFrom(prepareSalMatch(salFlow, MtchType.ipv6));
+        checkOdMatch(odNodeFlow.getMatch(), MtchType.ipv6);
+
+        odNodeFlow = FromSalConversionsUtils.flowFrom(prepareSalMatch(salFlow, MtchType.sctp));
+        checkOdMatch(odNodeFlow.getMatch(), MtchType.sctp);
+
+        odNodeFlow = FromSalConversionsUtils.flowFrom(prepareSalMatch(salFlow, MtchType.tcp));
+        checkOdMatch(odNodeFlow.getMatch(), MtchType.tcp);
+
+        odNodeFlow = FromSalConversionsUtils.flowFrom(prepareSalMatch(salFlow, MtchType.udp));
+        checkOdMatch(odNodeFlow.getMatch(), MtchType.udp);
+    }
+
+    private void checkOdMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.Match match,
+            MtchType mt) {
+        switch (mt) {
+        case arp:
+            assertEquals("Ether type is incorrect.", ETHERNET_ARP, (long) match.getEthernetMatch().getEthernetType()
+                    .getType().getValue());
+            Layer3Match layer3Match = match.getLayer3Match();
+            boolean arpFound = false;
+            if (layer3Match instanceof ArpMatch) {
+                assertEquals("Source IP address is wrong.", "192.168.100.100", ((ArpMatch) layer3Match)
+                        .getArpSourceTransportAddress().getValue());
+                assertEquals("Destination IP address is wrong.", "192.168.100.101", ((ArpMatch) layer3Match)
+                        .getArpTargetTransportAddress().getValue());
+                assertEquals("Source MAC address is wrong.", "aa:bb:cc:dd:ee:ff", ((ArpMatch) layer3Match)
+                        .getArpSourceHardwareAddress().getAddress().getValue());
+                assertEquals("Destination MAC address is wrong.", "ff:ee:dd:cc:bb:aa", ((ArpMatch) layer3Match)
+                        .getArpTargetHardwareAddress().getAddress().getValue());
+                arpFound = true;
+            }
+            assertNotNull("Arp wasn't found", arpFound);
+            break;
+        case ipv4:
+            assertEquals("Ether type is incorrect.", 0xffff, (long) match.getEthernetMatch().getEthernetType()
+                    .getType().getValue());
+            boolean ipv4Found = false;
+            layer3Match = match.getLayer3Match();
+            if (layer3Match instanceof Ipv4Match) {
+                assertEquals("Source IP address is wrong.", "192.168.100.102", ((Ipv4Match) layer3Match)
+                        .getIpv4Source().getValue());
+                assertEquals("Destination IP address is wrong.", "192.168.100.103", ((Ipv4Match) layer3Match)
+                        .getIpv4Destination().getValue());
+            }
+            assertNotNull("Ipv4 wasn't found", ipv4Found);
+            break;
+        case ipv6:
+            assertEquals("Ether type is incorrect.", 0xffff, (long) match.getEthernetMatch().getEthernetType()
+                    .getType().getValue());
+            boolean ipv6Found = false;
+            layer3Match = match.getLayer3Match();
+            if (layer3Match instanceof Ipv6Match) {
+                assertEquals("Source IP address is wrong.", "2001:db8:85a3::8a2e:370:7335", ((Ipv6Match) layer3Match)
+                        .getIpv6Source().getValue());
+                assertEquals("Destination IP address is wrong.", "2001:db8:85a3::8a2e:370:7336",
+                        ((Ipv6Match) layer3Match).getIpv6Destination().getValue());
+            }
+            assertNotNull("Ipv6 wasn't found", ipv6Found);
+            break;
+        case other:
+            assertEquals("Source MAC address is wrong.", "24:77:03:7C:C5:F1", match.getEthernetMatch()
+                    .getEthernetSource().getAddress().getValue());
+            assertEquals("Destinatio MAC address is wrong.", "3C:A9:F4:00:E0:C8", match.getEthernetMatch()
+                    .getEthernetDestination().getAddress().getValue());
+            assertEquals("Vlan ID is wrong.", (Integer) 0xfff, match.getVlanMatch().getVlanId().getVlanId().getValue());
+            assertEquals("Vlan ID priority is wrong.", (short) 0x7, (short) match.getVlanMatch().getVlanPcp()
+                    .getValue());
+            assertEquals("DCSP is wrong.", (short) 0x3f, (short) match.getIpMatch().getIpDscp().getValue());
+            break;
+        case sctp:
+            boolean sctpFound = false;
+            assertEquals("Wrong protocol", SCTP, match.getIpMatch().getIpProtocol().byteValue());
+            Layer4Match layer4Match = match.getLayer4Match();
+            if (layer4Match instanceof SctpMatch) {
+                assertEquals("Sctp source port is incorrect.", 0xffff, (int) ((SctpMatch) layer4Match)
+                        .getSctpSourcePort().getValue());
+                assertEquals("Sctp dest port is incorrect.", (int) 0xfffe, (int) ((SctpMatch) layer4Match)
+                        .getSctpDestinationPort().getValue());
+                sctpFound = true;
+            }
+            assertNotNull("Sctp wasn't found", sctpFound);
+            break;
+        case tcp:
+            boolean tcpFound = false;
+            assertEquals("Wrong protocol", TCP, match.getIpMatch().getIpProtocol().byteValue());
+            layer4Match = match.getLayer4Match();
+            if (layer4Match instanceof TcpMatch) {
+                assertEquals("Tcp source port is incorrect.", (int) 0xabcd, (int) ((TcpMatch) layer4Match)
+                        .getTcpSourcePort().getValue());
+                assertEquals("Tcp dest port is incorrect.", (int) 0xdcba, (int) ((TcpMatch) layer4Match)
+                        .getTcpDestinationPort().getValue());
+                sctpFound = true;
+            }
+            assertNotNull("Tcp wasn't found", tcpFound);
+            break;
+        case udp:
+            boolean udpFound = false;
+            assertEquals("Wrong protocol", UDP, match.getIpMatch().getIpProtocol().byteValue());
+            layer4Match = match.getLayer4Match();
+            if (layer4Match instanceof UdpMatch) {
+                assertEquals("Udp source port is incorrect.", (int) 0xcdef, (int) ((UdpMatch) layer4Match)
+                        .getUdpSourcePort().getValue());
+                assertEquals("Udp dest port is incorrect.", (int) 0xfedc, (int) ((UdpMatch) layer4Match)
+                        .getUdpDestinationPort().getValue());
+                sctpFound = true;
+            }
+            assertNotNull("Udp wasn't found", udpFound);
+            break;
+        }
+
+    }
+
+    private void checkOdFlow(NodeFlow odNodeFlow) {
+        assertEquals("Cookie is incorrect.", 9223372036854775807L, odNodeFlow.getCookie().longValue());
+        assertEquals("Hard timeout is incorrect.", 32765, odNodeFlow.getHardTimeout().shortValue());
+        assertEquals("Iddle timeout is incorrect.", 32766, odNodeFlow.getIdleTimeout().shortValue());
+        assertEquals("Priority is incorrect.", 32767, odNodeFlow.getPriority().shortValue());
+
+        checkOdActions(odNodeFlow.getAction());
+    }
+
+    private void checkOdActions(
+            List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.Action> actions) {
+        checkOdAction(actions, FloodAction.class, false);
+        checkOdAction(actions, FloodAllAction.class, false);
+        checkOdAction(actions, HwPathAction.class, false);
+        checkOdAction(actions, LoopbackAction.class, false);
+        checkOdAction(actions, PopVlanAction.class, false);
+        checkOdAction(actions, PushVlanAction.class, true);
+        checkOdAction(actions, SetDlDstAction.class, true);
+        checkOdAction(actions, SetDlSrcAction.class, true);
+        checkOdAction(actions, SetDlTypeAction.class, true);
+        checkOdAction(actions, SetNwTosAction.class, true);
+        checkOdAction(actions, SetNwDstAction.class, true);
+        checkOdAction(actions, SetNwSrcAction.class, true);
+        checkOdAction(actions, SetNextHopAction.class, true);
+        checkOdAction(actions, SetTpDstAction.class, true);
+        checkOdAction(actions, SetTpSrcAction.class, true);
+        checkOdAction(actions, SetVlanCfiAction.class, true);
+        checkOdAction(actions, SetVlanIdAction.class, true);
+        checkOdAction(actions, SetVlanPcpAction.class, true);
+        checkOdAction(actions, SwPathAction.class, false);
+    }
+
+    private void checkOdAction(
+            List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.Action> actions, Class<?> cl,
+            boolean b) {
+        int numOfFoundActions = 0;
+        for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.Action action : actions) {
+            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.action.Action innerAction = action
+                    .getAction();
+            if (cl.isInstance(innerAction)) {
+                numOfFoundActions++;
+                if (innerAction instanceof PushVlanAction) {
+                    assertEquals("Wrong value of cfi in PushVlanAction.", (Integer) 1, ((PushVlanAction) innerAction)
+                            .getCfi().getValue());
+                    assertEquals("Wrong value of pcp in PushVlanAction.", (Integer) 7,
+                            ((PushVlanAction) innerAction).getPcp());
+                    assertEquals("Wrong value of tag in PushVlanAction.", (Integer) 0x8100,
+                            ((PushVlanAction) innerAction).getTag());
+                    assertEquals("Wrong value of vlad ID in PushVlanAction.", (Integer) 4095,
+                            ((PushVlanAction) innerAction).getVlanId().getValue());
+                } else if (innerAction instanceof SetDlDstAction) {
+                    assertEquals("Wrong MAC destination address in SetDlDstAction.", "3C:A9:F4:00:E0:C8", new String(
+                            ((SetDlDstAction) innerAction).getAddress().getValue()));
+                } else if (innerAction instanceof SetDlSrcAction) {
+                    assertEquals("Wrong MAC source address in SetDlDstAction.", "24:77:03:7C:C5:F1", new String(
+                            ((SetDlSrcAction) innerAction).getAddress().getValue()));
+                } else if (innerAction instanceof SetDlTypeAction) {
+                    assertEquals("Wrong data link type in SetDlTypeAction.", (long) 513,
+                            (long) ((SetDlTypeAction) innerAction).getDlType().getValue());
+                } else if (innerAction instanceof SetNextHopAction) {
+                    Address address = ((SetNextHopAction) innerAction).getAddress();
+                    boolean ipv4AddressFound = false;
+                    if (address instanceof Ipv4) {
+                        ipv4AddressFound = true;
+                        assertEquals("Wrong IP address type in SetNextHopAction.", "192.168.100.100", ((Ipv4) address)
+                                .getIpv4Address().getValue());
+                    }
+                    assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
+                } else if (innerAction instanceof SetNwTosAction) {
+                    assertEquals("Wrong TOS in SetNwTosAction.", (Integer) 63, ((SetNwTosAction) innerAction).getTos());
+                } else if (innerAction instanceof SetNwDstAction) {
+                    Address address = ((SetNwDstAction) innerAction).getAddress();
+                    boolean ipv4AddressFound = false;
+                    if (address instanceof Ipv4) {
+                        ipv4AddressFound = true;
+                        assertEquals("Wrong IP address type in SetNwDstAction.", "192.168.100.101", ((Ipv4) address)
+                                .getIpv4Address().getValue());
+                    }
+                    assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
+                } else if (innerAction instanceof SetNwSrcAction) {
+                    Address address = ((SetNwSrcAction) innerAction).getAddress();
+                    boolean ipv4AddressFound = false;
+                    if (address instanceof Ipv4) {
+                        ipv4AddressFound = true;
+                        assertEquals("Wrong IP address type in SetNwSrcAction.", "192.168.100.102", ((Ipv4) address)
+                                .getIpv4Address().getValue());
+                    }
+                    assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
+                } else if (innerAction instanceof SetTpDstAction) {
+                    assertEquals("Port number is incorrect in SetTpDstAction.", (Integer) 65534,
+                            ((SetTpDstAction) innerAction).getPort().getValue());
+                } else if (innerAction instanceof SetTpSrcAction) {
+                    assertEquals("Port number is incorrect in SetTpSrcAction.", (Integer) 65535,
+                            ((SetTpSrcAction) innerAction).getPort().getValue());
+                } else if (innerAction instanceof SetVlanCfiAction) {
+                    assertEquals("Vlan cfi number is incorrect in SetVlanCfiAction.", (Integer) 1,
+                            ((SetVlanCfiAction) innerAction).getVlanCfi().getValue());
+                } else if (innerAction instanceof SetVlanIdAction) {
+                    assertEquals("Vlan id number is incorrect in SetVlanIdAction.", (Integer) 4095,
+                            ((SetVlanIdAction) innerAction).getVlanId().getValue());
+                } else if (innerAction instanceof SetVlanPcpAction) {
+                    assertEquals("Vlan pcp number is incorrect in SetVlanPcpAction.", new Short((short) 7),
+                            ((SetVlanPcpAction) innerAction).getVlanPcp().getValue());
+                }
+            }
+        }
+        assertEquals("Incorrrect number of action " + cl.getName() + ".", 1, numOfFoundActions);
+
+    }
+
+    private Flow prepareSalFlowCommon() {
+        Flow salFlow = new Flow();
+        salFlow.setId(9223372036854775807L);
+        salFlow.setHardTimeout((short) 32765);
+        salFlow.setIdleTimeout((short) 32766);
+        salFlow.setPriority((short) 32767);
+        salFlow.setActions(prepareSalActions());
+        salFlow.setMatch(new Match());
+
+        return salFlow;
+    }
+
+    private Flow prepareSalMatch(Flow salFlow, MtchType mt) {
+        Match salMatch = new Match();
+        switch (mt) {
+        case arp:
+            salMatch.setField(MatchType.DL_TYPE, ETHERNET_ARP);
+            salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("192.168.100.100"));
+            salMatch.setField(MatchType.NW_DST, InetAddresses.forString("192.168.100.101"));
+            salMatch.setField(MatchType.DL_SRC, "aa:bb:cc:dd:ee:ff".getBytes());
+            salMatch.setField(MatchType.DL_DST, "ff:ee:dd:cc:bb:aa".getBytes());
+            break;
+        case ipv4:
+            salMatch.setField(MatchType.DL_TYPE, (short) 0xffff);
+            salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("192.168.100.102"));
+            salMatch.setField(MatchType.NW_DST, InetAddresses.forString("192.168.100.103"));
+            break;
+        case ipv6:
+            salMatch.setField(MatchType.DL_TYPE, (short) 0xffff);
+            salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("2001:0db8:85a3:0000:0000:8a2e:0370:7335"));
+            salMatch.setField(MatchType.NW_DST, InetAddresses.forString("2001:0db8:85a3:0000:0000:8a2e:0370:7336"));
+            break;
+        case other:
+            salMatch.setField(MatchType.DL_SRC, "24:77:03:7C:C5:F1".getBytes());
+            salMatch.setField(MatchType.DL_DST, "3C:A9:F4:00:E0:C8".getBytes());
+            salMatch.setField(MatchType.DL_VLAN, (short) 0xfff);
+            salMatch.setField(MatchType.DL_VLAN_PR, (byte) 0x7);
+            salMatch.setField(MatchType.NW_TOS, (byte) 0x3f);
+            break;
+        case sctp:
+            salMatch.setField(MatchType.NW_PROTO, SCTP);
+            salMatch.setField(MatchType.TP_SRC, (short) 0xffff);
+            salMatch.setField(MatchType.TP_DST, (short) 0xfffe);
+            break;
+        case tcp:
+            salMatch.setField(MatchType.NW_PROTO, TCP);
+            salMatch.setField(MatchType.TP_SRC, (short) 0xabcd);
+            salMatch.setField(MatchType.TP_DST, (short) 0xdcba);
+            break;
+        case udp:
+            salMatch.setField(MatchType.NW_PROTO, UDP);
+            salMatch.setField(MatchType.TP_SRC, (short) 0xcdef);
+            salMatch.setField(MatchType.TP_DST, (short) 0xfedc);
+            break;
+        default:
+            break;
+
+        }
+
+        salFlow.setMatch(salMatch);
+        return salFlow;
+    }
+
+    private List<Action> prepareSalActions() {
+        List<Action> salActions = new ArrayList<>();
+        salActions.add(new Flood());
+        salActions.add(new FloodAll());
+        salActions.add(new HwPath());
+        salActions.add(new Loopback());
+        // salActions.add(new Output //TODO: mapping is missing
+        salActions.add(new PopVlan());
+        salActions.add(new PushVlan(0x8100, 7, 1, 4095));
+        salActions.add(new SetDlDst("3C:A9:F4:00:E0:C8".getBytes()));
+        salActions.add(new SetDlSrc("24:77:03:7C:C5:F1".getBytes()));
+        salActions.add(new SetDlType(513));
+        salActions.add(new SetNextHop(InetAddresses.forString("192.168.100.100")));
+        salActions.add(new SetNwDst(InetAddresses.forString("192.168.100.101")));
+        salActions.add(new SetNwSrc(InetAddresses.forString("192.168.100.102")));
+        salActions.add(new SetNwTos(63));
+        salActions.add(new SetTpDst(65534));
+        salActions.add(new SetTpSrc(65535));
+        salActions.add(new SetVlanCfi(1));
+        salActions.add(new SetVlanId(4095));
+        salActions.add(new SetVlanPcp(7));
+        salActions.add(new SwPath());
+
+        return salActions;
+    }
+
+}
index 33af3a123641cb4afd78a01a7ec6fc9178c54306..fc9a8b48c558e78c5851633b88287d3ed5757712 100644 (file)
@@ -13,10 +13,8 @@ import java.util.List;
 import org.junit.Test;
 import org.opendaylight.controller.sal.action.*;
 import org.opendaylight.controller.sal.flowprogrammer.Flow;
-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.Ipv6Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.controller.sal.match.MatchType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.*;
 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.service.rev130819.FlowAddedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeFlow;
@@ -32,20 +30,118 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.M
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.EthernetMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.arp.match.fields.ArpSourceHardwareAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.arp.match.fields.ArpTargetHardwareAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.ethernet.match.fields.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._3.match.ArpMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._3.match.Ipv4MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._3.match.Ipv6MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._4.match.SctpMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._4.match.TcpMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._4.match.UdpMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.vlan.match.fields.VlanIdBuilder;
 
 import com.google.common.net.InetAddresses;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.ETHERNET_ARP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.SCTP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.TCP;
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.UDP;
 
 public class TestToSalConversionsUtils {
     // prefix:
     // od|Od = Open Daylight
+    private enum MtchType {
+        other, ipv4, ipv6, arp, sctp, tcp, udp
+    }
 
     @Test
     public void testToSalConversion() {
-        Flow salFlow = ToSalConversionsUtils.flowFrom(prepareOdFlow());
+        FlowAddedBuilder odNodeFlowBuilder = new FlowAddedBuilder();
+        odNodeFlowBuilder = prepareOdFlowCommon();
+
+        Flow salFlow = ToSalConversionsUtils.flowFrom(prepareOdFlow(odNodeFlowBuilder, MtchType.other));
+        checkSalMatch(salFlow.getMatch(), MtchType.other);
+
+        salFlow = ToSalConversionsUtils.flowFrom(prepareOdFlow(odNodeFlowBuilder, MtchType.ipv4));
+        checkSalMatch(salFlow.getMatch(), MtchType.ipv4);
+
+        salFlow = ToSalConversionsUtils.flowFrom(prepareOdFlow(odNodeFlowBuilder, MtchType.ipv6));
+        checkSalMatch(salFlow.getMatch(), MtchType.ipv6);
+
+        salFlow = ToSalConversionsUtils.flowFrom(prepareOdFlow(odNodeFlowBuilder, MtchType.arp));
+        checkSalMatch(salFlow.getMatch(), MtchType.arp);
+
+        salFlow = ToSalConversionsUtils.flowFrom(prepareOdFlow(odNodeFlowBuilder, MtchType.sctp));
+        checkSalMatch(salFlow.getMatch(), MtchType.sctp);
+
+        salFlow = ToSalConversionsUtils.flowFrom(prepareOdFlow(odNodeFlowBuilder, MtchType.tcp));
+        checkSalMatch(salFlow.getMatch(), MtchType.tcp);
+
+        salFlow = ToSalConversionsUtils.flowFrom(prepareOdFlow(odNodeFlowBuilder, MtchType.udp));
+        checkSalMatch(salFlow.getMatch(), MtchType.udp);
+
         checkSalFlow(salFlow);
     }
 
+    private void checkSalMatch(org.opendaylight.controller.sal.match.Match match, MtchType mt) {
+        switch (mt) {
+        case other:
+            assertEquals("DL_DST isn't equal.", "3C:A9:F4:00:E0:C8",
+                    new String((byte[]) match.getField(MatchType.DL_DST).getValue()));
+            assertEquals("DL_SRC isn't equal.", "24:77:03:7C:C5:F1",
+                    new String((byte[]) match.getField(MatchType.DL_SRC).getValue()));
+            assertEquals("DL_TYPE isn't equal.", (short) 0xffff, (short) match.getField(MatchType.DL_TYPE).getValue());
+            assertEquals("NW_TOS isn't equal.", (byte) 0x33, (byte) match.getField(MatchType.NW_TOS).getValue());
+            assertEquals("NW_PROTO isn't equal.", (byte) 0x3f, (byte) match.getField(MatchType.NW_PROTO).getValue());
+            assertEquals("DL_VLAN isn't equal.", (short) 0xfff, (short) match.getField(MatchType.DL_VLAN).getValue());
+            assertEquals("DL_VLAN_PR isn't equal.", (byte) 0x7, (byte) match.getField(MatchType.DL_VLAN_PR).getValue());
+            break;
+        case arp:
+            assertEquals("DL_SRC isn't equal.", "22:44:66:88:AA:CC",
+                    new String((byte[]) match.getField(MatchType.DL_SRC).getValue()));
+            assertEquals("DL_DST isn't equal.", "11:33:55:77:BB:DD",
+                    new String((byte[]) match.getField(MatchType.DL_DST).getValue()));
+            assertEquals("NW_SRC isn't equal.", "192.168.1.101",
+                    InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_SRC).getValue()));
+            assertEquals("NW_DST isn't equal.", "192.168.1.102",
+                    InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_DST).getValue()));
+            assertEquals("DL_TYPE isn't equal.", ETHERNET_ARP, match.getField(MatchType.DL_TYPE).getValue());
+            break;
+        case ipv4:
+            assertEquals("NW_SRC isn't equal.", "192.168.1.104",
+                    InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_SRC).getValue()));
+            assertEquals("NW_DST isn't equal.", "192.168.1.105",
+                    InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_DST).getValue()));
+            break;
+        case ipv6:
+            assertEquals("NW_SRC isn't equal.", "3001:db8:85a3::8a2e:370:7334",
+                    InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_SRC).getValue()));
+            assertEquals("NW_DST isn't equal.", "3001:db8:85a3::8a2e:370:7335",
+                    InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_DST).getValue()));
+            break;
+        case sctp:
+            assertEquals("TP_SRC isn't equal.", 31, (short) match.getField(MatchType.TP_SRC).getValue());
+            assertEquals("TP_DST isn't equal.", 32, (short) match.getField(MatchType.TP_DST).getValue());
+            assertEquals("NW_PROTO isn't equal.", SCTP, (byte) match.getField(MatchType.NW_PROTO).getValue());
+            break;
+        case tcp:
+            assertEquals("TP_SRC isn't equal.", 21, (short) match.getField(MatchType.TP_SRC).getValue());
+            assertEquals("TP_DST isn't equal.", 22, (short) match.getField(MatchType.TP_DST).getValue());
+            assertEquals("NW_PROTO isn't equal.", TCP, (byte) match.getField(MatchType.NW_PROTO).getValue());
+            break;
+        case udp:
+            assertEquals("TP_SRC isn't equal.", 11, (short) match.getField(MatchType.TP_SRC).getValue());
+            assertEquals("TP_DST isn't equal.", 12, (short) match.getField(MatchType.TP_DST).getValue());
+            assertEquals("NW_PROTO isn't equal.", UDP, (byte) match.getField(MatchType.NW_PROTO).getValue());
+            break;
+        default:
+            break;
+
+        }
+
+    }
+
     private void checkSalFlow(Flow salFlow) {
         assertTrue("Id value is incorrect.", salFlow.getId() == 9223372036854775807L);
         assertTrue("Hard timeout is incorrect.", salFlow.getHardTimeout() == 32767);
@@ -148,15 +244,19 @@ public class TestToSalConversionsUtils {
         }
     }
 
-    private NodeFlow prepareOdFlow() {
+    private FlowAddedBuilder prepareOdFlowCommon() {
         FlowAddedBuilder odNodeFlowBuilder = new FlowAddedBuilder();
+
         odNodeFlowBuilder.setCookie(new BigInteger("9223372036854775807"));
         odNodeFlowBuilder.setHardTimeout(32767);
         odNodeFlowBuilder.setIdleTimeout(32767);
         odNodeFlowBuilder.setPriority(32767);
         odNodeFlowBuilder.setAction(prepareOdActions());
-        odNodeFlowBuilder.setMatch(prepareOdMatch());
+        return odNodeFlowBuilder;
+    }
 
+    private NodeFlow prepareOdFlow(FlowAddedBuilder odNodeFlowBuilder, MtchType mt) {
+        odNodeFlowBuilder.setMatch(prepOdMatch(mt));
         return odNodeFlowBuilder.build();
     }
 
@@ -331,11 +431,133 @@ public class TestToSalConversionsUtils {
         outputActionBuilder.setOutputNodeConnector(uris);
     }
 
-    private Match prepareOdMatch() {
+    private Match prepOdMatch(MtchType mt) {
         MatchBuilder odMatchBuilder = new MatchBuilder();
+        switch (mt) {
+        case other:
+            odMatchBuilder.setEthernetMatch(prepEthernetMatch());
+            odMatchBuilder.setIpMatch(prepIpMatch());
+            odMatchBuilder.setVlanMatch(prepVlanMatch());
+            break;
+        case ipv4:
+            odMatchBuilder.setLayer3Match(prepLayer3MatchIpv4());
+            break;
+        case ipv6:
+            odMatchBuilder.setLayer3Match(prepLayer3MatchIpv6());
+            break;
+        case arp:
+            odMatchBuilder.setLayer3Match(prepLayer3MatchArp());
+            break;
+        case sctp:
+            odMatchBuilder.setLayer4Match(prepLayer4MatchSctp());
+            break;
+        case tcp:
+            odMatchBuilder.setLayer4Match(prepLayer4MatchTcp());
+            break;
+        case udp:
+            odMatchBuilder.setLayer4Match(prepLayer4MatchUdp());
+            break;
+        }
+        return odMatchBuilder.build();
+    }
+
+    private Layer4Match prepLayer4MatchUdp() {
+        UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
+
+        udpMatchBuilder.setUdpSourcePort(new PortNumber(11));
+        udpMatchBuilder.setUdpDestinationPort(new PortNumber(12));
+
+        return udpMatchBuilder.build();
+    }
+
+    private Layer4Match prepLayer4MatchTcp() {
+        TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
+
+        tcpMatchBuilder.setTcpSourcePort(new PortNumber(21));
+        tcpMatchBuilder.setTcpDestinationPort(new PortNumber(22));
+
+        return tcpMatchBuilder.build();
+    }
+
+    private Layer4Match prepLayer4MatchSctp() {
+        SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
+
+        sctpMatchBuilder.setSctpSourcePort(new PortNumber(31));
+        sctpMatchBuilder.setSctpDestinationPort(new PortNumber(32));
+
+        return sctpMatchBuilder.build();
+    }
+
+    private Layer3Match prepLayer3MatchIpv4() {
+        Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
+        ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix("192.168.1.104"));
+        ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix("192.168.1.105"));
+        return ipv4MatchBuilder.build();
+    }
+
+    private Layer3Match prepLayer3MatchIpv6() {
+        Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
+        ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix("3001:0db8:85a3:0000:0000:8a2e:0370:7334"));
+        ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix("3001:0db8:85a3:0000:0000:8a2e:0370:7335"));
+        return ipv6MatchBuilder.build();
+    }
+
+    private Layer3Match prepLayer3MatchArp() {
+        ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
+        arpMatchBuilder.setArpSourceTransportAddress(new Ipv4Prefix("192.168.1.101"));
+        arpMatchBuilder.setArpTargetTransportAddress(new Ipv4Prefix("192.168.1.102"));
+
+        ArpSourceHardwareAddressBuilder arpSourAddressBuild = new ArpSourceHardwareAddressBuilder();
+        arpSourAddressBuild.setAddress(new MacAddress("22:44:66:88:AA:CC"));
+        arpMatchBuilder.setArpSourceHardwareAddress(arpSourAddressBuild.build());
+
+        ArpTargetHardwareAddressBuilder arpTarAddressBuild = new ArpTargetHardwareAddressBuilder();
+        arpTarAddressBuild.setAddress(new MacAddress("11:33:55:77:BB:DD"));
+        arpMatchBuilder.setArpTargetHardwareAddress(arpTarAddressBuild.build());
+        return arpMatchBuilder.build();
+    }
+
+    private VlanMatch prepVlanMatch() {
+        VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
+
+        VlanIdBuilder vlanIdBuilder = new VlanIdBuilder().setVlanId(new VlanId(0xfff));
+        vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
+        vlanMatchBuilder.setVlanPcp(new VlanPcp((short) 0x7));
+
+        return vlanMatchBuilder.build();
+
+    }
+
+    private IpMatch prepIpMatch() {
+        IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
+        ipMatchBuilder.setIpDscp(new Dscp((short) 0x33));
+        ipMatchBuilder.setIpProtocol((short) 0x3f);
+        return ipMatchBuilder.build();
+    }
+
+    private EthernetMatch prepEthernetMatch() {
         EthernetMatchBuilder odEthernetMatchBuilder = new EthernetMatchBuilder();
-        odMatchBuilder.setEthernetMatch(odEthernetMatchBuilder.build());
+        odEthernetMatchBuilder.setEthernetDestination(prepEthDest());
+        odEthernetMatchBuilder.setEthernetSource(prepEthSour());
+        odEthernetMatchBuilder.setEthernetType(prepEthType());
+        return odEthernetMatchBuilder.build();
+    }
 
-        return odMatchBuilder.build();
+    private EthernetType prepEthType() {
+        EthernetTypeBuilder ethTypeBuild = new EthernetTypeBuilder();
+        ethTypeBuild.setType(new EtherType(0xffffl));
+        return ethTypeBuild.build();
+    }
+
+    private EthernetSource prepEthSour() {
+        EthernetSourceBuilder ethSourBuild = new EthernetSourceBuilder();
+        ethSourBuild.setAddress(new MacAddress("24:77:03:7C:C5:F1"));
+        return ethSourBuild.build();
+    }
+
+    private EthernetDestination prepEthDest() {
+        EthernetDestinationBuilder ethDestBuild = new EthernetDestinationBuilder();
+        ethDestBuild.setAddress(new MacAddress("3C:A9:F4:00:E0:C8"));
+        return ethDestBuild.build();
     }
 }