[ONOS-7683] Add ByteBuffer codec of StatsInfo and FlowInfo w/ tests

Change-Id: Ifbc09093954c8f1c073febc8199b2013e3d01714
diff --git a/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/FlowInfo.java b/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/FlowInfo.java
index 502d692..7507482 100644
--- a/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/FlowInfo.java
+++ b/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/FlowInfo.java
@@ -17,9 +17,9 @@
 
 import org.onlab.packet.IpPrefix;
 import org.onlab.packet.MacAddress;
+import org.onlab.packet.TpPort;
 import org.onlab.packet.VlanId;
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 
 /**
  * Flow info interface.
@@ -87,14 +87,14 @@
      *
      * @return source port
      */
-    PortNumber srcPort();
+    TpPort srcPort();
 
     /**
      * Obtains destination port.
      *
      * @return destination port
      */
-    PortNumber dstPort();
+    TpPort dstPort();
 
     /**
      * Obtains protocol type.
@@ -196,7 +196,7 @@
          * @param srcPort source port number
          * @return builder instance
          */
-        Builder withSrcPort(PortNumber srcPort);
+        Builder withSrcPort(TpPort srcPort);
 
         /**
          * Sets destination port number.
@@ -204,7 +204,7 @@
          * @param dstPort destination port number
          * @return builder instance
          */
