Fixed silly bug with downlink teid
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnP4Communicator.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnP4Communicator.java
index 9f8bad6..f795769 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnP4Communicator.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnP4Communicator.java
@@ -16,13 +16,12 @@
 
 package org.onosproject.fpcagent.protocols;
 
-import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
+import org.apache.commons.lang.ArrayUtils;
 import org.onlab.packet.Ip4Address;
-import org.onlab.packet.VlanId;
+import org.onlab.util.ImmutableByteSequence;
 import org.onosproject.core.ApplicationId;
-import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.flow.DefaultFlowRule;
 import org.onosproject.net.flow.DefaultTrafficSelector;
@@ -31,8 +30,6 @@
 import org.onosproject.net.flow.FlowRuleOperations;
 import org.onosproject.net.flow.FlowRuleService;
 import org.onosproject.net.flow.criteria.PiCriterion;
-import org.onosproject.net.host.InterfaceIpAddress;
-import org.onosproject.net.intf.Interface;
 import org.onosproject.net.intf.InterfaceAdminService;
 import org.onosproject.net.pi.model.PiActionId;
 import org.onosproject.net.pi.model.PiActionParamId;
@@ -49,9 +46,8 @@
 import org.slf4j.LoggerFactory;
 
 import java.math.BigInteger;
+import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
@@ -229,14 +225,14 @@
             Route route = new Route(Route.Source.STATIC, ueAddr.toIpPrefix(), s1UEnodebIpv4);
             routeStore.updateRoute(route);
 
-            List<InterfaceIpAddress> ifaceIpAddrList = Lists.newArrayList();
-            ifaceIpAddrList.add(InterfaceIpAddress.valueOf(s1USgwIpv4.toString()));
-            Interface intf = new Interface(
-                    "s1u-sgw",
-                    ConnectPoint.deviceConnectPoint(deviceId.toString() + "/" + 144),
-                    ifaceIpAddrList, null, VlanId.NONE, VlanId.vlanId((short) 20),
-                    Collections.emptySet(), VlanId.NONE);
-            interfaceService.add(intf);
+//            List<InterfaceIpAddress> ifaceIpAddrList = Lists.newArrayList();
+//            ifaceIpAddrList.add(InterfaceIpAddress.valueOf(s1USgwIpv4.toIpPrefix().toString()));
+//            Interface intf = new Interface(
+//                    "s1u-sgw",
+//                    ConnectPoint.deviceConnectPoint(deviceId.toString() + "/" + 144),
+//                    ifaceIpAddrList, null, VlanId.NONE, VlanId.vlanId((short) 20),
+//                    Collections.emptySet(), VlanId.NONE);
+//            interfaceService.add(intf);
 
             applySessionRules(sessionId);
 
@@ -334,11 +330,18 @@
 
     private FlowRule dlSessLookupRule(Ip4Address ueAddr, long teid,
                                       Ip4Address enbAddr, Ip4Address s1uAddr) {
+
+        // FIXME: the long teid is obtained from the wrong byte order
+        ImmutableByteSequence teidBs = copyFrom(teid);
+        byte[] byteArray = teidBs.asArray();
+        ArrayUtils.reverse(byteArray);
+        byte[] trimmedArray = Arrays.copyOfRange(byteArray, 0, 4);
+        ImmutableByteSequence revTeidBs = copyFrom(trimmedArray);
+
         // Add rule to
         final PiAction action = PiAction.builder()
                 .withId(ACT_ID_SET_DL_SESS_INFO)
-                .withParameter(new PiActionParam(TEID,
-                                                 copyFrom(teid)))
+                .withParameter(new PiActionParam(TEID, revTeidBs))
                 .withParameter(new PiActionParam(PARAM_S1U_ENB_ADDR,
                                                  copyFrom(enbAddr.toOctets())))
                 .withParameter(new PiActionParam(PARAM_ID_S1U_SGW_ADDR,