[SEBA-568] Adding Serial number to authentication and DHCP events

Change-Id: I00b030687021948f5fc5d575b2f13adb5fe8b143
diff --git a/src/main/java/org/opencord/kafka/integrations/AaaKafkaIntegration.java b/src/main/java/org/opencord/kafka/integrations/AaaKafkaIntegration.java
index 6db44cb..a09cb41 100644
--- a/src/main/java/org/opencord/kafka/integrations/AaaKafkaIntegration.java
+++ b/src/main/java/org/opencord/kafka/integrations/AaaKafkaIntegration.java
@@ -24,6 +24,8 @@
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.device.DeviceService;
 import org.opencord.aaa.AuthenticationEvent;
 import org.opencord.aaa.AuthenticationEventListener;
 import org.opencord.aaa.AuthenticationService;
@@ -44,6 +46,9 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected EventBusService eventBusService;
 
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceService deviceService;
+
     @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY,
             bind = "bindAuthenticationService",
             unbind = "unbindAuthenticationService")
@@ -56,6 +61,7 @@
     private static final String TIMESTAMP = "timestamp";
     private static final String DEVICE_ID = "deviceId";
     private static final String PORT_NUMBER = "portNumber";
+    private static final String SERIAL_NUMBER = "serialNumber";
     private static final String AUTHENTICATION_STATE = "authenticationState";
 
     protected void bindAuthenticationService(AuthenticationService authenticationService) {
@@ -95,11 +101,15 @@
     }
 
     private JsonNode serialize(AuthenticationEvent event) {
+
+        String sn = deviceService.getPort(event.subject()).annotations().value(AnnotationKeys.PORT_NAME);
+
         ObjectMapper mapper = new ObjectMapper();
         ObjectNode authEvent = mapper.createObjectNode();
         authEvent.put(TIMESTAMP, Instant.now().toString());
         authEvent.put(DEVICE_ID, event.subject().deviceId().toString());
         authEvent.put(PORT_NUMBER, event.subject().port().toString());
+        authEvent.put(SERIAL_NUMBER, sn);
         authEvent.put(AUTHENTICATION_STATE, event.type().toString());
         return authEvent;
     }
diff --git a/src/main/java/org/opencord/kafka/integrations/DhcpL2RelayKafkaIntegration.java b/src/main/java/org/opencord/kafka/integrations/DhcpL2RelayKafkaIntegration.java
index 3eca723..867bcfe 100644
--- a/src/main/java/org/opencord/kafka/integrations/DhcpL2RelayKafkaIntegration.java
+++ b/src/main/java/org/opencord/kafka/integrations/DhcpL2RelayKafkaIntegration.java
@@ -24,6 +24,8 @@
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.device.DeviceService;
 import org.opencord.dhcpl2relay.DhcpAllocationInfo;
 import org.opencord.dhcpl2relay.DhcpL2RelayEvent;
 import org.opencord.dhcpl2relay.DhcpL2RelayListener;
@@ -45,6 +47,9 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected EventBusService eventBusService;
 
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceService deviceService;
+
     @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY,
             bind = "bindDhcpL2RelayService",
             unbind = "unbindDhcpL2RelayService")
@@ -56,9 +61,10 @@
 
     private static final String TIMESTAMP = "timestamp";
     private static final String DEVICE_ID = "deviceId";
+    private static final String PORT_NUMBER = "portNumber";
+    private static final String SERIAL_NUMBER = "serialNumber";
     private static final String TYPE = "type";
     private static final String MESSAGE_TYPE = "messageType";
-    private static final String PORT_NUMBER = "portNumber";
     private static final String MAC_ADDRESS = "macAddress";
     private static final String IP_ADDRESS = "ipAddress";
 
@@ -99,14 +105,18 @@
     }
 
     private JsonNode serialize(DhcpL2RelayEvent event) {
+
+        String sn = deviceService.getPort(event.subject().location()).annotations().value(AnnotationKeys.PORT_NAME);
+
         ObjectMapper mapper = new ObjectMapper();
         ObjectNode dhcpEvent = mapper.createObjectNode();
         DhcpAllocationInfo allocationInfo = event.subject();
         dhcpEvent.put(TYPE, event.type().toString());
         dhcpEvent.put(TIMESTAMP, Instant.now().toString());
         dhcpEvent.put(DEVICE_ID, event.connectPoint().deviceId().toString());
-        dhcpEvent.put(MESSAGE_TYPE, allocationInfo.type().toString());
         dhcpEvent.put(PORT_NUMBER, event.connectPoint().port().toString());
+        dhcpEvent.put(SERIAL_NUMBER, sn);
+        dhcpEvent.put(MESSAGE_TYPE, allocationInfo.type().toString());
         dhcpEvent.put(MAC_ADDRESS, allocationInfo.macAddress().toString());
         dhcpEvent.put(IP_ADDRESS, allocationInfo.ipAddress().toString());
         return dhcpEvent;