Handle huge egress port number in PreReplicaCodec

When using logical port for replica such as SDN CPU port (0xfffffffd), the
PreReplicaCodec will throw an ArithmeticException since this value is too
big for an signed 32-bit integer.

In that example, we need to convert the value to -3

According to the protobuf document[1]:
"In Java, unsigned 32-bit and 64-bit integers are represented using their
signed counterparts, with the top bit simply being stored in the sign bit."

[1]: https://developers.google.com/protocol-buffers/docs/proto#scalar

Change-Id: Ie3bda828d499b7d26d7b790f9ed76bb687243e57
diff --git a/protocols/p4runtime/utils/src/main/java/org/onosproject/p4runtime/ctl/codec/PreReplicaCodec.java b/protocols/p4runtime/utils/src/main/java/org/onosproject/p4runtime/ctl/codec/PreReplicaCodec.java
index 7402b14..315e269 100644
--- a/protocols/p4runtime/utils/src/main/java/org/onosproject/p4runtime/ctl/codec/PreReplicaCodec.java
+++ b/protocols/p4runtime/utils/src/main/java/org/onosproject/p4runtime/ctl/codec/PreReplicaCodec.java
@@ -16,6 +16,7 @@
 
 package org.onosproject.p4runtime.ctl.codec;
 
+import com.google.common.primitives.UnsignedInteger;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.pi.model.PiPipeconf;
 import org.onosproject.net.pi.runtime.PiPreReplica;
@@ -37,8 +38,9 @@
             throws CodecException, P4InfoBrowser.NotFoundException {
         final int p4PortId;
         try {
-            p4PortId = Math.toIntExact(replica.egressPort().toLong());
-        } catch (ArithmeticException e) {
+            UnsignedInteger egressPort = UnsignedInteger.valueOf(replica.egressPort().toLong());
+            p4PortId = egressPort.intValue();
+        } catch (IllegalArgumentException e) {
             throw new CodecException(format(
                     "Cannot cast 64 bit port value '%s' to 32 bit",
                     replica.egressPort()));