blob: 0fd58b124c30900fb4b3345394f729feb4212ed2 [file] [log] [blame]
Jonathan Hart501f7882018-07-24 14:39:57 -07001/*
Joey Armstrong89c55e02023-01-09 18:09:41 -05002 * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors
Jonathan Hart501f7882018-07-24 14:39:57 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.opencord.kafka.integrations;
Carmelo Cascone7e73fa12019-07-15 18:29:01 -070018
Jonathan Hart501f7882018-07-24 14:39:57 -070019import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.ObjectMapper;
21import com.fasterxml.jackson.databind.node.ObjectNode;
Matteo Scandolo580fb7f2019-04-17 15:33:15 -070022import org.onosproject.net.AnnotationKeys;
23import org.onosproject.net.device.DeviceService;
Jonathan Hart501f7882018-07-24 14:39:57 -070024import org.opencord.aaa.AuthenticationEvent;
25import org.opencord.aaa.AuthenticationEventListener;
26import org.opencord.aaa.AuthenticationService;
kartikey dubey6e903092019-05-22 13:35:28 +000027import org.opencord.aaa.AuthenticationStatisticsEvent;
28import org.opencord.aaa.AuthenticationStatisticsEventListener;
29import org.opencord.aaa.AuthenticationStatisticsService;
Shubham Sharmaab296ff2019-06-27 12:31:01 +000030import org.opencord.aaa.RadiusOperationalStatusEvent;
31import org.opencord.aaa.RadiusOperationalStatusEventListener;
32import org.opencord.aaa.RadiusOperationalStatusService;
Carmelo Cascone7e73fa12019-07-15 18:29:01 -070033import org.opencord.kafka.EventBusService;
34import org.osgi.service.component.annotations.Activate;
35import org.osgi.service.component.annotations.Component;
36import org.osgi.service.component.annotations.Deactivate;
37import org.osgi.service.component.annotations.Reference;
38import org.osgi.service.component.annotations.ReferenceCardinality;
39import org.osgi.service.component.annotations.ReferencePolicy;
Kartikey Dubey648a9972019-12-02 11:03:06 +000040import org.opencord.aaa.AaaMachineStatisticsEvent;
41import org.opencord.aaa.AaaMachineStatisticsEventListener;
42import org.opencord.aaa.AaaMachineStatisticsService;
43import org.opencord.aaa.AaaSupplicantMachineStats;
Jonathan Hart501f7882018-07-24 14:39:57 -070044
Shubham Sharmaab296ff2019-06-27 12:31:01 +000045import java.time.Instant;
Carmelo Cascone7e73fa12019-07-15 18:29:01 -070046import java.util.concurrent.atomic.AtomicReference;
Jonathan Hart2aad7792018-07-31 15:09:17 -040047
Jonathan Hart501f7882018-07-24 14:39:57 -070048/**
49 * Listens for AAA events and pushes them on a Kafka bus.
50 */
51@Component(immediate = true)
Carmelo Cascone7e73fa12019-07-15 18:29:01 -070052public class AaaKafkaIntegration extends AbstractKafkaIntegration {
Jonathan Hart501f7882018-07-24 14:39:57 -070053
Carmelo Cascone7e73fa12019-07-15 18:29:01 -070054 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jonathan Hart501f7882018-07-24 14:39:57 -070055 protected EventBusService eventBusService;
56
Carmelo Cascone7e73fa12019-07-15 18:29:01 -070057 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Matteo Scandolo580fb7f2019-04-17 15:33:15 -070058 protected DeviceService deviceService;
59
Carmelo Cascone7e73fa12019-07-15 18:29:01 -070060 @Reference(cardinality = ReferenceCardinality.OPTIONAL,
Matteo Scandolod50a4d32019-04-24 12:10:21 -070061 policy = ReferencePolicy.DYNAMIC,
Matteo Scandolo03f13c12019-03-20 14:38:12 -070062 bind = "bindAuthenticationService",
63 unbind = "unbindAuthenticationService")
Carmelo Cascone7e73fa12019-07-15 18:29:01 -070064 protected volatile AuthenticationService ignore;
65 private final AtomicReference<AuthenticationService> authServiceRef = new AtomicReference<>();
66 @Reference(cardinality = ReferenceCardinality.OPTIONAL,
kartikey dubey6e903092019-05-22 13:35:28 +000067 policy = ReferencePolicy.DYNAMIC,
68 bind = "bindAuthenticationStatService",
69 unbind = "unbindAuthenticationStatService")
Carmelo Cascone7e73fa12019-07-15 18:29:01 -070070 protected volatile AuthenticationStatisticsService ignore2;
71 private final AtomicReference<AuthenticationStatisticsService> authStatServiceRef = new AtomicReference<>();
Jonathan Hart501f7882018-07-24 14:39:57 -070072
Shubham Sharmaab296ff2019-06-27 12:31:01 +000073 @Reference(cardinality = ReferenceCardinality.OPTIONAL,
74 policy = ReferencePolicy.DYNAMIC,
75 bind = "bindRadiusOperationalStatusService",
76 unbind = "unbindRadiusOperationalStatusService")
77 protected volatile RadiusOperationalStatusService ignore3;
78 protected final AtomicReference<RadiusOperationalStatusService> radiusOperationalStatusServiceRef
79 = new AtomicReference<>();
80
Kartikey Dubey648a9972019-12-02 11:03:06 +000081 @Reference(cardinality = ReferenceCardinality.OPTIONAL,
82 policy = ReferencePolicy.DYNAMIC,
83 bind = "bindAaaMachineStatisticsService",
84 unbind = "unbindAaaMachineStatisticsService")
85 protected volatile AaaMachineStatisticsService ignore4;
86 protected final AtomicReference<AaaMachineStatisticsService> machineStatisticsServiceRef = new AtomicReference<>();
87
Jonathan Hart501f7882018-07-24 14:39:57 -070088 private final AuthenticationEventListener listener = new InternalAuthenticationListener();
kartikey dubey6e903092019-05-22 13:35:28 +000089 private final AuthenticationStatisticsEventListener authenticationStatisticsEventListener =
Shubham Sharma4cf37602019-06-20 07:16:08 +000090 new InternalAuthenticationStatisticsListner();
Shubham Sharmaab296ff2019-06-27 12:31:01 +000091 private final RadiusOperationalStatusEventListener radiusOperationalStatusEventListener =
92 new InternalRadiusOperationalStatusEventListener();
Kartikey Dubey648a9972019-12-02 11:03:06 +000093 private final AaaMachineStatisticsEventListener machineStatisticsEventListener =
Jonathan Harted589982020-02-25 15:11:37 -080094 new InternalAaaMachineStatisticsListener();
Jonathan Hart501f7882018-07-24 14:39:57 -070095
kartikey dubey6e903092019-05-22 13:35:28 +000096 // topics
kishoreefa3db52020-03-23 16:09:26 +053097 protected static final String TOPIC = "authentication.events";
98 protected static final String AUTHENTICATION_STATISTICS_TOPIC = "onos.aaa.stats.kpis";
99 protected static final String RADIUS_OPERATION_STATUS_TOPIC = "radiusOperationalStatus.events";
kartikey dubey6e903092019-05-22 13:35:28 +0000100 // auth event params
Jonathan Hart2aad7792018-07-31 15:09:17 -0400101 private static final String TIMESTAMP = "timestamp";
Jonathan Hartf54e5ba2018-07-31 14:57:22 -0400102 private static final String DEVICE_ID = "deviceId";
103 private static final String PORT_NUMBER = "portNumber";
Matteo Scandolo580fb7f2019-04-17 15:33:15 -0700104 private static final String SERIAL_NUMBER = "serialNumber";
Jonathan Hartf54e5ba2018-07-31 14:57:22 -0400105 private static final String AUTHENTICATION_STATE = "authenticationState";
Jonathan Hart501f7882018-07-24 14:39:57 -0700106
kartikey dubey6e903092019-05-22 13:35:28 +0000107 // auth stats event params
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200108 private static final String RADIUS_ACCEPT_RESPONSES_RX = "radiusAccessAcceptRx";
109 private static final String RADIUS_REJECT_RESPONSES_RX = "radiusRejectResponsesRx";
110 private static final String RADIUS_CHALLENGE_RESPONSES_RX = "radiusAccessChallengeRx";
111 private static final String RADIUS_ACCESS_REQUESTS_TX = "radiusAccessRequestTx";
112 private static final String RADIUS_ACCESS_REQUESTS_IDENTITY_TX = "radiusAccessRequestIdentityTx";
113 private static final String RADIUS_ACCESS_REQUESTS_CHALLENGE_TX = "radiusAccessRequestChallengeTx";
114 private static final String RADIUS_PENDING_REQUESTS = "radiusPendingRequests";
115 private static final String TIMED_OUT_PACKETS = "timedOutPackets";
kartikey dubey6e903092019-05-22 13:35:28 +0000116 private static final String UNKNOWN_TYPE_RX = "unknownTypeRx";
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200117 private static final String INVALID_VALIDATORS_RX = "invalidValidatorsRx";
kartikey dubey6e903092019-05-22 13:35:28 +0000118 private static final String DROPPED_RESPONSES_RX = "droppedResponsesRx";
119 private static final String MALFORMED_RESPONSES_RX = "malformedResponsesRx";
120 private static final String UNKNOWN_SERVER_RX = "unknownServerRx";
121 private static final String REQUEST_RTT_MILLIS = "requestRttMillis";
122 private static final String REQUEST_RE_TX = "requestReTx";
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200123 private static final String NUM_SESSIONS_EXPIRED = "numSessionsExpired";
Shubham Sharma51207a32019-08-09 06:54:22 +0000124 private static final String EAPOL_LOGOFF_RX = "eapolLogoffRx";
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200125 private static final String EAPOL_AUTH_SUCCESS_TX = "eapolAuthSuccessTx";
126 private static final String EAPOL_AUTH_FAILURE_TX = "eapolAuthFailureTrans";
127 private static final String EAPOL_START_REQ_RX = "eapolStartRequestRx";
128 private static final String EAPOL_MD5_CHALLENGE_RESP_RX = "eapolMd5ChallengeResponseRx";
129 private static final String EAPOL_TLS_CHALLENGE_RESP = "eapolTlsRespChallenge";
Shubham Sharma51207a32019-08-09 06:54:22 +0000130 private static final String EAPOL_TRANS_RESP_NOT_NAK = "eapolTransRespNotNak";
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200131 private static final String EAPOL_CHALLENGE_REQ_TX = "eapolChallengeRequestTx";
132 private static final String EAPOL_ID_RESP_FRAMES_RX = "eapolIdentityResponseRx";
133 private static final String EAPOL_ID_MSG_RESP_TX = "eapolIdentityMsgResponseTx";
Shubham Sharma22a3e4f2019-09-16 10:07:02 +0000134 private static final String EAPOL_FRAMES_TX = "eapolFramesTx";
135 private static final String AUTH_STATE_IDLE = "authStateIdle";
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200136 private static final String EAPOL_ID_REQUEST_FRAMES_TX = "eapolIdentityRequestTx";
137 private static final String EAPOL_REQUEST_FRAMES_TX = "eapolRequestFramesTx"; //TODO check
Shubham Sharma22a3e4f2019-09-16 10:07:02 +0000138 private static final String INVALID_PKT_TYPE = "invalidPktType";
139 private static final String INVALID_BODY_LENGTH = "invalidBodyLength";
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200140 private static final String EAPOL_VALID_FRAMES_RX = "eapolValidFramesRx";
141 private static final String EAPOL_PENDING_REQUESTS = "eapolPendingRequests";
kartikey dubey6e903092019-05-22 13:35:28 +0000142
Shubham Sharmaab296ff2019-06-27 12:31:01 +0000143 private static final String OPERATIONAL_STATUS = "radiusOperationalStatus";
144
Kartikey Dubey648a9972019-12-02 11:03:06 +0000145 //Supplicant machine stats event params
146 private static final String SESSION_ID = "sessionId";
147 private static final String SESSION_NAME = "sessionName";
148 private static final String MAC_ADDRESS = "macAddress";
149 private static final String EAPOL_TYPE = "eapolType";
150 private static final String SESSION_DURATION = "sessionDuration";
151 private static final String TOTAL_FRAMES_RX = "totalFramesRx";
152 private static final String TOTAL_FRAMES_TX = "totalFramesTx";
153 private static final String TOTAL_PACKETS_RX = "totalPacketsRx";
154 private static final String TOTAL_PACKETS_TX = "totalFramesTx";
155 private static final String SESSION_TERMINATE_REASON = "sessionTerminateReason";
156 private static final String TOTAL_OCTETS_TX = "totalOctetsTx";
157 private static final String TOTAL_OCTETS_RX = "totalOctetsRx";
158
Carmelo Cascone7e73fa12019-07-15 18:29:01 -0700159 protected void bindAuthenticationService(AuthenticationService incomingService) {
160 bindAndAddListener(incomingService, authServiceRef, listener);
Matteo Scandolo03f13c12019-03-20 14:38:12 -0700161 }
162
Carmelo Cascone7e73fa12019-07-15 18:29:01 -0700163 protected void unbindAuthenticationService(AuthenticationService outgoingService) {
164 unbindAndRemoveListener(outgoingService, authServiceRef, listener);
Matteo Scandolo03f13c12019-03-20 14:38:12 -0700165 }
166
Carmelo Cascone7e73fa12019-07-15 18:29:01 -0700167 protected void bindAuthenticationStatService(AuthenticationStatisticsService incomingService) {
168 bindAndAddListener(incomingService, authStatServiceRef, authenticationStatisticsEventListener);
kartikey dubey6e903092019-05-22 13:35:28 +0000169 }
170
Carmelo Cascone7e73fa12019-07-15 18:29:01 -0700171 protected void unbindAuthenticationStatService(AuthenticationStatisticsService outgoingService) {
172 unbindAndRemoveListener(outgoingService, authStatServiceRef, authenticationStatisticsEventListener);
kartikey dubey6e903092019-05-22 13:35:28 +0000173 }
174
Shubham Sharmaab296ff2019-06-27 12:31:01 +0000175 protected void bindRadiusOperationalStatusService(
176 RadiusOperationalStatusService radiusOperationalStatusService) {
177 bindAndAddListener(radiusOperationalStatusService, radiusOperationalStatusServiceRef,
178 radiusOperationalStatusEventListener);
179 }
180
181 protected void unbindRadiusOperationalStatusService(RadiusOperationalStatusService radiusOperationalStatusService) {
182 unbindAndRemoveListener(radiusOperationalStatusService, radiusOperationalStatusServiceRef,
183 radiusOperationalStatusEventListener);
184 }
185
Kartikey Dubey648a9972019-12-02 11:03:06 +0000186 protected void bindAaaMachineStatisticsService(AaaMachineStatisticsService machineStatisticsService) {
187 bindAndAddListener(machineStatisticsService, machineStatisticsServiceRef, machineStatisticsEventListener);
188 }
189
190 protected void unbindAaaMachineStatisticsService(AaaMachineStatisticsService machineStatisticsService) {
191 unbindAndRemoveListener(machineStatisticsService, machineStatisticsServiceRef, machineStatisticsEventListener);
192 }
193
Jonathan Hart501f7882018-07-24 14:39:57 -0700194 @Activate
195 public void activate() {
Matteo Scandolod50a4d32019-04-24 12:10:21 -0700196 log.info("Started AaaKafkaIntegration");
Jonathan Hart501f7882018-07-24 14:39:57 -0700197 }
198
199 @Deactivate
200 public void deactivate() {
Carmelo Cascone7e73fa12019-07-15 18:29:01 -0700201 unbindAuthenticationService(authServiceRef.get());
202 unbindAuthenticationStatService(authStatServiceRef.get());
Matteo Scandolod50a4d32019-04-24 12:10:21 -0700203 log.info("Stopped AaaKafkaIntegration");
Jonathan Hart501f7882018-07-24 14:39:57 -0700204 }
205
206 private void handle(AuthenticationEvent event) {
207 eventBusService.send(TOPIC, serialize(event));
208 }
209
kartikey dubey6e903092019-05-22 13:35:28 +0000210 private void handleStat(AuthenticationStatisticsEvent event) {
211 eventBusService.send(AUTHENTICATION_STATISTICS_TOPIC, serializeStat(event));
Jonathan Harted589982020-02-25 15:11:37 -0800212 if (log.isTraceEnabled()) {
213 log.trace("AuthenticationStatisticsEvent sent successfully");
214 }
kartikey dubey6e903092019-05-22 13:35:28 +0000215 }
Matteo Scandolo580fb7f2019-04-17 15:33:15 -0700216
Shubham Sharmaab296ff2019-06-27 12:31:01 +0000217 private void handleOperationalStatus(RadiusOperationalStatusEvent event) {
218 eventBusService.send(RADIUS_OPERATION_STATUS_TOPIC, serializeOperationalStatus(event));
Jonathan Harted589982020-02-25 15:11:37 -0800219 if (log.isTraceEnabled()) {
220 log.trace("RadiusOperationalStatusEvent sent successfully");
221 }
Shubham Sharmaab296ff2019-06-27 12:31:01 +0000222 }
223
Kartikey Dubey648a9972019-12-02 11:03:06 +0000224 private void handleMachineStat(AaaMachineStatisticsEvent machineStatEvent) {
225 eventBusService.send(AUTHENTICATION_STATISTICS_TOPIC, serializeMachineStat(machineStatEvent));
Jonathan Harted589982020-02-25 15:11:37 -0800226 if (log.isTraceEnabled()) {
227 log.trace("MachineStatisticsEvent sent successfully");
228 }
Kartikey Dubey648a9972019-12-02 11:03:06 +0000229 }
230
kartikey dubey6e903092019-05-22 13:35:28 +0000231 private JsonNode serialize(AuthenticationEvent event) {
Matteo Scandolo580fb7f2019-04-17 15:33:15 -0700232 String sn = deviceService.getPort(event.subject()).annotations().value(AnnotationKeys.PORT_NAME);
233
Jonathan Hart501f7882018-07-24 14:39:57 -0700234 ObjectMapper mapper = new ObjectMapper();
235 ObjectNode authEvent = mapper.createObjectNode();
Jonathan Hart2aad7792018-07-31 15:09:17 -0400236 authEvent.put(TIMESTAMP, Instant.now().toString());
Jonathan Hart501f7882018-07-24 14:39:57 -0700237 authEvent.put(DEVICE_ID, event.subject().deviceId().toString());
238 authEvent.put(PORT_NUMBER, event.subject().port().toString());
Matteo Scandolo580fb7f2019-04-17 15:33:15 -0700239 authEvent.put(SERIAL_NUMBER, sn);
Jonathan Hart501f7882018-07-24 14:39:57 -0700240 authEvent.put(AUTHENTICATION_STATE, event.type().toString());
241 return authEvent;
242 }
243
kartikey dubey6e903092019-05-22 13:35:28 +0000244 private JsonNode serializeStat(AuthenticationStatisticsEvent event) {
Jonathan Harted589982020-02-25 15:11:37 -0800245 if (log.isTraceEnabled()) {
246 log.trace("Serializing AuthenticationStatisticsEvent");
247 }
kartikey dubey6e903092019-05-22 13:35:28 +0000248 ObjectMapper mapper = new ObjectMapper();
249 ObjectNode authMetricsEvent = mapper.createObjectNode();
250 authMetricsEvent.put(TIMESTAMP, Instant.now().toString());
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200251 authMetricsEvent.put(RADIUS_ACCEPT_RESPONSES_RX, event.subject().getRadiusAcceptResponsesRx());
252 authMetricsEvent.put(RADIUS_REJECT_RESPONSES_RX, event.subject().getRadiusRejectResponsesRx());
253 authMetricsEvent.put(RADIUS_CHALLENGE_RESPONSES_RX, event.subject().getRadiusChallengeResponsesRx());
254 authMetricsEvent.put(RADIUS_ACCESS_REQUESTS_IDENTITY_TX, event.subject().getRadiusReqIdTx());
255 authMetricsEvent.put(RADIUS_ACCESS_REQUESTS_CHALLENGE_TX, event.subject().getRadiusReqChallengeTx());
256 authMetricsEvent.put(RADIUS_ACCESS_REQUESTS_TX, event.subject().getRadiusAccessRequestsTx());
kartikey dubey6e903092019-05-22 13:35:28 +0000257 authMetricsEvent.put(INVALID_VALIDATORS_RX, event.subject().getInvalidValidatorsRx());
258 authMetricsEvent.put(UNKNOWN_TYPE_RX, event.subject().getUnknownTypeRx());
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200259 authMetricsEvent.put(RADIUS_PENDING_REQUESTS, event.subject().getRadiusPendingRequests());
kartikey dubey6e903092019-05-22 13:35:28 +0000260 authMetricsEvent.put(DROPPED_RESPONSES_RX, event.subject().getDroppedResponsesRx());
261 authMetricsEvent.put(MALFORMED_RESPONSES_RX, event.subject().getMalformedResponsesRx());
262 authMetricsEvent.put(UNKNOWN_SERVER_RX, event.subject().getUnknownServerRx());
263 authMetricsEvent.put(REQUEST_RTT_MILLIS, event.subject().getRequestRttMilis());
264 authMetricsEvent.put(REQUEST_RE_TX, event.subject().getRequestReTx());
Shubham Sharma4cf37602019-06-20 07:16:08 +0000265 authMetricsEvent.put(TIMED_OUT_PACKETS, event.subject().getTimedOutPackets());
Shubham Sharma51207a32019-08-09 06:54:22 +0000266 authMetricsEvent.put(EAPOL_LOGOFF_RX, event.subject().getEapolLogoffRx());
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200267 authMetricsEvent.put(EAPOL_ID_MSG_RESP_TX, event.subject().getEapolResIdentityMsgTrans());
268 authMetricsEvent.put(EAPOL_AUTH_SUCCESS_TX, event.subject().getEapolAuthSuccessTx());
269 authMetricsEvent.put(EAPOL_AUTH_FAILURE_TX, event.subject().getEapolAuthFailureTx());
270 authMetricsEvent.put(EAPOL_START_REQ_RX, event.subject().getEapolStartReqRx());
271 authMetricsEvent.put(EAPOL_CHALLENGE_REQ_TX, event.subject().getEapolChallengeReqTx());
Shubham Sharma51207a32019-08-09 06:54:22 +0000272 authMetricsEvent.put(EAPOL_TRANS_RESP_NOT_NAK, event.subject().getEapolTransRespNotNak());
Shubham Sharma22a3e4f2019-09-16 10:07:02 +0000273 authMetricsEvent.put(EAPOL_FRAMES_TX, event.subject().getEapolFramesTx());
274 authMetricsEvent.put(AUTH_STATE_IDLE, event.subject().getAuthStateIdle());
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200275 authMetricsEvent.put(EAPOL_ID_REQUEST_FRAMES_TX, event.subject().getEapolIdRequestFramesTx());
276 authMetricsEvent.put(EAPOL_REQUEST_FRAMES_TX, event.subject().getEapolReqFramesTx());
Shubham Sharma22a3e4f2019-09-16 10:07:02 +0000277 authMetricsEvent.put(INVALID_PKT_TYPE, event.subject().getInvalidPktType());
278 authMetricsEvent.put(INVALID_BODY_LENGTH, event.subject().getInvalidBodyLength());
Andrea Campanella17c3cdf2020-10-14 11:17:03 +0200279 authMetricsEvent.put(EAPOL_VALID_FRAMES_RX, event.subject().getEapolValidFramesRx());
280 authMetricsEvent.put(EAPOL_PENDING_REQUESTS, event.subject().getEapolPendingReq());
281 authMetricsEvent.put(EAPOL_ID_RESP_FRAMES_RX, event.subject().getEapolattrIdentity());
kartikey dubey6e903092019-05-22 13:35:28 +0000282 return authMetricsEvent;
283 }
284
Shubham Sharmaab296ff2019-06-27 12:31:01 +0000285 private JsonNode serializeOperationalStatus(RadiusOperationalStatusEvent event) {
Jonathan Harted589982020-02-25 15:11:37 -0800286 if (log.isTraceEnabled()) {
287 log.trace("Serializing RadiusOperationalStatusEvent: {}", event.subject());
288 }
Shubham Sharmaab296ff2019-06-27 12:31:01 +0000289 ObjectMapper mapper = new ObjectMapper();
290 ObjectNode authMetricsEvent = mapper.createObjectNode();
291 authMetricsEvent.put(TIMESTAMP, Instant.now().toString());
Shubham Sharmaab296ff2019-06-27 12:31:01 +0000292 authMetricsEvent.put(OPERATIONAL_STATUS, event.subject());
293 return authMetricsEvent;
294 }
295
Kartikey Dubey648a9972019-12-02 11:03:06 +0000296 private JsonNode serializeMachineStat(AaaMachineStatisticsEvent machineStatEvent) {
Jonathan Harted589982020-02-25 15:11:37 -0800297 if (log.isTraceEnabled()) {
298 log.trace("Serializing AuthenticationStatisticsEvent");
299 }
Kartikey Dubey648a9972019-12-02 11:03:06 +0000300 ObjectMapper mapper = new ObjectMapper();
301 ObjectNode machineStat = mapper.createObjectNode();
302 AaaSupplicantMachineStats subject = machineStatEvent.subject();
303 machineStat.put(TIMESTAMP, Instant.now().toString());
304 machineStat.put(SESSION_ID, subject.getSessionId());
305 machineStat.put(SESSION_NAME, subject.getSessionName());
306 machineStat.put(MAC_ADDRESS, subject.getSrcMacAddress());
307 machineStat.put(SESSION_DURATION, subject.getSessionDuration());
308 machineStat.put(EAPOL_TYPE, subject.getEapolType());
309 machineStat.put(TOTAL_FRAMES_RX, subject.getTotalFramesReceived());
310 machineStat.put(TOTAL_FRAMES_TX, subject.getTotalFramesSent());
311 machineStat.put(TOTAL_PACKETS_RX, subject.getTotalFramesReceived());
312 machineStat.put(TOTAL_PACKETS_TX, subject.getTotalFramesSent());
313 machineStat.put(TOTAL_OCTETS_RX, subject.getTotalOctetRecieved());
314 machineStat.put(TOTAL_OCTETS_TX, subject.getTotalOctetSent());
315 machineStat.put(SESSION_TERMINATE_REASON, subject.getSessionTerminateReason());
316 log.debug(SESSION_ID + " - " + subject.getSessionId());
317 log.debug(SESSION_NAME + " - " + subject.getSessionName());
318 log.debug(MAC_ADDRESS + " - " + subject.getSrcMacAddress());
319 log.debug(SESSION_DURATION + " - " + subject.getSessionDuration());
320 log.debug(EAPOL_TYPE + " - " + subject.getEapolType());
321 log.debug(TOTAL_FRAMES_RX + " - " + subject.getTotalFramesReceived());
322 log.debug(TOTAL_FRAMES_TX + " - " + subject.getTotalFramesSent());
323 log.debug(TOTAL_PACKETS_RX + " - " + subject.getTotalFramesReceived());
324 log.debug(TOTAL_PACKETS_TX + " - " + subject.getTotalFramesSent());
325 log.debug(TOTAL_OCTETS_RX + " - " + subject.getTotalOctetRecieved());
326 log.debug(TOTAL_OCTETS_TX + " - " + subject.getTotalOctetSent());
327 log.debug(SESSION_TERMINATE_REASON + " - " + subject.getSessionTerminateReason());
328 return machineStat;
329 }
330
Jonathan Hart501f7882018-07-24 14:39:57 -0700331 private class InternalAuthenticationListener implements
Shubham Sharma4cf37602019-06-20 07:16:08 +0000332 AuthenticationEventListener {
Jonathan Hart501f7882018-07-24 14:39:57 -0700333 @Override
334 public void event(AuthenticationEvent authenticationEvent) {
335 handle(authenticationEvent);
336 }
337 }
kartikey dubey6e903092019-05-22 13:35:28 +0000338
339 private class InternalAuthenticationStatisticsListner implements
340 AuthenticationStatisticsEventListener {
341 @Override
342 public void event(AuthenticationStatisticsEvent authenticationStatisticsEvent) {
343 handleStat(authenticationStatisticsEvent);
344 }
345 }
Shubham Sharmaab296ff2019-06-27 12:31:01 +0000346
347 private class InternalRadiusOperationalStatusEventListener implements
348 RadiusOperationalStatusEventListener {
349 @Override
350 public void event(RadiusOperationalStatusEvent radiusOperationalStatusEvent) {
351 handleOperationalStatus(radiusOperationalStatusEvent);
352 }
Kartikey Dubey648a9972019-12-02 11:03:06 +0000353 }
Shubham Sharmaab296ff2019-06-27 12:31:01 +0000354
Jonathan Harted589982020-02-25 15:11:37 -0800355 private class InternalAaaMachineStatisticsListener implements AaaMachineStatisticsEventListener {
Kartikey Dubey648a9972019-12-02 11:03:06 +0000356
357 @Override
358 public void event(AaaMachineStatisticsEvent machineStatEvent) {
359 handleMachineStat(machineStatEvent);
360 }
Shubham Sharmaab296ff2019-06-27 12:31:01 +0000361 }
Shubham Sharma22a3e4f2019-09-16 10:07:02 +0000362}