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 98c64aa1a63ef6176aff6e3885056b14a1b665d5..8f3a29d585b5cc7f357187325087cf490ad89807 100644 (file)
@@ -9,14 +9,18 @@
  */
 package org.opendaylight.openflowplugin.openflow.md.core.translator;
 
-import org.opendaylight.openflowplugin.openflow.md.OFConstants;
-import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
+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.openflow.md.core.session.SessionContext;
+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.openflow.md.util.OpenflowVersion;
+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;
@@ -134,7 +138,6 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
@@ -417,7 +420,7 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
                     map.put(6, pseudoField.isHop());
                     map.put(7, pseudoField.isUnrep());
                     map.put(8, pseudoField.isUnseq());
-                    int bitmap = fillBitMaskFromMap(map);
+                    int bitmap = ByteBufUtils.fillBitMaskFromMap(map);
                     ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
                     if (entry.isHasMask()) {
                         ipv6ExtHeaderBuilder.setIpv6ExthdrMask(
@@ -452,9 +455,17 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
                     tunnel.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, entry.getAugmentation(MaskMatchEntry.class).getMask()));
                 }
                 matchBuilder.setTunnel(tunnel.build());
-            }
+            } 
         }
-
+        
+        AugmentTuple<Match> matchExtensionWrap = 
+                MatchExtensionHelper.processAllExtensions(
+                        ofMatch.getMatchEntries(), ofVersion, MatchPath.SWITCHFLOWREMOVED_MATCH);
+        if (matchExtensionWrap != null) {
+            matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject());
+        }
+        
+        
         if (ethernetMatch != null) {
             matchBuilder.setEthernetMatch(ethernetMatch.build());
         }
@@ -492,26 +503,8 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
         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);
@@ -519,8 +512,8 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
         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);