-        Builder withDstPort(PortNumber dstPort);
+        Builder withDstPort(TpPort dstPort);
 
         /**
          * Sets protocol type.
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/codec/TinaFlowInfoByteBufferCodec.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/codec/TinaFlowInfoByteBufferCodec.java
new file mode 100644
index 0000000..35547b2
--- /dev/null
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/codec/TinaFlowInfoByteBufferCodec.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstacktelemetry.codec;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpAddress.Version;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.TpPort;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.DeviceId;
+import org.onosproject.openstacktelemetry.api.ByteBufferCodec;
+import org.onosproject.openstacktelemetry.api.FlowInfo;
+import org.onosproject.openstacktelemetry.api.StatsInfo;
+import org.onosproject.openstacktelemetry.impl.DefaultFlowInfo;
+
+import java.nio.ByteBuffer;
+
+/**
+ * FlowInfo ByteBuffer Codec.
+ */
+public class TinaFlowInfoByteBufferCodec extends ByteBufferCodec<FlowInfo> {
+
+    private static final int MESSAGE_SIZE = 88;
+
+    @Override
+    public ByteBuffer encode(FlowInfo flowInfo) {
+
+        ByteBuffer byteBuffer = ByteBuffer.allocate(MESSAGE_SIZE);
+
+        byteBuffer.put(flowInfo.flowType())
+                .putShort(Short.valueOf(flowInfo.deviceId().toString()))
+                .putInt(flowInfo.inputInterfaceId())
+                .putInt(flowInfo.outputInterfaceId())
+                .putShort(flowInfo.vlanId().toShort())
+                .put(flowInfo.srcIp().address().toOctets())
+                .put((byte) flowInfo.srcIp().prefixLength())
+                .putShort((short) flowInfo.srcPort().toInt())
+                .put(flowInfo.dstIp().address().toOctets())
+                .put((byte) flowInfo.dstIp().prefixLength())
+                .putShort((short) flowInfo.dstPort().toInt())
+                .put(flowInfo.protocol())
+                .put(flowInfo.srcMac().toBytes())
+                .put(flowInfo.dstMac().toBytes());
+
+        TinaStatsInfoByteBufferCodec statsInfoByteBufferCodec =
+                new TinaStatsInfoByteBufferCodec();
+        byteBuffer.put(statsInfoByteBufferCodec.encode(flowInfo.statsInfo()).array());
+
+        return byteBuffer;
+    }
+
+    @Override
+    public FlowInfo decode(ByteBuffer byteBuffer) {
+
+        byte flowType = byteBuffer.get();
+        DeviceId deviceId = DeviceId.deviceId(String.valueOf(byteBuffer.getShort()));
+        int inputInterfaceId = byteBuffer.getInt();
+        int outputInterfaceId = byteBuffer.getInt();
+        VlanId vlanId = VlanId.vlanId(byteBuffer.getShort());
+        IpAddress srcIp = IpAddress.valueOf(Version.INET, getIpv4Octets(byteBuffer));
+        int srcPrefixLen = byteBuffer.get();
+        TpPort srcPort = TpPort.tpPort((int) byteBuffer.getShort());
+        IpAddress dstIp = IpAddress.valueOf(Version.INET, getIpv4Octets(byteBuffer));
+        int dstPrefixLen = byteBuffer.get();
+        TpPort dstPort = TpPort.tpPort((int) byteBuffer.getShort());
+
+        byte protocol = byteBuffer.get();
+        MacAddress srcMac = MacAddress.valueOf(getMacByteArray(byteBuffer));
+        MacAddress dstMac = MacAddress.valueOf(getMacByteArray(byteBuffer));
+
+        TinaStatsInfoByteBufferCodec statsInfoByteBufferCodec =
+                new TinaStatsInfoByteBufferCodec();
+        StatsInfo statsInfo = statsInfoByteBufferCodec.decode(byteBuffer);
+
+        return new DefaultFlowInfo.DefaultBuilder()
+                .withFlowType(flowType)
+                .withDeviceId(deviceId)
+                .withInputInterfaceId(inputInterfaceId)
+                .withOutputInterfaceId(outputInterfaceId)
+                .withVlanId(vlanId)
+                .withSrcIp(IpPrefix.valueOf(srcIp, srcPrefixLen))
+                .withSrcPort(srcPort)
+                .withDstIp(IpPrefix.valueOf(dstIp, dstPrefixLen))
+                .withDstPort(dstPort)
+                .withProtocol(protocol)
+                .withSrcMac(srcMac)
+                .withDstMac(dstMac)
+                .withStatsInfo(statsInfo)
+                .build();
+    }
+
+    /**
+     * Obtains IPv4 Octets from ByteBuffer.
+     *
+     * @param buffer byte buffer
+     * @return Ipv4 Octets
+     */
+    private byte[] getIpv4Octets(ByteBuffer buffer) {
+        byte[] octets = new byte[4];
+        for (int i = 0; i < octets.length; i++) {
+            octets[i] = buffer.get();
+        }
+        return octets;
+    }
+
+    /**
+     * Obtains MAC address byte array from ByteBuffer.
+     *
+     * @param buffer byte buffer
+     * @return MAC address byte array
+     */
+    private byte[] getMacByteArray(ByteBuffer buffer) {
+        byte[] array = new byte[6];
+        for (int i = 0; i < array.length; i++) {
+            array[i] = buffer.get();
+        }
+        return array;
+    }
+}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/codec/TinaStatsInfoByteBufferCodec.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/codec/TinaStatsInfoByteBufferCodec.java
new file mode 100644
index 0000000..ce3faa8
--- /dev/null
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/codec/TinaStatsInfoByteBufferCodec.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstacktelemetry.codec;
+
+import org.onosproject.openstacktelemetry.api.ByteBufferCodec;
+import org.onosproject.openstacktelemetry.api.StatsInfo;
+import org.onosproject.openstacktelemetry.impl.DefaultStatsInfo;
+
+import java.nio.ByteBuffer;
+
+/**
+ * StatsInfo ByteBuffer Codec.
+ */
+public class TinaStatsInfoByteBufferCodec extends ByteBufferCodec<StatsInfo> {
+
+    private static final int MESSAGE_SIZE = 48;
+
+    @Override
+    public ByteBuffer encode(StatsInfo statsInfo) {
+
+        ByteBuffer byteBuffer = ByteBuffer.allocate(MESSAGE_SIZE);
+
+        byteBuffer.putLong(statsInfo.startupTime())
+                .putLong(statsInfo.fstPktArrTime())
+                .putInt(statsInfo.lstPktOffset())
+                .putLong(statsInfo.prevAccBytes())
+                .putInt(statsInfo.prevAccPkts())
+                .putLong(statsInfo.currAccBytes())
+                .putInt(statsInfo.currAccPkts())
+                .putShort(statsInfo.errorPkts())
+                .putShort(statsInfo.dropPkts());
+
+        return byteBuffer;
+    }
+
+    @Override
+    public StatsInfo decode(ByteBuffer byteBuffer) {
+
+        long startupTime = byteBuffer.getLong();
+        long fstPktArrTime = byteBuffer.getLong();
+        int lstPktOffset = byteBuffer.getInt();
+        long prevAccBytes = byteBuffer.getLong();
+        int prevAccPkts = byteBuffer.getInt();
+        long currAccBytes = byteBuffer.getLong();
+        int currAccPkts = byteBuffer.getInt();
+        short errorPkts = byteBuffer.getShort();
+        short dropPkts = byteBuffer.getShort();
+
+        return new DefaultStatsInfo.DefaultBuilder()
+                .withStartupTime(startupTime)
+                .withFstPktArrTime(fstPktArrTime)
+                .withLstPktOffset(lstPktOffset)
+                .withPrevAccBytes(prevAccBytes)
+                .withPrevAccPkts(prevAccPkts)
+                .withCurrAccBytes(currAccBytes)
+                .withCurrAccPkts(currAccPkts)
+                .withErrorPkts(errorPkts)
+                .withDropPkts(dropPkts)
+                .build();
+    }
+}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/codec/package-info.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/codec/package-info.java
new file mode 100644
index 0000000..f7f6401
--- /dev/null
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/codec/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Implementations of the codec broker and openstack telemetry entity codecs.
+ */
+package org.onosproject.openstacktelemetry.codec;
\ No newline at end of file
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/DefaultFlowInfo.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/DefaultFlowInfo.java
index b7a9545..74a5016 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/DefaultFlowInfo.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/DefaultFlowInfo.java
@@ -17,9 +17,9 @@
 
 import org.onlab.packet.IpPrefix;
 import org.onlab.packet.MacAddress;
