Support for bitwise AND/OR/XOR in ImmutableByteSequence

Also, minor refactoring of the fit() method to improve code readability

Change-Id: I826650c3fc45573c723d9d2dd8692da174d9ae08
diff --git a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/BasicInterpreterImpl.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/BasicInterpreterImpl.java
index 8e7b399..5ff38ba 100644
--- a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/BasicInterpreterImpl.java
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/BasicInterpreterImpl.java
@@ -49,7 +49,6 @@
 import static java.lang.String.format;
 import static java.util.stream.Collectors.toList;
 import static org.onlab.util.ImmutableByteSequence.copyFrom;
-import static org.onlab.util.ImmutableByteSequence.fit;
 import static org.onosproject.net.PortNumber.CONTROLLER;
 import static org.onosproject.net.PortNumber.FLOOD;
 import static org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT;
@@ -130,7 +129,7 @@
                 return PiAction.builder()
                         .withId(ACT_SET_EGRESS_PORT_ID)
                         .withParameter(new PiActionParam(ACT_PRM_PORT_ID,
-                                                         fit(copyFrom(port.toLong()), PORT_BITWIDTH)))
+                                                         copyFrom(port.toLong()).fit(PORT_BITWIDTH)))
                         .build();
             } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
                 throw new PiInterpreterException(e.getMessage());
@@ -231,7 +230,7 @@
         try {
             return PiControlMetadata.builder()
                     .withId(PKT_META_EGRESS_PORT_ID)
-                    .withValue(fit(copyFrom(portNumber), PORT_BITWIDTH))
+                    .withValue(copyFrom(portNumber).fit(PORT_BITWIDTH))
                     .build();
         } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
             throw new PiInterpreterException(format(
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java
index 29e3a48..e79cd44 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java
@@ -53,7 +53,6 @@
 import static java.lang.String.format;
 import static java.util.stream.Collectors.toList;
 import static org.onlab.util.ImmutableByteSequence.copyFrom;
-import static org.onlab.util.ImmutableByteSequence.fit;
 import static org.onosproject.net.PortNumber.FLOOD;
 import static org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT;
 import static org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT;
@@ -208,7 +207,7 @@
         try {
             return PiControlMetadata.builder()
                     .withId(FabricConstants.CTRL_META_EGRESS_PORT_ID)
-                    .withValue(fit(copyFrom(portNumber), FabricConstants.PORT_BITWIDTH))
+                    .withValue(copyFrom(portNumber).fit(FabricConstants.PORT_BITWIDTH))
                     .build();
         } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
             throw new PiInterpreterException(format(
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricTreatmentInterpreter.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricTreatmentInterpreter.java
index 6346302..00c4047 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricTreatmentInterpreter.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricTreatmentInterpreter.java
@@ -250,7 +250,7 @@
                 MplsLabel mplsLabel = modMplsInst.label();
                 try {
                     ImmutableByteSequence mplsValue =
-                            ImmutableByteSequence.fit(ImmutableByteSequence.copyFrom(mplsLabel.toInt()), 20);
+                            ImmutableByteSequence.copyFrom(mplsLabel.toInt()).fit(20);
                     PiActionParam mplsParam = new PiActionParam(FabricConstants.ACT_PRM_LABEL_ID, mplsValue);
                     return PiAction.builder()
                             // FIXME: fins a way to determine v4 or v6
diff --git a/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/FabricInterpreterTest.java b/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/FabricInterpreterTest.java
index 8d97f20..c60a5e8 100644
--- a/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/FabricInterpreterTest.java
+++ b/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/FabricInterpreterTest.java
@@ -233,7 +233,7 @@
         PiActionParam portParam = new PiActionParam(FabricConstants.ACT_PRM_PORT_NUM_ID,
                                                     ImmutableByteSequence.copyFrom(portNumVal));
         ImmutableByteSequence mplsVal =
-                ImmutableByteSequence.fit(ImmutableByteSequence.copyFrom(MPLS_10.toInt()), 20);
+                ImmutableByteSequence.copyFrom(MPLS_10.toInt()).fit(20);
         PiActionParam mplsParam = new PiActionParam(FabricConstants.ACT_PRM_LABEL_ID, mplsVal);
         PiAction expectedAction = PiAction.builder()
                 .withId(FabricConstants.ACT_NEXT_MPLS_ROUTING_V4_ID)