ONOS-6106 Adding Missing Fields in the " get flows and get devices" rest api

Change-Id: I6657b8d75388e850acaa53fe4f5be261e45a9bca
diff --git a/core/common/BUCK b/core/common/BUCK
index a00d4fd..75999d5 100644
--- a/core/common/BUCK
+++ b/core/common/BUCK
@@ -1,6 +1,7 @@
 SRC_DEPS = [
     '//lib:CORE_DEPS',
     '//incubator/api:onos-incubator-api',
+    '//core/api:onos-api',
 ]
 
 TEST_DEPS = [
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/DeviceCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/DeviceCodec.java
index 2409767..d51cb8c 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/DeviceCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/DeviceCodec.java
@@ -25,6 +25,7 @@
 import org.onosproject.net.Device.Type;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.DriverService;
 import org.onosproject.net.provider.ProviderId;
 
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -38,26 +39,31 @@
     // JSON fieldNames
     private static final String ID = "id";
     private static final String TYPE = "type";
+    private static final String AVAILABLE = "available";
+    private static final String ROLE = "role";
     private static final String MFR = "mfr";
     private static final String HW = "hw";
     private static final String SW = "sw";
     private static final String SERIAL = "serial";
     private static final String CHASSIS_ID = "chassisId";
+    private static final String DRIVER = "driver";
 
 
     @Override
     public ObjectNode encode(Device device, CodecContext context) {
         checkNotNull(device, "Device cannot be null");
         DeviceService service = context.getService(DeviceService.class);
+        DriverService driveService = context.getService(DriverService.class);
         ObjectNode result = context.mapper().createObjectNode()
                 .put(ID, device.id().toString())
                 .put(TYPE, device.type().name())
-                .put("available", service.isAvailable(device.id()))
-                .put("role", service.getRole(device.id()).toString())
+                .put(AVAILABLE, service.isAvailable(device.id()))
+                .put(ROLE, service.getRole(device.id()).toString())
                 .put(MFR, device.manufacturer())
                 .put(HW, device.hwVersion())
                 .put(SW, device.swVersion())
                 .put(SERIAL, device.serialNumber())
+                .put(DRIVER, driveService.getDriver(device.id()).name())
                 .put(CHASSIS_ID, device.chassisId().toString());
         return annotate(result, device, context);
     }
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/FlowEntryCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/FlowEntryCodec.java
index 1f2d359..9a2fd44 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/FlowEntryCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/FlowEntryCodec.java
@@ -54,6 +54,7 @@
                 .put("life", flowEntry.life()) //FIXME life is destroying precision (seconds granularity is default)
                 .put("packets", flowEntry.packets())
                 .put("bytes", flowEntry.bytes())
+                .put("liveType", flowEntry.liveType().toString())
                 .put("lastSeen", flowEntry.lastSeen());
 
         if (flowEntry.treatment() != null) {
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/DeviceCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/DeviceCodecTest.java
index 321385c..40334df 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/DeviceCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/DeviceCodecTest.java
@@ -20,18 +20,30 @@
 import static org.hamcrest.Matchers.notNullValue;
 import static org.hamcrest.Matchers.is;
 import static org.onosproject.codec.impl.JsonCodecUtils.assertJsonEncodable;
-
+import com.google.common.collect.ImmutableMap;
 import org.junit.Test;
 import org.onosproject.codec.JsonCodec;
 import org.onosproject.net.DefaultDevice;
 import org.onosproject.net.Device;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.createMock;
 import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.DriverService;
 import org.onosproject.net.device.DeviceServiceAdapter;
+import org.onosproject.net.driver.DefaultDriver;
+import org.onosproject.net.driver.TestBehaviourImpl;
+import org.onosproject.net.driver.TestBehaviour;
+import org.onosproject.net.driver.TestBehaviourTwo;
+import org.onosproject.net.driver.TestBehaviourTwoImpl;
+
+import java.util.ArrayList;
 
 /**
  * Unit test for DeviceCodec.
  */
 public class DeviceCodecTest {
+    DriverService mockDriverService = createMock(DriverService.class);
 
     private Device device = new DefaultDevice(JsonCodecUtils.PID,
                                               JsonCodecUtils.DID1,
@@ -42,15 +54,28 @@
                                               JsonCodecUtils.SN,
                                               JsonCodecUtils.CID,
                                               JsonCodecUtils.A1);
-
-
+    private DefaultDriver driver = new DefaultDriver("ovs", new ArrayList<>(), "Circus", "lux", "1.2a",
+            ImmutableMap.of(TestBehaviour.class,
+                    TestBehaviourImpl.class,
+                    TestBehaviourTwo.class,
+                    TestBehaviourTwoImpl.class),
+            ImmutableMap.of("foo", "bar"));
 
     @Test
     public void deviceCodecTest() {
         final MockCodecContext context = new MockCodecContext();
+
+        expect(mockDriverService.getDriver(JsonCodecUtils.DID1))
+                .andReturn(driver)
+                .anyTimes();
+
+        replay(mockDriverService);
+
         context.registerService(DeviceService.class, new DeviceServiceAdapter());
+        context.registerService(DriverService.class, mockDriverService);
         final JsonCodec<Device> codec = context.codec(Device.class);
         assertThat(codec, is(notNullValue()));
+
         final Device pojoIn = device;
 
         assertJsonEncodable(context, codec, pojoIn);