Bug 1764 - moved Session related interfaces to openflowplugin-api
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / translator / FlowRemovedTranslator.java
index e454e3cfce943aa0a3f34fdb050eee0eb88dde84..8f3a29d585b5cc7f357187325087cf490ad89807 100644 (file)
@@ -1,19 +1,37 @@
+/**
+ * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. 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
+ *
+ * Contributor: deepthi.v.v@ericsson.com
+ */
 package org.opendaylight.openflowplugin.openflow.md.core.translator;
 
-import java.math.BigInteger;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
-import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.api.openflow.md.core.IMDMessageTranslator;
+import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
+import org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
+import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
+import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
+import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
+import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
 import org.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.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemovedBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.RemovedReasonFlags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.mod.removed.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.mod.removed.MatchBuilder;
+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.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
@@ -21,6 +39,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 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.ipv6.match.fields.Ipv6ExtHeaderBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
@@ -59,10 +78,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry.PseudoField;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
@@ -100,32 +120,44 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Sctp
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Dst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Src;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, DataObject> {
+import java.math.BigInteger;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
 
     protected static final Logger LOG = LoggerFactory.getLogger(FlowRemovedTranslator.class);
     private static final String PREFIX_SEPARATOR = "/";
 
     @Override
-    public DataObject translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) {
+    public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) {
         if (msg instanceof FlowRemovedMessage) {
             FlowRemovedMessage ofFlow = (FlowRemovedMessage) msg;
+            List<DataObject> list = new CopyOnWriteArrayList<DataObject>();
             LOG.debug("Flow Removed Message received: Table Id={}, Flow removed reason={} ", ofFlow.getTableId(),
                     ofFlow.getReason());
 
             SwitchFlowRemovedBuilder salFlowRemoved = new SwitchFlowRemovedBuilder();
 
-            salFlowRemoved.setCookie(ofFlow.getCookie());
+            if (ofFlow.getCookie() != null) {
+                salFlowRemoved.setCookie(new FlowCookie(ofFlow.getCookie()));
+            }
             salFlowRemoved.setPriority(ofFlow.getPriority());
 
             if (ofFlow.getTableId() != null) {
@@ -138,21 +170,38 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
             salFlowRemoved.setHardTimeout(ofFlow.getHardTimeout());
             salFlowRemoved.setPacketCount(ofFlow.getPacketCount());
             salFlowRemoved.setByteCount(ofFlow.getByteCount());
-            org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match ofMatch = ofFlow
+            RemovedReasonFlags removeReasonFlag = new RemovedReasonFlags(
+                    FlowRemovedReason.OFPRRDELETE.equals(ofFlow.getReason()),
+                    FlowRemovedReason.OFPRRGROUPDELETE.equals(ofFlow.getReason()),
+                    FlowRemovedReason.OFPRRHARDTIMEOUT.equals(ofFlow.getReason()),
+                    FlowRemovedReason.OFPRRIDLETIMEOUT.equals(ofFlow.getReason())
+                    );
+
+            salFlowRemoved.setRemovedReason(removeReasonFlag);
+
+            OpenflowVersion ofVersion = OpenflowVersion.get(sc.getPrimaryConductor().getVersion());
+            org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match ofMatch = ofFlow
                     .getMatch();
             if (ofMatch != null) {
-                salFlowRemoved.setMatch(fromMatch(ofMatch));
+                salFlowRemoved.setMatch(fromMatch(ofMatch, sc.getFeatures().getDatapathId(), ofVersion));
             }
-
-            return salFlowRemoved.build();
+            else if(ofFlow.getMatchV10() != null){
+                MatchBuilder matchBuilder = new MatchBuilder(MatchConvertorImpl.fromOFMatchV10ToSALMatch(ofFlow.getMatchV10(), sc.getFeatures().getDatapathId(), ofVersion));
+                salFlowRemoved.setMatch(matchBuilder.build());
+            }
+            salFlowRemoved.setNode(new NodeRef(InventoryDataServiceUtil.identifierFromDatapathId(sc.getFeatures()
+                    .getDatapathId())));
+            list.add(salFlowRemoved.build());
+            return list;
         } else {
             LOG.error("Message is not a flow removed message ");
-            return null;
+            return Collections.emptyList();
         }
     }
 
-    public Match fromMatch(
-            org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match ofMatch) {
+
+    public Match fromMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match ofMatch,
+            BigInteger datapathid, OpenflowVersion ofVersion) {
         MatchBuilder matchBuilder = new MatchBuilder();
         EthernetMatchBuilder ethernetMatch = null;
         VlanMatchBuilder vlanMatch = null;
@@ -170,16 +219,16 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
         for (MatchEntries entry : ofMatch.getMatchEntries()) {
             Class<? extends MatchField> field = entry.getOxmMatchField();
             if (field.equals(InPort.class)) {
-                matchBuilder.setInPort(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue()
-                        .longValue());
+                matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
+                        entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().longValue(), ofVersion));
             } else if (field.equals(InPhyPort.class)) {
-                matchBuilder.setInPhyPort(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue()
-                        .longValue());
+                matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
+                        entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().longValue(), ofVersion));
             } else if (field.equals(Metadata.class)) {
                 MetadataBuilder metadata = new MetadataBuilder();
-                metadata.setMetadata(new BigInteger(entry.getAugmentation(MetadataMatchEntry.class).getMetadata()));
+                metadata.setMetadata(new BigInteger(1, entry.getAugmentation(MetadataMatchEntry.class).getMetadata()));
                 if (entry.isHasMask()) {
-                    metadata.setMetadataMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+                    metadata.setMetadataMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, entry.getAugmentation(MaskMatchEntry.class).getMask()));
                 }
                 matchBuilder.setMetadata(metadata.build());
             } else if (field.equals(EthDst.class) || field.equals(EthSrc.class) || field.equals(EthType.class)) {
@@ -190,14 +239,14 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
                     EthernetDestinationBuilder ethDst = new EthernetDestinationBuilder();
                     ethDst.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
                     if (entry.isHasMask()) {
-                        ethDst.setMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+                        ethDst.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
                     }
                     ethernetMatch.setEthernetDestination(ethDst.build());
                 } else if (field.equals(EthSrc.class)) {
                     EthernetSourceBuilder ethSrc = new EthernetSourceBuilder();
                     ethSrc.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
                     if (entry.isHasMask()) {
-                        ethSrc.setMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+                        ethSrc.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
                     }
                     ethernetMatch.setEthernetSource(ethSrc.build());
                 } else if (field.equals(EthType.class)) {
@@ -211,15 +260,16 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
                     vlanMatch = new VlanMatchBuilder();
                 }
                 if (field.equals(VlanVid.class)) {
+                    boolean vlanIdPresent = false;
                     VlanIdBuilder vlanId = new VlanIdBuilder();
                     VlanVidMatchEntry vlanVid = entry.getAugmentation(VlanVidMatchEntry.class);
-                    int vlanVidValue = vlanVid.getVlanVid() << 1;
+                    Integer vlanVidValue = vlanVid.getVlanVid();
                     if (vlanVid.isCfiBit()) {
-                        vlanVidValue = vlanVidValue | 1;
+                        vlanIdPresent = true;
                     }
-                    vlanId.setVlanId(new VlanId(vlanVidValue));
-                    if (entry.isHasMask()) {
-                        vlanId.setMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+                    vlanId.setVlanIdPresent(vlanIdPresent);
+                    if (vlanVidValue != null) {
+                        vlanId.setVlanId(new VlanId(vlanVidValue));
                     }
                     vlanMatch.setVlanId(vlanId.build());
                 } else if (field.equals(VlanPcp.class)) {
@@ -236,9 +286,7 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
                 } else if (field.equals(IpEcn.class)) {
                     ipMatch.setIpEcn(entry.getAugmentation(EcnMatchEntry.class).getEcn());
                 } else if (field.equals(IpProto.class)) {
-                    ipMatch.setIpProto(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpVersion
-                            .forValue(entry.getAugmentation(ProtocolNumberMatchEntry.class).getProtocolNumber()
-                                    .intValue()));
+                    ipMatch.setIpProtocol(entry.getAugmentation(ProtocolNumberMatchEntry.class).getProtocolNumber());
                 }
             } else if (field.equals(TcpSrc.class) || field.equals(TcpDst.class)) {
                 if (tcpMatch == null) {
@@ -315,17 +363,26 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
                     ArpSourceHardwareAddressBuilder arpSha = new ArpSourceHardwareAddressBuilder();
                     arpSha.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
                     if (entry.isHasMask()) {
-                        arpSha.setMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+                        arpSha.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
                     }
                     arpMatch.setArpSourceHardwareAddress(arpSha.build());
                 } else if (field.equals(ArpTha.class)) {
                     ArpTargetHardwareAddressBuilder arpTha = new ArpTargetHardwareAddressBuilder();
                     arpTha.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
                     if (entry.isHasMask()) {
-                        arpTha.setMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+                        arpTha.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
                     }
                     arpMatch.setArpTargetHardwareAddress(arpTha.build());
                 }
+            } else if (field.equals(TunnelIpv4Src.class) || field.equals(TunnelIpv4Dst.class)) {
+                if (ipv4Match == null) {
+                    ipv4Match = new Ipv4MatchBuilder();
+                }
+                if (field.equals(TunnelIpv4Src.class)) {
+                    ipv4Match.setIpv4Source(toIpv4Prefix(entry));
+                } else if (field.equals(TunnelIpv4Dst.class)) {
+                    ipv4Match.setIpv4Destination(toIpv4Prefix(entry));
+                }
             } else if (field.equals(Ipv6Src.class) || field.equals(Ipv6Dst.class) || field.equals(Ipv6Flabel.class)
                     || field.equals(Ipv6NdTarget.class) || field.equals(Ipv6NdSll.class)
                     || field.equals(Ipv6NdTll.class) || field.equals(Ipv6Exthdr.class)) {
@@ -340,7 +397,7 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
                     Ipv6LabelBuilder ipv6Label = new Ipv6LabelBuilder();
                     ipv6Label.setIpv6Flabel(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel());
                     if (entry.isHasMask()) {
-                        ipv6Label.setFlabelMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+                        ipv6Label.setFlabelMask(new Ipv6FlowLabel(ByteUtil.bytesToUnsignedInt(entry.getAugmentation(MaskMatchEntry.class).getMask())));
                     }
                     ipv6Match.setIpv6Label(ipv6Label.build());
                 } else if (field.equals(Ipv6NdTarget.class)) {
@@ -351,7 +408,8 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
                     ipv6Match.setIpv6NdTll(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
                 } else if (field.equals(Ipv6Exthdr.class)) {
                     // verify
-                    PseudoField pseudoField = entry.getAugmentation(PseudoFieldMatchEntry.class).getPseudoField();
+                    Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
+                    Ipv6ExthdrFlags pseudoField = entry.getAugmentation(PseudoFieldMatchEntry.class).getPseudoField();
                     Map<Integer, Boolean> map = new HashMap<>();
                     map.put(0, pseudoField.isNonext());
                     map.put(1, pseudoField.isEsp());
@@ -362,8 +420,13 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
                     map.put(6, pseudoField.isHop());
                     map.put(7, pseudoField.isUnrep());
                     map.put(8, pseudoField.isUnseq());
-                    int bitmap = fillBitMaskFromMap(map);
-                    ipv6Match.setIpv6Exthdr(bitmap);
+                    int bitmap = ByteBufUtils.fillBitMaskFromMap(map);
+                    ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
+                    if (entry.isHasMask()) {
+                        ipv6ExtHeaderBuilder.setIpv6ExthdrMask(
+                            ByteUtil.bytesToUnsignedShort(entry.getAugmentation(MaskMatchEntry.class).getMask()));
+                    }
+                    ipv6Match.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
                 }
             } else if (field.equals(MplsLabel.class) || field.equals(MplsTc.class) || field.equals(MplsBos.class)
                     || field.equals(PbbIsid.class)) {
@@ -381,20 +444,28 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
                     PbbBuilder pbb = new PbbBuilder();
                     pbb.setPbbIsid(entry.getAugmentation(IsidMatchEntry.class).getIsid());
                     if (entry.isHasMask()) {
-                        pbb.setPbbMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+                        pbb.setPbbMask(ByteUtil.bytesToUnsignedInt(entry.getAugmentation(MaskMatchEntry.class).getMask()));
                     }
                     protocolMatchFields.setPbb(pbb.build());
                 }
             } else if (field.equals(TunnelId.class)) {
                 TunnelBuilder tunnel = new TunnelBuilder();
-                tunnel.setTunnelId(new BigInteger(entry.getAugmentation(MetadataMatchEntry.class).getMetadata()));
+                tunnel.setTunnelId(new BigInteger(1, entry.getAugmentation(MetadataMatchEntry.class).getMetadata()));
                 if (entry.isHasMask()) {
-                    tunnel.setTunnelMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+                    tunnel.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, entry.getAugmentation(MaskMatchEntry.class).getMask()));
                 }
                 matchBuilder.setTunnel(tunnel.build());
