blob: 1a246f4d67006e2e4eacbfe00bbafe0df1a409cb [file] [log] [blame]
Ari Saha89831742015-06-26 10:31:48 -07001/*
Amit Ghoshc9ac1e52017-07-28 12:31:18 +01002 * Copyright 2017-present Open Networking Foundation
Ari Saha89831742015-06-26 10:31:48 -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 */
Matteo Scandolocf847b82019-04-26 15:00:00 -070016package org.opencord.aaa.impl;
Ari Saha89831742015-06-26 10:31:48 -070017
Saurav Das987441a2018-09-18 16:33:47 -070018import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
19import static org.slf4j.LoggerFactory.getLogger;
20
Girish Kumar8bc4eb32020-02-04 08:32:46 +000021import com.google.common.collect.Sets;
Saurav Das987441a2018-09-18 16:33:47 -070022import java.net.InetAddress;
kartikey dubeye1545422019-05-22 12:53:45 +000023import java.net.UnknownHostException;
Saurav Das987441a2018-09-18 16:33:47 -070024import java.nio.ByteBuffer;
25import java.util.Map;
kartikey dubeye1545422019-05-22 12:53:45 +000026import java.util.Dictionary;
27import java.util.HashSet;
Vijaykumar Kushwaha056e4cd2019-08-06 13:16:25 +000028import java.util.Arrays;
Shubham Sharma47869542019-09-13 10:39:47 +000029import java.util.List;
Girish Kumar8bc4eb32020-02-04 08:32:46 +000030import java.util.Set;
31import java.util.Map.Entry;
Saurav Das987441a2018-09-18 16:33:47 -070032
Jonathan Hart932bedc2018-07-12 13:46:09 -070033import org.apache.commons.lang3.builder.ToStringBuilder;
Ari Saha89831742015-06-26 10:31:48 -070034import org.apache.felix.scr.annotations.Component;
35import org.apache.felix.scr.annotations.Deactivate;
kartikey dubeye1545422019-05-22 12:53:45 +000036import org.apache.felix.scr.annotations.Property;
Ari Saha89831742015-06-26 10:31:48 -070037import org.apache.felix.scr.annotations.Reference;
38import org.apache.felix.scr.annotations.ReferenceCardinality;
Jonathan Hart5db44532018-07-12 18:13:54 -070039import org.apache.felix.scr.annotations.Service;
Jonathan Hart4731dd92018-05-02 17:30:05 -070040import org.onlab.packet.DeserializationException;
Jonathan Harta46dddf2015-06-30 15:31:20 -070041import org.onlab.packet.EAP;
42import org.onlab.packet.EAPOL;
43import org.onlab.packet.EthType;
Ari Saha89831742015-06-26 10:31:48 -070044import org.onlab.packet.Ethernet;
Ari Saha89831742015-06-26 10:31:48 -070045import org.onlab.packet.MacAddress;
Jonathan Harta46dddf2015-06-30 15:31:20 -070046import org.onlab.packet.RADIUS;
47import org.onlab.packet.RADIUSAttribute;
kartikey dubeye1545422019-05-22 12:53:45 +000048import org.onlab.util.Tools;
49import org.onosproject.cfg.ComponentConfigService;
Ari Saha89831742015-06-26 10:31:48 -070050import org.onosproject.core.ApplicationId;
51import org.onosproject.core.CoreService;
Jonathan Hart5db44532018-07-12 18:13:54 -070052import org.onosproject.event.AbstractListenerManager;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010053import org.onosproject.mastership.MastershipService;
Ari Saha89831742015-06-26 10:31:48 -070054import org.onosproject.net.ConnectPoint;
55import org.onosproject.net.DeviceId;
Ari Saha89831742015-06-26 10:31:48 -070056import org.onosproject.net.PortNumber;
Ray Milkeyfcb623d2015-10-01 16:48:18 -070057import org.onosproject.net.config.ConfigFactory;
58import org.onosproject.net.config.NetworkConfigEvent;
59import org.onosproject.net.config.NetworkConfigListener;
60import org.onosproject.net.config.NetworkConfigRegistry;
Amit Ghoshf739be52017-09-21 15:49:37 +010061import org.onosproject.net.device.DeviceEvent;
62import org.onosproject.net.device.DeviceListener;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010063import org.onosproject.net.device.DeviceService;
Ari Saha89831742015-06-26 10:31:48 -070064import org.onosproject.net.flow.DefaultTrafficTreatment;
Ari Saha89831742015-06-26 10:31:48 -070065import org.onosproject.net.flow.TrafficTreatment;
Ari Saha89831742015-06-26 10:31:48 -070066import org.onosproject.net.packet.DefaultOutboundPacket;
67import org.onosproject.net.packet.InboundPacket;
68import org.onosproject.net.packet.OutboundPacket;
69import org.onosproject.net.packet.PacketContext;
Ari Saha89831742015-06-26 10:31:48 -070070import org.onosproject.net.packet.PacketProcessor;
71import org.onosproject.net.packet.PacketService;
Matteo Scandolocf847b82019-04-26 15:00:00 -070072import org.opencord.aaa.AaaConfig;
Kartikey Dubeybe14f472019-10-01 12:18:35 +000073import org.opencord.aaa.AaaMachineStatisticsEvent;
74import org.opencord.aaa.AaaMachineStatisticsService;
75import org.opencord.aaa.AaaSupplicantMachineStats;
Matteo Scandolocf847b82019-04-26 15:00:00 -070076import org.opencord.aaa.AuthenticationEvent;
77import org.opencord.aaa.AuthenticationEventListener;
78import org.opencord.aaa.AuthenticationService;
kartikey dubeye1545422019-05-22 12:53:45 +000079import org.opencord.aaa.AuthenticationStatisticsEvent;
80import org.opencord.aaa.AuthenticationStatisticsService;
Matteo Scandolocf847b82019-04-26 15:00:00 -070081import org.opencord.aaa.RadiusCommunicator;
Shubham Sharma048cc262019-06-19 14:18:50 +000082import org.opencord.aaa.RadiusOperationalStatusEvent;
83import org.opencord.aaa.RadiusOperationalStatusService;
Matteo Scandolocf847b82019-04-26 15:00:00 -070084import org.opencord.aaa.StateMachineDelegate;
Shubham Sharma048cc262019-06-19 14:18:50 +000085import org.opencord.aaa.RadiusOperationalStatusService.RadiusOperationalStatusEvaluationMode;
Gamze Abaka1cfdb192018-10-25 11:39:19 +000086import org.opencord.sadis.BaseInformationService;
87import org.opencord.sadis.SadisService;
88import org.opencord.sadis.SubscriberAndDeviceInformation;
kartikey dubeye1545422019-05-22 12:53:45 +000089import org.osgi.service.component.ComponentContext;
Kartikey Dubeyf72e1952019-06-24 07:09:00 +000090import org.apache.felix.scr.annotations.Modified;
91import org.apache.felix.scr.annotations.Activate;
Ari Saha89831742015-06-26 10:31:48 -070092import org.slf4j.Logger;
kartikey dubeye1545422019-05-22 12:53:45 +000093import com.google.common.base.Strings;
Ari Saha89831742015-06-26 10:31:48 -070094
kartikey dubeye1545422019-05-22 12:53:45 +000095import java.util.concurrent.Executors;
96import java.util.concurrent.ScheduledExecutorService;
97import java.util.concurrent.ScheduledFuture;
98import java.util.concurrent.TimeUnit;
Vijaykumar Kushwaha056e4cd2019-08-06 13:16:25 +000099
100import javax.crypto.Mac;
101import javax.crypto.spec.SecretKeySpec;
Ari Saha89831742015-06-26 10:31:48 -0700102/**
Jonathan Harta46dddf2015-06-30 15:31:20 -0700103 * AAA application for ONOS.
Ari Saha89831742015-06-26 10:31:48 -0700104 */
Jonathan Hart5db44532018-07-12 18:13:54 -0700105@Service
Ari Saha89831742015-06-26 10:31:48 -0700106@Component(immediate = true)
Jonathan Hart5db44532018-07-12 18:13:54 -0700107public class AaaManager
108 extends AbstractListenerManager<AuthenticationEvent, AuthenticationEventListener>
109 implements AuthenticationService {
110
Charles Chandf7ff862017-01-20 11:22:05 -0800111 private static final String APP_NAME = "org.opencord.aaa";
Ray Milkeyf51eba22015-09-25 10:24:23 -0700112
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700113 private final Logger log = getLogger(getClass());
Ray Milkeyf51eba22015-09-25 10:24:23 -0700114
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700115 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
116 protected CoreService coreService;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700117
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700118 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
119 protected PacketService packetService;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700120
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700121 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700122 protected NetworkConfigRegistry netCfgService;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700123
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100124 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
125 protected DeviceService deviceService;
126
127 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Gamze Abaka1cfdb192018-10-25 11:39:19 +0000128 protected SadisService sadisService;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100129
130 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
131 protected MastershipService mastershipService;
132
kartikey dubeye1545422019-05-22 12:53:45 +0000133 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
134 protected AuthenticationStatisticsService aaaStatisticsManager;
Gamze Abaka1cfdb192018-10-25 11:39:19 +0000135
kartikey dubeye1545422019-05-22 12:53:45 +0000136 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Kartikey Dubeybe14f472019-10-01 12:18:35 +0000137 protected AaaMachineStatisticsService aaaSupplicantStatsManager;
138
139 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
kartikey dubeye1545422019-05-22 12:53:45 +0000140 protected ComponentConfigService cfgService;
141
Shubham Sharma048cc262019-06-19 14:18:50 +0000142 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
143 protected RadiusOperationalStatusService radiusOperationalStatusService;
144
kartikey dubeye1545422019-05-22 12:53:45 +0000145 protected AuthenticationStatisticsEventPublisher authenticationStatisticsPublisher;
146 protected BaseInformationService<SubscriberAndDeviceInformation> subsService;
Amit Ghoshf739be52017-09-21 15:49:37 +0100147 private final DeviceListener deviceListener = new InternalDeviceListener();
148
kartikey dubeye1545422019-05-22 12:53:45 +0000149 private static final int DEFAULT_REPEAT_DELAY = 20;
Shubham Sharma048cc262019-06-19 14:18:50 +0000150 @Property(name = "statisticsGenerationPeriodInSeconds", intValue = DEFAULT_REPEAT_DELAY,
151 label = "AAA Statistics generation frequency in seconds")
152 private int statisticsGenerationPeriodInSeconds = DEFAULT_REPEAT_DELAY;
153
154 private static final int DEFAULT_OPERATIONAL_STATUS_SERVER_EVENT_GENERATION = 30;
155 @Property(name = "operationalStatusEventGenerationPeriodInSeconds",
156 intValue = DEFAULT_OPERATIONAL_STATUS_SERVER_EVENT_GENERATION, label = "AAA Radius Server Operational "
157 + "Status Frequency in seconds")
158 private int operationalStatusEventGenerationPeriodInSeconds = DEFAULT_OPERATIONAL_STATUS_SERVER_EVENT_GENERATION;
159
160 private static final int DEFAULT_OPERATIONAL_STATUS_SERVER_TIMEOUT = 10;
161 @Property(name = "operationalStatusServerTimeoutInSeconds",
162 intValue = DEFAULT_OPERATIONAL_STATUS_SERVER_TIMEOUT, label = "Maximum period(in Seconds) to "
163 + "wait for Status response from AAA Server ")
164 private int operationalStatusServerTimeoutInSeconds = DEFAULT_OPERATIONAL_STATUS_SERVER_TIMEOUT;
165
166 private static final String DEFAULT_STATUS_SERVER_MODE = "AUTO";
167 @Property(name = "operationalStatusEvaluationMode", value = DEFAULT_STATUS_SERVER_MODE,
168 label = "Evaluation mode for determining the Operational Status of Radius Server. Valid values are AUTO "
169 + "(default), STATUS_REQUEST and ACCESS_REQUEST")
170 protected String operationalStatusEvaluationMode = DEFAULT_STATUS_SERVER_MODE;
kartikey dubeye1545422019-05-22 12:53:45 +0000171
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700172 // NAS IP address
173 protected InetAddress nasIpAddress;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100174
175 // self MAC address
Jonathan Hart5db44532018-07-12 18:13:54 -0700176 protected String nasMacAddress;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100177
178 // Parsed RADIUS server addresses
179 protected InetAddress radiusIpAddress;
180
181 // MAC address of RADIUS server or net hop router
182 protected String radiusMacAddress;
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700183
184 // RADIUS server secret
185 protected String radiusSecret;
186
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100187 // bindings
188 protected CustomizationInfo customInfo;
Ray Milkey5d99bd12015-10-06 15:41:30 -0700189
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700190 // our application-specific event handler
191 private ReactivePacketProcessor processor = new ReactivePacketProcessor();
Ray Milkeyf51eba22015-09-25 10:24:23 -0700192
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700193 // our unique identifier
194 private ApplicationId appId;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700195
Shubham Sharmaa3b1bd32019-06-19 14:18:12 +0000196 // TimeOut time for cleaning up stateMachines stuck due to pending AAA/EAPOL message.
197 protected int cleanupTimerTimeOutInMins;
198
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100199 // Setup specific customization/attributes on the RADIUS packets
200 PacketCustomizer pktCustomizer;
Ray Milkey967776a2015-10-07 14:37:17 -0700201
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100202 // packet customizer to use
203 private String customizer;
204
205 // Type of connection to use to communicate with Radius server, options are
206 // "socket" or "packet_out"
207 private String radiusConnectionType;
208
Jonathan Hart5db44532018-07-12 18:13:54 -0700209 // Object for the specific type of communication with the RADIUS
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100210 // server, socket based or packet_out based
211 RadiusCommunicator impl = null;
212
213 // latest configuration
214 AaaConfig newCfg;
Ray Milkey967776a2015-10-07 14:37:17 -0700215
kartikey dubeye1545422019-05-22 12:53:45 +0000216 ScheduledFuture<?> scheduledFuture;
Shubham Sharma048cc262019-06-19 14:18:50 +0000217 ScheduledFuture<?> scheduledStatusServerChecker;
kartikey dubeye1545422019-05-22 12:53:45 +0000218 ScheduledExecutorService executor;
219 String configuredAaaServerAddress;
220 HashSet<Byte> outPacketSet = new HashSet<Byte>();
Shubham Sharma47869542019-09-13 10:39:47 +0000221 HashSet<Byte> outPacketSupp = new HashSet<Byte>();
222 static final List<Byte> VALID_EAPOL_TYPE = Arrays.asList(EAPOL.EAPOL_START, EAPOL.EAPOL_LOGOFF, EAPOL.EAPOL_PACKET);
223 static final int HEADER_LENGTH = 4;
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700224 // Configuration properties factory
225 private final ConfigFactory factory =
Jonathan Hart092dfb22015-11-16 23:05:21 -0800226 new ConfigFactory<ApplicationId, AaaConfig>(APP_SUBJECT_FACTORY,
227 AaaConfig.class,
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700228 "AAA") {
229 @Override
Jonathan Hart092dfb22015-11-16 23:05:21 -0800230 public AaaConfig createConfig() {
231 return new AaaConfig();
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700232 }
233 };
Ray Milkeyf51eba22015-09-25 10:24:23 -0700234
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700235 // Listener for config changes
236 private final InternalConfigListener cfgListener = new InternalConfigListener();
Ari Saha89831742015-06-26 10:31:48 -0700237
Jonathan Hart5db44532018-07-12 18:13:54 -0700238 private StateMachineDelegate delegate = new InternalStateMachineDelegate();
239
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700240 /**
241 * Builds an EAPOL packet based on the given parameters.
242 *
243 * @param dstMac destination MAC address
244 * @param srcMac source MAC address
245 * @param vlan vlan identifier
246 * @param eapolType EAPOL type
247 * @param eap EAP payload
248 * @return Ethernet frame
249 */
250 private static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac,
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100251 short vlan, byte eapolType, EAP eap, byte priorityCode) {
Ari Saha89831742015-06-26 10:31:48 -0700252
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700253 Ethernet eth = new Ethernet();
254 eth.setDestinationMACAddress(dstMac.toBytes());
255 eth.setSourceMACAddress(srcMac.toBytes());
256 eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort());
257 if (vlan != Ethernet.VLAN_UNTAGGED) {
258 eth.setVlanID(vlan);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100259 eth.setPriorityCode(priorityCode);
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700260 }
261 //eapol header
262 EAPOL eapol = new EAPOL();
263 eapol.setEapolType(eapolType);
264 eapol.setPacketLength(eap.getLength());
Ari Saha89831742015-06-26 10:31:48 -0700265
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700266 //eap part
267 eapol.setPayload(eap);
268
269 eth.setPayload(eapol);
270 eth.setPad(true);
271 return eth;
272 }
Ari Saha89831742015-06-26 10:31:48 -0700273
Ari Saha89831742015-06-26 10:31:48 -0700274 @Activate
kartikey dubeye1545422019-05-22 12:53:45 +0000275 public void activate(ComponentContext context) {
Charles Chandf7ff862017-01-20 11:22:05 -0800276 appId = coreService.registerApplication(APP_NAME);
Jonathan Hart5db44532018-07-12 18:13:54 -0700277 eventDispatcher.addSink(AuthenticationEvent.class, listenerRegistry);
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400278 netCfgService.addListener(cfgListener);
279 netCfgService.registerConfigFactory(factory);
kartikey dubeye1545422019-05-22 12:53:45 +0000280 cfgService.registerProperties(getClass());
281 modified(context);
Gamze Abaka1cfdb192018-10-25 11:39:19 +0000282 subsService = sadisService.getSubscriberInfoService();
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530283 customInfo = new CustomizationInfo(subsService, deviceService);
Jonathan Hart092dfb22015-11-16 23:05:21 -0800284 cfgListener.reconfigureNetwork(netCfgService.getConfig(appId, AaaConfig.class));
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400285 log.info("Starting with config {} {}", this, newCfg);
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530286 configureRadiusCommunication();
Ari Saha89831742015-06-26 10:31:48 -0700287 // register our event handler
Brian O'Connord9c7da02015-07-29 17:49:24 -0700288 packetService.addProcessor(processor, PacketProcessor.director(2));
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700289 StateMachine.initializeMaps();
Jonathan Hart5db44532018-07-12 18:13:54 -0700290 StateMachine.setDelegate(delegate);
Shubham Sharmaa3b1bd32019-06-19 14:18:12 +0000291 cleanupTimerTimeOutInMins = newCfg.sessionCleanupTimer();
292 StateMachine.setcleanupTimerTimeOutInMins(cleanupTimerTimeOutInMins);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100293 impl.initializeLocalState(newCfg);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100294 impl.requestIntercepts();
Amit Ghoshf739be52017-09-21 15:49:37 +0100295 deviceService.addListener(deviceListener);
kartikey dubeye1545422019-05-22 12:53:45 +0000296 getConfiguredAaaServerAddress();
Shubham Sharma048cc262019-06-19 14:18:50 +0000297 radiusOperationalStatusService.initialize(nasIpAddress.getAddress(), radiusSecret, impl);
kartikey dubeye1545422019-05-22 12:53:45 +0000298 authenticationStatisticsPublisher =
299 new AuthenticationStatisticsEventPublisher();
Shubham Sharma048cc262019-06-19 14:18:50 +0000300 executor = Executors.newScheduledThreadPool(3);
301
kartikey dubeye1545422019-05-22 12:53:45 +0000302 scheduledFuture = executor.scheduleAtFixedRate(authenticationStatisticsPublisher,
Shubham Sharma048cc262019-06-19 14:18:50 +0000303 0, statisticsGenerationPeriodInSeconds, TimeUnit.SECONDS);
304 scheduledStatusServerChecker = executor.scheduleAtFixedRate(new ServerStatusChecker(), 0,
305 operationalStatusEventGenerationPeriodInSeconds, TimeUnit.SECONDS);
Amit Ghoshf739be52017-09-21 15:49:37 +0100306
Jian Li13c67162015-12-09 13:20:34 -0800307 log.info("Started");
Ari Saha89831742015-06-26 10:31:48 -0700308 }
309
310 @Deactivate
kartikey dubeye1545422019-05-22 12:53:45 +0000311 public void deactivate(ComponentContext context) {
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100312 impl.withdrawIntercepts();
Ari Saha89831742015-06-26 10:31:48 -0700313 packetService.removeProcessor(processor);
Deepa Vaddireddyb9c24c62017-09-21 13:45:30 +0530314 netCfgService.removeListener(cfgListener);
kartikey dubeye1545422019-05-22 12:53:45 +0000315 cfgService.unregisterProperties(getClass(), false);
Jonathan Hart5db44532018-07-12 18:13:54 -0700316 StateMachine.unsetDelegate(delegate);
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530317 StateMachine.destroyMaps();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100318 impl.deactivate();
Amit Ghoshf739be52017-09-21 15:49:37 +0100319 deviceService.removeListener(deviceListener);
Jonathan Hart5db44532018-07-12 18:13:54 -0700320 eventDispatcher.removeSink(AuthenticationEvent.class);
kartikey dubeye1545422019-05-22 12:53:45 +0000321 scheduledFuture.cancel(true);
Shubham Sharma048cc262019-06-19 14:18:50 +0000322 scheduledStatusServerChecker.cancel(true);
kartikey dubeye1545422019-05-22 12:53:45 +0000323 executor.shutdown();
Jian Li13c67162015-12-09 13:20:34 -0800324 log.info("Stopped");
Ray Milkey967776a2015-10-07 14:37:17 -0700325 }
kartikey dubeye1545422019-05-22 12:53:45 +0000326 @Modified
327 public void modified(ComponentContext context) {
Shubham Sharma048cc262019-06-19 14:18:50 +0000328 Dictionary<String, Object> properties = context.getProperties();
329 String s = Tools.get(properties, "statisticsGenerationPeriodInSeconds");
330 statisticsGenerationPeriodInSeconds = Strings.isNullOrEmpty(s) ? DEFAULT_REPEAT_DELAY
331 : Integer.parseInt(s.trim());
332
333 s = Tools.get(properties, "operationalStatusEventGenerationPeriodInSeconds");
334 operationalStatusEventGenerationPeriodInSeconds = Strings.isNullOrEmpty(s)
335 ? DEFAULT_OPERATIONAL_STATUS_SERVER_EVENT_GENERATION
336 : Integer.parseInt(s.trim());
337
338 s = Tools.get(properties, "operationalStatusServerTimeoutInSeconds");
339 operationalStatusServerTimeoutInSeconds = Strings.isNullOrEmpty(s) ? DEFAULT_OPERATIONAL_STATUS_SERVER_TIMEOUT
340 : Integer.parseInt(s.trim());
341
342 s = Tools.get(properties, "operationalStatusEvaluationMode");
343 String newEvaluationModeString = Strings.isNullOrEmpty(s) ? DEFAULT_STATUS_SERVER_MODE : s.trim();
344
345 radiusOperationalStatusService
346 .setOperationalStatusServerTimeoutInMillis(operationalStatusServerTimeoutInSeconds * 1000);
347 RadiusOperationalStatusEvaluationMode newEvaluationMode =
348 RadiusOperationalStatusEvaluationMode.getValue(newEvaluationModeString);
349 if (newEvaluationMode != null) {
350 radiusOperationalStatusService.setRadiusOperationalStatusEvaluationMode(newEvaluationMode);
351 operationalStatusEvaluationMode = newEvaluationModeString;
352 } else {
353 properties.put("operationalStatusEvaluationMode", operationalStatusEvaluationMode);
354 }
kartikey dubeye1545422019-05-22 12:53:45 +0000355 }
356
Shubham Sharma1ad16632019-11-26 11:09:21 +0000357 protected void configureRadiusCommunication() {
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530358 if (radiusConnectionType.toLowerCase().equals("socket")) {
359 impl = new SocketBasedRadiusCommunicator(appId, packetService, this);
360 } else {
361 impl = new PortBasedRadiusCommunicator(appId, packetService, mastershipService,
362 deviceService, subsService, pktCustomizer, this);
363 }
364 }
365
366 private void configurePacketCustomizer() {
367 switch (customizer.toLowerCase()) {
368 case "sample":
369 pktCustomizer = new SamplePacketCustomizer(customInfo);
370 log.info("Created SamplePacketCustomizer");
371 break;
Saurav Dase72358a2018-11-13 21:56:46 -0800372 case "att":
373 pktCustomizer = new AttPacketCustomizer(customInfo);
374 log.info("Created AttPacketCustomizer");
375 break;
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530376 default:
377 pktCustomizer = new PacketCustomizer(customInfo);
378 log.info("Created default PacketCustomizer");
379 break;
380 }
381 }
382
kartikey dubeye1545422019-05-22 12:53:45 +0000383 private void getConfiguredAaaServerAddress() {
384 try {
385 InetAddress address;
386 if (newCfg.radiusHostName() != null) {
387 address = InetAddress.getByName(newCfg.radiusHostName());
388 } else {
389 address = newCfg.radiusIp();
390 }
391
392 configuredAaaServerAddress = address.getHostAddress();
393 } catch (UnknownHostException uhe) {
394 log.warn("Unable to resolve host {}", newCfg.radiusHostName());
395 }
396 }
397
Vijaykumar Kushwaha056e4cd2019-08-06 13:16:25 +0000398 private void checkReceivedPacketForValidValidator(RADIUS radiusPacket, byte[] requestAuthenticator) {
399 if (!checkResponseMessageAuthenticator(radiusSecret, radiusPacket, requestAuthenticator)) {
kartikey dubeye1545422019-05-22 12:53:45 +0000400 aaaStatisticsManager.getAaaStats().increaseInvalidValidatorsRx();
401 }
402 }
Vijaykumar Kushwaha056e4cd2019-08-06 13:16:25 +0000403
404 private boolean checkResponseMessageAuthenticator(String key, RADIUS radiusPacket, byte[] requestAuthenticator) {
405 byte[] newHash = new byte[16];
406 Arrays.fill(newHash, (byte) 0);
407 byte[] messageAuthenticator = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH).getValue();
408 byte[] authenticator = radiusPacket.getAuthenticator();
409 radiusPacket.updateAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH, newHash);
410 radiusPacket.setAuthenticator(requestAuthenticator);
411 // Calculate the MD5 HMAC based on the message
412 try {
413 SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacMD5");
414 Mac mac = Mac.getInstance("HmacMD5");
415 mac.init(keySpec);
416 newHash = mac.doFinal(radiusPacket.serialize());
417 } catch (Exception e) {
418 log.error("Failed to generate message authenticator: {}", e.getMessage());
419 }
420 radiusPacket.updateAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH, messageAuthenticator);
421 radiusPacket.setAuthenticator(authenticator);
422 // Compare the calculated Message-Authenticator with the one in the message
423 return Arrays.equals(newHash, messageAuthenticator);
424 }
kartikey dubeye1545422019-05-22 12:53:45 +0000425 public void checkForPacketFromUnknownServer(String hostAddress) {
426 if (!hostAddress.equals(configuredAaaServerAddress)) {
Vijaykumar Kushwahafffd3d12019-08-01 11:09:59 +0000427 getConfiguredAaaServerAddress();
428 if (!hostAddress.equals(configuredAaaServerAddress)) {
429 aaaStatisticsManager.getAaaStats().incrementUnknownServerRx();
430 }
kartikey dubeye1545422019-05-22 12:53:45 +0000431 }
432 }
433
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100434 /**
435 * Send RADIUS packet to the RADIUS server.
436 *
437 * @param radiusPacket RADIUS packet to be sent to server.
438 * @param inPkt Incoming EAPOL packet
439 */
440 protected void sendRadiusPacket(RADIUS radiusPacket, InboundPacket inPkt) {
kartikey dubeye1545422019-05-22 12:53:45 +0000441 outPacketSet.add(radiusPacket.getIdentifier());
442 aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(true);
443 aaaStatisticsManager.getAaaStats().increaseAccessRequestsTx();
Shubham Sharma048cc262019-06-19 14:18:50 +0000444 aaaStatisticsManager.putOutgoingIdentifierToMap(radiusPacket.getIdentifier());
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100445 impl.sendRadiusPacket(radiusPacket, inPkt);
446 }
Ray Milkey967776a2015-10-07 14:37:17 -0700447
Shubham Sharmaa3b1bd32019-06-19 14:18:12 +0000448 /**
449 * For scheduling the timer required for cleaning up StateMachine
450 * when no response
451 * from RADIUS SERVER.
452 *
453 * @param sessionId SessionId of the current session
454 * @param stateMachine StateMachine for the id
455 */
456 public void scheduleStateMachineCleanupTimer(String sessionId, StateMachine stateMachine) {
457 StateMachine.CleanupTimerTask cleanupTask = stateMachine.new CleanupTimerTask(sessionId, this);
458 ScheduledFuture<?> cleanupTimer = executor.schedule(cleanupTask, cleanupTimerTimeOutInMins, TimeUnit.MINUTES);
459 stateMachine.setCleanupTimer(cleanupTimer);
460
461 }
462
463 /**
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100464 * Handles RADIUS packets.
465 *
466 * @param radiusPacket RADIUS packet coming from the RADIUS server.
467 * @throws StateMachineException if an illegal state transition is triggered
Jonathan Hart4731dd92018-05-02 17:30:05 -0700468 * @throws DeserializationException if packet deserialization fails
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100469 */
Jonathan Hart4731dd92018-05-02 17:30:05 -0700470 public void handleRadiusPacket(RADIUS radiusPacket)
471 throws StateMachineException, DeserializationException {
Saurav Das987441a2018-09-18 16:33:47 -0700472 if (log.isTraceEnabled()) {
473 log.trace("Received RADIUS packet {}", radiusPacket);
474 }
Shubham Sharma048cc262019-06-19 14:18:50 +0000475 if (radiusOperationalStatusService.isRadiusResponseForOperationalStatus(radiusPacket.getIdentifier())) {
476 radiusOperationalStatusService.handleRadiusPacketForOperationalStatus(radiusPacket);
477 return;
478 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100479 StateMachine stateMachine = StateMachine.lookupStateMachineById(radiusPacket.getIdentifier());
480 if (stateMachine == null) {
Saurav Das987441a2018-09-18 16:33:47 -0700481 log.error("Invalid packet identifier {}, could not find corresponding "
482 + "state machine ... exiting", radiusPacket.getIdentifier());
kartikey dubeye1545422019-05-22 12:53:45 +0000483 aaaStatisticsManager.getAaaStats().incrementNumberOfSessionsExpired();
484 aaaStatisticsManager.getAaaStats().countDroppedResponsesRx();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100485 return;
Ray Milkey967776a2015-10-07 14:37:17 -0700486 }
Kartikey Dubeybe14f472019-10-01 12:18:35 +0000487
488 //instance of StateMachine using the sessionId for updating machine stats
489 StateMachine machineStats = StateMachine.lookupStateMachineBySessionId(stateMachine.sessionId());
490
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100491 EAP eapPayload;
492 Ethernet eth;
Vijaykumar Kushwaha056e4cd2019-08-06 13:16:25 +0000493 checkReceivedPacketForValidValidator(radiusPacket, stateMachine.requestAuthenticator());
Kartikey Dubeybe14f472019-10-01 12:18:35 +0000494
495 //increasing packets and octets received from server
496 machineStats.incrementTotalPacketsReceived();
497 machineStats.incrementTotalOctetReceived(radiusPacket.decapsulateMessage().getLength());
498
kartikey dubeye1545422019-05-22 12:53:45 +0000499 if (outPacketSet.contains(radiusPacket.getIdentifier())) {
500 aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(false);
501 outPacketSet.remove(new Byte(radiusPacket.getIdentifier()));
502 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100503 switch (radiusPacket.getCode()) {
504 case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400505 log.debug("RADIUS packet: RADIUS_CODE_ACCESS_CHALLENGE");
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100506 RADIUSAttribute radiusAttrState = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE);
507 byte[] challengeState = null;
508 if (radiusAttrState != null) {
509 challengeState = radiusAttrState.getValue();
510 }
511 eapPayload = radiusPacket.decapsulateMessage();
512 stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState);
513 eth = buildEapolResponse(stateMachine.supplicantAddress(),
514 MacAddress.valueOf(nasMacAddress),
515 stateMachine.vlanId(),
516 EAPOL.EAPOL_PACKET,
517 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400518 log.debug("Send EAP challenge response to supplicant {}", stateMachine.supplicantAddress().toString());
Shubham Sharmac155ef82019-07-11 12:12:41 +0000519 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), true);
kartikey dubeye1545422019-05-22 12:53:45 +0000520 aaaStatisticsManager.getAaaStats().increaseChallengeResponsesRx();
Shubham Sharma47869542019-09-13 10:39:47 +0000521 outPacketSupp.add(eapPayload.getIdentifier());
522 aaaStatisticsManager.getAaaStats().incrementPendingResSupp();
Kartikey Dubeybe14f472019-10-01 12:18:35 +0000523 //increasing packets send to server
524 machineStats.incrementTotalPacketsSent();
525 machineStats.incrementTotalOctetSent(eapPayload.getLength());
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100526 break;
527 case RADIUS.RADIUS_CODE_ACCESS_ACCEPT:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400528 log.debug("RADIUS packet: RADIUS_CODE_ACCESS_ACCEPT");
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100529 //send an EAPOL - Success to the supplicant.
530 byte[] eapMessageSuccess =
531 radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue();
Jonathan Hart4731dd92018-05-02 17:30:05 -0700532 eapPayload = EAP.deserializer().deserialize(
533 eapMessageSuccess, 0, eapMessageSuccess.length);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100534 eth = buildEapolResponse(stateMachine.supplicantAddress(),
535 MacAddress.valueOf(nasMacAddress),
536 stateMachine.vlanId(),
537 EAPOL.EAPOL_PACKET,
538 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400539 log.info("Send EAP success message to supplicant {}", stateMachine.supplicantAddress().toString());
Shubham Sharmac155ef82019-07-11 12:12:41 +0000540 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false);
541 aaaStatisticsManager.getAaaStats().incrementEapolAuthSuccessTrans();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100542
543 stateMachine.authorizeAccess();
kartikey dubeye1545422019-05-22 12:53:45 +0000544 aaaStatisticsManager.getAaaStats().increaseAcceptResponsesRx();
Kartikey Dubeybe14f472019-10-01 12:18:35 +0000545 //increasing packets send to server
546 machineStats.incrementTotalPacketsSent();
547 machineStats.incrementTotalOctetSent(eapPayload.getLength());
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100548 break;
549 case RADIUS.RADIUS_CODE_ACCESS_REJECT:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400550 log.debug("RADIUS packet: RADIUS_CODE_ACCESS_REJECT");
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100551 //send an EAPOL - Failure to the supplicant.
552 byte[] eapMessageFailure;
553 eapPayload = new EAP();
554 RADIUSAttribute radiusAttrEap = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE);
555 if (radiusAttrEap == null) {
556 eapPayload.setCode(EAP.FAILURE);
557 eapPayload.setIdentifier(stateMachine.challengeIdentifier());
558 eapPayload.setLength(EAP.EAP_HDR_LEN_SUC_FAIL);
559 } else {
560 eapMessageFailure = radiusAttrEap.getValue();
Jonathan Hart4731dd92018-05-02 17:30:05 -0700561 eapPayload = EAP.deserializer().deserialize(
562 eapMessageFailure, 0, eapMessageFailure.length);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100563 }
564 eth = buildEapolResponse(stateMachine.supplicantAddress(),
565 MacAddress.valueOf(nasMacAddress),
566 stateMachine.vlanId(),
567 EAPOL.EAPOL_PACKET,
568 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400569 log.warn("Send EAP failure message to supplicant {}", stateMachine.supplicantAddress().toString());
Shubham Sharmac155ef82019-07-11 12:12:41 +0000570 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false);
571 aaaStatisticsManager.getAaaStats().incrementEapolauthFailureTrans();
572
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100573 stateMachine.denyAccess();
kartikey dubeye1545422019-05-22 12:53:45 +0000574 aaaStatisticsManager.getAaaStats().increaseRejectResponsesRx();
Kartikey Dubeybe14f472019-10-01 12:18:35 +0000575 //increasing packets send to server
576 machineStats.incrementTotalPacketsSent();
577 machineStats.incrementTotalOctetSent(eapPayload.getLength());
578 //pushing machine stats to kafka
579 AaaSupplicantMachineStats machineObj = aaaSupplicantStatsManager.getSupplicantStats(machineStats);
580 aaaSupplicantStatsManager.getMachineStatsDelegate()
581 .notify(new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE, machineObj));
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100582 break;
583 default:
584 log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode());
kartikey dubeye1545422019-05-22 12:53:45 +0000585 aaaStatisticsManager.getAaaStats().increaseUnknownTypeRx();
Kartikey Dubeybe14f472019-10-01 12:18:35 +0000586 //increasing packets received to server
587 machineStats.incrementTotalPacketsReceived();
588 machineStats.incrementTotalOctetReceived(radiusPacket.decapsulateMessage().getLength());
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100589 }
kartikey dubeye1545422019-05-22 12:53:45 +0000590 aaaStatisticsManager.getAaaStats().countDroppedResponsesRx();
Aaron Kruglikovd39d99e2015-07-03 13:30:57 -0700591 }
592
Ray Milkey967776a2015-10-07 14:37:17 -0700593 /**
594 * Send the ethernet packet to the supplicant.
595 *
596 * @param ethernetPkt the ethernet packet
597 * @param connectPoint the connect point to send out
598 */
Shubham Sharmac155ef82019-07-11 12:12:41 +0000599 private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint, boolean isChallengeResponse) {
Ray Milkey967776a2015-10-07 14:37:17 -0700600 TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
601 OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(),
602 treatment, ByteBuffer.wrap(ethernetPkt.serialize()));
Shubham Sharmac155ef82019-07-11 12:12:41 +0000603 EAPOL eap = ((EAPOL) ethernetPkt.getPayload());
604 EAP eapPkt = (EAP) eap.getPayload();
Saurav Das987441a2018-09-18 16:33:47 -0700605 if (log.isTraceEnabled()) {
Saurav Das987441a2018-09-18 16:33:47 -0700606 log.trace("Sending eapol payload {} enclosed in {} to supplicant at {}",
607 eap, ethernetPkt, connectPoint);
608 }
Ray Milkey967776a2015-10-07 14:37:17 -0700609 packetService.emit(packet);
Shubham Sharmac155ef82019-07-11 12:12:41 +0000610 if (isChallengeResponse) {
611 aaaStatisticsManager.getAaaStats().incrementEapPktTxauthEap();
612 }
Shubham Sharma47869542019-09-13 10:39:47 +0000613 aaaStatisticsManager.getAaaStats().incrementEapolFramesTx();
614 aaaStatisticsManager.getAaaStats().countReqEapFramesTx();
Ray Milkey967776a2015-10-07 14:37:17 -0700615 }
616
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400617 @Override
618 public String toString() {
619 return ToStringBuilder.reflectionToString(this);
620 }
621
Ari Saha89831742015-06-26 10:31:48 -0700622 // our handler defined as a private inner class
623
624 /**
625 * Packet processor responsible for forwarding packets along their paths.
626 */
627 private class ReactivePacketProcessor implements PacketProcessor {
628 @Override
629 public void process(PacketContext context) {
630
631 // Extract the original Ethernet frame from the packet information
632 InboundPacket pkt = context.inPacket();
633 Ethernet ethPkt = pkt.parsed();
634 if (ethPkt == null) {
635 return;
636 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100637
Ray Milkeyf51eba22015-09-25 10:24:23 -0700638 try {
639 // identify if incoming packet comes from supplicant (EAP) or RADIUS
640 switch (EthType.EtherType.lookup(ethPkt.getEtherType())) {
641 case EAPOL:
642 handleSupplicantPacket(context.inPacket());
643 break;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700644 default:
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100645 // any other packets let the specific implementation handle
646 impl.handlePacketFromServer(context);
Ray Milkeyf51eba22015-09-25 10:24:23 -0700647 }
Ray Milkey967776a2015-10-07 14:37:17 -0700648 } catch (StateMachineException e) {
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100649 log.warn("Unable to process packet:", e);
Ari Saha89831742015-06-26 10:31:48 -0700650 }
651 }
652
Ray Milkey9eb293f2015-09-30 15:09:17 -0700653 /**
654 * Creates and initializes common fields of a RADIUS packet.
655 *
Ray Milkey967776a2015-10-07 14:37:17 -0700656 * @param stateMachine state machine for the request
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700657 * @param eapPacket EAP packet
Ray Milkey9eb293f2015-09-30 15:09:17 -0700658 * @return RADIUS packet
659 */
Ray Milkey967776a2015-10-07 14:37:17 -0700660 private RADIUS getRadiusPayload(StateMachine stateMachine, byte identifier, EAP eapPacket) {
Ray Milkey9eb293f2015-09-30 15:09:17 -0700661 RADIUS radiusPayload =
662 new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST,
663 eapPacket.getIdentifier());
Ray Milkey967776a2015-10-07 14:37:17 -0700664
665 // set Request Authenticator in StateMachine
666 stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode());
667
Ray Milkey9eb293f2015-09-30 15:09:17 -0700668 radiusPayload.setIdentifier(identifier);
669 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME,
Ray Milkey967776a2015-10-07 14:37:17 -0700670 stateMachine.username());
Ray Milkey9eb293f2015-09-30 15:09:17 -0700671
672 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP,
Jonathan Hart092dfb22015-11-16 23:05:21 -0800673 AaaManager.this.nasIpAddress.getAddress());
Ray Milkey9eb293f2015-09-30 15:09:17 -0700674
675 radiusPayload.encapsulateMessage(eapPacket);
Ray Milkey9eb293f2015-09-30 15:09:17 -0700676
677 return radiusPayload;
678 }
Ari Saha89831742015-06-26 10:31:48 -0700679
680 /**
Jonathan Harta46dddf2015-06-30 15:31:20 -0700681 * Handles PAE packets (supplicant).
682 *
683 * @param inPacket Ethernet packet coming from the supplicant
Ari Saha89831742015-06-26 10:31:48 -0700684 */
Ray Milkeyf51eba22015-09-25 10:24:23 -0700685 private void handleSupplicantPacket(InboundPacket inPacket) throws StateMachineException {
Jonathan Harta46dddf2015-06-30 15:31:20 -0700686 Ethernet ethPkt = inPacket.parsed();
Ari Saha89831742015-06-26 10:31:48 -0700687 // Where does it come from?
Jonathan Hart092dfb22015-11-16 23:05:21 -0800688 MacAddress srcMac = ethPkt.getSourceMAC();
Ari Saha89831742015-06-26 10:31:48 -0700689
Jonathan Harta46dddf2015-06-30 15:31:20 -0700690 DeviceId deviceId = inPacket.receivedFrom().deviceId();
691 PortNumber portNumber = inPacket.receivedFrom().port();
Ari Saha89831742015-06-26 10:31:48 -0700692 String sessionId = deviceId.toString() + portNumber.toString();
Saurav Das987441a2018-09-18 16:33:47 -0700693 EAPOL eapol = (EAPOL) ethPkt.getPayload();
694 if (log.isTraceEnabled()) {
695 log.trace("Received EAPOL packet {} in enclosing packet {} from "
696 + "dev/port: {}/{}", eapol, ethPkt, deviceId,
697 portNumber);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100698 }
Jonathan Harta46dddf2015-06-30 15:31:20 -0700699
Shubham Sharma47869542019-09-13 10:39:47 +0000700 short pktlen = eapol.getPacketLength();
701 byte[] eapPayLoadBuffer = eapol.serialize();
702 int len = eapPayLoadBuffer.length;
703 if (len != (HEADER_LENGTH + pktlen)) {
704 aaaStatisticsManager.getAaaStats().incrementInvalidBodyLength();
705 return;
706 }
707 if (!VALID_EAPOL_TYPE.contains(eapol.getEapolType())) {
708 aaaStatisticsManager.getAaaStats().incrementInvalidPktType();
709 return;
710 }
711 if (pktlen >= 0 && ethPkt.getEtherType() == EthType.EtherType.EAPOL.ethType().toShort()) {
712 aaaStatisticsManager.getAaaStats().incrementValidEapolFramesRx();
713 }
Saurav Das987441a2018-09-18 16:33:47 -0700714 StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(sessionId);
715 if (stateMachine == null) {
716 log.debug("Creating new state machine for sessionId: {} for "
717 + "dev/port: {}/{}", sessionId, deviceId, portNumber);
718 stateMachine = new StateMachine(sessionId);
719 } else {
720 log.debug("Using existing state-machine for sessionId: {}", sessionId);
Kartikey Dubeybe14f472019-10-01 12:18:35 +0000721 stateMachine.setEapolTypeVal(eapol.getEapolType());
Saurav Das987441a2018-09-18 16:33:47 -0700722 }
723
Ari Saha89831742015-06-26 10:31:48 -0700724 switch (eapol.getEapolType()) {
725 case EAPOL.EAPOL_START:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400726 log.debug("EAP packet: EAPOL_START");
Ray Milkeyf51eba22015-09-25 10:24:23 -0700727 stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom());
Shubham Sharmaa3b1bd32019-06-19 14:18:12 +0000728 if (stateMachine.getCleanupTimer() == null) {
729 scheduleStateMachineCleanupTimer(sessionId, stateMachine);
730 }
Jonathan Hart5db44532018-07-12 18:13:54 -0700731 stateMachine.start();
Shubham Sharmac155ef82019-07-11 12:12:41 +0000732 aaaStatisticsManager.getAaaStats().incrementEapolStartReqTrans();
Ray Milkeyf51eba22015-09-25 10:24:23 -0700733 //send an EAP Request/Identify to the supplicant
734 EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100735 if (ethPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) {
736 stateMachine.setPriorityCode(ethPkt.getPriorityCode());
737 }
Jonathan Hart092dfb22015-11-16 23:05:21 -0800738 Ethernet eth = buildEapolResponse(srcMac, MacAddress.valueOf(nasMacAddress),
Ray Milkeyf51eba22015-09-25 10:24:23 -0700739 ethPkt.getVlanID(), EAPOL.EAPOL_PACKET,
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100740 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400741
Jonathan Hart092dfb22015-11-16 23:05:21 -0800742 stateMachine.setSupplicantAddress(srcMac);
Ray Milkeyf51eba22015-09-25 10:24:23 -0700743 stateMachine.setVlanId(ethPkt.getVlanID());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400744 log.debug("Getting EAP identity from supplicant {}", stateMachine.supplicantAddress().toString());
Shubham Sharmac155ef82019-07-11 12:12:41 +0000745 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false);
Shubham Sharma47869542019-09-13 10:39:47 +0000746 aaaStatisticsManager.getAaaStats().incrementRequestIdFramesTx();
Ari Saha89831742015-06-26 10:31:48 -0700747
748 break;
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800749 case EAPOL.EAPOL_LOGOFF:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400750 log.debug("EAP packet: EAPOL_LOGOFF");
Kartikey Dubeybe14f472019-10-01 12:18:35 +0000751 //posting the machine stat data for current supplicant device.
752 if (stateMachine.getSessionTerminateReason() == null ||
753 stateMachine.getSessionTerminateReason().equals("")) {
754 stateMachine.setSessionTerminateReason(
755 StateMachine.SessionTerminationReasons.SUPPLICANT_LOGOFF.getReason());
756 }
757 AaaSupplicantMachineStats obj = aaaSupplicantStatsManager.getSupplicantStats(stateMachine);
758 aaaSupplicantStatsManager.getMachineStatsDelegate()
759 .notify(new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE, obj));
Ray Milkeyb34b4962016-01-04 10:24:43 -0800760 if (stateMachine.state() == StateMachine.STATE_AUTHORIZED) {
761 stateMachine.logoff();
Shubham Sharmac155ef82019-07-11 12:12:41 +0000762 aaaStatisticsManager.getAaaStats().incrementEapolLogoffRx();
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800763 }
Shubham Sharma47869542019-09-13 10:39:47 +0000764 if (stateMachine.state() == StateMachine.STATE_IDLE) {
765 aaaStatisticsManager.getAaaStats().incrementAuthStateIdle();
766 }
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800767
768 break;
Ari Saha89831742015-06-26 10:31:48 -0700769 case EAPOL.EAPOL_PACKET:
Ray Milkeyf51eba22015-09-25 10:24:23 -0700770 RADIUS radiusPayload;
Ray Milkey9eb293f2015-09-30 15:09:17 -0700771 // check if this is a Response/Identify or a Response/TLS
Ari Saha89831742015-06-26 10:31:48 -0700772 EAP eapPacket = (EAP) eapol.getPayload();
Shubham Sharma47869542019-09-13 10:39:47 +0000773 Byte identifier = new Byte(eapPacket.getIdentifier());
Ari Saha89831742015-06-26 10:31:48 -0700774
775 byte dataType = eapPacket.getDataType();
776 switch (dataType) {
Ari Saha89831742015-06-26 10:31:48 -0700777
Ray Milkey9eb293f2015-09-30 15:09:17 -0700778 case EAP.ATTR_IDENTITY:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400779 log.debug("EAP packet: EAPOL_PACKET ATTR_IDENTITY");
Shubham Sharmaa3b1bd32019-06-19 14:18:12 +0000780 //Setting the time of this response from RG, only when its not a re-transmission.
781 if (stateMachine.getLastPacketReceivedTime() == 0) {
782 stateMachine.setLastPacketReceivedTime(System.currentTimeMillis());
783 }
Ray Milkey9eb293f2015-09-30 15:09:17 -0700784 // request id access to RADIUS
785 stateMachine.setUsername(eapPacket.getData());
Ari Saha89831742015-06-26 10:31:48 -0700786
Ray Milkey967776a2015-10-07 14:37:17 -0700787 radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100788 radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket);
Jonathan Hart092dfb22015-11-16 23:05:21 -0800789 radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret);
Ari Saha89831742015-06-26 10:31:48 -0700790
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100791 sendRadiusPacket(radiusPayload, inPacket);
Shubham Sharmaa3b1bd32019-06-19 14:18:12 +0000792 stateMachine.setWaitingForRadiusResponse(true);
Shubham Sharmac155ef82019-07-11 12:12:41 +0000793 aaaStatisticsManager.getAaaStats().incrementEapolAtrrIdentity();
Ray Milkey9eb293f2015-09-30 15:09:17 -0700794 // change the state to "PENDING"
kartikey dubeye1545422019-05-22 12:53:45 +0000795 if (stateMachine.state() == StateMachine.STATE_PENDING) {
796 aaaStatisticsManager.getAaaStats().increaseRequestReTx();
Kartikey Dubeybe14f472019-10-01 12:18:35 +0000797 stateMachine.incrementTotalPacketsSent();
798 stateMachine.incrementTotalOctetSent(eapol.getPacketLength());
kartikey dubeye1545422019-05-22 12:53:45 +0000799 }
Ray Milkey9eb293f2015-09-30 15:09:17 -0700800 stateMachine.requestAccess();
801 break;
Ari Saha89831742015-06-26 10:31:48 -0700802 case EAP.ATTR_MD5:
Shubham Sharmaa3b1bd32019-06-19 14:18:12 +0000803 stateMachine.setLastPacketReceivedTime(System.currentTimeMillis());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400804 log.debug("EAP packet: EAPOL_PACKET ATTR_MD5");
Ray Milkey9eb293f2015-09-30 15:09:17 -0700805 // verify if the EAP identifier corresponds to the
806 // challenge identifier from the client state
807 // machine.
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700808 if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) {
Ari Saha89831742015-06-26 10:31:48 -0700809 //send the RADIUS challenge response
Ray Milkey967776a2015-10-07 14:37:17 -0700810 radiusPayload =
811 getRadiusPayload(stateMachine,
812 stateMachine.identifier(),
813 eapPacket);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100814 radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket);
Ari Saha89831742015-06-26 10:31:48 -0700815
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800816 if (stateMachine.challengeState() != null) {
817 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
818 stateMachine.challengeState());
819 }
Jonathan Hart092dfb22015-11-16 23:05:21 -0800820 radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret);
Shubham Sharma47869542019-09-13 10:39:47 +0000821 if (outPacketSupp.contains(eapPacket.getIdentifier())) {
822 aaaStatisticsManager.getAaaStats().decrementPendingResSupp();
823 outPacketSupp.remove(identifier);
824 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100825 sendRadiusPacket(radiusPayload, inPacket);
Shubham Sharmaa3b1bd32019-06-19 14:18:12 +0000826 stateMachine.setWaitingForRadiusResponse(true);
Shubham Sharmac155ef82019-07-11 12:12:41 +0000827 aaaStatisticsManager.getAaaStats().incrementEapolMd5RspChall();
Ari Saha89831742015-06-26 10:31:48 -0700828 }
829 break;
830 case EAP.ATTR_TLS:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400831 log.debug("EAP packet: EAPOL_PACKET ATTR_TLS");
Ray Milkey9eb293f2015-09-30 15:09:17 -0700832 // request id access to RADIUS
Ray Milkey967776a2015-10-07 14:37:17 -0700833 radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100834 radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket);
Ari Saha89831742015-06-26 10:31:48 -0700835
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800836 if (stateMachine.challengeState() != null) {
837 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
838 stateMachine.challengeState());
839 }
Ray Milkeyf51eba22015-09-25 10:24:23 -0700840 stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode());
Ari Saha89831742015-06-26 10:31:48 -0700841
Jonathan Hart092dfb22015-11-16 23:05:21 -0800842 radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret);
Shubham Sharma47869542019-09-13 10:39:47 +0000843 if (outPacketSupp.contains(eapPacket.getIdentifier())) {
844 aaaStatisticsManager.getAaaStats().decrementPendingResSupp();
845 outPacketSupp.remove(identifier);
846 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100847 sendRadiusPacket(radiusPayload, inPacket);
Shubham Sharmaa3b1bd32019-06-19 14:18:12 +0000848 stateMachine.setWaitingForRadiusResponse(true);
Shubham Sharmac155ef82019-07-11 12:12:41 +0000849 aaaStatisticsManager.getAaaStats().incrementEapolTlsRespChall();
Ray Milkey5493b512015-10-21 12:13:49 -0700850
Ray Milkeyf3790b82015-10-21 16:28:08 -0700851 if (stateMachine.state() != StateMachine.STATE_PENDING) {
852 stateMachine.requestAccess();
853 }
Ray Milkeyf51eba22015-09-25 10:24:23 -0700854
Ari Saha89831742015-06-26 10:31:48 -0700855 break;
856 default:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400857 log.warn("Unknown EAP packet type");
Ari Saha89831742015-06-26 10:31:48 -0700858 return;
859 }
860 break;
861 default:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400862 log.debug("Skipping EAPOL message {}", eapol.getEapolType());
Ari Saha89831742015-06-26 10:31:48 -0700863 }
Shubham Sharmac155ef82019-07-11 12:12:41 +0000864 aaaStatisticsManager.getAaaStats().countTransRespNotNak();
865 aaaStatisticsManager.getAaaStats().countEapolResIdentityMsgTrans();
Ari Saha89831742015-06-26 10:31:48 -0700866 }
Ray Milkey967776a2015-10-07 14:37:17 -0700867 }
868
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100869 /**
Jonathan Hart5db44532018-07-12 18:13:54 -0700870 * Delegate allowing the StateMachine to notify us of events.
871 */
872 private class InternalStateMachineDelegate implements StateMachineDelegate {
873
874 @Override
875 public void notify(AuthenticationEvent authenticationEvent) {
876 log.info("Auth event {} for {}",
877 authenticationEvent.type(), authenticationEvent.subject());
878 post(authenticationEvent);
879 }
880 }
881
882 /**
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100883 * Configuration Listener, handles change in configuration.
884 */
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700885 private class InternalConfigListener implements NetworkConfigListener {
886
887 /**
Ray Milkeyc9e8dcc2015-12-30 10:31:32 -0800888 * Reconfigures the AAA application according to the
889 * configuration parameters passed.
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700890 *
891 * @param cfg configuration object
892 */
Jonathan Hart092dfb22015-11-16 23:05:21 -0800893 private void reconfigureNetwork(AaaConfig cfg) {
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400894 log.info("Reconfiguring AaaConfig from config: {}", cfg);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100895
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700896 if (cfg == null) {
Jonathan Hart092dfb22015-11-16 23:05:21 -0800897 newCfg = new AaaConfig();
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700898 } else {
899 newCfg = cfg;
900 }
901 if (newCfg.nasIp() != null) {
902 nasIpAddress = newCfg.nasIp();
903 }
904 if (newCfg.radiusIp() != null) {
905 radiusIpAddress = newCfg.radiusIp();
906 }
907 if (newCfg.radiusMac() != null) {
908 radiusMacAddress = newCfg.radiusMac();
909 }
910 if (newCfg.nasMac() != null) {
911 nasMacAddress = newCfg.nasMac();
912 }
913 if (newCfg.radiusSecret() != null) {
914 radiusSecret = newCfg.radiusSecret();
915 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100916
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530917 boolean reconfigureCustomizer = false;
918 if (customizer == null || !customizer.equals(newCfg.radiusPktCustomizer())) {
919 customizer = newCfg.radiusPktCustomizer();
920 configurePacketCustomizer();
921 reconfigureCustomizer = true;
922 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100923
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530924 if (radiusConnectionType == null
925 || reconfigureCustomizer
926 || !radiusConnectionType.equals(newCfg.radiusConnectionType())) {
927 radiusConnectionType = newCfg.radiusConnectionType();
928 if (impl != null) {
929 impl.withdrawIntercepts();
930 impl.clearLocalState();
931 }
932 configureRadiusCommunication();
933 impl.initializeLocalState(newCfg);
934 impl.requestIntercepts();
935 } else if (impl != null) {
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100936 impl.clearLocalState();
937 impl.initializeLocalState(newCfg);
Ray Milkey5d99bd12015-10-06 15:41:30 -0700938 }
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700939 }
940
941 @Override
942 public void event(NetworkConfigEvent event) {
943
944 if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
945 event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) &&
Jonathan Hart092dfb22015-11-16 23:05:21 -0800946 event.configClass().equals(AaaConfig.class)) {
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700947
Jonathan Hart092dfb22015-11-16 23:05:21 -0800948 AaaConfig cfg = netCfgService.getConfig(appId, AaaConfig.class);
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700949 reconfigureNetwork(cfg);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100950
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400951 log.info("Reconfigured: {}", cfg.toString());
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700952 }
953 }
954 }
Amit Ghoshf739be52017-09-21 15:49:37 +0100955
956 private class InternalDeviceListener implements DeviceListener {
957 @Override
958 public void event(DeviceEvent event) {
959
960 switch (event.type()) {
961 case PORT_REMOVED:
962 DeviceId devId = event.subject().id();
963 PortNumber portNumber = event.port().number();
964 String sessionId = devId.toString() + portNumber.toString();
965
Girish Kumar8bc4eb32020-02-04 08:32:46 +0000966 log.info("Received PORT_REMOVED event. Clearing AAA Session with Id {}", sessionId);
967 flushStateMachineSession(sessionId,
968 StateMachine.SessionTerminationReasons.PORT_REMOVED.getReason());
Kartikey Dubeybe14f472019-10-01 12:18:35 +0000969
Girish Kumar8bc4eb32020-02-04 08:32:46 +0000970 break;
971
972 case DEVICE_REMOVED:
973 DeviceId deviceId = event.subject().id();
974 log.info("Received DEVICE_REMOVED event for {}", deviceId);
975
976 Set<String> associatedSessions = Sets.newHashSet();
977 for (Entry<String, StateMachine> stateMachineEntry : StateMachine.sessionIdMap().entrySet()) {
978 ConnectPoint cp = stateMachineEntry.getValue().supplicantConnectpoint();
979 if (cp != null && cp.deviceId().toString().equals(deviceId.toString())) {
980 associatedSessions.add(stateMachineEntry.getKey());
981 }
982 }
983
984 for (String session : associatedSessions) {
985 log.info("Clearing AAA Session {} associated with Removed Device", session);
986 flushStateMachineSession(session,
987 StateMachine.SessionTerminationReasons.DEVICE_REMOVED.getReason());
Amit Ghoshf739be52017-09-21 15:49:37 +0100988 }
989
990 break;
Girish Kumar8bc4eb32020-02-04 08:32:46 +0000991
Amit Ghoshf739be52017-09-21 15:49:37 +0100992 default:
993 return;
994 }
995 }
Girish Kumar8bc4eb32020-02-04 08:32:46 +0000996
997 private void flushStateMachineSession(String sessionId, String terminationReason) {
998 StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(sessionId);
999 if (stateMachine != null) {
1000 stateMachine.setSessionTerminateReason(terminationReason);
1001 }
1002
1003 //pushing captured machine stats to kafka
1004 AaaSupplicantMachineStats obj = aaaSupplicantStatsManager.getSupplicantStats(stateMachine);
1005 aaaSupplicantStatsManager.getMachineStatsDelegate()
1006 .notify(new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE, obj));
1007
1008 Map<String, StateMachine> sessionIdMap = StateMachine.sessionIdMap();
1009 StateMachine removed = sessionIdMap.remove(sessionId);
1010 if (removed != null) {
1011 StateMachine.deleteStateMachineMapping(removed);
1012 }
1013 }
Amit Ghoshf739be52017-09-21 15:49:37 +01001014 }
Girish Kumar8bc4eb32020-02-04 08:32:46 +00001015
kartikey dubeye1545422019-05-22 12:53:45 +00001016 private class AuthenticationStatisticsEventPublisher implements Runnable {
1017 private final Logger log = getLogger(getClass());
1018 public void run() {
1019 log.info("Notifying AuthenticationStatisticsEvent");
1020 aaaStatisticsManager.calculatePacketRoundtripTime();
1021 log.debug("AcceptResponsesRx---" + aaaStatisticsManager.getAaaStats().getAcceptResponsesRx());
1022 log.debug("AccessRequestsTx---" + aaaStatisticsManager.getAaaStats().getAccessRequestsTx());
1023 log.debug("ChallengeResponsesRx---" + aaaStatisticsManager.getAaaStats().getChallengeResponsesRx());
1024 log.debug("DroppedResponsesRx---" + aaaStatisticsManager.getAaaStats().getDroppedResponsesRx());
1025 log.debug("InvalidValidatorsRx---" + aaaStatisticsManager.getAaaStats().getInvalidValidatorsRx());
1026 log.debug("MalformedResponsesRx---" + aaaStatisticsManager.getAaaStats().getMalformedResponsesRx());
1027 log.debug("PendingRequests---" + aaaStatisticsManager.getAaaStats().getPendingRequests());
1028 log.debug("RejectResponsesRx---" + aaaStatisticsManager.getAaaStats().getRejectResponsesRx());
1029 log.debug("RequestReTx---" + aaaStatisticsManager.getAaaStats().getRequestReTx());
1030 log.debug("RequestRttMilis---" + aaaStatisticsManager.getAaaStats().getRequestRttMilis());
1031 log.debug("UnknownServerRx---" + aaaStatisticsManager.getAaaStats().getUnknownServerRx());
1032 log.debug("UnknownTypeRx---" + aaaStatisticsManager.getAaaStats().getUnknownTypeRx());
Shubham Sharmaa3b1bd32019-06-19 14:18:12 +00001033 log.debug("TimedOutPackets----" + aaaStatisticsManager.getAaaStats().getTimedOutPackets());
Shubham Sharmac155ef82019-07-11 12:12:41 +00001034 log.debug("EapolLogoffRx---" + aaaStatisticsManager.getAaaStats().getEapolLogoffRx());
1035 log.debug("EapolAuthSuccessTrans---" + aaaStatisticsManager.getAaaStats().getEapolAuthSuccessTrans());
1036 log.debug("EapolAuthFailureTrans---" +
1037 aaaStatisticsManager.getAaaStats().getEapolAuthFailureTrans());
1038 log.debug("EapolStartReqTrans---" +
1039 aaaStatisticsManager.getAaaStats().getEapolStartReqTrans());
1040 log.debug("EapolTransRespNotNak---" +
1041 aaaStatisticsManager.getAaaStats().getEapolTransRespNotNak());
1042 log.debug("EapPktTxauthChooseEap---" +
1043 aaaStatisticsManager.getAaaStats().getEapPktTxauthChooseEap());
1044 log.debug("EapolResIdentityMsgTrans---" +
1045 aaaStatisticsManager.getAaaStats().getEapolResIdentityMsgTrans());
Shubham Sharma47869542019-09-13 10:39:47 +00001046 log.debug("EapolFramesTx---" + aaaStatisticsManager.getAaaStats().getEapolFramesTx());
1047 log.debug("AuthStateIdle---" + aaaStatisticsManager.getAaaStats().getAuthStateIdle());
1048 log.debug("RequestIdFramesTx---" + aaaStatisticsManager.getAaaStats().getRequestIdFramesTx());
1049 log.debug("ReqEapFramesTx---" + aaaStatisticsManager.getAaaStats().getReqEapFramesTx());
1050 log.debug("InvalidPktType---" + aaaStatisticsManager.getAaaStats().getInvalidPktType());
1051 log.debug("InvalidBodyLength---" + aaaStatisticsManager.getAaaStats().getInvalidBodyLength());
1052 log.debug("ValidEapolFramesRx---" + aaaStatisticsManager.getAaaStats().getValidEapolFramesRx());
1053 log.debug("PendingResSupp---" + aaaStatisticsManager.getAaaStats().getPendingResSupp());
1054 log.debug("ResIdEapFramesRx---" + aaaStatisticsManager.getAaaStats().getEapolattrIdentity());
kartikey dubeye1545422019-05-22 12:53:45 +00001055 aaaStatisticsManager.getStatsDelegate().
1056 notify(new AuthenticationStatisticsEvent(AuthenticationStatisticsEvent.Type.STATS_UPDATE,
1057 aaaStatisticsManager.getAaaStats()));
1058 }
Shubham Sharma048cc262019-06-19 14:18:50 +00001059 }
1060
1061 private class ServerStatusChecker implements Runnable {
1062 @Override
1063 public void run() {
1064 log.info("Notifying RadiusOperationalStatusEvent");
1065 radiusOperationalStatusService.checkServerOperationalStatus();
1066 log.info("--POSTING--" + radiusOperationalStatusService.getRadiusServerOperationalStatus());
1067 radiusOperationalStatusService.getRadiusOprStDelegate()
1068 .notify(new RadiusOperationalStatusEvent(
1069 RadiusOperationalStatusEvent.Type.RADIUS_OPERATIONAL_STATUS,
1070 radiusOperationalStatusService.
1071 getRadiusServerOperationalStatus()));
kartikey dubeye1545422019-05-22 12:53:45 +00001072 }
Shubham Sharma048cc262019-06-19 14:18:50 +00001073
1074 }
Girish Kumar8bc4eb32020-02-04 08:32:46 +00001075}