+import org.onlab.packet.TpPort;
 import org.onlab.packet.VlanId;
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.openstacktelemetry.api.FlowInfo;
 import org.onosproject.openstacktelemetry.api.StatsInfo;
 
@@ -41,8 +41,8 @@
     private final short vxlanId;
     private final IpPrefix srcIp;
     private final IpPrefix dstIp;
-    private final PortNumber srcPort;
-    private final PortNumber dstPort;
+    private final TpPort srcPort;
+    private final TpPort dstPort;
     private final byte protocol;
     private final MacAddress srcMac;
     private final MacAddress dstMac;
@@ -51,7 +51,7 @@
     private DefaultFlowInfo(byte flowType, DeviceId deviceId,
                             int inputInterfaceId, int outputInterfaceId,
                             VlanId vlanId, short vxlanId, IpPrefix srcIp,
-                            IpPrefix dstIp, PortNumber srcPort, PortNumber dstPort,
+                            IpPrefix dstIp, TpPort srcPort, TpPort dstPort,
                             byte protocol, MacAddress srcMac, MacAddress dstMac,
                             StatsInfo statsInfo) {
         this.flowType = flowType;
@@ -111,12 +111,12 @@
     }
 
     @Override
-    public PortNumber srcPort() {
+    public TpPort srcPort() {
         return srcPort;
     }
 
     @Override
-    public PortNumber dstPort() {
+    public TpPort dstPort() {
         return dstPort;
     }
 
@@ -206,8 +206,8 @@
         private short vxlanId;
         private IpPrefix srcIp;
         private IpPrefix dstIp;
-        private PortNumber srcPort;
-        private PortNumber dstPort;
+        private TpPort srcPort;
+        private TpPort dstPort;
         private byte protocol;
         private MacAddress srcMac;
         private MacAddress dstMac;
@@ -262,13 +262,13 @@
         }
 
         @Override
-        public Builder withSrcPort(PortNumber srcPort) {
+        public Builder withSrcPort(TpPort srcPort) {
             this.srcPort = srcPort;
             return this;
         }
 
         @Override
-        public Builder withDstPort(PortNumber dstPort) {
+        public Builder withDstPort(TpPort dstPort) {
             this.dstPort = dstPort;
             return this;
         }
diff --git a/apps/openstacktelemetry/app/src/test/java/org/onosproject/openstacktelemetry/codec/TestTinaFlowInfoByteBufferCodec.java b/apps/openstacktelemetry/app/src/test/java/org/onosproject/openstacktelemetry/codec/TestTinaFlowInfoByteBufferCodec.java
new file mode 100644
index 0000000..110bfc2
--- /dev/null
+++ b/apps/openstacktelemetry/app/src/test/java/org/onosproject/openstacktelemetry/codec/TestTinaFlowInfoByteBufferCodec.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstacktelemetry.codec;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.TpPort;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.DeviceId;
+import org.onosproject.openstacktelemetry.api.FlowInfo;
+import org.onosproject.openstacktelemetry.api.StatsInfo;
+import org.onosproject.openstacktelemetry.impl.DefaultFlowInfo;
+import org.onosproject.openstacktelemetry.impl.DefaultStatsInfo;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Unit tests for TinaFlowInfoByteBufferCodec.
+ */
+public final class TestTinaFlowInfoByteBufferCodec {
+
+    private static final byte FLOW_TYPE = 1;
+    private static final DeviceId DEVICE_ID = DeviceId.deviceId("1234");
+    private static final int INPUT_INTERFACE_ID = 10;
+    private static final int OUTPUT_INTERFACE_ID = 10;
+    private static final VlanId VLAN_ID = VlanId.vlanId("100");
+    private static final IpAddress SRC_IP_ADDRESS = IpAddress.valueOf("10.10.10.1");
+    private static final IpPrefix SRC_IP_PREFIX = IpPrefix.valueOf(SRC_IP_ADDRESS, 24);
+    private static final IpAddress DST_IP_ADDRESS = IpAddress.valueOf("20.20.20.1");
+    private static final IpPrefix DST_IP_PREFIX = IpPrefix.valueOf(DST_IP_ADDRESS, 24);
+    private static final TpPort SRC_PORT_NUMBER = TpPort.tpPort(1000);
+    private static final TpPort DST_PORT_NUMBER = TpPort.tpPort(2000);
+    private static final byte PROTOCOL = 10;
+    private static final MacAddress SRC_MAC_ADDRESS = MacAddress.valueOf("AA:BB:CC:DD:EE:FF");
+    private static final MacAddress DST_MAC_ADDRESS = MacAddress.valueOf("FF:EE:DD:CC:BB:AA");
+
+    private FlowInfo info;
+    private final TinaFlowInfoByteBufferCodec codec =
+            new TinaFlowInfoByteBufferCodec();
+
+    @Before
+    public void setup() {
+        StatsInfo statsInfo = new DefaultStatsInfo.DefaultBuilder().build();
+        FlowInfo.Builder builder = new DefaultFlowInfo.DefaultBuilder();
+
+        info = builder
+                .withFlowType(FLOW_TYPE)
+                .withDeviceId(DEVICE_ID)
+                .withInputInterfaceId(INPUT_INTERFACE_ID)
+                .withOutputInterfaceId(OUTPUT_INTERFACE_ID)
+                .withVlanId(VLAN_ID)
+                .withSrcIp(SRC_IP_PREFIX)
+                .withDstIp(DST_IP_PREFIX)
+                .withSrcPort(SRC_PORT_NUMBER)
+                .withDstPort(DST_PORT_NUMBER)
+                .withProtocol(PROTOCOL)
+                .withSrcMac(SRC_MAC_ADDRESS)
+                .withDstMac(DST_MAC_ADDRESS)
+                .withStatsInfo(statsInfo)
+                .build();
+    }
+
+    @Test
+    public void testEncodeDecode() {
+        ByteBuffer buffer = codec.encode(info);
+        FlowInfo decoded = codec.decode(ByteBuffer.wrap(buffer.array()));
+        new EqualsTester().addEqualityGroup(info, decoded).testEquals();
+    }
+}
diff --git a/apps/openstacktelemetry/app/src/test/java/org/onosproject/openstacktelemetry/codec/TestTinaStatsInfoByteBufferCodec.java b/apps/openstacktelemetry/app/src/test/java/org/onosproject/openstacktelemetry/codec/TestTinaStatsInfoByteBufferCodec.java
new file mode 100644
index 0000000..04a527b
--- /dev/null
+++ b/apps/openstacktelemetry/app/src/test/java/org/onosproject/openstacktelemetry/codec/TestTinaStatsInfoByteBufferCodec.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstacktelemetry.codec;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.openstacktelemetry.api.StatsInfo;
+import org.onosproject.openstacktelemetry.impl.DefaultStatsInfo;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Unit tests for TinaStatsInfoByteBufferCodef.
+ */
+public class TestTinaStatsInfoByteBufferCodec {
+
+    private static final int STARTUP_TIME = 1000;
+    private static final int CURRENT_ACCUMULATED_PACKETS = 8000;
+    private static final long CURRENT_ACCUMULATED_BYTES = 9000;
+    private static final int PREVIOUS_ACCUMULATED_PACKETS = 8000;
+    private static final long PREVIOUS_ACCUMULATED_BYTES = 9000;
+    private static final long FIRST_PACKET_ARRIVAL_TIME = 10000;
+    private static final int LAST_PACKET_OFFSET = 20000;
+    private static final short ERROR_PACKETS = 30000;
+    private static final short DROP_PACKETS = 30000;
+
+    private StatsInfo info;
+    private final TinaStatsInfoByteBufferCodec codec =
+                                            new TinaStatsInfoByteBufferCodec();
+
+    @Before
+    public void setup() {
+        StatsInfo.Builder builder = new DefaultStatsInfo.DefaultBuilder();
+
+        info = builder
+                .withStartupTime(STARTUP_TIME)
+                .withCurrAccPkts(CURRENT_ACCUMULATED_PACKETS)
+                .withCurrAccBytes(CURRENT_ACCUMULATED_BYTES)
+                .withPrevAccPkts(PREVIOUS_ACCUMULATED_PACKETS)
+                .withPrevAccBytes(PREVIOUS_ACCUMULATED_BYTES)
+                .withFstPktArrTime(FIRST_PACKET_ARRIVAL_TIME)
+                .withLstPktOffset(LAST_PACKET_OFFSET)
+                .withErrorPkts(ERROR_PACKETS)
+                .withDropPkts(DROP_PACKETS)
+                .build();
+    }
+
+    @Test
+    public void testEncodeDecode() {
+        ByteBuffer buffer = codec.encode(info);
+        StatsInfo decoded = codec.decode(ByteBuffer.wrap(buffer.array()));
+        new EqualsTester().addEqualityGroup(info, decoded).testEquals();
+    }
+}
diff --git a/apps/openstacktelemetry/app/src/test/java/org/onosproject/openstacktelemetry/impl/TestDefaultFlowInfo.java b/apps/openstacktelemetry/app/src/test/java/org/onosproject/openstacktelemetry/impl/TestDefaultFlowInfo.java
index e661672..fcbbdc5 100644
--- a/apps/openstacktelemetry/app/src/test/java/org/onosproject/openstacktelemetry/impl/TestDefaultFlowInfo.java
+++ b/apps/openstacktelemetry/app/src/test/java/org/onosproject/openstacktelemetry/impl/TestDefaultFlowInfo.java
@@ -21,9 +21,9 @@
 import org.onlab.packet.IpAddress;
 import org.onlab.packet.IpPrefix;
 import org.onlab.packet.MacAddress;
+import org.onlab.packet.TpPort;
 import org.onlab.packet.VlanId;
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.openstacktelemetry.api.FlowInfo;
 import org.onosproject.openstacktelemetry.api.StatsInfo;
 
@@ -76,8 +76,8 @@
                         IpAddress.valueOf(IP_ADDRESS_1), IP_PREFIX_LENGTH_1))
                 .withDstIp(IpPrefix.valueOf(
                         IpAddress.valueOf(IP_ADDRESS_1), IP_PREFIX_LENGTH_1))
-                .withSrcPort(PortNumber.portNumber(PORT_1))
-                .withDstPort(PortNumber.portNumber(PORT_1))
+                .withSrcPort(TpPort.tpPort(PORT_1))
+                .withDstPort(TpPort.tpPort(PORT_1))
                 .withProtocol((byte) STATIC_INTEGER_1)
                 .withVlanId(VlanId.vlanId(STATIC_STRING_1))
                 .withSrcMac(MacAddress.valueOf(MAC_ADDRESS_1))
@@ -94,8 +94,8 @@
                         IpAddress.valueOf(IP_ADDRESS_1), IP_PREFIX_LENGTH_1))
                 .withDstIp(IpPrefix.valueOf(
                         IpAddress.valueOf(IP_ADDRESS_1), IP_PREFIX_LENGTH_1))
