Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 1 | /* |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 3 | * |
| 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 Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 16 | package org.opencord.aaa.impl; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 17 | |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 18 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
| 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
Girish Kumar | 8bc4eb3 | 2020-02-04 08:32:46 +0000 | [diff] [blame^] | 21 | import com.google.common.collect.Sets; |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 22 | import java.net.InetAddress; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 23 | import java.net.UnknownHostException; |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 24 | import java.nio.ByteBuffer; |
| 25 | import java.util.Map; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 26 | import java.util.Dictionary; |
| 27 | import java.util.HashSet; |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 28 | import java.util.Arrays; |
Shubham Sharma | 4786954 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 29 | import java.util.List; |
Girish Kumar | 8bc4eb3 | 2020-02-04 08:32:46 +0000 | [diff] [blame^] | 30 | import java.util.Set; |
| 31 | import java.util.Map.Entry; |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 32 | |
Jonathan Hart | 932bedc | 2018-07-12 13:46:09 -0700 | [diff] [blame] | 33 | import org.apache.commons.lang3.builder.ToStringBuilder; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 34 | import org.apache.felix.scr.annotations.Component; |
| 35 | import org.apache.felix.scr.annotations.Deactivate; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 36 | import org.apache.felix.scr.annotations.Property; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 37 | import org.apache.felix.scr.annotations.Reference; |
| 38 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 39 | import org.apache.felix.scr.annotations.Service; |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 40 | import org.onlab.packet.DeserializationException; |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 41 | import org.onlab.packet.EAP; |
| 42 | import org.onlab.packet.EAPOL; |
| 43 | import org.onlab.packet.EthType; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 44 | import org.onlab.packet.Ethernet; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 45 | import org.onlab.packet.MacAddress; |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 46 | import org.onlab.packet.RADIUS; |
| 47 | import org.onlab.packet.RADIUSAttribute; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 48 | import org.onlab.util.Tools; |
| 49 | import org.onosproject.cfg.ComponentConfigService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 50 | import org.onosproject.core.ApplicationId; |
| 51 | import org.onosproject.core.CoreService; |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 52 | import org.onosproject.event.AbstractListenerManager; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 53 | import org.onosproject.mastership.MastershipService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 54 | import org.onosproject.net.ConnectPoint; |
| 55 | import org.onosproject.net.DeviceId; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 56 | import org.onosproject.net.PortNumber; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 57 | import org.onosproject.net.config.ConfigFactory; |
| 58 | import org.onosproject.net.config.NetworkConfigEvent; |
| 59 | import org.onosproject.net.config.NetworkConfigListener; |
| 60 | import org.onosproject.net.config.NetworkConfigRegistry; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 61 | import org.onosproject.net.device.DeviceEvent; |
| 62 | import org.onosproject.net.device.DeviceListener; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 63 | import org.onosproject.net.device.DeviceService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 64 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 65 | import org.onosproject.net.flow.TrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 66 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 67 | import org.onosproject.net.packet.InboundPacket; |
| 68 | import org.onosproject.net.packet.OutboundPacket; |
| 69 | import org.onosproject.net.packet.PacketContext; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 70 | import org.onosproject.net.packet.PacketProcessor; |
| 71 | import org.onosproject.net.packet.PacketService; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 72 | import org.opencord.aaa.AaaConfig; |
Kartikey Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 73 | import org.opencord.aaa.AaaMachineStatisticsEvent; |
| 74 | import org.opencord.aaa.AaaMachineStatisticsService; |
| 75 | import org.opencord.aaa.AaaSupplicantMachineStats; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 76 | import org.opencord.aaa.AuthenticationEvent; |
| 77 | import org.opencord.aaa.AuthenticationEventListener; |
| 78 | import org.opencord.aaa.AuthenticationService; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 79 | import org.opencord.aaa.AuthenticationStatisticsEvent; |
| 80 | import org.opencord.aaa.AuthenticationStatisticsService; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 81 | import org.opencord.aaa.RadiusCommunicator; |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 82 | import org.opencord.aaa.RadiusOperationalStatusEvent; |
| 83 | import org.opencord.aaa.RadiusOperationalStatusService; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 84 | import org.opencord.aaa.StateMachineDelegate; |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 85 | import org.opencord.aaa.RadiusOperationalStatusService.RadiusOperationalStatusEvaluationMode; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 86 | import org.opencord.sadis.BaseInformationService; |
| 87 | import org.opencord.sadis.SadisService; |
| 88 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 89 | import org.osgi.service.component.ComponentContext; |
Kartikey Dubey | f72e195 | 2019-06-24 07:09:00 +0000 | [diff] [blame] | 90 | import org.apache.felix.scr.annotations.Modified; |
| 91 | import org.apache.felix.scr.annotations.Activate; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 92 | import org.slf4j.Logger; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 93 | import com.google.common.base.Strings; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 94 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 95 | import java.util.concurrent.Executors; |
| 96 | import java.util.concurrent.ScheduledExecutorService; |
| 97 | import java.util.concurrent.ScheduledFuture; |
| 98 | import java.util.concurrent.TimeUnit; |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 99 | |
| 100 | import javax.crypto.Mac; |
| 101 | import javax.crypto.spec.SecretKeySpec; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 102 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 103 | * AAA application for ONOS. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 104 | */ |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 105 | @Service |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 106 | @Component(immediate = true) |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 107 | public class AaaManager |
| 108 | extends AbstractListenerManager<AuthenticationEvent, AuthenticationEventListener> |
| 109 | implements AuthenticationService { |
| 110 | |
Charles Chan | df7ff86 | 2017-01-20 11:22:05 -0800 | [diff] [blame] | 111 | private static final String APP_NAME = "org.opencord.aaa"; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 112 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 113 | private final Logger log = getLogger(getClass()); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 114 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 115 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 116 | protected CoreService coreService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 117 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 118 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 119 | protected PacketService packetService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 120 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 121 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 122 | protected NetworkConfigRegistry netCfgService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 123 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 124 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 125 | protected DeviceService deviceService; |
| 126 | |
| 127 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 128 | protected SadisService sadisService; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 129 | |
| 130 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 131 | protected MastershipService mastershipService; |
| 132 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 133 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 134 | protected AuthenticationStatisticsService aaaStatisticsManager; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 135 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 136 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Kartikey Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 137 | protected AaaMachineStatisticsService aaaSupplicantStatsManager; |
| 138 | |
| 139 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 140 | protected ComponentConfigService cfgService; |
| 141 | |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 142 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 143 | protected RadiusOperationalStatusService radiusOperationalStatusService; |
| 144 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 145 | protected AuthenticationStatisticsEventPublisher authenticationStatisticsPublisher; |
| 146 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 147 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 148 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 149 | private static final int DEFAULT_REPEAT_DELAY = 20; |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 150 | @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 dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 171 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 172 | // NAS IP address |
| 173 | protected InetAddress nasIpAddress; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 174 | |
| 175 | // self MAC address |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 176 | protected String nasMacAddress; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 177 | |
| 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 Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 183 | |
| 184 | // RADIUS server secret |
| 185 | protected String radiusSecret; |
| 186 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 187 | // bindings |
| 188 | protected CustomizationInfo customInfo; |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 189 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 190 | // our application-specific event handler |
| 191 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 192 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 193 | // our unique identifier |
| 194 | private ApplicationId appId; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 195 | |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 196 | // TimeOut time for cleaning up stateMachines stuck due to pending AAA/EAPOL message. |
| 197 | protected int cleanupTimerTimeOutInMins; |
| 198 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 199 | // Setup specific customization/attributes on the RADIUS packets |
| 200 | PacketCustomizer pktCustomizer; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 201 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 202 | // 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 Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 209 | // Object for the specific type of communication with the RADIUS |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 210 | // server, socket based or packet_out based |
| 211 | RadiusCommunicator impl = null; |
| 212 | |
| 213 | // latest configuration |
| 214 | AaaConfig newCfg; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 215 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 216 | ScheduledFuture<?> scheduledFuture; |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 217 | ScheduledFuture<?> scheduledStatusServerChecker; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 218 | ScheduledExecutorService executor; |
| 219 | String configuredAaaServerAddress; |
| 220 | HashSet<Byte> outPacketSet = new HashSet<Byte>(); |
Shubham Sharma | 4786954 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 221 | 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 Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 224 | // Configuration properties factory |
| 225 | private final ConfigFactory factory = |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 226 | new ConfigFactory<ApplicationId, AaaConfig>(APP_SUBJECT_FACTORY, |
| 227 | AaaConfig.class, |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 228 | "AAA") { |
| 229 | @Override |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 230 | public AaaConfig createConfig() { |
| 231 | return new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 232 | } |
| 233 | }; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 234 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 235 | // Listener for config changes |
| 236 | private final InternalConfigListener cfgListener = new InternalConfigListener(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 237 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 238 | private StateMachineDelegate delegate = new InternalStateMachineDelegate(); |
| 239 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 240 | /** |
| 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 251 | short vlan, byte eapolType, EAP eap, byte priorityCode) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 252 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 253 | 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 259 | eth.setPriorityCode(priorityCode); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 260 | } |
| 261 | //eapol header |
| 262 | EAPOL eapol = new EAPOL(); |
| 263 | eapol.setEapolType(eapolType); |
| 264 | eapol.setPacketLength(eap.getLength()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 265 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 266 | //eap part |
| 267 | eapol.setPayload(eap); |
| 268 | |
| 269 | eth.setPayload(eapol); |
| 270 | eth.setPad(true); |
| 271 | return eth; |
| 272 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 273 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 274 | @Activate |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 275 | public void activate(ComponentContext context) { |
Charles Chan | df7ff86 | 2017-01-20 11:22:05 -0800 | [diff] [blame] | 276 | appId = coreService.registerApplication(APP_NAME); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 277 | eventDispatcher.addSink(AuthenticationEvent.class, listenerRegistry); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 278 | netCfgService.addListener(cfgListener); |
| 279 | netCfgService.registerConfigFactory(factory); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 280 | cfgService.registerProperties(getClass()); |
| 281 | modified(context); |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 282 | subsService = sadisService.getSubscriberInfoService(); |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 283 | customInfo = new CustomizationInfo(subsService, deviceService); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 284 | cfgListener.reconfigureNetwork(netCfgService.getConfig(appId, AaaConfig.class)); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 285 | log.info("Starting with config {} {}", this, newCfg); |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 286 | configureRadiusCommunication(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 287 | // register our event handler |
Brian O'Connor | d9c7da0 | 2015-07-29 17:49:24 -0700 | [diff] [blame] | 288 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 289 | StateMachine.initializeMaps(); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 290 | StateMachine.setDelegate(delegate); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 291 | cleanupTimerTimeOutInMins = newCfg.sessionCleanupTimer(); |
| 292 | StateMachine.setcleanupTimerTimeOutInMins(cleanupTimerTimeOutInMins); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 293 | impl.initializeLocalState(newCfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 294 | impl.requestIntercepts(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 295 | deviceService.addListener(deviceListener); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 296 | getConfiguredAaaServerAddress(); |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 297 | radiusOperationalStatusService.initialize(nasIpAddress.getAddress(), radiusSecret, impl); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 298 | authenticationStatisticsPublisher = |
| 299 | new AuthenticationStatisticsEventPublisher(); |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 300 | executor = Executors.newScheduledThreadPool(3); |
| 301 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 302 | scheduledFuture = executor.scheduleAtFixedRate(authenticationStatisticsPublisher, |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 303 | 0, statisticsGenerationPeriodInSeconds, TimeUnit.SECONDS); |
| 304 | scheduledStatusServerChecker = executor.scheduleAtFixedRate(new ServerStatusChecker(), 0, |
| 305 | operationalStatusEventGenerationPeriodInSeconds, TimeUnit.SECONDS); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 306 | |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 307 | log.info("Started"); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | @Deactivate |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 311 | public void deactivate(ComponentContext context) { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 312 | impl.withdrawIntercepts(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 313 | packetService.removeProcessor(processor); |
Deepa Vaddireddy | b9c24c6 | 2017-09-21 13:45:30 +0530 | [diff] [blame] | 314 | netCfgService.removeListener(cfgListener); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 315 | cfgService.unregisterProperties(getClass(), false); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 316 | StateMachine.unsetDelegate(delegate); |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 317 | StateMachine.destroyMaps(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 318 | impl.deactivate(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 319 | deviceService.removeListener(deviceListener); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 320 | eventDispatcher.removeSink(AuthenticationEvent.class); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 321 | scheduledFuture.cancel(true); |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 322 | scheduledStatusServerChecker.cancel(true); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 323 | executor.shutdown(); |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 324 | log.info("Stopped"); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 325 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 326 | @Modified |
| 327 | public void modified(ComponentContext context) { |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 328 | 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 dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Shubham Sharma | 1ad1663 | 2019-11-26 11:09:21 +0000 | [diff] [blame] | 357 | protected void configureRadiusCommunication() { |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 358 | 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 Das | e72358a | 2018-11-13 21:56:46 -0800 | [diff] [blame] | 372 | case "att": |
| 373 | pktCustomizer = new AttPacketCustomizer(customInfo); |
| 374 | log.info("Created AttPacketCustomizer"); |
| 375 | break; |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 376 | default: |
| 377 | pktCustomizer = new PacketCustomizer(customInfo); |
| 378 | log.info("Created default PacketCustomizer"); |
| 379 | break; |
| 380 | } |
| 381 | } |
| 382 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 383 | 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 Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 398 | private void checkReceivedPacketForValidValidator(RADIUS radiusPacket, byte[] requestAuthenticator) { |
| 399 | if (!checkResponseMessageAuthenticator(radiusSecret, radiusPacket, requestAuthenticator)) { |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 400 | aaaStatisticsManager.getAaaStats().increaseInvalidValidatorsRx(); |
| 401 | } |
| 402 | } |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 403 | |
| 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 dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 425 | public void checkForPacketFromUnknownServer(String hostAddress) { |
| 426 | if (!hostAddress.equals(configuredAaaServerAddress)) { |
Vijaykumar Kushwaha | fffd3d1 | 2019-08-01 11:09:59 +0000 | [diff] [blame] | 427 | getConfiguredAaaServerAddress(); |
| 428 | if (!hostAddress.equals(configuredAaaServerAddress)) { |
| 429 | aaaStatisticsManager.getAaaStats().incrementUnknownServerRx(); |
| 430 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 434 | /** |
| 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 dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 441 | outPacketSet.add(radiusPacket.getIdentifier()); |
| 442 | aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(true); |
| 443 | aaaStatisticsManager.getAaaStats().increaseAccessRequestsTx(); |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 444 | aaaStatisticsManager.putOutgoingIdentifierToMap(radiusPacket.getIdentifier()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 445 | impl.sendRadiusPacket(radiusPacket, inPkt); |
| 446 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 447 | |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 448 | /** |
| 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 464 | * 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 Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 468 | * @throws DeserializationException if packet deserialization fails |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 469 | */ |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 470 | public void handleRadiusPacket(RADIUS radiusPacket) |
| 471 | throws StateMachineException, DeserializationException { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 472 | if (log.isTraceEnabled()) { |
| 473 | log.trace("Received RADIUS packet {}", radiusPacket); |
| 474 | } |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 475 | if (radiusOperationalStatusService.isRadiusResponseForOperationalStatus(radiusPacket.getIdentifier())) { |
| 476 | radiusOperationalStatusService.handleRadiusPacketForOperationalStatus(radiusPacket); |
| 477 | return; |
| 478 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 479 | StateMachine stateMachine = StateMachine.lookupStateMachineById(radiusPacket.getIdentifier()); |
| 480 | if (stateMachine == null) { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 481 | log.error("Invalid packet identifier {}, could not find corresponding " |
| 482 | + "state machine ... exiting", radiusPacket.getIdentifier()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 483 | aaaStatisticsManager.getAaaStats().incrementNumberOfSessionsExpired(); |
| 484 | aaaStatisticsManager.getAaaStats().countDroppedResponsesRx(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 485 | return; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 486 | } |
Kartikey Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 487 | |
| 488 | //instance of StateMachine using the sessionId for updating machine stats |
| 489 | StateMachine machineStats = StateMachine.lookupStateMachineBySessionId(stateMachine.sessionId()); |
| 490 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 491 | EAP eapPayload; |
| 492 | Ethernet eth; |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 493 | checkReceivedPacketForValidValidator(radiusPacket, stateMachine.requestAuthenticator()); |
Kartikey Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 494 | |
| 495 | //increasing packets and octets received from server |
| 496 | machineStats.incrementTotalPacketsReceived(); |
| 497 | machineStats.incrementTotalOctetReceived(radiusPacket.decapsulateMessage().getLength()); |
| 498 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 499 | if (outPacketSet.contains(radiusPacket.getIdentifier())) { |
| 500 | aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(false); |
| 501 | outPacketSet.remove(new Byte(radiusPacket.getIdentifier())); |
| 502 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 503 | switch (radiusPacket.getCode()) { |
| 504 | case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 505 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_CHALLENGE"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 506 | 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 Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 518 | log.debug("Send EAP challenge response to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 519 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), true); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 520 | aaaStatisticsManager.getAaaStats().increaseChallengeResponsesRx(); |
Shubham Sharma | 4786954 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 521 | outPacketSupp.add(eapPayload.getIdentifier()); |
| 522 | aaaStatisticsManager.getAaaStats().incrementPendingResSupp(); |
Kartikey Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 523 | //increasing packets send to server |
| 524 | machineStats.incrementTotalPacketsSent(); |
| 525 | machineStats.incrementTotalOctetSent(eapPayload.getLength()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 526 | break; |
| 527 | case RADIUS.RADIUS_CODE_ACCESS_ACCEPT: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 528 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_ACCEPT"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 529 | //send an EAPOL - Success to the supplicant. |
| 530 | byte[] eapMessageSuccess = |
| 531 | radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue(); |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 532 | eapPayload = EAP.deserializer().deserialize( |
| 533 | eapMessageSuccess, 0, eapMessageSuccess.length); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 534 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 535 | MacAddress.valueOf(nasMacAddress), |
| 536 | stateMachine.vlanId(), |
| 537 | EAPOL.EAPOL_PACKET, |
| 538 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 539 | log.info("Send EAP success message to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 540 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
| 541 | aaaStatisticsManager.getAaaStats().incrementEapolAuthSuccessTrans(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 542 | |
| 543 | stateMachine.authorizeAccess(); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 544 | aaaStatisticsManager.getAaaStats().increaseAcceptResponsesRx(); |
Kartikey Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 545 | //increasing packets send to server |
| 546 | machineStats.incrementTotalPacketsSent(); |
| 547 | machineStats.incrementTotalOctetSent(eapPayload.getLength()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 548 | break; |
| 549 | case RADIUS.RADIUS_CODE_ACCESS_REJECT: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 550 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_REJECT"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 551 | //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 Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 561 | eapPayload = EAP.deserializer().deserialize( |
| 562 | eapMessageFailure, 0, eapMessageFailure.length); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 563 | } |
| 564 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 565 | MacAddress.valueOf(nasMacAddress), |
| 566 | stateMachine.vlanId(), |
| 567 | EAPOL.EAPOL_PACKET, |
| 568 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 569 | log.warn("Send EAP failure message to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 570 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
| 571 | aaaStatisticsManager.getAaaStats().incrementEapolauthFailureTrans(); |
| 572 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 573 | stateMachine.denyAccess(); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 574 | aaaStatisticsManager.getAaaStats().increaseRejectResponsesRx(); |
Kartikey Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 575 | //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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 582 | break; |
| 583 | default: |
| 584 | log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 585 | aaaStatisticsManager.getAaaStats().increaseUnknownTypeRx(); |
Kartikey Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 586 | //increasing packets received to server |
| 587 | machineStats.incrementTotalPacketsReceived(); |
| 588 | machineStats.incrementTotalOctetReceived(radiusPacket.decapsulateMessage().getLength()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 589 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 590 | aaaStatisticsManager.getAaaStats().countDroppedResponsesRx(); |
Aaron Kruglikov | d39d99e | 2015-07-03 13:30:57 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 593 | /** |
| 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 Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 599 | private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint, boolean isChallengeResponse) { |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 600 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build(); |
| 601 | OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(), |
| 602 | treatment, ByteBuffer.wrap(ethernetPkt.serialize())); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 603 | EAPOL eap = ((EAPOL) ethernetPkt.getPayload()); |
| 604 | EAP eapPkt = (EAP) eap.getPayload(); |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 605 | if (log.isTraceEnabled()) { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 606 | log.trace("Sending eapol payload {} enclosed in {} to supplicant at {}", |
| 607 | eap, ethernetPkt, connectPoint); |
| 608 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 609 | packetService.emit(packet); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 610 | if (isChallengeResponse) { |
| 611 | aaaStatisticsManager.getAaaStats().incrementEapPktTxauthEap(); |
| 612 | } |
Shubham Sharma | 4786954 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 613 | aaaStatisticsManager.getAaaStats().incrementEapolFramesTx(); |
| 614 | aaaStatisticsManager.getAaaStats().countReqEapFramesTx(); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 617 | @Override |
| 618 | public String toString() { |
| 619 | return ToStringBuilder.reflectionToString(this); |
| 620 | } |
| 621 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 622 | // 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 637 | |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 638 | 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 Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 644 | default: |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 645 | // any other packets let the specific implementation handle |
| 646 | impl.handlePacketFromServer(context); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 647 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 648 | } catch (StateMachineException e) { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 649 | log.warn("Unable to process packet:", e); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 653 | /** |
| 654 | * Creates and initializes common fields of a RADIUS packet. |
| 655 | * |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 656 | * @param stateMachine state machine for the request |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 657 | * @param eapPacket EAP packet |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 658 | * @return RADIUS packet |
| 659 | */ |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 660 | private RADIUS getRadiusPayload(StateMachine stateMachine, byte identifier, EAP eapPacket) { |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 661 | RADIUS radiusPayload = |
| 662 | new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, |
| 663 | eapPacket.getIdentifier()); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 664 | |
| 665 | // set Request Authenticator in StateMachine |
| 666 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
| 667 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 668 | radiusPayload.setIdentifier(identifier); |
| 669 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 670 | stateMachine.username()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 671 | |
| 672 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 673 | AaaManager.this.nasIpAddress.getAddress()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 674 | |
| 675 | radiusPayload.encapsulateMessage(eapPacket); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 676 | |
| 677 | return radiusPayload; |
| 678 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 679 | |
| 680 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 681 | * Handles PAE packets (supplicant). |
| 682 | * |
| 683 | * @param inPacket Ethernet packet coming from the supplicant |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 684 | */ |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 685 | private void handleSupplicantPacket(InboundPacket inPacket) throws StateMachineException { |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 686 | Ethernet ethPkt = inPacket.parsed(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 687 | // Where does it come from? |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 688 | MacAddress srcMac = ethPkt.getSourceMAC(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 689 | |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 690 | DeviceId deviceId = inPacket.receivedFrom().deviceId(); |
| 691 | PortNumber portNumber = inPacket.receivedFrom().port(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 692 | String sessionId = deviceId.toString() + portNumber.toString(); |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 693 | 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 698 | } |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 699 | |
Shubham Sharma | 4786954 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 700 | 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 Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 714 | 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 Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 721 | stateMachine.setEapolTypeVal(eapol.getEapolType()); |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 724 | switch (eapol.getEapolType()) { |
| 725 | case EAPOL.EAPOL_START: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 726 | log.debug("EAP packet: EAPOL_START"); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 727 | stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom()); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 728 | if (stateMachine.getCleanupTimer() == null) { |
| 729 | scheduleStateMachineCleanupTimer(sessionId, stateMachine); |
| 730 | } |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 731 | stateMachine.start(); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 732 | aaaStatisticsManager.getAaaStats().incrementEapolStartReqTrans(); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 733 | //send an EAP Request/Identify to the supplicant |
| 734 | EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 735 | if (ethPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) { |
| 736 | stateMachine.setPriorityCode(ethPkt.getPriorityCode()); |
| 737 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 738 | Ethernet eth = buildEapolResponse(srcMac, MacAddress.valueOf(nasMacAddress), |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 739 | ethPkt.getVlanID(), EAPOL.EAPOL_PACKET, |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 740 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 741 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 742 | stateMachine.setSupplicantAddress(srcMac); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 743 | stateMachine.setVlanId(ethPkt.getVlanID()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 744 | log.debug("Getting EAP identity from supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 745 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
Shubham Sharma | 4786954 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 746 | aaaStatisticsManager.getAaaStats().incrementRequestIdFramesTx(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 747 | |
| 748 | break; |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 749 | case EAPOL.EAPOL_LOGOFF: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 750 | log.debug("EAP packet: EAPOL_LOGOFF"); |
Kartikey Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 751 | //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 Milkey | b34b496 | 2016-01-04 10:24:43 -0800 | [diff] [blame] | 760 | if (stateMachine.state() == StateMachine.STATE_AUTHORIZED) { |
| 761 | stateMachine.logoff(); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 762 | aaaStatisticsManager.getAaaStats().incrementEapolLogoffRx(); |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 763 | } |
Shubham Sharma | 4786954 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 764 | if (stateMachine.state() == StateMachine.STATE_IDLE) { |
| 765 | aaaStatisticsManager.getAaaStats().incrementAuthStateIdle(); |
| 766 | } |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 767 | |
| 768 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 769 | case EAPOL.EAPOL_PACKET: |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 770 | RADIUS radiusPayload; |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 771 | // check if this is a Response/Identify or a Response/TLS |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 772 | EAP eapPacket = (EAP) eapol.getPayload(); |
Shubham Sharma | 4786954 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 773 | Byte identifier = new Byte(eapPacket.getIdentifier()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 774 | |
| 775 | byte dataType = eapPacket.getDataType(); |
| 776 | switch (dataType) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 777 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 778 | case EAP.ATTR_IDENTITY: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 779 | log.debug("EAP packet: EAPOL_PACKET ATTR_IDENTITY"); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 780 | //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 Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 784 | // request id access to RADIUS |
| 785 | stateMachine.setUsername(eapPacket.getData()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 786 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 787 | radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 788 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 789 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 790 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 791 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 792 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 793 | aaaStatisticsManager.getAaaStats().incrementEapolAtrrIdentity(); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 794 | // change the state to "PENDING" |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 795 | if (stateMachine.state() == StateMachine.STATE_PENDING) { |
| 796 | aaaStatisticsManager.getAaaStats().increaseRequestReTx(); |
Kartikey Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 797 | stateMachine.incrementTotalPacketsSent(); |
| 798 | stateMachine.incrementTotalOctetSent(eapol.getPacketLength()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 799 | } |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 800 | stateMachine.requestAccess(); |
| 801 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 802 | case EAP.ATTR_MD5: |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 803 | stateMachine.setLastPacketReceivedTime(System.currentTimeMillis()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 804 | log.debug("EAP packet: EAPOL_PACKET ATTR_MD5"); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 805 | // verify if the EAP identifier corresponds to the |
| 806 | // challenge identifier from the client state |
| 807 | // machine. |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 808 | if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 809 | //send the RADIUS challenge response |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 810 | radiusPayload = |
| 811 | getRadiusPayload(stateMachine, |
| 812 | stateMachine.identifier(), |
| 813 | eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 814 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 815 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 816 | if (stateMachine.challengeState() != null) { |
| 817 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 818 | stateMachine.challengeState()); |
| 819 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 820 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Shubham Sharma | 4786954 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 821 | if (outPacketSupp.contains(eapPacket.getIdentifier())) { |
| 822 | aaaStatisticsManager.getAaaStats().decrementPendingResSupp(); |
| 823 | outPacketSupp.remove(identifier); |
| 824 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 825 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 826 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 827 | aaaStatisticsManager.getAaaStats().incrementEapolMd5RspChall(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 828 | } |
| 829 | break; |
| 830 | case EAP.ATTR_TLS: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 831 | log.debug("EAP packet: EAPOL_PACKET ATTR_TLS"); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 832 | // request id access to RADIUS |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 833 | radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 834 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 835 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 836 | if (stateMachine.challengeState() != null) { |
| 837 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 838 | stateMachine.challengeState()); |
| 839 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 840 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 841 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 842 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Shubham Sharma | 4786954 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 843 | if (outPacketSupp.contains(eapPacket.getIdentifier())) { |
| 844 | aaaStatisticsManager.getAaaStats().decrementPendingResSupp(); |
| 845 | outPacketSupp.remove(identifier); |
| 846 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 847 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 848 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 849 | aaaStatisticsManager.getAaaStats().incrementEapolTlsRespChall(); |
Ray Milkey | 5493b51 | 2015-10-21 12:13:49 -0700 | [diff] [blame] | 850 | |
Ray Milkey | f3790b8 | 2015-10-21 16:28:08 -0700 | [diff] [blame] | 851 | if (stateMachine.state() != StateMachine.STATE_PENDING) { |
| 852 | stateMachine.requestAccess(); |
| 853 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 854 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 855 | break; |
| 856 | default: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 857 | log.warn("Unknown EAP packet type"); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 858 | return; |
| 859 | } |
| 860 | break; |
| 861 | default: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 862 | log.debug("Skipping EAPOL message {}", eapol.getEapolType()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 863 | } |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 864 | aaaStatisticsManager.getAaaStats().countTransRespNotNak(); |
| 865 | aaaStatisticsManager.getAaaStats().countEapolResIdentityMsgTrans(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 866 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 869 | /** |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 870 | * 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 883 | * Configuration Listener, handles change in configuration. |
| 884 | */ |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 885 | private class InternalConfigListener implements NetworkConfigListener { |
| 886 | |
| 887 | /** |
Ray Milkey | c9e8dcc | 2015-12-30 10:31:32 -0800 | [diff] [blame] | 888 | * Reconfigures the AAA application according to the |
| 889 | * configuration parameters passed. |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 890 | * |
| 891 | * @param cfg configuration object |
| 892 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 893 | private void reconfigureNetwork(AaaConfig cfg) { |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 894 | log.info("Reconfiguring AaaConfig from config: {}", cfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 895 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 896 | if (cfg == null) { |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 897 | newCfg = new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 898 | } 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 916 | |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 917 | boolean reconfigureCustomizer = false; |
| 918 | if (customizer == null || !customizer.equals(newCfg.radiusPktCustomizer())) { |
| 919 | customizer = newCfg.radiusPktCustomizer(); |
| 920 | configurePacketCustomizer(); |
| 921 | reconfigureCustomizer = true; |
| 922 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 923 | |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 924 | 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 936 | impl.clearLocalState(); |
| 937 | impl.initializeLocalState(newCfg); |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 938 | } |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 939 | } |
| 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 Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 946 | event.configClass().equals(AaaConfig.class)) { |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 947 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 948 | AaaConfig cfg = netCfgService.getConfig(appId, AaaConfig.class); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 949 | reconfigureNetwork(cfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 950 | |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 951 | log.info("Reconfigured: {}", cfg.toString()); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | } |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 955 | |
| 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 Kumar | 8bc4eb3 | 2020-02-04 08:32:46 +0000 | [diff] [blame^] | 966 | log.info("Received PORT_REMOVED event. Clearing AAA Session with Id {}", sessionId); |
| 967 | flushStateMachineSession(sessionId, |
| 968 | StateMachine.SessionTerminationReasons.PORT_REMOVED.getReason()); |
Kartikey Dubey | be14f47 | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 969 | |
Girish Kumar | 8bc4eb3 | 2020-02-04 08:32:46 +0000 | [diff] [blame^] | 970 | 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 Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | break; |
Girish Kumar | 8bc4eb3 | 2020-02-04 08:32:46 +0000 | [diff] [blame^] | 991 | |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 992 | default: |
| 993 | return; |
| 994 | } |
| 995 | } |
Girish Kumar | 8bc4eb3 | 2020-02-04 08:32:46 +0000 | [diff] [blame^] | 996 | |
| 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 Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 1014 | } |
Girish Kumar | 8bc4eb3 | 2020-02-04 08:32:46 +0000 | [diff] [blame^] | 1015 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 1016 | 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 Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 1033 | log.debug("TimedOutPackets----" + aaaStatisticsManager.getAaaStats().getTimedOutPackets()); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 1034 | 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 Sharma | 4786954 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 1046 | 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 dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 1055 | aaaStatisticsManager.getStatsDelegate(). |
| 1056 | notify(new AuthenticationStatisticsEvent(AuthenticationStatisticsEvent.Type.STATS_UPDATE, |
| 1057 | aaaStatisticsManager.getAaaStats())); |
| 1058 | } |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 1059 | } |
| 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 dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 1072 | } |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 1073 | |
| 1074 | } |
Girish Kumar | 8bc4eb3 | 2020-02-04 08:32:46 +0000 | [diff] [blame^] | 1075 | } |