Class FlowServiceAdapter was created as mirror class to
[controller.git] / opendaylight / md-sal / sal-compability / src / main / java / org / opendaylight / controller / sal / compability / FromSalConversionsUtils.java
index 1d4f42c7999ebb4269fa9a047f0261715f4aedb4..6503a3031e96461e89240d637d6f90e7c768a5d0 100644 (file)
@@ -12,231 +12,94 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import org.opendaylight.controller.sal.action.*;
 import org.opendaylight.controller.sal.core.NodeConnector;
-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;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.VlanCfi;
-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.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.address.address.Ipv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.Action;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.ActionBuilder;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.address.Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.address.address.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 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.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.EthernetDestinationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.ethernet.match.fields.EthernetSourceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.ethernet.match.fields.EthernetTypeBuilder;
-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 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.ArpTargetHardwareAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.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);
 
-    // 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;
 
-    private FromSalConversionsUtils() {
 
-    }
 
-    public static FlowAdded flowFrom(Flow sourceFlow) {
-        if (sourceFlow != null) {
-            final FlowAddedBuilder targetFlow = new FlowAddedBuilder();
 
-            targetFlow.setHardTimeout(new Integer(sourceFlow.getHardTimeout()));
-            targetFlow.setIdleTimeout(new Integer(sourceFlow.getIdleTimeout()));
-            targetFlow.setPriority(new Integer(sourceFlow.getPriority()));
-            targetFlow.setCookie(new BigInteger(String.valueOf(sourceFlow.getId())));
 
-            List<org.opendaylight.controller.sal.action.Action> sourceActions = sourceFlow.getActions();
-            List<Action> targetActions = new ArrayList<>();
-            for (org.opendaylight.controller.sal.action.Action sourceAction : sourceActions) {
-                targetActions.add(actionFrom(sourceAction));
-            }
-            targetFlow.setAction(targetActions);
 
-            targetFlow.setMatch(matchFrom(sourceFlow.getMatch()));
+import static org.opendaylight.controller.sal.compability.ProtocolConstants.*;
+import static org.opendaylight.controller.sal.compability.NodeMapping.*;
+
+public class FromSalConversionsUtils {
+
+    private FromSalConversionsUtils() {
 
-            return targetFlow.build();
-        }
-        return null;
     }
 
-    private static Action actionFrom(org.opendaylight.controller.sal.action.Action sourceAction) {
-
-        ActionBuilder targetActionBuilder = new ActionBuilder();
-        org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.action.Action targetAction = null;
-
-        if (sourceAction instanceof Controller) {
-            targetAction = new ControllerActionBuilder().build();
-        } else if (sourceAction instanceof Drop) {
-            targetAction = new DropActionBuilder().build();
-        } else if (sourceAction instanceof Flood) {
-            targetAction = new FloodActionBuilder().build();
-        } else if (sourceAction instanceof FloodAll) {
-            targetAction = new FloodAllActionBuilder().build();
-        } else if (sourceAction instanceof HwPath) {
-            targetAction = new HwPathActionBuilder().build();
-        } else if (sourceAction instanceof Loopback) {
-            targetAction = new LoopbackActionBuilder().build();
-        } else if (sourceAction instanceof Output) {
-            NodeConnector nodeConnector = ((Output) sourceAction).getPort();
-
-            OutputActionBuilder outputActionBuilder = new OutputActionBuilder();
-            outputActionBuilder.setOutputNodeConnector(nodeConnectorToUri(nodeConnector));
-            targetAction = outputActionBuilder.build();
-
-        } else if (sourceAction instanceof PopVlan) {
-            targetAction = new PopVlanActionBuilder().build();
-        } else if (sourceAction instanceof PushVlan) {
-            PushVlan pushVlan = (PushVlan) sourceAction;
-            PushVlanActionBuilder pushVlanActionBuilder = new PushVlanActionBuilder();
-
-            pushVlanActionBuilder.setCfi(new VlanCfi(pushVlan.getCfi()));
-            pushVlanActionBuilder.setVlanId(new VlanId(pushVlan.getVlanId()));
-            pushVlanActionBuilder.setPcp(pushVlan.getPcp());
-            pushVlanActionBuilder.setTag(pushVlan.getTag());
-            targetAction = pushVlanActionBuilder.build();
-        } else if (sourceAction instanceof SetDlDst) {
-            SetDlDst setDlDst = (SetDlDst) sourceAction;
-            SetDlDstActionBuilder setDlDstActionBuilder = new SetDlDstActionBuilder();
-
-            setDlDstActionBuilder.setAddress(new MacAddress(Arrays.toString(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())));
-            targetAction = setDlSrcActionBuilder.build();
-        } else if (sourceAction instanceof SetDlType) {
-            SetDlType setDlType = (SetDlType) sourceAction;
-            SetDlTypeActionBuilder setDlTypeActionBuilder = new SetDlTypeActionBuilder();
-
-            setDlTypeActionBuilder.setDlType(new EtherType(new Long(setDlType.getDlType())));
-            targetAction = setDlTypeActionBuilder.build();
-        } else if (sourceAction instanceof SetNextHop) {
-            SetNextHop setNextHop = (SetNextHop) sourceAction;
-            SetNextHopActionBuilder setNextHopActionBuilder = new SetNextHopActionBuilder();
-
-            InetAddress inetAddress = setNextHop.getAddress();
-            setNextHopActionBuilder.setAddress(addressFromAction(inetAddress));
-
-            targetAction = setNextHopActionBuilder.build();
-        } else if (sourceAction instanceof SetNwDst) {
-            SetNwDst setNwDst = (SetNwDst) sourceAction;
-            SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
-
-            InetAddress inetAddress = setNwDst.getAddress();
-            setNwDstActionBuilder.setAddress(addressFromAction(inetAddress));
-
-            targetAction = setNwDstActionBuilder.build();
-        } else if (sourceAction instanceof SetNwSrc) {
-            SetNwSrc setNwSrc = (SetNwSrc) sourceAction;
-            SetNwSrcActionBuilder setNwSrcActionBuilder = new SetNwSrcActionBuilder();
-
-            InetAddress inetAddress = setNwSrc.getAddress();
-            setNwSrcActionBuilder.setAddress(addressFromAction(inetAddress));
-
-            targetAction = setNwSrcActionBuilder.build();
-        } else if (sourceAction instanceof SetNwTos) {
-            SetNwTos setNwTos = (SetNwTos) sourceAction;
-            SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
-
-            setNwTosActionBuilder.setTos(setNwTos.getNwTos());
-            targetAction = setNwTosActionBuilder.build();
-        } else if (sourceAction instanceof SetTpDst) {
-            SetTpDst setTpDst = (SetTpDst) sourceAction;
-            SetTpDstActionBuilder setTpDstActionBuilder = new SetTpDstActionBuilder();
-
-            setTpDstActionBuilder.setPort(new PortNumber(setTpDst.getPort()));
-
-            targetAction = setTpDstActionBuilder.build();
-        } else if (sourceAction instanceof SetTpSrc) {
-            SetTpSrc setTpSrc = (SetTpSrc) sourceAction;
-            SetTpSrcActionBuilder setTpSrcActionBuilder = new SetTpSrcActionBuilder();
-
-            setTpSrcActionBuilder.setPort(new PortNumber(setTpSrc.getPort()));
-
-            targetAction = setTpSrcActionBuilder.build();
-        } else if (sourceAction instanceof SetVlanCfi) {
-            SetVlanCfi setVlanCfi = (SetVlanCfi) sourceAction;
-            SetVlanCfiActionBuilder setVlanCfiActionBuilder = new SetVlanCfiActionBuilder();
-
-            setVlanCfiActionBuilder.setVlanCfi(new VlanCfi(setVlanCfi.getCfi()));
-
-            targetAction = setVlanCfiActionBuilder.build();
-        } else if (sourceAction instanceof SetVlanId) {
-            SetVlanId setVlanId = (SetVlanId) sourceAction;
-            SetVlanIdActionBuilder setVlanIdActionBuilder = new SetVlanIdActionBuilder();
-
-            setVlanIdActionBuilder.setVlanId(new VlanId(setVlanId.getVlanId()));
-
-            targetAction = setVlanIdActionBuilder.build();
-        } else if (sourceAction instanceof SetVlanPcp) {
-            SetVlanPcp setVlanPcp = (SetVlanPcp) sourceAction;
-            SetVlanPcpActionBuilder setVlanPcpActionBuilder = new SetVlanPcpActionBuilder();
-
-            setVlanPcpActionBuilder.setVlanPcp(new VlanPcp((short) setVlanPcp.getPcp()));
-
-            targetAction = setVlanPcpActionBuilder.build();
-        } else if (sourceAction instanceof SwPath) {
-            targetAction = new SwPathActionBuilder().build();
-        }
+    public static GetNodeConnectorStatisticsInput nodeConnectorStatistics(
+            NodeConnector connector) {
+        GetNodeConnectorStatisticsInputBuilder target = new GetNodeConnectorStatisticsInputBuilder();
 
-        targetActionBuilder.setAction(targetAction);
+        NodeRef nodeRef = toNodeRef(connector.getNode());
+        target.setNode(nodeRef);
 
-        return targetActionBuilder.build();
+        NodeConnectorRef nodeConnectorRef = toNodeConnectorRef(connector);
+        target.setNodeConnector(nodeConnectorRef);
+
+        return target.build();
     }
 
     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;
     }
 
-    private static List<Uri> nodeConnectorToUri(NodeConnector nodeConnector) {
-        // TODO Define mapping
-        return null;
-    }
-
-    private static org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.Match matchFrom(
+    public static org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match toMatch(
             Match sourceMatch) {
         if (sourceMatch != null) {
-            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.MatchBuilder targetBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.MatchBuilder();
+            MatchBuilder targetBuilder = new MatchBuilder();
 
-            targetBuilder.setEthernetMatch(ethernetMatchFrom(sourceMatch));
-            targetBuilder.setIpMatch(ipMatchFrom(sourceMatch));
-            targetBuilder.setVlanMatch(vlanMatchFrom(sourceMatch));
+            targetBuilder.setEthernetMatch(ethernetMatch(sourceMatch));
+            targetBuilder.setIpMatch(ipMatch(sourceMatch));
+            targetBuilder.setVlanMatch(vlanMatch(sourceMatch));
             targetBuilder.setLayer3Match(layer3Match(sourceMatch));
             targetBuilder.setLayer4Match(layer4Match(sourceMatch));
 
@@ -250,16 +113,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;
     }
@@ -267,14 +129,16 @@ public class FromSalConversionsUtils {
     private static Layer4Match Layer4MatchAsSctp(final Match sourceMatch) {
         SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
 
-        Integer sourcePort = transportPortFrom(sourceMatch, MatchType.TP_SRC);
-        Integer destinationPort = transportPortFrom(sourceMatch, MatchType.TP_DST);
+        Integer sourcePort = transportPort(sourceMatch, MatchType.TP_SRC);
+        Integer destinationPort = transportPort(sourceMatch,
+                MatchType.TP_DST);
 
         if (sourcePort != null) {
             sctpMatchBuilder.setSctpSourcePort(new PortNumber(sourcePort));
         }
         if (destinationPort != null) {
-            sctpMatchBuilder.setSctpDestinationPort(new PortNumber(destinationPort));
+            sctpMatchBuilder.setSctpDestinationPort(new PortNumber(
+                    destinationPort));
         }
 
         return sctpMatchBuilder.build();
@@ -283,15 +147,17 @@ public class FromSalConversionsUtils {
     private static Layer4Match Layer4MatchAsUdp(final Match sourceMatch) {
         UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
 
-        Integer sourcePort = transportPortFrom(sourceMatch, MatchType.TP_SRC);
-        Integer destinationPort = transportPortFrom(sourceMatch, MatchType.TP_DST);
+        Integer sourcePort = transportPort(sourceMatch, MatchType.TP_SRC);
+        Integer destinationPort = transportPort(sourceMatch,
+                MatchType.TP_DST);
 
         if (sourcePort != null) {
             udpMatchBuilder.setUdpSourcePort(new PortNumber(sourcePort));
         }
 
         if (destinationPort != null) {
-            udpMatchBuilder.setUdpDestinationPort(new PortNumber(destinationPort));
+            udpMatchBuilder.setUdpDestinationPort(new PortNumber(
+                    destinationPort));
         }
 
         return udpMatchBuilder.build();
@@ -300,86 +166,98 @@ public class FromSalConversionsUtils {
     private static Layer4Match Layer4MatchAsTcp(final Match sourceMatch) {
         TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
 
-        Integer sourcePort = transportPortFrom(sourceMatch, MatchType.TP_SRC);
-        Integer destinationPort = transportPortFrom(sourceMatch, MatchType.TP_DST);
+        Integer sourcePort = transportPort(sourceMatch, MatchType.TP_SRC);
+        Integer destinationPort = transportPort(sourceMatch,
+                MatchType.TP_DST);
 
         if (sourcePort != null) {
             tcpMatchBuilder.setTcpSourcePort(new PortNumber(sourcePort));
         }
         if (destinationPort != null) {
-            tcpMatchBuilder.setTcpDestinationPort(new PortNumber(destinationPort));
+            tcpMatchBuilder.setTcpDestinationPort(new PortNumber(
+                    destinationPort));
         }
 
         return tcpMatchBuilder.build();
     }
 
-    private static Integer transportPortFrom(final Match sourceMatch, final MatchType matchType) {
+    private static Integer transportPort(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;
     }
 
-    private static VlanMatch vlanMatchFrom(final Match sourceMatch) {
+    private static VlanMatch vlanMatch(final Match sourceMatch) {
         VlanMatchBuilder vlanMatchBuild = new VlanMatchBuilder();
 
         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();
     }
 
-    private static IpMatch ipMatchFrom(final Match sourceMatch) {
+    private static IpMatch ipMatch(final Match sourceMatch) {
         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();
 
     }
 
-    private static EthernetMatch ethernetMatchFrom(final Match sourceMatch) {
+    private static EthernetMatch ethernetMatch(final Match sourceMatch) {
         final EthernetMatchBuilder targetEthMatchBuild = new EthernetMatchBuilder();
 
         EthernetSourceBuilder ethSourBuild = new EthernetSourceBuilder()
-                .setAddress(ethernetSourceAddressFrom(sourceMatch));
+                .setAddress(ethernetSourceAddress(sourceMatch));
         targetEthMatchBuild.setEthernetSource(ethSourBuild.build());
 
         EthernetDestinationBuilder ethDestBuild = new EthernetDestinationBuilder()
-                .setAddress(ethernetDestAddressFrom(sourceMatch));
+                .setAddress(ethernetDestAddress(sourceMatch));
         targetEthMatchBuild.setEthernetDestination(ethDestBuild.build());
 
         final MatchField dataLinkType = sourceMatch.getField(MatchType.DL_TYPE);
         if (dataLinkType != null && dataLinkType.getValue() != null) {
-            EtherType etherType = new EtherType((Long) (dataLinkType.getValue()));
-            EthernetTypeBuilder ethType = new EthernetTypeBuilder().setType(etherType);
+            EtherType etherType = new EtherType(new Long(
+                    NetUtils.getUnsignedShort((Short) dataLinkType.getValue())));
+            EthernetTypeBuilder ethType = new EthernetTypeBuilder()
+                    .setType(etherType);
             targetEthMatchBuild.setEthernetType(ethType.build());
         }
         return targetEthMatchBuild.build();
     }
 
-    private static MacAddress ethernetSourceAddressFrom(final Match sourceMatch) {
+    private static MacAddress ethernetSourceAddress(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 MDFlowMapping.toMacAddress((byte[])dataLinkSource.getValue());
         }
         return null;
 
@@ -398,75 +276,101 @@ public class FromSalConversionsUtils {
             inetDestAddress = (InetAddress) (netDest.getValue());
         }
 
-        if ((inetSourceAddress instanceof Inet4Address) && (inetDestAddress instanceof Inet4Address)) {
+        if ((inetSourceAddress instanceof Inet4Address)
+                && (inetDestAddress instanceof Inet4Address)) {
             MatchField dataLinkType = sourceMatch.getField(DL_TYPE);
             Short dLType = null;
             if (dataLinkType != null && dataLinkType.getValue() != null) {
                 dLType = (Short) (dataLinkType.getValue());
             }
-            if (dLType.equals(ETHERNET_ARP)) {
-                return setLayer3MatchAsArp(sourceMatch, (Inet4Address) inetSourceAddress,
+            if (dLType != null && dLType.equals(ETHERNET_ARP)) {
+                return setLayer3MatchAsArp(sourceMatch,
+                        (Inet4Address) inetSourceAddress,
                         (Inet4Address) inetDestAddress);
             } else {
-                return setLayer3MatchAsIpv4((Inet4Address) inetSourceAddress, (Inet4Address) inetDestAddress);
+                return setLayer3MatchAsIpv4((Inet4Address) inetSourceAddress,
+                        (Inet4Address) inetDestAddress);
             }
-        } else if ((inetSourceAddress instanceof Inet6Address) && (inetDestAddress instanceof Inet6Address)) {
-            return setLayer3MatchAsIpv6((Inet6Address) inetSourceAddress, (Inet6Address) inetDestAddress);
+        } else if ((inetSourceAddress instanceof Inet6Address)
+                && (inetDestAddress instanceof Inet6Address)) {
+            return setLayer3MatchAsIpv6((Inet6Address) inetSourceAddress,
+                    (Inet6Address) inetDestAddress);
         }
 
         return null;
 
     }
 
-    private static Layer3Match setLayer3MatchAsArp(final Match sourceMatch, final Inet4Address inetSourceAddress,
+    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));
-        arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
+        arpSourceHardwareAddressBuilder
+                .setAddress(ethernetSourceAddress(sourceMatch));
+        arpMatchBuilder
+                .setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder
+                        .build());
 
         ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
-        arpTargetHardwareAddressBuilder.setAddress(ethernetDestAddressFrom(sourceMatch));
-        arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
+        arpTargetHardwareAddressBuilder
+                .setAddress(ethernetDestAddress(sourceMatch));
+        arpMatchBuilder
+                .setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder
+                        .build());
 
         return arpMatchBuilder.build();
 
     }
 
-    private static MacAddress ethernetDestAddressFrom(final Match sourceMatch) {
+    private static MacAddress ethernetDestAddress(final Match sourceMatch) {
         final MatchField dataLinkDest = sourceMatch.getField(DL_DST);
         if (dataLinkDest != null && dataLinkDest.getValue() != null) {
-            return new MacAddress((String) (dataLinkDest.getValue()));
+            return MDFlowMapping.toMacAddress((byte[]) dataLinkDest.getValue());
         }
         return null;
     }
 
-    private static Layer3Match setLayer3MatchAsIpv4(final Inet4Address inetSourceAddress,
+    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,
+    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();
     }