-                .withSrcPort(PortNumber.portNumber(PORT_1))
-                .withDstPort(PortNumber.portNumber(PORT_1))
+                .withSrcPort(TpPort.tpPort(PORT_1))
+                .withDstPort(TpPort.tpPort(PORT_1))
                 .withProtocol((byte) STATIC_INTEGER_1)
                 .withVlanId(VlanId.vlanId(STATIC_STRING_1))
                 .withSrcMac(MacAddress.valueOf(MAC_ADDRESS_1))
@@ -112,8 +112,8 @@
                         IpAddress.valueOf(IP_ADDRESS_2), IP_PREFIX_LENGTH_2))
                 .withDstIp(IpPrefix.valueOf(
                         IpAddress.valueOf(IP_ADDRESS_2), IP_PREFIX_LENGTH_2))
-                .withSrcPort(PortNumber.portNumber(PORT_2))
-                .withDstPort(PortNumber.portNumber(PORT_2))
+                .withSrcPort(TpPort.tpPort(PORT_2))
+                .withDstPort(TpPort.tpPort(PORT_2))
                 .withProtocol((byte) STATIC_INTEGER_2)
                 .withVlanId(VlanId.vlanId(STATIC_STRING_2))
                 .withSrcMac(MacAddress.valueOf(MAC_ADDRESS_2))
@@ -141,8 +141,8 @@
                 IpAddress.valueOf(IP_ADDRESS_1), IP_PREFIX_LENGTH_1)));
         assertThat(info.dstIp(), is(IpPrefix.valueOf(
                 IpAddress.valueOf(IP_ADDRESS_1), IP_PREFIX_LENGTH_1)));
-        assertThat(info.srcPort(), is(PortNumber.portNumber(PORT_1)));
-        assertThat(info.dstPort(), is(PortNumber.portNumber(PORT_1)));
+        assertThat(info.srcPort(), is(TpPort.tpPort(PORT_1)));
+        assertThat(info.dstPort(), is(TpPort.tpPort(PORT_1)));
         assertThat(info.protocol(), is((byte) STATIC_INTEGER_1));
         assertThat(info.vlanId(), is(VlanId.vlanId(STATIC_STRING_1)));
         assertThat(info.srcMac(), is(MacAddress.valueOf(MAC_ADDRESS_1)));