-            }
+            } 
         }
-
+        
+        AugmentTuple<Match> matchExtensionWrap = 
+                MatchExtensionHelper.processAllExtensions(
+                        ofMatch.getMatchEntries(), ofVersion, MatchPath.SWITCHFLOWREMOVED_MATCH);
+        if (matchExtensionWrap != null) {
+            matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject());
+        }
+        
+        
         if (ethernetMatch != null) {
             matchBuilder.setEthernetMatch(ethernetMatch.build());
         }
@@ -432,26 +503,8 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
         return matchBuilder.build();
     }
 
-    /**
-     * Fills the bitmask from boolean map where key is bit position
-     *
-     * @param booleanMap
-     *            bit to boolean mapping
-     * @return bit mask
-     */
-    private int fillBitMaskFromMap(Map<Integer, Boolean> booleanMap) {
-        int bitmask = 0;
-
-        for (Entry<Integer, Boolean> iterator : booleanMap.entrySet()) {
-            if (iterator.getValue() != null && iterator.getValue().booleanValue()) {
-                bitmask |= 1 << iterator.getKey();
-            }
-        }
-        return bitmask;
-    }
-
-    private Ipv4Prefix toIpv4Prefix(MatchEntries entry) {
-        String ipv4Prefix = entry.getAugmentation(Ipv4AddressMatchEntry.class).getIpv4Address().toString();
+    protected Ipv4Prefix toIpv4Prefix(MatchEntries entry) {
+        String ipv4Prefix = entry.getAugmentation(Ipv4AddressMatchEntry.class).getIpv4Address().getValue();
         if (entry.isHasMask()) {
             byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();
             ipv4Prefix = ipv4Prefix + PREFIX_SEPARATOR + countBits(mask);
@@ -459,8 +512,8 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Dat
         return new Ipv4Prefix(ipv4Prefix);
     }
 
-    private Ipv6Prefix toIpv6Prefix(MatchEntries entry) {
-        String ipv6Prefix = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().toString();
+    protected Ipv6Prefix toIpv6Prefix(MatchEntries entry) {
+        String ipv6Prefix = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue();
         if (entry.isHasMask()) {
             byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();
             ipv6Prefix = ipv6Prefix + PREFIX_SEPARATOR + countBits(mask);