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 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 18 | import com.google.common.base.Strings; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 19 | import com.google.common.collect.Maps; |
Jonathan Hart | 932bedc | 2018-07-12 13:46:09 -0700 | [diff] [blame] | 20 | import org.apache.commons.lang3.builder.ToStringBuilder; |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 21 | import org.onlab.packet.DeserializationException; |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 22 | import org.onlab.packet.EAP; |
| 23 | import org.onlab.packet.EAPOL; |
| 24 | import org.onlab.packet.EthType; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 25 | import org.onlab.packet.Ethernet; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 26 | import org.onlab.packet.MacAddress; |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 27 | import org.onlab.packet.RADIUS; |
| 28 | import org.onlab.packet.RADIUSAttribute; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 29 | import org.onlab.util.Tools; |
| 30 | import org.onosproject.cfg.ComponentConfigService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 31 | import org.onosproject.core.ApplicationId; |
| 32 | import org.onosproject.core.CoreService; |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 33 | import org.onosproject.event.AbstractListenerManager; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 34 | import org.onosproject.mastership.MastershipService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 35 | import org.onosproject.net.ConnectPoint; |
| 36 | import org.onosproject.net.DeviceId; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 37 | import org.onosproject.net.PortNumber; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 38 | import org.onosproject.net.config.ConfigFactory; |
| 39 | import org.onosproject.net.config.NetworkConfigEvent; |
| 40 | import org.onosproject.net.config.NetworkConfigListener; |
| 41 | import org.onosproject.net.config.NetworkConfigRegistry; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 42 | import org.onosproject.net.device.DeviceEvent; |
| 43 | import org.onosproject.net.device.DeviceListener; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 44 | import org.onosproject.net.device.DeviceService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 45 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 46 | import org.onosproject.net.flow.TrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 47 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 48 | import org.onosproject.net.packet.InboundPacket; |
| 49 | import org.onosproject.net.packet.OutboundPacket; |
| 50 | import org.onosproject.net.packet.PacketContext; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 51 | import org.onosproject.net.packet.PacketProcessor; |
| 52 | import org.onosproject.net.packet.PacketService; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 53 | import org.opencord.aaa.AaaConfig; |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 54 | import org.opencord.aaa.AaaMachineStatisticsEvent; |
| 55 | import org.opencord.aaa.AaaMachineStatisticsService; |
| 56 | import org.opencord.aaa.AaaSupplicantMachineStats; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 57 | import org.opencord.aaa.AuthenticationEvent; |
| 58 | import org.opencord.aaa.AuthenticationEventListener; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 59 | import org.opencord.aaa.AuthenticationRecord; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 60 | import org.opencord.aaa.AuthenticationService; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 61 | import org.opencord.aaa.AuthenticationStatisticsEvent; |
| 62 | import org.opencord.aaa.AuthenticationStatisticsService; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 63 | import org.opencord.aaa.RadiusCommunicator; |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 64 | import org.opencord.aaa.RadiusOperationalStatusEvent; |
| 65 | import org.opencord.aaa.RadiusOperationalStatusService; |
| 66 | import org.opencord.aaa.RadiusOperationalStatusService.RadiusOperationalStatusEvaluationMode; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 67 | import org.opencord.aaa.StateMachineDelegate; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 68 | import org.opencord.sadis.BaseInformationService; |
| 69 | import org.opencord.sadis.SadisService; |
| 70 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 71 | import org.osgi.service.component.ComponentContext; |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 72 | import org.osgi.service.component.annotations.Activate; |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 73 | import org.osgi.service.component.annotations.Component; |
| 74 | import org.osgi.service.component.annotations.Deactivate; |
| 75 | import org.osgi.service.component.annotations.Modified; |
| 76 | import org.osgi.service.component.annotations.Reference; |
| 77 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 78 | import org.slf4j.Logger; |
| 79 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 80 | import javax.crypto.Mac; |
| 81 | import javax.crypto.spec.SecretKeySpec; |
| 82 | import java.net.InetAddress; |
| 83 | import java.net.UnknownHostException; |
| 84 | import java.nio.ByteBuffer; |
| 85 | import java.util.Arrays; |
| 86 | import java.util.Dictionary; |
| 87 | import java.util.HashSet; |
| 88 | import java.util.List; |
| 89 | import java.util.Map; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 90 | import java.util.concurrent.ConcurrentMap; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 91 | import java.util.concurrent.Executors; |
| 92 | import java.util.concurrent.ScheduledExecutorService; |
| 93 | import java.util.concurrent.ScheduledFuture; |
| 94 | import java.util.concurrent.TimeUnit; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 95 | import java.util.stream.Collectors; |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 96 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 97 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
| 98 | import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_EVENT_GENERATION; |
| 99 | import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_EVENT_GENERATION_DEFAULT; |
| 100 | import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_TIMEOUT; |
| 101 | import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_TIMEOUT_DEFAULT; |
| 102 | import static org.opencord.aaa.impl.OsgiPropertyConstants.STATISTICS_GENERATION_PERIOD; |
| 103 | import static org.opencord.aaa.impl.OsgiPropertyConstants.STATISTICS_GENERATION_PERIOD_DEFAULT; |
| 104 | import static org.opencord.aaa.impl.OsgiPropertyConstants.STATUS_SERVER_MODE; |
| 105 | import static org.opencord.aaa.impl.OsgiPropertyConstants.STATUS_SERVER_MODE_DEFAULT; |
| 106 | import static org.slf4j.LoggerFactory.getLogger; |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 107 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 108 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 109 | * AAA application for ONOS. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 110 | */ |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 111 | @Component(immediate = true, property = { |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 112 | 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 Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 116 | }) |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 117 | public class AaaManager |
| 118 | extends AbstractListenerManager<AuthenticationEvent, AuthenticationEventListener> |
| 119 | implements AuthenticationService { |
| 120 | |
Charles Chan | df7ff86 | 2017-01-20 11:22:05 -0800 | [diff] [blame] | 121 | private static final String APP_NAME = "org.opencord.aaa"; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 122 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 123 | private final Logger log = getLogger(getClass()); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 124 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 126 | protected CoreService coreService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 127 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 128 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 129 | protected PacketService packetService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 130 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 131 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 132 | protected NetworkConfigRegistry netCfgService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 133 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 134 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 135 | protected DeviceService deviceService; |
| 136 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 137 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 138 | protected SadisService sadisService; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 139 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 140 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 141 | protected MastershipService mastershipService; |
| 142 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 143 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 144 | protected AuthenticationStatisticsService aaaStatisticsManager; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 145 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 146 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 147 | protected AaaMachineStatisticsService aaaSupplicantStatsManager; |
| 148 | |
| 149 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 150 | protected ComponentConfigService cfgService; |
| 151 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 152 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 153 | protected RadiusOperationalStatusService radiusOperationalStatusService; |
| 154 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 155 | protected AuthenticationStatisticsEventPublisher authenticationStatisticsPublisher; |
| 156 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 157 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 158 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 159 | // 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 dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 164 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 165 | private IdentifierManager idManager; |
| 166 | |
| 167 | private ConcurrentMap<String, StateMachine> stateMachines; |
| 168 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 169 | // NAS IP address |
| 170 | protected InetAddress nasIpAddress; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 171 | |
| 172 | // self MAC address |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 173 | protected String nasMacAddress; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 174 | |
| 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 Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 180 | |
| 181 | // RADIUS server secret |
| 182 | protected String radiusSecret; |
| 183 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 184 | // bindings |
| 185 | protected CustomizationInfo customInfo; |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 186 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 187 | // our application-specific event handler |
| 188 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 189 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 190 | // our unique identifier |
| 191 | private ApplicationId appId; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 192 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 193 | // TimeOut time for cleaning up stateMachines stuck due to pending AAA/EAPOL message. |
| 194 | protected int cleanupTimerTimeOutInMins; |
| 195 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 196 | // Setup specific customization/attributes on the RADIUS packets |
| 197 | PacketCustomizer pktCustomizer; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 198 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 199 | // 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 Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 206 | // Object for the specific type of communication with the RADIUS |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 207 | // server, socket based or packet_out based |
| 208 | RadiusCommunicator impl = null; |
| 209 | |
| 210 | // latest configuration |
| 211 | AaaConfig newCfg; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 212 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 213 | ScheduledFuture<?> scheduledFuture; |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 214 | ScheduledFuture<?> scheduledStatusServerChecker; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 215 | ScheduledExecutorService executor; |
| 216 | String configuredAaaServerAddress; |
| 217 | HashSet<Byte> outPacketSet = new HashSet<Byte>(); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 218 | 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 Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 221 | // Configuration properties factory |
| 222 | private final ConfigFactory factory = |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 223 | new ConfigFactory<ApplicationId, AaaConfig>(APP_SUBJECT_FACTORY, |
| 224 | AaaConfig.class, |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 225 | "AAA") { |
| 226 | @Override |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 227 | public AaaConfig createConfig() { |
| 228 | return new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 229 | } |
| 230 | }; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 231 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 232 | // Listener for config changes |
| 233 | private final InternalConfigListener cfgListener = new InternalConfigListener(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 234 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 235 | private StateMachineDelegate delegate = new InternalStateMachineDelegate(); |
| 236 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 237 | /** |
| 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 248 | short vlan, byte eapolType, EAP eap, byte priorityCode) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 249 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 250 | 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 256 | eth.setPriorityCode(priorityCode); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 257 | } |
| 258 | //eapol header |
| 259 | EAPOL eapol = new EAPOL(); |
| 260 | eapol.setEapolType(eapolType); |
| 261 | eapol.setPacketLength(eap.getLength()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 262 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 263 | //eap part |
| 264 | eapol.setPayload(eap); |
| 265 | |
| 266 | eth.setPayload(eapol); |
| 267 | eth.setPad(true); |
| 268 | return eth; |
| 269 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 270 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 271 | @Activate |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 272 | public void activate(ComponentContext context) { |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 273 | idManager = new IdentifierManager(); |
| 274 | stateMachines = Maps.newConcurrentMap(); |
Charles Chan | df7ff86 | 2017-01-20 11:22:05 -0800 | [diff] [blame] | 275 | appId = coreService.registerApplication(APP_NAME); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 276 | eventDispatcher.addSink(AuthenticationEvent.class, listenerRegistry); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 277 | netCfgService.addListener(cfgListener); |
| 278 | netCfgService.registerConfigFactory(factory); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 279 | cfgService.registerProperties(getClass()); |
| 280 | modified(context); |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 281 | subsService = sadisService.getSubscriberInfoService(); |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 282 | customInfo = new CustomizationInfo(subsService, deviceService); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 283 | cfgListener.reconfigureNetwork(netCfgService.getConfig(appId, AaaConfig.class)); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 284 | log.info("Starting with config {} {}", this, newCfg); |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 285 | configureRadiusCommunication(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 286 | // register our event handler |
Brian O'Connor | d9c7da0 | 2015-07-29 17:49:24 -0700 | [diff] [blame] | 287 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 288 | StateMachine.setDelegate(delegate); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 289 | cleanupTimerTimeOutInMins = newCfg.sessionCleanupTimer(); |
| 290 | StateMachine.setcleanupTimerTimeOutInMins(cleanupTimerTimeOutInMins); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 291 | impl.initializeLocalState(newCfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 292 | impl.requestIntercepts(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 293 | deviceService.addListener(deviceListener); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 294 | getConfiguredAaaServerAddress(); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 295 | radiusOperationalStatusService.initialize(nasIpAddress.getAddress(), radiusSecret, impl); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 296 | authenticationStatisticsPublisher = |
| 297 | new AuthenticationStatisticsEventPublisher(); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 298 | executor = Executors.newScheduledThreadPool(3); |
| 299 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 300 | scheduledFuture = executor.scheduleAtFixedRate(authenticationStatisticsPublisher, |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 301 | 0, statisticsGenerationPeriodInSeconds, TimeUnit.SECONDS); |
| 302 | scheduledStatusServerChecker = executor.scheduleAtFixedRate(new ServerStatusChecker(), 0, |
| 303 | operationalStatusEventGenerationPeriodInSeconds, TimeUnit.SECONDS); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 304 | |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 305 | log.info("Started"); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | @Deactivate |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 309 | public void deactivate(ComponentContext context) { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 310 | impl.withdrawIntercepts(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 311 | packetService.removeProcessor(processor); |
Deepa Vaddireddy | b9c24c6 | 2017-09-21 13:45:30 +0530 | [diff] [blame] | 312 | netCfgService.removeListener(cfgListener); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 313 | cfgService.unregisterProperties(getClass(), false); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 314 | StateMachine.unsetDelegate(delegate); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 315 | impl.deactivate(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 316 | deviceService.removeListener(deviceListener); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 317 | eventDispatcher.removeSink(AuthenticationEvent.class); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 318 | scheduledFuture.cancel(true); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 319 | scheduledStatusServerChecker.cancel(true); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 320 | executor.shutdown(); |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 321 | log.info("Stopped"); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 322 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 323 | @Modified |
| 324 | public void modified(ComponentContext context) { |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 325 | 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 dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Shubham Sharma | cf5e503 | 2019-11-26 11:09:21 +0000 | [diff] [blame] | 355 | protected void configureRadiusCommunication() { |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 356 | 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 Das | e72358a | 2018-11-13 21:56:46 -0800 | [diff] [blame] | 370 | case "att": |
| 371 | pktCustomizer = new AttPacketCustomizer(customInfo); |
| 372 | log.info("Created AttPacketCustomizer"); |
| 373 | break; |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 374 | default: |
| 375 | pktCustomizer = new PacketCustomizer(customInfo); |
| 376 | log.info("Created default PacketCustomizer"); |
| 377 | break; |
| 378 | } |
| 379 | } |
| 380 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 381 | 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 Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 396 | private void checkReceivedPacketForValidValidator(RADIUS radiusPacket, byte[] requestAuthenticator) { |
| 397 | if (!checkResponseMessageAuthenticator(radiusSecret, radiusPacket, requestAuthenticator)) { |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 398 | aaaStatisticsManager.getAaaStats().increaseInvalidValidatorsRx(); |
| 399 | } |
| 400 | } |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 401 | |
| 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 dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 423 | public void checkForPacketFromUnknownServer(String hostAddress) { |
| 424 | if (!hostAddress.equals(configuredAaaServerAddress)) { |
Vijaykumar Kushwaha | fffd3d1 | 2019-08-01 11:09:59 +0000 | [diff] [blame] | 425 | getConfiguredAaaServerAddress(); |
| 426 | if (!hostAddress.equals(configuredAaaServerAddress)) { |
| 427 | aaaStatisticsManager.getAaaStats().incrementUnknownServerRx(); |
| 428 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 432 | /** |
| 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 dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 439 | outPacketSet.add(radiusPacket.getIdentifier()); |
| 440 | aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(true); |
| 441 | aaaStatisticsManager.getAaaStats().increaseAccessRequestsTx(); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 442 | aaaStatisticsManager.putOutgoingIdentifierToMap(radiusPacket.getIdentifier()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 443 | impl.sendRadiusPacket(radiusPacket, inPkt); |
| 444 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 445 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 446 | /** |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 447 | * Handles RADIUS packets. |
| 448 | * |
| 449 | * @param radiusPacket RADIUS packet coming from the RADIUS server. |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 450 | * @throws DeserializationException if packet deserialization fails |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 451 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 452 | public void handleRadiusPacket(RADIUS radiusPacket) throws DeserializationException { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 453 | if (log.isTraceEnabled()) { |
| 454 | log.trace("Received RADIUS packet {}", radiusPacket); |
| 455 | } |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 456 | if (radiusOperationalStatusService.isRadiusResponseForOperationalStatus(radiusPacket.getIdentifier())) { |
| 457 | radiusOperationalStatusService.handleRadiusPacketForOperationalStatus(radiusPacket); |
| 458 | return; |
| 459 | } |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 460 | |
| 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 474 | if (stateMachine == null) { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 475 | log.error("Invalid packet identifier {}, could not find corresponding " |
| 476 | + "state machine ... exiting", radiusPacket.getIdentifier()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 477 | aaaStatisticsManager.getAaaStats().incrementNumberOfSessionsExpired(); |
| 478 | aaaStatisticsManager.getAaaStats().countDroppedResponsesRx(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 479 | return; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 480 | } |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 481 | |
| 482 | //instance of StateMachine using the sessionId for updating machine stats |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 483 | StateMachine machineStats = stateMachines.get(stateMachine.sessionId()); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 484 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 485 | EAP eapPayload; |
| 486 | Ethernet eth; |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 487 | checkReceivedPacketForValidValidator(radiusPacket, stateMachine.requestAuthenticator()); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 488 | |
| 489 | //increasing packets and octets received from server |
| 490 | machineStats.incrementTotalPacketsReceived(); |
| 491 | machineStats.incrementTotalOctetReceived(radiusPacket.decapsulateMessage().getLength()); |
| 492 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 493 | if (outPacketSet.contains(radiusPacket.getIdentifier())) { |
| 494 | aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(false); |
| 495 | outPacketSet.remove(new Byte(radiusPacket.getIdentifier())); |
| 496 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 497 | switch (radiusPacket.getCode()) { |
| 498 | case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 499 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_CHALLENGE"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 500 | 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 Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 512 | log.debug("Send EAP challenge response to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 513 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), true); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 514 | aaaStatisticsManager.getAaaStats().increaseChallengeResponsesRx(); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 515 | outPacketSupp.add(eapPayload.getIdentifier()); |
| 516 | aaaStatisticsManager.getAaaStats().incrementPendingResSupp(); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 517 | //increasing packets send to server |
| 518 | machineStats.incrementTotalPacketsSent(); |
| 519 | machineStats.incrementTotalOctetSent(eapPayload.getLength()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 520 | break; |
| 521 | case RADIUS.RADIUS_CODE_ACCESS_ACCEPT: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 522 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_ACCEPT"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 523 | //send an EAPOL - Success to the supplicant. |
| 524 | byte[] eapMessageSuccess = |
| 525 | radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue(); |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 526 | eapPayload = EAP.deserializer().deserialize( |
| 527 | eapMessageSuccess, 0, eapMessageSuccess.length); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 528 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 529 | MacAddress.valueOf(nasMacAddress), |
| 530 | stateMachine.vlanId(), |
| 531 | EAPOL.EAPOL_PACKET, |
| 532 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 533 | log.info("Send EAP success message to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 534 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
| 535 | aaaStatisticsManager.getAaaStats().incrementEapolAuthSuccessTrans(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 536 | |
| 537 | stateMachine.authorizeAccess(); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 538 | aaaStatisticsManager.getAaaStats().increaseAcceptResponsesRx(); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 539 | //increasing packets send to server |
| 540 | machineStats.incrementTotalPacketsSent(); |
| 541 | machineStats.incrementTotalOctetSent(eapPayload.getLength()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 542 | break; |
| 543 | case RADIUS.RADIUS_CODE_ACCESS_REJECT: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 544 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_REJECT"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 545 | //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 Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 555 | eapPayload = EAP.deserializer().deserialize( |
| 556 | eapMessageFailure, 0, eapMessageFailure.length); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 557 | } |
| 558 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 559 | MacAddress.valueOf(nasMacAddress), |
| 560 | stateMachine.vlanId(), |
| 561 | EAPOL.EAPOL_PACKET, |
| 562 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 563 | log.warn("Send EAP failure message to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 564 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
| 565 | aaaStatisticsManager.getAaaStats().incrementEapolauthFailureTrans(); |
| 566 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 567 | stateMachine.denyAccess(); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 568 | aaaStatisticsManager.getAaaStats().increaseRejectResponsesRx(); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 569 | //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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 576 | break; |
| 577 | default: |
| 578 | log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 579 | aaaStatisticsManager.getAaaStats().increaseUnknownTypeRx(); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 580 | //increasing packets received to server |
| 581 | machineStats.incrementTotalPacketsReceived(); |
| 582 | machineStats.incrementTotalOctetReceived(radiusPacket.decapsulateMessage().getLength()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 583 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 584 | aaaStatisticsManager.getAaaStats().countDroppedResponsesRx(); |
Aaron Kruglikov | d39d99e | 2015-07-03 13:30:57 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 587 | /** |
| 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 Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 593 | private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint, boolean isChallengeResponse) { |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 594 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build(); |
| 595 | OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(), |
| 596 | treatment, ByteBuffer.wrap(ethernetPkt.serialize())); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 597 | EAPOL eap = ((EAPOL) ethernetPkt.getPayload()); |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 598 | if (log.isTraceEnabled()) { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 599 | log.trace("Sending eapol payload {} enclosed in {} to supplicant at {}", |
| 600 | eap, ethernetPkt, connectPoint); |
| 601 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 602 | packetService.emit(packet); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 603 | if (isChallengeResponse) { |
| 604 | aaaStatisticsManager.getAaaStats().incrementEapPktTxauthEap(); |
| 605 | } |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 606 | aaaStatisticsManager.getAaaStats().incrementEapolFramesTx(); |
| 607 | aaaStatisticsManager.getAaaStats().countReqEapFramesTx(); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 610 | @Override |
| 611 | public String toString() { |
| 612 | return ToStringBuilder.reflectionToString(this); |
| 613 | } |
| 614 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 615 | @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 Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 656 | // 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 671 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 672 | // 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 Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 683 | /** |
| 684 | * Creates and initializes common fields of a RADIUS packet. |
| 685 | * |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 686 | * @param stateMachine state machine for the request |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 687 | * @param eapPacket EAP packet |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 688 | * @return RADIUS packet |
| 689 | */ |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 690 | private RADIUS getRadiusPayload(StateMachine stateMachine, byte identifier, EAP eapPacket) { |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 691 | RADIUS radiusPayload = |
| 692 | new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, |
| 693 | eapPacket.getIdentifier()); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 694 | |
| 695 | // set Request Authenticator in StateMachine |
| 696 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
| 697 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 698 | radiusPayload.setIdentifier(identifier); |
| 699 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 700 | stateMachine.username()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 701 | |
| 702 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 703 | AaaManager.this.nasIpAddress.getAddress()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 704 | |
| 705 | radiusPayload.encapsulateMessage(eapPacket); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 706 | |
| 707 | return radiusPayload; |
| 708 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 709 | |
| 710 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 711 | * Handles PAE packets (supplicant). |
| 712 | * |
| 713 | * @param inPacket Ethernet packet coming from the supplicant |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 714 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 715 | private void handleSupplicantPacket(InboundPacket inPacket) { |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 716 | Ethernet ethPkt = inPacket.parsed(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 717 | // Where does it come from? |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 718 | MacAddress srcMac = ethPkt.getSourceMAC(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 719 | |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 720 | DeviceId deviceId = inPacket.receivedFrom().deviceId(); |
| 721 | PortNumber portNumber = inPacket.receivedFrom().port(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 722 | String sessionId = deviceId.toString() + portNumber.toString(); |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 723 | 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 728 | } |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 729 | |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 730 | 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 Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 744 | |
| 745 | StateMachine stateMachine = stateMachines.computeIfAbsent(sessionId, id -> new StateMachine(id, executor)); |
| 746 | stateMachine.setEapolTypeVal(eapol.getEapolType()); |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 747 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 748 | switch (eapol.getEapolType()) { |
| 749 | case EAPOL.EAPOL_START: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 750 | log.debug("EAP packet: EAPOL_START"); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 751 | stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom()); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 752 | stateMachine.start(); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 753 | |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 754 | aaaStatisticsManager.getAaaStats().incrementEapolStartReqTrans(); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 755 | //send an EAP Request/Identify to the supplicant |
| 756 | EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 757 | if (ethPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) { |
| 758 | stateMachine.setPriorityCode(ethPkt.getPriorityCode()); |
| 759 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 760 | Ethernet eth = buildEapolResponse(srcMac, MacAddress.valueOf(nasMacAddress), |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 761 | ethPkt.getVlanID(), EAPOL.EAPOL_PACKET, |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 762 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 763 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 764 | stateMachine.setSupplicantAddress(srcMac); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 765 | stateMachine.setVlanId(ethPkt.getVlanID()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 766 | log.debug("Getting EAP identity from supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 767 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 768 | aaaStatisticsManager.getAaaStats().incrementRequestIdFramesTx(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 769 | |
| 770 | break; |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 771 | case EAPOL.EAPOL_LOGOFF: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 772 | log.debug("EAP packet: EAPOL_LOGOFF"); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 773 | //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 Milkey | b34b496 | 2016-01-04 10:24:43 -0800 | [diff] [blame] | 782 | if (stateMachine.state() == StateMachine.STATE_AUTHORIZED) { |
| 783 | stateMachine.logoff(); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 784 | aaaStatisticsManager.getAaaStats().incrementEapolLogoffRx(); |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 785 | } |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 786 | if (stateMachine.state() == StateMachine.STATE_IDLE) { |
| 787 | aaaStatisticsManager.getAaaStats().incrementAuthStateIdle(); |
| 788 | } |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 789 | |
| 790 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 791 | case EAPOL.EAPOL_PACKET: |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 792 | RADIUS radiusPayload; |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 793 | // check if this is a Response/Identify or a Response/TLS |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 794 | EAP eapPacket = (EAP) eapol.getPayload(); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 795 | Byte identifier = new Byte(eapPacket.getIdentifier()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 796 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 797 | // get identifier for request and store mapping to session ID |
| 798 | RequestIdentifier radiusIdentifier = idManager.getNewIdentifier(sessionId); |
| 799 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 800 | byte dataType = eapPacket.getDataType(); |
| 801 | switch (dataType) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 802 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 803 | case EAP.ATTR_IDENTITY: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 804 | log.debug("EAP packet: EAPOL_PACKET ATTR_IDENTITY"); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 805 | //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 Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 809 | // request id access to RADIUS |
| 810 | stateMachine.setUsername(eapPacket.getData()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 811 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 812 | radiusPayload = getRadiusPayload(stateMachine, radiusIdentifier.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 813 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 814 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 815 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 816 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 817 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 818 | aaaStatisticsManager.getAaaStats().incrementEapolAtrrIdentity(); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 819 | // change the state to "PENDING" |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 820 | if (stateMachine.state() == StateMachine.STATE_PENDING) { |
| 821 | aaaStatisticsManager.getAaaStats().increaseRequestReTx(); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 822 | stateMachine.incrementTotalPacketsSent(); |
| 823 | stateMachine.incrementTotalOctetSent(eapol.getPacketLength()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 824 | } |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 825 | stateMachine.requestAccess(); |
| 826 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 827 | case EAP.ATTR_MD5: |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 828 | stateMachine.setLastPacketReceivedTime(System.currentTimeMillis()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 829 | log.debug("EAP packet: EAPOL_PACKET ATTR_MD5"); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 830 | // verify if the EAP identifier corresponds to the |
| 831 | // challenge identifier from the client state |
| 832 | // machine. |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 833 | if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 834 | //send the RADIUS challenge response |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 835 | radiusPayload = getRadiusPayload(stateMachine, |
| 836 | radiusIdentifier.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 837 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 838 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 839 | if (stateMachine.challengeState() != null) { |
| 840 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 841 | stateMachine.challengeState()); |
| 842 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 843 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 844 | if (outPacketSupp.contains(eapPacket.getIdentifier())) { |
| 845 | aaaStatisticsManager.getAaaStats().decrementPendingResSupp(); |
| 846 | outPacketSupp.remove(identifier); |
| 847 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 848 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 849 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 850 | aaaStatisticsManager.getAaaStats().incrementEapolMd5RspChall(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 851 | } |
| 852 | break; |
| 853 | case EAP.ATTR_TLS: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 854 | log.debug("EAP packet: EAPOL_PACKET ATTR_TLS"); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 855 | // request id access to RADIUS |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 856 | radiusPayload = getRadiusPayload(stateMachine, radiusIdentifier.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 857 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 858 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 859 | if (stateMachine.challengeState() != null) { |
| 860 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 861 | stateMachine.challengeState()); |
| 862 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 863 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 864 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 865 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 866 | if (outPacketSupp.contains(eapPacket.getIdentifier())) { |
| 867 | aaaStatisticsManager.getAaaStats().decrementPendingResSupp(); |
| 868 | outPacketSupp.remove(identifier); |
| 869 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 870 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 871 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 872 | aaaStatisticsManager.getAaaStats().incrementEapolTlsRespChall(); |
Ray Milkey | 5493b51 | 2015-10-21 12:13:49 -0700 | [diff] [blame] | 873 | |
Ray Milkey | f3790b8 | 2015-10-21 16:28:08 -0700 | [diff] [blame] | 874 | if (stateMachine.state() != StateMachine.STATE_PENDING) { |
| 875 | stateMachine.requestAccess(); |
| 876 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 877 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 878 | break; |
| 879 | default: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 880 | log.warn("Unknown EAP packet type"); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 881 | return; |
| 882 | } |
| 883 | break; |
| 884 | default: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 885 | log.debug("Skipping EAPOL message {}", eapol.getEapolType()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 886 | } |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 887 | aaaStatisticsManager.getAaaStats().countTransRespNotNak(); |
| 888 | aaaStatisticsManager.getAaaStats().countEapolResIdentityMsgTrans(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 889 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 892 | /** |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 893 | * 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 Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 901 | |
| 902 | if (authenticationEvent.type() == AuthenticationEvent.Type.TIMEOUT) { |
| 903 | handleStateMachineTimeout(authenticationEvent.subject()); |
| 904 | } |
| 905 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 906 | post(authenticationEvent); |
| 907 | } |
| 908 | } |
| 909 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 910 | 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 Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 920 | /** |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 921 | * Configuration Listener, handles change in configuration. |
| 922 | */ |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 923 | private class InternalConfigListener implements NetworkConfigListener { |
| 924 | |
| 925 | /** |
Ray Milkey | c9e8dcc | 2015-12-30 10:31:32 -0800 | [diff] [blame] | 926 | * Reconfigures the AAA application according to the |
| 927 | * configuration parameters passed. |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 928 | * |
| 929 | * @param cfg configuration object |
| 930 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 931 | private void reconfigureNetwork(AaaConfig cfg) { |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 932 | log.info("Reconfiguring AaaConfig from config: {}", cfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 933 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 934 | if (cfg == null) { |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 935 | newCfg = new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 936 | } 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 954 | |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 955 | boolean reconfigureCustomizer = false; |
| 956 | if (customizer == null || !customizer.equals(newCfg.radiusPktCustomizer())) { |
| 957 | customizer = newCfg.radiusPktCustomizer(); |
| 958 | configurePacketCustomizer(); |
| 959 | reconfigureCustomizer = true; |
| 960 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 961 | |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 962 | 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 Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 974 | impl.clearLocalState(); |
| 975 | impl.initializeLocalState(newCfg); |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 976 | } |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 977 | } |
| 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 Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 984 | event.configClass().equals(AaaConfig.class)) { |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 985 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 986 | AaaConfig cfg = netCfgService.getConfig(appId, AaaConfig.class); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 987 | reconfigureNetwork(cfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 988 | |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 989 | log.info("Reconfigured: {}", cfg.toString()); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | } |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 993 | |
| 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 Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 1004 | StateMachine stateMachine = stateMachines.get(sessionId); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 1005 | 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 Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 1014 | StateMachine removed = stateMachines.remove(sessionId); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 1015 | if (removed != null) { |
| 1016 | StateMachine.deleteStateMachineMapping(removed); |
| 1017 | } |
| 1018 | |
| 1019 | break; |
| 1020 | default: |
| 1021 | return; |
| 1022 | } |
| 1023 | } |
| 1024 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 1025 | 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 Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 1042 | log.debug("TimedOutPackets----" + aaaStatisticsManager.getAaaStats().getTimedOutPackets()); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 1043 | 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 Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 1055 | 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 dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 1064 | aaaStatisticsManager.getStatsDelegate(). |
| 1065 | notify(new AuthenticationStatisticsEvent(AuthenticationStatisticsEvent.Type.STATS_UPDATE, |
| 1066 | aaaStatisticsManager.getAaaStats())); |
| 1067 | } |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | private class ServerStatusChecker implements Runnable { |
| 1071 | @Override |
| 1072 | public void run() { |
Matteo Scandolo | 3498bc0 | 2020-01-08 09:54:12 -0800 | [diff] [blame] | 1073 | log.debug("Notifying RadiusOperationalStatusEvent"); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 1074 | radiusOperationalStatusService.checkServerOperationalStatus(); |
Matteo Scandolo | 3498bc0 | 2020-01-08 09:54:12 -0800 | [diff] [blame] | 1075 | log.trace("--POSTING--" + radiusOperationalStatusService.getRadiusServerOperationalStatus()); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 1076 | radiusOperationalStatusService.getRadiusOprStDelegate() |
| 1077 | .notify(new RadiusOperationalStatusEvent( |
| 1078 | RadiusOperationalStatusEvent.Type.RADIUS_OPERATIONAL_STATUS, |
| 1079 | radiusOperationalStatusService. |
| 1080 | getRadiusServerOperationalStatus())); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 1081 | } |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 1082 | |
| 1083 | } |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 1084 | } |