From be1b2312a9ec740407dc6b7459b303f7ff470de0 Mon Sep 17 00:00:00 2001
From: meiyangbigswitch <mei.yang@bigswitch.com>
Date: Fri, 22 Mar 2013 14:55:10 -0700
Subject: [PATCH] APPCookie change to accomodate REWRITE FLAGS

---
 .../core/util/AppCookie.java                  | 47 ++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/main/java/net/floodlightcontroller/core/util/AppCookie.java b/src/main/java/net/floodlightcontroller/core/util/AppCookie.java
index 210823efc..3a72b3017 100644
--- a/src/main/java/net/floodlightcontroller/core/util/AppCookie.java
+++ b/src/main/java/net/floodlightcontroller/core/util/AppCookie.java
@@ -27,10 +27,17 @@ package net.floodlightcontroller.core.util;
 public class AppCookie {
     static final int APP_ID_BITS = 12;
     static final int APP_ID_SHIFT = (64 - APP_ID_BITS);
-    // we have bits 13-31 unused here ... that's ok!
+    /**the following bit will be set accordingly if the field is rewritten by application. e.g. VRS or floating IP */
+    static final int SRC_MAC_REWRITE_BIT=13;
+    static final int DEST_MAC_REWRITE_BIT=14;
+    static final int SRC_IP_REWRITE_BIT=15;
+    static final int DEST_IP_REWRITE_BIT=16;
+
+ // we have bits 17-31 unused here ... that's ok!
     static final int USER_BITS = 32;
     static final int USER_SHIFT = 0;
 
+    static final long REWRITE_MASK= 0x000f000000000000L;
 
     /**
      * Encapsulate an application ID and a user block of stuff into a cookie
@@ -51,4 +58,42 @@ public class AppCookie {
     static public int extractUser(long cookie) {
         return (int)((cookie>> USER_SHIFT) & ((1L << USER_BITS) - 1));
     }
+
+    static public boolean isRewriteFlagSet(long cookie) {
+        if ((cookie & REWRITE_MASK) !=0L)
+            return true;
+        return false;
+    }
+    static public boolean isSrcMacRewriteFlagSet(long cookie) {
+        if ((cookie & (1L << (64-SRC_MAC_REWRITE_BIT))) !=0L)
+            return true;
+        return false;
+    }
+    static public boolean isDestMacRewriteFlagSet(long cookie) {
+        if ((cookie & (1L << (64-DEST_MAC_REWRITE_BIT))) !=0L)
+            return true;
+        return false;
+    }
+    static public boolean isSrcIpRewriteFlagSet(long cookie) {
+        if ((cookie & (1L << (64-SRC_IP_REWRITE_BIT))) !=0L)
+            return true;
+        return false;
+    }
+    static public boolean isDestIpRewriteFlagSet(long cookie) {
+        if ((cookie & (1L << (64-DEST_IP_REWRITE_BIT))) !=0L)
+            return true;
+        return false;
+    }
+    static public long setSrcMacRewriteFlag(long cookie) {
+        return cookie | (1L << (64-SRC_MAC_REWRITE_BIT));
+    }
+    static public long setDestMacRewriteFlag(long cookie) {
+        return cookie | (1L << (64-DEST_MAC_REWRITE_BIT));
+    }
+    static public long setSrcIpRewriteFlag(long cookie) {
+        return cookie | (1L << (64-SRC_IP_REWRITE_BIT));
+    }
+    static public long setDestIpRewriteFlag(long cookie) {
+        return cookie | (1L << (64-DEST_IP_REWRITE_BIT));
+    }
 }
-- 
GitLab