Refactor OpenstackTelemetry App for better readability
Change-Id: I93353de31fb9671d8670ee44fc248fe7f36ac12b
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
index 35547b2..8b28797 100644
--- 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
@@ -35,14 +35,19 @@
public class TinaFlowInfoByteBufferCodec extends ByteBufferCodec<FlowInfo> {
private static final int MESSAGE_SIZE = 88;
+ private static final String OF_PREFIX = "of:";
@Override
public ByteBuffer encode(FlowInfo flowInfo) {
ByteBuffer byteBuffer = ByteBuffer.allocate(MESSAGE_SIZE);
+ String deviceId = flowInfo.deviceId().toString();
+ short switchId = (short) Integer.parseInt(deviceId.substring(3,
+ deviceId.length()), 16);
+
byteBuffer.put(flowInfo.flowType())
- .putShort(Short.valueOf(flowInfo.deviceId().toString()))
+ .putShort(switchId)
.putInt(flowInfo.inputInterfaceId())
.putInt(flowInfo.outputInterfaceId())
.putShort(flowInfo.vlanId().toShort())
@@ -67,7 +72,8 @@
public FlowInfo decode(ByteBuffer byteBuffer) {
byte flowType = byteBuffer.get();
- DeviceId deviceId = DeviceId.deviceId(String.valueOf(byteBuffer.getShort()));
+ String deviceIdStr = String.format("%016x", byteBuffer.getShort());
+ DeviceId deviceId = DeviceId.deviceId(OF_PREFIX + deviceIdStr);
int inputInterfaceId = byteBuffer.getInt();
int outputInterfaceId = byteBuffer.getInt();
VlanId vlanId = VlanId.vlanId(byteBuffer.getShort());