blob: 67cfb75ba4b394eb94266cf45fcfa544a642eb8a [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
Shubham Sharma4900ce62019-06-19 14:18:50 +000018import com.google.common.base.Strings;
Jonathan Hart612651f2019-11-25 09:21:43 -080019import com.google.common.collect.Maps;
Jonathan Hart932bedc2018-07-12 13:46:09 -070020import org.apache.commons.lang3.builder.ToStringBuilder;
Jonathan Hart4731dd92018-05-02 17:30:05 -070021import org.onlab.packet.DeserializationException;
Jonathan Harta46dddf2015-06-30 15:31:20 -070022import org.onlab.packet.EAP;
23import org.onlab.packet.EAPOL;
24import org.onlab.packet.EthType;
Ari Saha89831742015-06-26 10:31:48 -070025import org.onlab.packet.Ethernet;
Ari Saha89831742015-06-26 10:31:48 -070026import org.onlab.packet.MacAddress;
Jonathan Harta46dddf2015-06-30 15:31:20 -070027import org.onlab.packet.RADIUS;
28import org.onlab.packet.RADIUSAttribute;
kartikey dubeye1545422019-05-22 12:53:45 +000029import org.onlab.util.Tools;
30import org.onosproject.cfg.ComponentConfigService;
Ari Saha89831742015-06-26 10:31:48 -070031import org.onosproject.core.ApplicationId;
32import org.onosproject.core.CoreService;
Jonathan Hart5db44532018-07-12 18:13:54 -070033import org.onosproject.event.AbstractListenerManager;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010034import org.onosproject.mastership.MastershipService;
Ari Saha89831742015-06-26 10:31:48 -070035import org.onosproject.net.ConnectPoint;
36import org.onosproject.net.DeviceId;
Ari Saha89831742015-06-26 10:31:48 -070037import org.onosproject.net.PortNumber;
Ray Milkeyfcb623d2015-10-01 16:48:18 -070038import org.onosproject.net.config.ConfigFactory;
39import org.onosproject.net.config.NetworkConfigEvent;
40import org.onosproject.net.config.NetworkConfigListener;
41import org.onosproject.net.config.NetworkConfigRegistry;
Amit Ghoshf739be52017-09-21 15:49:37 +010042import org.onosproject.net.device.DeviceEvent;
43import org.onosproject.net.device.DeviceListener;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010044import org.onosproject.net.device.DeviceService;
Ari Saha89831742015-06-26 10:31:48 -070045import org.onosproject.net.flow.DefaultTrafficTreatment;
Ari Saha89831742015-06-26 10:31:48 -070046import org.onosproject.net.flow.TrafficTreatment;
Ari Saha89831742015-06-26 10:31:48 -070047import org.onosproject.net.packet.DefaultOutboundPacket;
48import org.onosproject.net.packet.InboundPacket;
49import org.onosproject.net.packet.OutboundPacket;
50import org.onosproject.net.packet.PacketContext;
Ari Saha89831742015-06-26 10:31:48 -070051import org.onosproject.net.packet.PacketProcessor;
52import org.onosproject.net.packet.PacketService;
Matteo Scandolocf847b82019-04-26 15:00:00 -070053import org.opencord.aaa.AaaConfig;
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +000054import org.opencord.aaa.AaaMachineStatisticsEvent;
55import org.opencord.aaa.AaaMachineStatisticsService;
56import org.opencord.aaa.AaaSupplicantMachineStats;
Matteo Scandolocf847b82019-04-26 15:00:00 -070057import org.opencord.aaa.AuthenticationEvent;
58import org.opencord.aaa.AuthenticationEventListener;
Jonathan Hart612651f2019-11-25 09:21:43 -080059import org.opencord.aaa.AuthenticationRecord;
Matteo Scandolocf847b82019-04-26 15:00:00 -070060import org.opencord.aaa.AuthenticationService;
kartikey dubeye1545422019-05-22 12:53:45 +000061import org.opencord.aaa.AuthenticationStatisticsEvent;
62import org.opencord.aaa.AuthenticationStatisticsService;
Matteo Scandolocf847b82019-04-26 15:00:00 -070063import org.opencord.aaa.RadiusCommunicator;
Shubham Sharma4900ce62019-06-19 14:18:50 +000064import org.opencord.aaa.RadiusOperationalStatusEvent;
65import org.opencord.aaa.RadiusOperationalStatusService;
66import org.opencord.aaa.RadiusOperationalStatusService.RadiusOperationalStatusEvaluationMode;
Matteo Scandolocf847b82019-04-26 15:00:00 -070067import org.opencord.aaa.StateMachineDelegate;
Gamze Abaka1cfdb192018-10-25 11:39:19 +000068import org.opencord.sadis.BaseInformationService;
69import org.opencord.sadis.SadisService;
70import org.opencord.sadis.SubscriberAndDeviceInformation;
kartikey dubeye1545422019-05-22 12:53:45 +000071import org.osgi.service.component.ComponentContext;
Carmelo Cascone58b53292019-09-30 12:35:31 -070072import org.osgi.service.component.annotations.Activate;
Shubham Sharma4900ce62019-06-19 14:18:50 +000073import org.osgi.service.component.annotations.Component;
74import org.osgi.service.component.annotations.Deactivate;
75import org.osgi.service.component.annotations.Modified;
76import org.osgi.service.component.annotations.Reference;
77import org.osgi.service.component.annotations.ReferenceCardinality;
Ari Saha89831742015-06-26 10:31:48 -070078import org.slf4j.Logger;
79
Shubham Sharma4900ce62019-06-19 14:18:50 +000080import javax.crypto.Mac;
81import javax.crypto.spec.SecretKeySpec;
82import java.net.InetAddress;
83import java.net.UnknownHostException;
84import java.nio.ByteBuffer;
85import java.util.Arrays;
86import java.util.Dictionary;
87import java.util.HashSet;
88import java.util.List;
89import java.util.Map;
Jonathan Hart612651f2019-11-25 09:21:43 -080090import java.util.concurrent.ConcurrentMap;
kartikey dubeye1545422019-05-22 12:53:45 +000091import java.util.concurrent.Executors;
92import java.util.concurrent.ScheduledExecutorService;
93import java.util.concurrent.ScheduledFuture;
94import java.util.concurrent.TimeUnit;
Jonathan Hart612651f2019-11-25 09:21:43 -080095import java.util.stream.Collectors;
Vijaykumar Kushwaha056e4cd2019-08-06 13:16:25 +000096
Shubham Sharma4900ce62019-06-19 14:18:50 +000097import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
98import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_EVENT_GENERATION;
99import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_EVENT_GENERATION_DEFAULT;
100import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_TIMEOUT;
101import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_TIMEOUT_DEFAULT;
102import static org.opencord.aaa.impl.OsgiPropertyConstants.STATISTICS_GENERATION_PERIOD;
103import static org.opencord.aaa.impl.OsgiPropertyConstants.STATISTICS_GENERATION_PERIOD_DEFAULT;
104import static org.opencord.aaa.impl.OsgiPropertyConstants.STATUS_SERVER_MODE;
105import static org.opencord.aaa.impl.OsgiPropertyConstants.STATUS_SERVER_MODE_DEFAULT;
106import static org.slf4j.LoggerFactory.getLogger;
Carmelo Cascone58b53292019-09-30 12:35:31 -0700107
Ari Saha89831742015-06-26 10:31:48 -0700108/**
Jonathan Harta46dddf2015-06-30 15:31:20 -0700109 * AAA application for ONOS.
Ari Saha89831742015-06-26 10:31:48 -0700110 */
Carmelo Cascone58b53292019-09-30 12:35:31 -0700111@Component(immediate = true, property = {
Shubham Sharma4900ce62019-06-19 14:18:50 +0000112 STATISTICS_GENERATION_PERIOD + ":Integer=" + STATISTICS_GENERATION_PERIOD_DEFAULT,
113 OPERATIONAL_STATUS_SERVER_EVENT_GENERATION + ":Integer=" + OPERATIONAL_STATUS_SERVER_EVENT_GENERATION_DEFAULT,
114 OPERATIONAL_STATUS_SERVER_TIMEOUT + ":Integer=" + OPERATIONAL_STATUS_SERVER_TIMEOUT_DEFAULT,
115 STATUS_SERVER_MODE + ":String=" + STATUS_SERVER_MODE_DEFAULT,
Carmelo Cascone58b53292019-09-30 12:35:31 -0700116})
Jonathan Hart5db44532018-07-12 18:13:54 -0700117public class AaaManager
118 extends AbstractListenerManager<AuthenticationEvent, AuthenticationEventListener>
119 implements AuthenticationService {
120
Charles Chandf7ff862017-01-20 11:22:05 -0800121 private static final String APP_NAME = "org.opencord.aaa";
Ray Milkeyf51eba22015-09-25 10:24:23 -0700122
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700123 private final Logger log = getLogger(getClass());
Ray Milkeyf51eba22015-09-25 10:24:23 -0700124
Carmelo Cascone58b53292019-09-30 12:35:31 -0700125 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700126 protected CoreService coreService;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700127
Carmelo Cascone58b53292019-09-30 12:35:31 -0700128 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700129 protected PacketService packetService;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700130
Carmelo Cascone58b53292019-09-30 12:35:31 -0700131 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700132 protected NetworkConfigRegistry netCfgService;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700133
Carmelo Cascone58b53292019-09-30 12:35:31 -0700134 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100135 protected DeviceService deviceService;
136
Carmelo Cascone58b53292019-09-30 12:35:31 -0700137 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Gamze Abaka1cfdb192018-10-25 11:39:19 +0000138 protected SadisService sadisService;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100139
Carmelo Cascone58b53292019-09-30 12:35:31 -0700140 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100141 protected MastershipService mastershipService;
142
Carmelo Cascone58b53292019-09-30 12:35:31 -0700143 @Reference(cardinality = ReferenceCardinality.MANDATORY)
kartikey dubeye1545422019-05-22 12:53:45 +0000144 protected AuthenticationStatisticsService aaaStatisticsManager;
Gamze Abaka1cfdb192018-10-25 11:39:19 +0000145
Carmelo Cascone58b53292019-09-30 12:35:31 -0700146 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +0000147 protected AaaMachineStatisticsService aaaSupplicantStatsManager;
148
149 @Reference(cardinality = ReferenceCardinality.MANDATORY)
kartikey dubeye1545422019-05-22 12:53:45 +0000150 protected ComponentConfigService cfgService;
151
Shubham Sharma4900ce62019-06-19 14:18:50 +0000152 @Reference(cardinality = ReferenceCardinality.MANDATORY)
153 protected RadiusOperationalStatusService radiusOperationalStatusService;
154
kartikey dubeye1545422019-05-22 12:53:45 +0000155 protected AuthenticationStatisticsEventPublisher authenticationStatisticsPublisher;
156 protected BaseInformationService<SubscriberAndDeviceInformation> subsService;
Amit Ghoshf739be52017-09-21 15:49:37 +0100157 private final DeviceListener deviceListener = new InternalDeviceListener();
158
Shubham Sharma4900ce62019-06-19 14:18:50 +0000159 // Properties
160 private int statisticsGenerationPeriodInSeconds = STATISTICS_GENERATION_PERIOD_DEFAULT;
161 private int operationalStatusEventGenerationPeriodInSeconds = OPERATIONAL_STATUS_SERVER_EVENT_GENERATION_DEFAULT;
162 private int operationalStatusServerTimeoutInSeconds = OPERATIONAL_STATUS_SERVER_TIMEOUT_DEFAULT;
163 protected String operationalStatusEvaluationMode = STATUS_SERVER_MODE_DEFAULT;
kartikey dubeye1545422019-05-22 12:53:45 +0000164
Jonathan Hart612651f2019-11-25 09:21:43 -0800165 private IdentifierManager idManager;
166
167 private ConcurrentMap<String, StateMachine> stateMachines;
168
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700169 // NAS IP address
170 protected InetAddress nasIpAddress;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100171
172 // self MAC address
Jonathan Hart5db44532018-07-12 18:13:54 -0700173 protected String nasMacAddress;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100174
175 // Parsed RADIUS server addresses
176 protected InetAddress radiusIpAddress;
177
178 // MAC address of RADIUS server or net hop router
179 protected String radiusMacAddress;
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700180
181 // RADIUS server secret
182 protected String radiusSecret;
183
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100184 // bindings
185 protected CustomizationInfo customInfo;
Ray Milkey5d99bd12015-10-06 15:41:30 -0700186
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700187 // our application-specific event handler
188 private ReactivePacketProcessor processor = new ReactivePacketProcessor();
Ray Milkeyf51eba22015-09-25 10:24:23 -0700189
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700190 // our unique identifier
191 private ApplicationId appId;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700192
Shubham Sharma1e43c562019-06-19 14:18:12 +0000193 // TimeOut time for cleaning up stateMachines stuck due to pending AAA/EAPOL message.
194 protected int cleanupTimerTimeOutInMins;
195
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100196 // Setup specific customization/attributes on the RADIUS packets
197 PacketCustomizer pktCustomizer;
Ray Milkey967776a2015-10-07 14:37:17 -0700198
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100199 // packet customizer to use
200 private String customizer;
201
202 // Type of connection to use to communicate with Radius server, options are
203 // "socket" or "packet_out"
204 private String radiusConnectionType;
205
Jonathan Hart5db44532018-07-12 18:13:54 -0700206 // Object for the specific type of communication with the RADIUS
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100207 // server, socket based or packet_out based
208 RadiusCommunicator impl = null;
209
210 // latest configuration
211 AaaConfig newCfg;
Ray Milkey967776a2015-10-07 14:37:17 -0700212
kartikey dubeye1545422019-05-22 12:53:45 +0000213 ScheduledFuture<?> scheduledFuture;
Shubham Sharma4900ce62019-06-19 14:18:50 +0000214 ScheduledFuture<?> scheduledStatusServerChecker;
kartikey dubeye1545422019-05-22 12:53:45 +0000215 ScheduledExecutorService executor;
216 String configuredAaaServerAddress;
217 HashSet<Byte> outPacketSet = new HashSet<Byte>();
Shubham Sharma3c8c7022019-09-13 10:39:47 +0000218 HashSet<Byte> outPacketSupp = new HashSet<Byte>();
219 static final List<Byte> VALID_EAPOL_TYPE = Arrays.asList(EAPOL.EAPOL_START, EAPOL.EAPOL_LOGOFF, EAPOL.EAPOL_PACKET);
220 static final int HEADER_LENGTH = 4;
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700221 // Configuration properties factory
222 private final ConfigFactory factory =
Jonathan Hart092dfb22015-11-16 23:05:21 -0800223 new ConfigFactory<ApplicationId, AaaConfig>(APP_SUBJECT_FACTORY,
224 AaaConfig.class,
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700225 "AAA") {
226 @Override
Jonathan Hart092dfb22015-11-16 23:05:21 -0800227 public AaaConfig createConfig() {
228 return new AaaConfig();
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700229 }
230 };
Ray Milkeyf51eba22015-09-25 10:24:23 -0700231
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700232 // Listener for config changes
233 private final InternalConfigListener cfgListener = new InternalConfigListener();
Ari Saha89831742015-06-26 10:31:48 -0700234
Jonathan Hart5db44532018-07-12 18:13:54 -0700235 private StateMachineDelegate delegate = new InternalStateMachineDelegate();
236
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700237 /**
238 * Builds an EAPOL packet based on the given parameters.
239 *
240 * @param dstMac destination MAC address
241 * @param srcMac source MAC address
242 * @param vlan vlan identifier
243 * @param eapolType EAPOL type
244 * @param eap EAP payload
245 * @return Ethernet frame
246 */
247 private static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac,
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100248 short vlan, byte eapolType, EAP eap, byte priorityCode) {
Ari Saha89831742015-06-26 10:31:48 -0700249
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700250 Ethernet eth = new Ethernet();
251 eth.setDestinationMACAddress(dstMac.toBytes());
252 eth.setSourceMACAddress(srcMac.toBytes());
253 eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort());
254 if (vlan != Ethernet.VLAN_UNTAGGED) {
255 eth.setVlanID(vlan);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100256 eth.setPriorityCode(priorityCode);
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700257 }
258 //eapol header
259 EAPOL eapol = new EAPOL();
260 eapol.setEapolType(eapolType);
261 eapol.setPacketLength(eap.getLength());
Ari Saha89831742015-06-26 10:31:48 -0700262
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700263 //eap part
264 eapol.setPayload(eap);
265
266 eth.setPayload(eapol);
267 eth.setPad(true);
268 return eth;
269 }
Ari Saha89831742015-06-26 10:31:48 -0700270
Ari Saha89831742015-06-26 10:31:48 -0700271 @Activate
kartikey dubeye1545422019-05-22 12:53:45 +0000272 public void activate(ComponentContext context) {
Jonathan Hart612651f2019-11-25 09:21:43 -0800273 idManager = new IdentifierManager();
274 stateMachines = Maps.newConcurrentMap();
Charles Chandf7ff862017-01-20 11:22:05 -0800275 appId = coreService.registerApplication(APP_NAME);
Jonathan Hart5db44532018-07-12 18:13:54 -0700276 eventDispatcher.addSink(AuthenticationEvent.class, listenerRegistry);
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400277 netCfgService.addListener(cfgListener);
278 netCfgService.registerConfigFactory(factory);
kartikey dubeye1545422019-05-22 12:53:45 +0000279 cfgService.registerProperties(getClass());
280 modified(context);
Gamze Abaka1cfdb192018-10-25 11:39:19 +0000281 subsService = sadisService.getSubscriberInfoService();
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530282 customInfo = new CustomizationInfo(subsService, deviceService);
Jonathan Hart092dfb22015-11-16 23:05:21 -0800283 cfgListener.reconfigureNetwork(netCfgService.getConfig(appId, AaaConfig.class));
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400284 log.info("Starting with config {} {}", this, newCfg);
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530285 configureRadiusCommunication();
Ari Saha89831742015-06-26 10:31:48 -0700286 // register our event handler
Brian O'Connord9c7da02015-07-29 17:49:24 -0700287 packetService.addProcessor(processor, PacketProcessor.director(2));
Jonathan Hart5db44532018-07-12 18:13:54 -0700288 StateMachine.setDelegate(delegate);
Shubham Sharma1e43c562019-06-19 14:18:12 +0000289 cleanupTimerTimeOutInMins = newCfg.sessionCleanupTimer();
290 StateMachine.setcleanupTimerTimeOutInMins(cleanupTimerTimeOutInMins);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100291 impl.initializeLocalState(newCfg);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100292 impl.requestIntercepts();
Amit Ghoshf739be52017-09-21 15:49:37 +0100293 deviceService.addListener(deviceListener);
kartikey dubeye1545422019-05-22 12:53:45 +0000294 getConfiguredAaaServerAddress();
Shubham Sharma4900ce62019-06-19 14:18:50 +0000295 radiusOperationalStatusService.initialize(nasIpAddress.getAddress(), radiusSecret, impl);
kartikey dubeye1545422019-05-22 12:53:45 +0000296 authenticationStatisticsPublisher =
297 new AuthenticationStatisticsEventPublisher();
Shubham Sharma4900ce62019-06-19 14:18:50 +0000298 executor = Executors.newScheduledThreadPool(3);
299
kartikey dubeye1545422019-05-22 12:53:45 +0000300 scheduledFuture = executor.scheduleAtFixedRate(authenticationStatisticsPublisher,
Shubham Sharma4900ce62019-06-19 14:18:50 +0000301 0, statisticsGenerationPeriodInSeconds, TimeUnit.SECONDS);
302 scheduledStatusServerChecker = executor.scheduleAtFixedRate(new ServerStatusChecker(), 0,
303 operationalStatusEventGenerationPeriodInSeconds, TimeUnit.SECONDS);
Amit Ghoshf739be52017-09-21 15:49:37 +0100304
Jian Li13c67162015-12-09 13:20:34 -0800305 log.info("Started");
Ari Saha89831742015-06-26 10:31:48 -0700306 }
307
308 @Deactivate
kartikey dubeye1545422019-05-22 12:53:45 +0000309 public void deactivate(ComponentContext context) {
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100310 impl.withdrawIntercepts();
Ari Saha89831742015-06-26 10:31:48 -0700311 packetService.removeProcessor(processor);
Deepa Vaddireddyb9c24c62017-09-21 13:45:30 +0530312 netCfgService.removeListener(cfgListener);
kartikey dubeye1545422019-05-22 12:53:45 +0000313 cfgService.unregisterProperties(getClass(), false);
Jonathan Hart5db44532018-07-12 18:13:54 -0700314 StateMachine.unsetDelegate(delegate);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100315 impl.deactivate();
Amit Ghoshf739be52017-09-21 15:49:37 +0100316 deviceService.removeListener(deviceListener);
Jonathan Hart5db44532018-07-12 18:13:54 -0700317 eventDispatcher.removeSink(AuthenticationEvent.class);
kartikey dubeye1545422019-05-22 12:53:45 +0000318 scheduledFuture.cancel(true);
Shubham Sharma4900ce62019-06-19 14:18:50 +0000319 scheduledStatusServerChecker.cancel(true);
kartikey dubeye1545422019-05-22 12:53:45 +0000320 executor.shutdown();
Jian Li13c67162015-12-09 13:20:34 -0800321 log.info("Stopped");
Ray Milkey967776a2015-10-07 14:37:17 -0700322 }
kartikey dubeye1545422019-05-22 12:53:45 +0000323 @Modified
324 public void modified(ComponentContext context) {
Shubham Sharma4900ce62019-06-19 14:18:50 +0000325 Dictionary<String, Object> properties = context.getProperties();
326
327 String s = Tools.get(properties, "statisticsGenerationPeriodInSeconds");
328 statisticsGenerationPeriodInSeconds = Strings.isNullOrEmpty(s) ? STATISTICS_GENERATION_PERIOD_DEFAULT
329 : Integer.parseInt(s.trim());
330
331 s = Tools.get(properties, "operationalStatusEventGenerationPeriodInSeconds");
332 operationalStatusEventGenerationPeriodInSeconds = Strings.isNullOrEmpty(s)
333 ? OPERATIONAL_STATUS_SERVER_EVENT_GENERATION_DEFAULT
334 : Integer.parseInt(s.trim());
335
336 s = Tools.get(properties, "operationalStatusServerTimeoutInSeconds");
337 operationalStatusServerTimeoutInSeconds = Strings.isNullOrEmpty(s) ? OPERATIONAL_STATUS_SERVER_TIMEOUT_DEFAULT
338 : Integer.parseInt(s.trim());
339
340 s = Tools.get(properties, "operationalStatusEvaluationMode");
341 String newEvaluationModeString = Strings.isNullOrEmpty(s) ? STATUS_SERVER_MODE_DEFAULT : s.trim();
342
343 radiusOperationalStatusService
344 .setOperationalStatusServerTimeoutInMillis(operationalStatusServerTimeoutInSeconds * 1000);
345 RadiusOperationalStatusEvaluationMode newEvaluationMode =
346 RadiusOperationalStatusEvaluationMode.getValue(newEvaluationModeString);
347 if (newEvaluationMode != null) {
348 radiusOperationalStatusService.setRadiusOperationalStatusEvaluationMode(newEvaluationMode);
349 operationalStatusEvaluationMode = newEvaluationModeString;
350 } else {
351 properties.put("operationalStatusEvaluationMode", operationalStatusEvaluationMode);
352 }
kartikey dubeye1545422019-05-22 12:53:45 +0000353 }
354
Shubham Sharmacf5e5032019-11-26 11:09:21 +0000355 protected void configureRadiusCommunication() {
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530356 if (radiusConnectionType.toLowerCase().equals("socket")) {
357 impl = new SocketBasedRadiusCommunicator(appId, packetService, this);
358 } else {
359 impl = new PortBasedRadiusCommunicator(appId, packetService, mastershipService,
360 deviceService, subsService, pktCustomizer, this);
361 }
362 }
363
364 private void configurePacketCustomizer() {
365 switch (customizer.toLowerCase()) {
366 case "sample":
367 pktCustomizer = new SamplePacketCustomizer(customInfo);
368 log.info("Created SamplePacketCustomizer");
369 break;
Saurav Dase72358a2018-11-13 21:56:46 -0800370 case "att":
371 pktCustomizer = new AttPacketCustomizer(customInfo);
372 log.info("Created AttPacketCustomizer");
373 break;
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530374 default:
375 pktCustomizer = new PacketCustomizer(customInfo);
376 log.info("Created default PacketCustomizer");
377 break;
378 }
379 }
380
kartikey dubeye1545422019-05-22 12:53:45 +0000381 private void getConfiguredAaaServerAddress() {
382 try {
383 InetAddress address;
384 if (newCfg.radiusHostName() != null) {
385 address = InetAddress.getByName(newCfg.radiusHostName());
386 } else {
387 address = newCfg.radiusIp();
388 }
389
390 configuredAaaServerAddress = address.getHostAddress();
391 } catch (UnknownHostException uhe) {
392 log.warn("Unable to resolve host {}", newCfg.radiusHostName());
393 }
394 }
395
Vijaykumar Kushwaha056e4cd2019-08-06 13:16:25 +0000396 private void checkReceivedPacketForValidValidator(RADIUS radiusPacket, byte[] requestAuthenticator) {
397 if (!checkResponseMessageAuthenticator(radiusSecret, radiusPacket, requestAuthenticator)) {
kartikey dubeye1545422019-05-22 12:53:45 +0000398 aaaStatisticsManager.getAaaStats().increaseInvalidValidatorsRx();
399 }
400 }
Vijaykumar Kushwaha056e4cd2019-08-06 13:16:25 +0000401
402 private boolean checkResponseMessageAuthenticator(String key, RADIUS radiusPacket, byte[] requestAuthenticator) {
403 byte[] newHash = new byte[16];
404 Arrays.fill(newHash, (byte) 0);
405 byte[] messageAuthenticator = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH).getValue();
406 byte[] authenticator = radiusPacket.getAuthenticator();
407 radiusPacket.updateAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH, newHash);
408 radiusPacket.setAuthenticator(requestAuthenticator);
409 // Calculate the MD5 HMAC based on the message
410 try {
411 SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacMD5");
412 Mac mac = Mac.getInstance("HmacMD5");
413 mac.init(keySpec);
414 newHash = mac.doFinal(radiusPacket.serialize());
415 } catch (Exception e) {
416 log.error("Failed to generate message authenticator: {}", e.getMessage());
417 }
418 radiusPacket.updateAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH, messageAuthenticator);
419 radiusPacket.setAuthenticator(authenticator);
420 // Compare the calculated Message-Authenticator with the one in the message
421 return Arrays.equals(newHash, messageAuthenticator);
422 }
kartikey dubeye1545422019-05-22 12:53:45 +0000423 public void checkForPacketFromUnknownServer(String hostAddress) {
424 if (!hostAddress.equals(configuredAaaServerAddress)) {
Vijaykumar Kushwahafffd3d12019-08-01 11:09:59 +0000425 getConfiguredAaaServerAddress();
426 if (!hostAddress.equals(configuredAaaServerAddress)) {
427 aaaStatisticsManager.getAaaStats().incrementUnknownServerRx();
428 }
kartikey dubeye1545422019-05-22 12:53:45 +0000429 }
430 }
431
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100432 /**
433 * Send RADIUS packet to the RADIUS server.
434 *
435 * @param radiusPacket RADIUS packet to be sent to server.
436 * @param inPkt Incoming EAPOL packet
437 */
438 protected void sendRadiusPacket(RADIUS radiusPacket, InboundPacket inPkt) {
kartikey dubeye1545422019-05-22 12:53:45 +0000439 outPacketSet.add(radiusPacket.getIdentifier());
440 aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(true);
441 aaaStatisticsManager.getAaaStats().increaseAccessRequestsTx();
Shubham Sharma4900ce62019-06-19 14:18:50 +0000442 aaaStatisticsManager.putOutgoingIdentifierToMap(radiusPacket.getIdentifier());
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100443 impl.sendRadiusPacket(radiusPacket, inPkt);
444 }
Ray Milkey967776a2015-10-07 14:37:17 -0700445
Jonathan Hart612651f2019-11-25 09:21:43 -0800446 /**
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100447 * Handles RADIUS packets.
448 *
449 * @param radiusPacket RADIUS packet coming from the RADIUS server.
Jonathan Hart4731dd92018-05-02 17:30:05 -0700450 * @throws DeserializationException if packet deserialization fails
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100451 */
Jonathan Hart612651f2019-11-25 09:21:43 -0800452 public void handleRadiusPacket(RADIUS radiusPacket) throws DeserializationException {
Saurav Das987441a2018-09-18 16:33:47 -0700453 if (log.isTraceEnabled()) {
454 log.trace("Received RADIUS packet {}", radiusPacket);
455 }
Shubham Sharma4900ce62019-06-19 14:18:50 +0000456 if (radiusOperationalStatusService.isRadiusResponseForOperationalStatus(radiusPacket.getIdentifier())) {
457 radiusOperationalStatusService.handleRadiusPacketForOperationalStatus(radiusPacket);
458 return;
459 }
Jonathan Hart612651f2019-11-25 09:21:43 -0800460
461 RequestIdentifier identifier = RequestIdentifier.of(radiusPacket.getIdentifier());
462 String sessionId = idManager.getSessionId(identifier);
463
464 if (sessionId == null) {
465 log.error("Invalid packet identifier {}, could not find corresponding "
466 + "state machine ... exiting", radiusPacket.getIdentifier());
467 aaaStatisticsManager.getAaaStats().incrementNumberOfSessionsExpired();
468 aaaStatisticsManager.getAaaStats().countDroppedResponsesRx();
469 return;
470 }
471
472 idManager.releaseIdentifier(identifier);
473 StateMachine stateMachine = stateMachines.get(sessionId);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100474 if (stateMachine == null) {
Saurav Das987441a2018-09-18 16:33:47 -0700475 log.error("Invalid packet identifier {}, could not find corresponding "
476 + "state machine ... exiting", radiusPacket.getIdentifier());
kartikey dubeye1545422019-05-22 12:53:45 +0000477 aaaStatisticsManager.getAaaStats().incrementNumberOfSessionsExpired();
478 aaaStatisticsManager.getAaaStats().countDroppedResponsesRx();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100479 return;
Ray Milkey967776a2015-10-07 14:37:17 -0700480 }
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +0000481
482 //instance of StateMachine using the sessionId for updating machine stats
Jonathan Hart612651f2019-11-25 09:21:43 -0800483 StateMachine machineStats = stateMachines.get(stateMachine.sessionId());
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +0000484
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100485 EAP eapPayload;
486 Ethernet eth;
Vijaykumar Kushwaha056e4cd2019-08-06 13:16:25 +0000487 checkReceivedPacketForValidValidator(radiusPacket, stateMachine.requestAuthenticator());
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +0000488
489 //increasing packets and octets received from server
490 machineStats.incrementTotalPacketsReceived();
491 machineStats.incrementTotalOctetReceived(radiusPacket.decapsulateMessage().getLength());
492
kartikey dubeye1545422019-05-22 12:53:45 +0000493 if (outPacketSet.contains(radiusPacket.getIdentifier())) {
494 aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(false);
495 outPacketSet.remove(new Byte(radiusPacket.getIdentifier()));
496 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100497 switch (radiusPacket.getCode()) {
498 case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400499 log.debug("RADIUS packet: RADIUS_CODE_ACCESS_CHALLENGE");
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100500 RADIUSAttribute radiusAttrState = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE);
501 byte[] challengeState = null;
502 if (radiusAttrState != null) {
503 challengeState = radiusAttrState.getValue();
504 }
505 eapPayload = radiusPacket.decapsulateMessage();
506 stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState);
507 eth = buildEapolResponse(stateMachine.supplicantAddress(),
508 MacAddress.valueOf(nasMacAddress),
509 stateMachine.vlanId(),
510 EAPOL.EAPOL_PACKET,
511 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400512 log.debug("Send EAP challenge response to supplicant {}", stateMachine.supplicantAddress().toString());
Shubham Sharma1f193582019-07-11 12:12:41 +0000513 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), true);
kartikey dubeye1545422019-05-22 12:53:45 +0000514 aaaStatisticsManager.getAaaStats().increaseChallengeResponsesRx();
Shubham Sharma3c8c7022019-09-13 10:39:47 +0000515 outPacketSupp.add(eapPayload.getIdentifier());
516 aaaStatisticsManager.getAaaStats().incrementPendingResSupp();
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +0000517 //increasing packets send to server
518 machineStats.incrementTotalPacketsSent();
519 machineStats.incrementTotalOctetSent(eapPayload.getLength());
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100520 break;
521 case RADIUS.RADIUS_CODE_ACCESS_ACCEPT:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400522 log.debug("RADIUS packet: RADIUS_CODE_ACCESS_ACCEPT");
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100523 //send an EAPOL - Success to the supplicant.
524 byte[] eapMessageSuccess =
525 radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue();
Jonathan Hart4731dd92018-05-02 17:30:05 -0700526 eapPayload = EAP.deserializer().deserialize(
527 eapMessageSuccess, 0, eapMessageSuccess.length);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100528 eth = buildEapolResponse(stateMachine.supplicantAddress(),
529 MacAddress.valueOf(nasMacAddress),
530 stateMachine.vlanId(),
531 EAPOL.EAPOL_PACKET,
532 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400533 log.info("Send EAP success message to supplicant {}", stateMachine.supplicantAddress().toString());
Shubham Sharma1f193582019-07-11 12:12:41 +0000534 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false);
535 aaaStatisticsManager.getAaaStats().incrementEapolAuthSuccessTrans();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100536
537 stateMachine.authorizeAccess();
kartikey dubeye1545422019-05-22 12:53:45 +0000538 aaaStatisticsManager.getAaaStats().increaseAcceptResponsesRx();
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +0000539 //increasing packets send to server
540 machineStats.incrementTotalPacketsSent();
541 machineStats.incrementTotalOctetSent(eapPayload.getLength());
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100542 break;
543 case RADIUS.RADIUS_CODE_ACCESS_REJECT:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400544 log.debug("RADIUS packet: RADIUS_CODE_ACCESS_REJECT");
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100545 //send an EAPOL - Failure to the supplicant.
546 byte[] eapMessageFailure;
547 eapPayload = new EAP();
548 RADIUSAttribute radiusAttrEap = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE);
549 if (radiusAttrEap == null) {
550 eapPayload.setCode(EAP.FAILURE);
551 eapPayload.setIdentifier(stateMachine.challengeIdentifier());
552 eapPayload.setLength(EAP.EAP_HDR_LEN_SUC_FAIL);
553 } else {
554 eapMessageFailure = radiusAttrEap.getValue();
Jonathan Hart4731dd92018-05-02 17:30:05 -0700555 eapPayload = EAP.deserializer().deserialize(
556 eapMessageFailure, 0, eapMessageFailure.length);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100557 }
558 eth = buildEapolResponse(stateMachine.supplicantAddress(),
559 MacAddress.valueOf(nasMacAddress),
560 stateMachine.vlanId(),
561 EAPOL.EAPOL_PACKET,
562 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400563 log.warn("Send EAP failure message to supplicant {}", stateMachine.supplicantAddress().toString());
Shubham Sharma1f193582019-07-11 12:12:41 +0000564 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false);
565 aaaStatisticsManager.getAaaStats().incrementEapolauthFailureTrans();
566
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100567 stateMachine.denyAccess();
kartikey dubeye1545422019-05-22 12:53:45 +0000568 aaaStatisticsManager.getAaaStats().increaseRejectResponsesRx();
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +0000569 //increasing packets send to server
570 machineStats.incrementTotalPacketsSent();
571 machineStats.incrementTotalOctetSent(eapPayload.getLength());
572 //pushing machine stats to kafka
573 AaaSupplicantMachineStats machineObj = aaaSupplicantStatsManager.getSupplicantStats(machineStats);
574 aaaSupplicantStatsManager.getMachineStatsDelegate()
575 .notify(new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE, machineObj));
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100576 break;
577 default:
578 log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode());
kartikey dubeye1545422019-05-22 12:53:45 +0000579 aaaStatisticsManager.getAaaStats().increaseUnknownTypeRx();
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +0000580 //increasing packets received to server
581 machineStats.incrementTotalPacketsReceived();
582 machineStats.incrementTotalOctetReceived(radiusPacket.decapsulateMessage().getLength());
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100583 }
kartikey dubeye1545422019-05-22 12:53:45 +0000584 aaaStatisticsManager.getAaaStats().countDroppedResponsesRx();
Aaron Kruglikovd39d99e2015-07-03 13:30:57 -0700585 }
586
Ray Milkey967776a2015-10-07 14:37:17 -0700587 /**
588 * Send the ethernet packet to the supplicant.
589 *
590 * @param ethernetPkt the ethernet packet
591 * @param connectPoint the connect point to send out
592 */
Shubham Sharma1f193582019-07-11 12:12:41 +0000593 private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint, boolean isChallengeResponse) {
Ray Milkey967776a2015-10-07 14:37:17 -0700594 TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
595 OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(),
596 treatment, ByteBuffer.wrap(ethernetPkt.serialize()));
Shubham Sharma1f193582019-07-11 12:12:41 +0000597 EAPOL eap = ((EAPOL) ethernetPkt.getPayload());
Saurav Das987441a2018-09-18 16:33:47 -0700598 if (log.isTraceEnabled()) {
Saurav Das987441a2018-09-18 16:33:47 -0700599 log.trace("Sending eapol payload {} enclosed in {} to supplicant at {}",
600 eap, ethernetPkt, connectPoint);
601 }
Ray Milkey967776a2015-10-07 14:37:17 -0700602 packetService.emit(packet);
Shubham Sharma1f193582019-07-11 12:12:41 +0000603 if (isChallengeResponse) {
604 aaaStatisticsManager.getAaaStats().incrementEapPktTxauthEap();
605 }
Shubham Sharma3c8c7022019-09-13 10:39:47 +0000606 aaaStatisticsManager.getAaaStats().incrementEapolFramesTx();
607 aaaStatisticsManager.getAaaStats().countReqEapFramesTx();
Ray Milkey967776a2015-10-07 14:37:17 -0700608 }
609
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400610 @Override
611 public String toString() {
612 return ToStringBuilder.reflectionToString(this);
613 }
614
Jonathan Hart612651f2019-11-25 09:21:43 -0800615 @Override
616 public List<AuthenticationRecord> getAuthenticationRecords() {
617 return stateMachines.values().stream()
618 .map(this::toAuthRecord)
619 .collect(Collectors.toList());
620 }
621
622 private AuthenticationRecord toAuthRecord(StateMachine stateMachine) {
623 return new AuthenticationRecord(stateMachine.supplicantConnectpoint(),
624 stateMachine.username(), stateMachine.supplicantAddress(), stateMachine.stateString());
625 }
626
627 @Override
628 public boolean removeAuthenticationStateByMac(MacAddress mac) {
629
630 StateMachine stateMachine = null;
631
632 for (Map.Entry<String, StateMachine> e : stateMachines.entrySet()) {
633 if (e.getValue().supplicantAddress() != null &&
634 e.getValue().supplicantAddress().equals(mac)) {
635 stateMachine = stateMachines.remove(e.getKey());
636 break;
637 }
638 }
639
640 if (stateMachine != null) {
641 stateMachine.stop();
642 return true;
643 }
644
645 return false;
646 }
647
648 public StateMachine getStateMachine(String sessionId) {
649 return stateMachines.get(sessionId);
650 }
651
652 private String sessionId(ConnectPoint cp) {
653 return cp.deviceId().toString() + cp.port().toString();
654 }
655
Ari Saha89831742015-06-26 10:31:48 -0700656 // our handler defined as a private inner class
657
658 /**
659 * Packet processor responsible for forwarding packets along their paths.
660 */
661 private class ReactivePacketProcessor implements PacketProcessor {
662 @Override
663 public void process(PacketContext context) {
664
665 // Extract the original Ethernet frame from the packet information
666 InboundPacket pkt = context.inPacket();
667 Ethernet ethPkt = pkt.parsed();
668 if (ethPkt == null) {
669 return;
670 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100671
Jonathan Hart612651f2019-11-25 09:21:43 -0800672 // identify if incoming packet comes from supplicant (EAP) or RADIUS
673 switch (EthType.EtherType.lookup(ethPkt.getEtherType())) {
674 case EAPOL:
675 handleSupplicantPacket(context.inPacket());
676 break;
677 default:
678 // any other packets let the specific implementation handle
679 impl.handlePacketFromServer(context);
Ari Saha89831742015-06-26 10:31:48 -0700680 }
681 }
682
Ray Milkey9eb293f2015-09-30 15:09:17 -0700683 /**
684 * Creates and initializes common fields of a RADIUS packet.
685 *
Ray Milkey967776a2015-10-07 14:37:17 -0700686 * @param stateMachine state machine for the request
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700687 * @param eapPacket EAP packet
Ray Milkey9eb293f2015-09-30 15:09:17 -0700688 * @return RADIUS packet
689 */
Ray Milkey967776a2015-10-07 14:37:17 -0700690 private RADIUS getRadiusPayload(StateMachine stateMachine, byte identifier, EAP eapPacket) {
Ray Milkey9eb293f2015-09-30 15:09:17 -0700691 RADIUS radiusPayload =
692 new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST,
693 eapPacket.getIdentifier());
Ray Milkey967776a2015-10-07 14:37:17 -0700694
695 // set Request Authenticator in StateMachine
696 stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode());
697
Ray Milkey9eb293f2015-09-30 15:09:17 -0700698 radiusPayload.setIdentifier(identifier);
699 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME,
Ray Milkey967776a2015-10-07 14:37:17 -0700700 stateMachine.username());
Ray Milkey9eb293f2015-09-30 15:09:17 -0700701
702 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP,
Jonathan Hart092dfb22015-11-16 23:05:21 -0800703 AaaManager.this.nasIpAddress.getAddress());
Ray Milkey9eb293f2015-09-30 15:09:17 -0700704
705 radiusPayload.encapsulateMessage(eapPacket);
Ray Milkey9eb293f2015-09-30 15:09:17 -0700706
707 return radiusPayload;
708 }
Ari Saha89831742015-06-26 10:31:48 -0700709
710 /**
Jonathan Harta46dddf2015-06-30 15:31:20 -0700711 * Handles PAE packets (supplicant).
712 *
713 * @param inPacket Ethernet packet coming from the supplicant
Ari Saha89831742015-06-26 10:31:48 -0700714 */
Jonathan Hart612651f2019-11-25 09:21:43 -0800715 private void handleSupplicantPacket(InboundPacket inPacket) {
Jonathan Harta46dddf2015-06-30 15:31:20 -0700716 Ethernet ethPkt = inPacket.parsed();
Ari Saha89831742015-06-26 10:31:48 -0700717 // Where does it come from?
Jonathan Hart092dfb22015-11-16 23:05:21 -0800718 MacAddress srcMac = ethPkt.getSourceMAC();
Ari Saha89831742015-06-26 10:31:48 -0700719
Jonathan Harta46dddf2015-06-30 15:31:20 -0700720 DeviceId deviceId = inPacket.receivedFrom().deviceId();
721 PortNumber portNumber = inPacket.receivedFrom().port();
Ari Saha89831742015-06-26 10:31:48 -0700722 String sessionId = deviceId.toString() + portNumber.toString();
Saurav Das987441a2018-09-18 16:33:47 -0700723 EAPOL eapol = (EAPOL) ethPkt.getPayload();
724 if (log.isTraceEnabled()) {
725 log.trace("Received EAPOL packet {} in enclosing packet {} from "
726 + "dev/port: {}/{}", eapol, ethPkt, deviceId,
727 portNumber);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100728 }
Jonathan Harta46dddf2015-06-30 15:31:20 -0700729
Shubham Sharma3c8c7022019-09-13 10:39:47 +0000730 short pktlen = eapol.getPacketLength();
731 byte[] eapPayLoadBuffer = eapol.serialize();
732 int len = eapPayLoadBuffer.length;
733 if (len != (HEADER_LENGTH + pktlen)) {
734 aaaStatisticsManager.getAaaStats().incrementInvalidBodyLength();
735 return;
736 }
737 if (!VALID_EAPOL_TYPE.contains(eapol.getEapolType())) {
738 aaaStatisticsManager.getAaaStats().incrementInvalidPktType();
739 return;
740 }
741 if (pktlen >= 0 && ethPkt.getEtherType() == EthType.EtherType.EAPOL.ethType().toShort()) {
742 aaaStatisticsManager.getAaaStats().incrementValidEapolFramesRx();
743 }
Jonathan Hart612651f2019-11-25 09:21:43 -0800744
745 StateMachine stateMachine = stateMachines.computeIfAbsent(sessionId, id -> new StateMachine(id, executor));
746 stateMachine.setEapolTypeVal(eapol.getEapolType());
Saurav Das987441a2018-09-18 16:33:47 -0700747
Ari Saha89831742015-06-26 10:31:48 -0700748 switch (eapol.getEapolType()) {
749 case EAPOL.EAPOL_START:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400750 log.debug("EAP packet: EAPOL_START");
Ray Milkeyf51eba22015-09-25 10:24:23 -0700751 stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom());
Jonathan Hart5db44532018-07-12 18:13:54 -0700752 stateMachine.start();
Jonathan Hart612651f2019-11-25 09:21:43 -0800753
Shubham Sharma1f193582019-07-11 12:12:41 +0000754 aaaStatisticsManager.getAaaStats().incrementEapolStartReqTrans();
Ray Milkeyf51eba22015-09-25 10:24:23 -0700755 //send an EAP Request/Identify to the supplicant
756 EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100757 if (ethPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) {
758 stateMachine.setPriorityCode(ethPkt.getPriorityCode());
759 }
Jonathan Hart092dfb22015-11-16 23:05:21 -0800760 Ethernet eth = buildEapolResponse(srcMac, MacAddress.valueOf(nasMacAddress),
Ray Milkeyf51eba22015-09-25 10:24:23 -0700761 ethPkt.getVlanID(), EAPOL.EAPOL_PACKET,
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100762 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400763
Jonathan Hart092dfb22015-11-16 23:05:21 -0800764 stateMachine.setSupplicantAddress(srcMac);
Ray Milkeyf51eba22015-09-25 10:24:23 -0700765 stateMachine.setVlanId(ethPkt.getVlanID());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400766 log.debug("Getting EAP identity from supplicant {}", stateMachine.supplicantAddress().toString());
Shubham Sharma1f193582019-07-11 12:12:41 +0000767 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false);
Shubham Sharma3c8c7022019-09-13 10:39:47 +0000768 aaaStatisticsManager.getAaaStats().incrementRequestIdFramesTx();
Ari Saha89831742015-06-26 10:31:48 -0700769
770 break;
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800771 case EAPOL.EAPOL_LOGOFF:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400772 log.debug("EAP packet: EAPOL_LOGOFF");
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +0000773 //posting the machine stat data for current supplicant device.
774 if (stateMachine.getSessionTerminateReason() == null ||
775 stateMachine.getSessionTerminateReason().equals("")) {
776 stateMachine.setSessionTerminateReason(
777 StateMachine.SessionTerminationReasons.SUPPLICANT_LOGOFF.getReason());
778 }
779 AaaSupplicantMachineStats obj = aaaSupplicantStatsManager.getSupplicantStats(stateMachine);
780 aaaSupplicantStatsManager.getMachineStatsDelegate()
781 .notify(new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE, obj));
Ray Milkeyb34b4962016-01-04 10:24:43 -0800782 if (stateMachine.state() == StateMachine.STATE_AUTHORIZED) {
783 stateMachine.logoff();
Shubham Sharma1f193582019-07-11 12:12:41 +0000784 aaaStatisticsManager.getAaaStats().incrementEapolLogoffRx();
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800785 }
Shubham Sharma3c8c7022019-09-13 10:39:47 +0000786 if (stateMachine.state() == StateMachine.STATE_IDLE) {
787 aaaStatisticsManager.getAaaStats().incrementAuthStateIdle();
788 }
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800789
790 break;
Ari Saha89831742015-06-26 10:31:48 -0700791 case EAPOL.EAPOL_PACKET:
Ray Milkeyf51eba22015-09-25 10:24:23 -0700792 RADIUS radiusPayload;
Ray Milkey9eb293f2015-09-30 15:09:17 -0700793 // check if this is a Response/Identify or a Response/TLS
Ari Saha89831742015-06-26 10:31:48 -0700794 EAP eapPacket = (EAP) eapol.getPayload();
Shubham Sharma3c8c7022019-09-13 10:39:47 +0000795 Byte identifier = new Byte(eapPacket.getIdentifier());
Ari Saha89831742015-06-26 10:31:48 -0700796
Jonathan Hart612651f2019-11-25 09:21:43 -0800797 // get identifier for request and store mapping to session ID
798 RequestIdentifier radiusIdentifier = idManager.getNewIdentifier(sessionId);
799
Ari Saha89831742015-06-26 10:31:48 -0700800 byte dataType = eapPacket.getDataType();
801 switch (dataType) {
Ari Saha89831742015-06-26 10:31:48 -0700802
Ray Milkey9eb293f2015-09-30 15:09:17 -0700803 case EAP.ATTR_IDENTITY:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400804 log.debug("EAP packet: EAPOL_PACKET ATTR_IDENTITY");
Shubham Sharma1e43c562019-06-19 14:18:12 +0000805 //Setting the time of this response from RG, only when its not a re-transmission.
806 if (stateMachine.getLastPacketReceivedTime() == 0) {
807 stateMachine.setLastPacketReceivedTime(System.currentTimeMillis());
808 }
Ray Milkey9eb293f2015-09-30 15:09:17 -0700809 // request id access to RADIUS
810 stateMachine.setUsername(eapPacket.getData());
Ari Saha89831742015-06-26 10:31:48 -0700811
Jonathan Hart612651f2019-11-25 09:21:43 -0800812 radiusPayload = getRadiusPayload(stateMachine, radiusIdentifier.identifier(), eapPacket);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100813 radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket);
Jonathan Hart092dfb22015-11-16 23:05:21 -0800814 radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret);
Ari Saha89831742015-06-26 10:31:48 -0700815
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100816 sendRadiusPacket(radiusPayload, inPacket);
Shubham Sharma1e43c562019-06-19 14:18:12 +0000817 stateMachine.setWaitingForRadiusResponse(true);
Shubham Sharma1f193582019-07-11 12:12:41 +0000818 aaaStatisticsManager.getAaaStats().incrementEapolAtrrIdentity();
Ray Milkey9eb293f2015-09-30 15:09:17 -0700819 // change the state to "PENDING"
kartikey dubeye1545422019-05-22 12:53:45 +0000820 if (stateMachine.state() == StateMachine.STATE_PENDING) {
821 aaaStatisticsManager.getAaaStats().increaseRequestReTx();
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +0000822 stateMachine.incrementTotalPacketsSent();
823 stateMachine.incrementTotalOctetSent(eapol.getPacketLength());
kartikey dubeye1545422019-05-22 12:53:45 +0000824 }
Ray Milkey9eb293f2015-09-30 15:09:17 -0700825 stateMachine.requestAccess();
826 break;
Ari Saha89831742015-06-26 10:31:48 -0700827 case EAP.ATTR_MD5:
Shubham Sharma1e43c562019-06-19 14:18:12 +0000828 stateMachine.setLastPacketReceivedTime(System.currentTimeMillis());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400829 log.debug("EAP packet: EAPOL_PACKET ATTR_MD5");
Ray Milkey9eb293f2015-09-30 15:09:17 -0700830 // verify if the EAP identifier corresponds to the
831 // challenge identifier from the client state
832 // machine.
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700833 if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) {
Ari Saha89831742015-06-26 10:31:48 -0700834 //send the RADIUS challenge response
Jonathan Hart612651f2019-11-25 09:21:43 -0800835 radiusPayload = getRadiusPayload(stateMachine,
836 radiusIdentifier.identifier(), eapPacket);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100837 radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket);
Ari Saha89831742015-06-26 10:31:48 -0700838
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800839 if (stateMachine.challengeState() != null) {
840 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
841 stateMachine.challengeState());
842 }
Jonathan Hart092dfb22015-11-16 23:05:21 -0800843 radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret);
Shubham Sharma3c8c7022019-09-13 10:39:47 +0000844 if (outPacketSupp.contains(eapPacket.getIdentifier())) {
845 aaaStatisticsManager.getAaaStats().decrementPendingResSupp();
846 outPacketSupp.remove(identifier);
847 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100848 sendRadiusPacket(radiusPayload, inPacket);
Shubham Sharma1e43c562019-06-19 14:18:12 +0000849 stateMachine.setWaitingForRadiusResponse(true);
Shubham Sharma1f193582019-07-11 12:12:41 +0000850 aaaStatisticsManager.getAaaStats().incrementEapolMd5RspChall();
Ari Saha89831742015-06-26 10:31:48 -0700851 }
852 break;
853 case EAP.ATTR_TLS:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400854 log.debug("EAP packet: EAPOL_PACKET ATTR_TLS");
Ray Milkey9eb293f2015-09-30 15:09:17 -0700855 // request id access to RADIUS
Jonathan Hart612651f2019-11-25 09:21:43 -0800856 radiusPayload = getRadiusPayload(stateMachine, radiusIdentifier.identifier(), eapPacket);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100857 radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket);
Ari Saha89831742015-06-26 10:31:48 -0700858
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800859 if (stateMachine.challengeState() != null) {
860 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
861 stateMachine.challengeState());
862 }
Ray Milkeyf51eba22015-09-25 10:24:23 -0700863 stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode());
Ari Saha89831742015-06-26 10:31:48 -0700864
Jonathan Hart092dfb22015-11-16 23:05:21 -0800865 radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret);
Shubham Sharma3c8c7022019-09-13 10:39:47 +0000866 if (outPacketSupp.contains(eapPacket.getIdentifier())) {
867 aaaStatisticsManager.getAaaStats().decrementPendingResSupp();
868 outPacketSupp.remove(identifier);
869 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100870 sendRadiusPacket(radiusPayload, inPacket);
Shubham Sharma1e43c562019-06-19 14:18:12 +0000871 stateMachine.setWaitingForRadiusResponse(true);
Shubham Sharma1f193582019-07-11 12:12:41 +0000872 aaaStatisticsManager.getAaaStats().incrementEapolTlsRespChall();
Ray Milkey5493b512015-10-21 12:13:49 -0700873
Ray Milkeyf3790b82015-10-21 16:28:08 -0700874 if (stateMachine.state() != StateMachine.STATE_PENDING) {
875 stateMachine.requestAccess();
876 }
Ray Milkeyf51eba22015-09-25 10:24:23 -0700877
Ari Saha89831742015-06-26 10:31:48 -0700878 break;
879 default:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400880 log.warn("Unknown EAP packet type");
Ari Saha89831742015-06-26 10:31:48 -0700881 return;
882 }
883 break;
884 default:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400885 log.debug("Skipping EAPOL message {}", eapol.getEapolType());
Ari Saha89831742015-06-26 10:31:48 -0700886 }
Shubham Sharma1f193582019-07-11 12:12:41 +0000887 aaaStatisticsManager.getAaaStats().countTransRespNotNak();
888 aaaStatisticsManager.getAaaStats().countEapolResIdentityMsgTrans();
Ari Saha89831742015-06-26 10:31:48 -0700889 }
Ray Milkey967776a2015-10-07 14:37:17 -0700890 }
891
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100892 /**
Jonathan Hart5db44532018-07-12 18:13:54 -0700893 * Delegate allowing the StateMachine to notify us of events.
894 */
895 private class InternalStateMachineDelegate implements StateMachineDelegate {
896
897 @Override
898 public void notify(AuthenticationEvent authenticationEvent) {
899 log.info("Auth event {} for {}",
900 authenticationEvent.type(), authenticationEvent.subject());
Jonathan Hart612651f2019-11-25 09:21:43 -0800901
902 if (authenticationEvent.type() == AuthenticationEvent.Type.TIMEOUT) {
903 handleStateMachineTimeout(authenticationEvent.subject());
904 }
905
Jonathan Hart5db44532018-07-12 18:13:54 -0700906 post(authenticationEvent);
907 }
908 }
909
Jonathan Hart612651f2019-11-25 09:21:43 -0800910 private void handleStateMachineTimeout(ConnectPoint supplicantConnectPoint) {
911 StateMachine stateMachine = stateMachines.remove(sessionId(supplicantConnectPoint));
912
913 if (stateMachine.state() == StateMachine.STATE_PENDING && stateMachine.isWaitingForRadiusResponse()) {
914 aaaStatisticsManager.getAaaStats().increaseTimedOutPackets();
915 }
916
917 StateMachine.deleteStateMachineMapping(stateMachine);
918 }
919
Jonathan Hart5db44532018-07-12 18:13:54 -0700920 /**
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100921 * Configuration Listener, handles change in configuration.
922 */
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700923 private class InternalConfigListener implements NetworkConfigListener {
924
925 /**
Ray Milkeyc9e8dcc2015-12-30 10:31:32 -0800926 * Reconfigures the AAA application according to the
927 * configuration parameters passed.
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700928 *
929 * @param cfg configuration object
930 */
Jonathan Hart092dfb22015-11-16 23:05:21 -0800931 private void reconfigureNetwork(AaaConfig cfg) {
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400932 log.info("Reconfiguring AaaConfig from config: {}", cfg);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100933
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700934 if (cfg == null) {
Jonathan Hart092dfb22015-11-16 23:05:21 -0800935 newCfg = new AaaConfig();
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700936 } else {
937 newCfg = cfg;
938 }
939 if (newCfg.nasIp() != null) {
940 nasIpAddress = newCfg.nasIp();
941 }
942 if (newCfg.radiusIp() != null) {
943 radiusIpAddress = newCfg.radiusIp();
944 }
945 if (newCfg.radiusMac() != null) {
946 radiusMacAddress = newCfg.radiusMac();
947 }
948 if (newCfg.nasMac() != null) {
949 nasMacAddress = newCfg.nasMac();
950 }
951 if (newCfg.radiusSecret() != null) {
952 radiusSecret = newCfg.radiusSecret();
953 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100954
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530955 boolean reconfigureCustomizer = false;
956 if (customizer == null || !customizer.equals(newCfg.radiusPktCustomizer())) {
957 customizer = newCfg.radiusPktCustomizer();
958 configurePacketCustomizer();
959 reconfigureCustomizer = true;
960 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100961
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530962 if (radiusConnectionType == null
963 || reconfigureCustomizer
964 || !radiusConnectionType.equals(newCfg.radiusConnectionType())) {
965 radiusConnectionType = newCfg.radiusConnectionType();
966 if (impl != null) {
967 impl.withdrawIntercepts();
968 impl.clearLocalState();
969 }
970 configureRadiusCommunication();
971 impl.initializeLocalState(newCfg);
972 impl.requestIntercepts();
973 } else if (impl != null) {
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100974 impl.clearLocalState();
975 impl.initializeLocalState(newCfg);
Ray Milkey5d99bd12015-10-06 15:41:30 -0700976 }
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700977 }
978
979 @Override
980 public void event(NetworkConfigEvent event) {
981
982 if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
983 event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) &&
Jonathan Hart092dfb22015-11-16 23:05:21 -0800984 event.configClass().equals(AaaConfig.class)) {
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700985
Jonathan Hart092dfb22015-11-16 23:05:21 -0800986 AaaConfig cfg = netCfgService.getConfig(appId, AaaConfig.class);
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700987 reconfigureNetwork(cfg);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100988
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400989 log.info("Reconfigured: {}", cfg.toString());
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700990 }
991 }
992 }
Amit Ghoshf739be52017-09-21 15:49:37 +0100993
994 private class InternalDeviceListener implements DeviceListener {
995 @Override
996 public void event(DeviceEvent event) {
997
998 switch (event.type()) {
999 case PORT_REMOVED:
1000 DeviceId devId = event.subject().id();
1001 PortNumber portNumber = event.port().number();
1002 String sessionId = devId.toString() + portNumber.toString();
1003
Jonathan Hart612651f2019-11-25 09:21:43 -08001004 StateMachine stateMachine = stateMachines.get(sessionId);
Kartikey Dubeyadeb26e2019-10-01 12:18:35 +00001005 if (stateMachine != null) {
1006 stateMachine.setSessionTerminateReason(
1007 StateMachine.SessionTerminationReasons.PORT_REMOVED.getReason());
1008 }
1009 //pushing captured machine stats to kafka
1010 AaaSupplicantMachineStats obj = aaaSupplicantStatsManager.getSupplicantStats(stateMachine);
1011 aaaSupplicantStatsManager.getMachineStatsDelegate()
1012 .notify(new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE, obj));
1013
Jonathan Hart612651f2019-11-25 09:21:43 -08001014 StateMachine removed = stateMachines.remove(sessionId);
Amit Ghoshf739be52017-09-21 15:49:37 +01001015 if (removed != null) {
1016 StateMachine.deleteStateMachineMapping(removed);
1017 }
1018
1019 break;
1020 default:
1021 return;
1022 }
1023 }
1024 }
kartikey dubeye1545422019-05-22 12:53:45 +00001025 private class AuthenticationStatisticsEventPublisher implements Runnable {
1026 private final Logger log = getLogger(getClass());
1027 public void run() {
1028 log.info("Notifying AuthenticationStatisticsEvent");
1029 aaaStatisticsManager.calculatePacketRoundtripTime();
1030 log.debug("AcceptResponsesRx---" + aaaStatisticsManager.getAaaStats().getAcceptResponsesRx());
1031 log.debug("AccessRequestsTx---" + aaaStatisticsManager.getAaaStats().getAccessRequestsTx());
1032 log.debug("ChallengeResponsesRx---" + aaaStatisticsManager.getAaaStats().getChallengeResponsesRx());
1033 log.debug("DroppedResponsesRx---" + aaaStatisticsManager.getAaaStats().getDroppedResponsesRx());
1034 log.debug("InvalidValidatorsRx---" + aaaStatisticsManager.getAaaStats().getInvalidValidatorsRx());
1035 log.debug("MalformedResponsesRx---" + aaaStatisticsManager.getAaaStats().getMalformedResponsesRx());
1036 log.debug("PendingRequests---" + aaaStatisticsManager.getAaaStats().getPendingRequests());
1037 log.debug("RejectResponsesRx---" + aaaStatisticsManager.getAaaStats().getRejectResponsesRx());
1038 log.debug("RequestReTx---" + aaaStatisticsManager.getAaaStats().getRequestReTx());
1039 log.debug("RequestRttMilis---" + aaaStatisticsManager.getAaaStats().getRequestRttMilis());
1040 log.debug("UnknownServerRx---" + aaaStatisticsManager.getAaaStats().getUnknownServerRx());
1041 log.debug("UnknownTypeRx---" + aaaStatisticsManager.getAaaStats().getUnknownTypeRx());
Shubham Sharma1e43c562019-06-19 14:18:12 +00001042 log.debug("TimedOutPackets----" + aaaStatisticsManager.getAaaStats().getTimedOutPackets());
Shubham Sharma1f193582019-07-11 12:12:41 +00001043 log.debug("EapolLogoffRx---" + aaaStatisticsManager.getAaaStats().getEapolLogoffRx());
1044 log.debug("EapolAuthSuccessTrans---" + aaaStatisticsManager.getAaaStats().getEapolAuthSuccessTrans());
1045 log.debug("EapolAuthFailureTrans---" +
1046 aaaStatisticsManager.getAaaStats().getEapolAuthFailureTrans());
1047 log.debug("EapolStartReqTrans---" +
1048 aaaStatisticsManager.getAaaStats().getEapolStartReqTrans());
1049 log.debug("EapolTransRespNotNak---" +
1050 aaaStatisticsManager.getAaaStats().getEapolTransRespNotNak());
1051 log.debug("EapPktTxauthChooseEap---" +
1052 aaaStatisticsManager.getAaaStats().getEapPktTxauthChooseEap());
1053 log.debug("EapolResIdentityMsgTrans---" +
1054 aaaStatisticsManager.getAaaStats().getEapolResIdentityMsgTrans());
Shubham Sharma3c8c7022019-09-13 10:39:47 +00001055 log.debug("EapolFramesTx---" + aaaStatisticsManager.getAaaStats().getEapolFramesTx());
1056 log.debug("AuthStateIdle---" + aaaStatisticsManager.getAaaStats().getAuthStateIdle());
1057 log.debug("RequestIdFramesTx---" + aaaStatisticsManager.getAaaStats().getRequestIdFramesTx());
1058 log.debug("ReqEapFramesTx---" + aaaStatisticsManager.getAaaStats().getReqEapFramesTx());
1059 log.debug("InvalidPktType---" + aaaStatisticsManager.getAaaStats().getInvalidPktType());
1060 log.debug("InvalidBodyLength---" + aaaStatisticsManager.getAaaStats().getInvalidBodyLength());
1061 log.debug("ValidEapolFramesRx---" + aaaStatisticsManager.getAaaStats().getValidEapolFramesRx());
1062 log.debug("PendingResSupp---" + aaaStatisticsManager.getAaaStats().getPendingResSupp());
1063 log.debug("ResIdEapFramesRx---" + aaaStatisticsManager.getAaaStats().getEapolattrIdentity());
kartikey dubeye1545422019-05-22 12:53:45 +00001064 aaaStatisticsManager.getStatsDelegate().
1065 notify(new AuthenticationStatisticsEvent(AuthenticationStatisticsEvent.Type.STATS_UPDATE,
1066 aaaStatisticsManager.getAaaStats()));
1067 }
Shubham Sharma4900ce62019-06-19 14:18:50 +00001068 }
1069
1070 private class ServerStatusChecker implements Runnable {
1071 @Override
1072 public void run() {
Matteo Scandolo3498bc02020-01-08 09:54:12 -08001073 log.debug("Notifying RadiusOperationalStatusEvent");
Shubham Sharma4900ce62019-06-19 14:18:50 +00001074 radiusOperationalStatusService.checkServerOperationalStatus();
Matteo Scandolo3498bc02020-01-08 09:54:12 -08001075 log.trace("--POSTING--" + radiusOperationalStatusService.getRadiusServerOperationalStatus());
Shubham Sharma4900ce62019-06-19 14:18:50 +00001076 radiusOperationalStatusService.getRadiusOprStDelegate()
1077 .notify(new RadiusOperationalStatusEvent(
1078 RadiusOperationalStatusEvent.Type.RADIUS_OPERATIONAL_STATUS,
1079 radiusOperationalStatusService.
1080 getRadiusServerOperationalStatus()));
kartikey dubeye1545422019-05-22 12:53:45 +00001081 }
Shubham Sharma4900ce62019-06-19 14:18:50 +00001082
1083 }
Jonathan Hart612651f2019-11-25 09:21:43 -08001084}