blob: bcd4cfafd7462f162a8a88125371e65853ebfbe6 [file] [log] [blame]
Ari Saha89831742015-06-26 10:31:48 -07001/*
Amit Ghoshc9ac1e52017-07-28 12:31:18 +01002 * Copyright 2017-present Open Networking Foundation
Ari Saha89831742015-06-26 10:31:48 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matteo Scandolocf847b82019-04-26 15:00:00 -070016package org.opencord.aaa.impl;
Ari Saha89831742015-06-26 10:31:48 -070017
Saurav Das987441a2018-09-18 16:33:47 -070018import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
19import static org.slf4j.LoggerFactory.getLogger;
20
21import java.net.InetAddress;
kartikey dubeye1545422019-05-22 12:53:45 +000022import java.net.UnknownHostException;
Saurav Das987441a2018-09-18 16:33:47 -070023import java.nio.ByteBuffer;
24import java.util.Map;
kartikey dubeye1545422019-05-22 12:53:45 +000025import java.util.Dictionary;
26import java.util.HashSet;
Saurav Das987441a2018-09-18 16:33:47 -070027
Jonathan Hart932bedc2018-07-12 13:46:09 -070028import org.apache.commons.lang3.builder.ToStringBuilder;
Ari Saha89831742015-06-26 10:31:48 -070029import org.apache.felix.scr.annotations.Component;
30import org.apache.felix.scr.annotations.Deactivate;
kartikey dubeye1545422019-05-22 12:53:45 +000031import org.apache.felix.scr.annotations.Property;
Ari Saha89831742015-06-26 10:31:48 -070032import org.apache.felix.scr.annotations.Reference;
33import org.apache.felix.scr.annotations.ReferenceCardinality;
Jonathan Hart5db44532018-07-12 18:13:54 -070034import org.apache.felix.scr.annotations.Service;
Jonathan Hart4731dd92018-05-02 17:30:05 -070035import org.onlab.packet.DeserializationException;
Jonathan Harta46dddf2015-06-30 15:31:20 -070036import org.onlab.packet.EAP;
37import org.onlab.packet.EAPOL;
38import org.onlab.packet.EthType;
Ari Saha89831742015-06-26 10:31:48 -070039import org.onlab.packet.Ethernet;
Ari Saha89831742015-06-26 10:31:48 -070040import org.onlab.packet.MacAddress;
Jonathan Harta46dddf2015-06-30 15:31:20 -070041import org.onlab.packet.RADIUS;
42import org.onlab.packet.RADIUSAttribute;
kartikey dubeye1545422019-05-22 12:53:45 +000043import org.onlab.util.Tools;
44import org.onosproject.cfg.ComponentConfigService;
Ari Saha89831742015-06-26 10:31:48 -070045import org.onosproject.core.ApplicationId;
46import org.onosproject.core.CoreService;
Jonathan Hart5db44532018-07-12 18:13:54 -070047import org.onosproject.event.AbstractListenerManager;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010048import org.onosproject.mastership.MastershipService;
Ari Saha89831742015-06-26 10:31:48 -070049import org.onosproject.net.ConnectPoint;
50import org.onosproject.net.DeviceId;
Ari Saha89831742015-06-26 10:31:48 -070051import org.onosproject.net.PortNumber;
Ray Milkeyfcb623d2015-10-01 16:48:18 -070052import org.onosproject.net.config.ConfigFactory;
53import org.onosproject.net.config.NetworkConfigEvent;
54import org.onosproject.net.config.NetworkConfigListener;
55import org.onosproject.net.config.NetworkConfigRegistry;
Amit Ghoshf739be52017-09-21 15:49:37 +010056import org.onosproject.net.device.DeviceEvent;
57import org.onosproject.net.device.DeviceListener;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010058import org.onosproject.net.device.DeviceService;
Ari Saha89831742015-06-26 10:31:48 -070059import org.onosproject.net.flow.DefaultTrafficTreatment;
Ari Saha89831742015-06-26 10:31:48 -070060import org.onosproject.net.flow.TrafficTreatment;
Ari Saha89831742015-06-26 10:31:48 -070061import org.onosproject.net.packet.DefaultOutboundPacket;
62import org.onosproject.net.packet.InboundPacket;
63import org.onosproject.net.packet.OutboundPacket;
64import org.onosproject.net.packet.PacketContext;
Ari Saha89831742015-06-26 10:31:48 -070065import org.onosproject.net.packet.PacketProcessor;
66import org.onosproject.net.packet.PacketService;
Matteo Scandolocf847b82019-04-26 15:00:00 -070067import org.opencord.aaa.AaaConfig;
68import org.opencord.aaa.AuthenticationEvent;
69import org.opencord.aaa.AuthenticationEventListener;
70import org.opencord.aaa.AuthenticationService;
kartikey dubeye1545422019-05-22 12:53:45 +000071import org.opencord.aaa.AuthenticationStatisticsEvent;
72import org.opencord.aaa.AuthenticationStatisticsService;
Matteo Scandolocf847b82019-04-26 15:00:00 -070073import org.opencord.aaa.RadiusCommunicator;
74import org.opencord.aaa.StateMachineDelegate;
Gamze Abaka1cfdb192018-10-25 11:39:19 +000075import org.opencord.sadis.BaseInformationService;
76import org.opencord.sadis.SadisService;
77import org.opencord.sadis.SubscriberAndDeviceInformation;
kartikey dubeye1545422019-05-22 12:53:45 +000078import org.osgi.service.component.ComponentContext;
79import org.osgi.service.component.annotations.Modified;
Deepa Vaddireddye0e10722017-09-27 05:00:10 +053080import org.osgi.service.component.annotations.Activate;
Ari Saha89831742015-06-26 10:31:48 -070081import org.slf4j.Logger;
kartikey dubeye1545422019-05-22 12:53:45 +000082import com.google.common.base.Strings;
Ari Saha89831742015-06-26 10:31:48 -070083
kartikey dubeye1545422019-05-22 12:53:45 +000084import java.util.concurrent.Executors;
85import java.util.concurrent.ScheduledExecutorService;
86import java.util.concurrent.ScheduledFuture;
87import java.util.concurrent.TimeUnit;
Ari Saha89831742015-06-26 10:31:48 -070088/**
Jonathan Harta46dddf2015-06-30 15:31:20 -070089 * AAA application for ONOS.
Ari Saha89831742015-06-26 10:31:48 -070090 */
Jonathan Hart5db44532018-07-12 18:13:54 -070091@Service
Ari Saha89831742015-06-26 10:31:48 -070092@Component(immediate = true)
Jonathan Hart5db44532018-07-12 18:13:54 -070093public class AaaManager
94 extends AbstractListenerManager<AuthenticationEvent, AuthenticationEventListener>
95 implements AuthenticationService {
96
Charles Chandf7ff862017-01-20 11:22:05 -080097 private static final String APP_NAME = "org.opencord.aaa";
Ray Milkeyf51eba22015-09-25 10:24:23 -070098
Ray Milkeyf61a24e2015-09-24 16:34:02 -070099 private final Logger log = getLogger(getClass());
Ray Milkeyf51eba22015-09-25 10:24:23 -0700100
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700101 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
102 protected CoreService coreService;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700103
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700104 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
105 protected PacketService packetService;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700106
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700107 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700108 protected NetworkConfigRegistry netCfgService;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700109
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100110 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
111 protected DeviceService deviceService;
112
113 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Gamze Abaka1cfdb192018-10-25 11:39:19 +0000114 protected SadisService sadisService;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100115
116 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
117 protected MastershipService mastershipService;
118
kartikey dubeye1545422019-05-22 12:53:45 +0000119 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
120 protected AuthenticationStatisticsService aaaStatisticsManager;
Gamze Abaka1cfdb192018-10-25 11:39:19 +0000121
kartikey dubeye1545422019-05-22 12:53:45 +0000122 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
123 protected ComponentConfigService cfgService;
124
125 protected AuthenticationStatisticsEventPublisher authenticationStatisticsPublisher;
126 protected BaseInformationService<SubscriberAndDeviceInformation> subsService;
Amit Ghoshf739be52017-09-21 15:49:37 +0100127 private final DeviceListener deviceListener = new InternalDeviceListener();
128
kartikey dubeye1545422019-05-22 12:53:45 +0000129 private static final int DEFAULT_REPEAT_DELAY = 20;
130 @Property(name = "statisticsGenerationEvent", intValue = DEFAULT_REPEAT_DELAY,
131 label = "statisticsGenerationEvent")
132 private int statisticsGenerationEvent = DEFAULT_REPEAT_DELAY;
133
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700134 // NAS IP address
135 protected InetAddress nasIpAddress;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100136
137 // self MAC address
Jonathan Hart5db44532018-07-12 18:13:54 -0700138 protected String nasMacAddress;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100139
140 // Parsed RADIUS server addresses
141 protected InetAddress radiusIpAddress;
142
143 // MAC address of RADIUS server or net hop router
144 protected String radiusMacAddress;
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700145
146 // RADIUS server secret
147 protected String radiusSecret;
148
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100149 // bindings
150 protected CustomizationInfo customInfo;
Ray Milkey5d99bd12015-10-06 15:41:30 -0700151
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700152 // our application-specific event handler
153 private ReactivePacketProcessor processor = new ReactivePacketProcessor();
Ray Milkeyf51eba22015-09-25 10:24:23 -0700154
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700155 // our unique identifier
156 private ApplicationId appId;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700157
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100158 // Setup specific customization/attributes on the RADIUS packets
159 PacketCustomizer pktCustomizer;
Ray Milkey967776a2015-10-07 14:37:17 -0700160
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100161 // packet customizer to use
162 private String customizer;
163
164 // Type of connection to use to communicate with Radius server, options are
165 // "socket" or "packet_out"
166 private String radiusConnectionType;
167
Jonathan Hart5db44532018-07-12 18:13:54 -0700168 // Object for the specific type of communication with the RADIUS
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100169 // server, socket based or packet_out based
170 RadiusCommunicator impl = null;
171
172 // latest configuration
173 AaaConfig newCfg;
Ray Milkey967776a2015-10-07 14:37:17 -0700174
kartikey dubeye1545422019-05-22 12:53:45 +0000175 ScheduledFuture<?> scheduledFuture;
176
177 ScheduledExecutorService executor;
178 String configuredAaaServerAddress;
179 HashSet<Byte> outPacketSet = new HashSet<Byte>();
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700180 // Configuration properties factory
181 private final ConfigFactory factory =
Jonathan Hart092dfb22015-11-16 23:05:21 -0800182 new ConfigFactory<ApplicationId, AaaConfig>(APP_SUBJECT_FACTORY,
183 AaaConfig.class,
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700184 "AAA") {
185 @Override
Jonathan Hart092dfb22015-11-16 23:05:21 -0800186 public AaaConfig createConfig() {
187 return new AaaConfig();
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700188 }
189 };
Ray Milkeyf51eba22015-09-25 10:24:23 -0700190
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700191 // Listener for config changes
192 private final InternalConfigListener cfgListener = new InternalConfigListener();
Ari Saha89831742015-06-26 10:31:48 -0700193
Jonathan Hart5db44532018-07-12 18:13:54 -0700194 private StateMachineDelegate delegate = new InternalStateMachineDelegate();
195
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700196 /**
197 * Builds an EAPOL packet based on the given parameters.
198 *
199 * @param dstMac destination MAC address
200 * @param srcMac source MAC address
201 * @param vlan vlan identifier
202 * @param eapolType EAPOL type
203 * @param eap EAP payload
204 * @return Ethernet frame
205 */
206 private static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac,
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100207 short vlan, byte eapolType, EAP eap, byte priorityCode) {
Ari Saha89831742015-06-26 10:31:48 -0700208
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700209 Ethernet eth = new Ethernet();
210 eth.setDestinationMACAddress(dstMac.toBytes());
211 eth.setSourceMACAddress(srcMac.toBytes());
212 eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort());
213 if (vlan != Ethernet.VLAN_UNTAGGED) {
214 eth.setVlanID(vlan);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100215 eth.setPriorityCode(priorityCode);
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700216 }
217 //eapol header
218 EAPOL eapol = new EAPOL();
219 eapol.setEapolType(eapolType);
220 eapol.setPacketLength(eap.getLength());
Ari Saha89831742015-06-26 10:31:48 -0700221
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700222 //eap part
223 eapol.setPayload(eap);
224
225 eth.setPayload(eapol);
226 eth.setPad(true);
227 return eth;
228 }
Ari Saha89831742015-06-26 10:31:48 -0700229
Ari Saha89831742015-06-26 10:31:48 -0700230 @Activate
kartikey dubeye1545422019-05-22 12:53:45 +0000231 public void activate(ComponentContext context) {
Charles Chandf7ff862017-01-20 11:22:05 -0800232 appId = coreService.registerApplication(APP_NAME);
Jonathan Hart5db44532018-07-12 18:13:54 -0700233 eventDispatcher.addSink(AuthenticationEvent.class, listenerRegistry);
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400234 netCfgService.addListener(cfgListener);
235 netCfgService.registerConfigFactory(factory);
kartikey dubeye1545422019-05-22 12:53:45 +0000236 cfgService.registerProperties(getClass());
237 modified(context);
Gamze Abaka1cfdb192018-10-25 11:39:19 +0000238 subsService = sadisService.getSubscriberInfoService();
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530239 customInfo = new CustomizationInfo(subsService, deviceService);
Jonathan Hart092dfb22015-11-16 23:05:21 -0800240 cfgListener.reconfigureNetwork(netCfgService.getConfig(appId, AaaConfig.class));
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400241 log.info("Starting with config {} {}", this, newCfg);
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530242 configureRadiusCommunication();
Ari Saha89831742015-06-26 10:31:48 -0700243 // register our event handler
Brian O'Connord9c7da02015-07-29 17:49:24 -0700244 packetService.addProcessor(processor, PacketProcessor.director(2));
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700245 StateMachine.initializeMaps();
Jonathan Hart5db44532018-07-12 18:13:54 -0700246 StateMachine.setDelegate(delegate);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100247 impl.initializeLocalState(newCfg);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100248 impl.requestIntercepts();
Amit Ghoshf739be52017-09-21 15:49:37 +0100249 deviceService.addListener(deviceListener);
kartikey dubeye1545422019-05-22 12:53:45 +0000250 getConfiguredAaaServerAddress();
251 authenticationStatisticsPublisher =
252 new AuthenticationStatisticsEventPublisher();
253 executor = Executors.newScheduledThreadPool(1);
254 scheduledFuture = executor.scheduleAtFixedRate(authenticationStatisticsPublisher,
255 0, statisticsGenerationEvent, TimeUnit.SECONDS);
Amit Ghoshf739be52017-09-21 15:49:37 +0100256
Jian Li13c67162015-12-09 13:20:34 -0800257 log.info("Started");
Ari Saha89831742015-06-26 10:31:48 -0700258 }
259
260 @Deactivate
kartikey dubeye1545422019-05-22 12:53:45 +0000261 public void deactivate(ComponentContext context) {
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100262 impl.withdrawIntercepts();
Ari Saha89831742015-06-26 10:31:48 -0700263 packetService.removeProcessor(processor);
Deepa Vaddireddyb9c24c62017-09-21 13:45:30 +0530264 netCfgService.removeListener(cfgListener);
kartikey dubeye1545422019-05-22 12:53:45 +0000265 cfgService.unregisterProperties(getClass(), false);
Jonathan Hart5db44532018-07-12 18:13:54 -0700266 StateMachine.unsetDelegate(delegate);
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530267 StateMachine.destroyMaps();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100268 impl.deactivate();
Amit Ghoshf739be52017-09-21 15:49:37 +0100269 deviceService.removeListener(deviceListener);
Jonathan Hart5db44532018-07-12 18:13:54 -0700270 eventDispatcher.removeSink(AuthenticationEvent.class);
kartikey dubeye1545422019-05-22 12:53:45 +0000271 scheduledFuture.cancel(true);
272 executor.shutdown();
Jian Li13c67162015-12-09 13:20:34 -0800273 log.info("Stopped");
Ray Milkey967776a2015-10-07 14:37:17 -0700274 }
275
kartikey dubeye1545422019-05-22 12:53:45 +0000276 @Modified
277 public void modified(ComponentContext context) {
278 Dictionary<?, ?> properties = context.getProperties();
279 String s = Tools.get(properties, "statisticsGenerationEvent");
280 statisticsGenerationEvent = Strings.isNullOrEmpty(s) ? DEFAULT_REPEAT_DELAY : Integer.parseInt(s.trim());
281 }
282
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530283 private void configureRadiusCommunication() {
284 if (radiusConnectionType.toLowerCase().equals("socket")) {
285 impl = new SocketBasedRadiusCommunicator(appId, packetService, this);
286 } else {
287 impl = new PortBasedRadiusCommunicator(appId, packetService, mastershipService,
288 deviceService, subsService, pktCustomizer, this);
289 }
290 }
291
292 private void configurePacketCustomizer() {
293 switch (customizer.toLowerCase()) {
294 case "sample":
295 pktCustomizer = new SamplePacketCustomizer(customInfo);
296 log.info("Created SamplePacketCustomizer");
297 break;
Saurav Dase72358a2018-11-13 21:56:46 -0800298 case "att":
299 pktCustomizer = new AttPacketCustomizer(customInfo);
300 log.info("Created AttPacketCustomizer");
301 break;
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530302 default:
303 pktCustomizer = new PacketCustomizer(customInfo);
304 log.info("Created default PacketCustomizer");
305 break;
306 }
307 }
308
kartikey dubeye1545422019-05-22 12:53:45 +0000309 private void getConfiguredAaaServerAddress() {
310 try {
311 InetAddress address;
312 if (newCfg.radiusHostName() != null) {
313 address = InetAddress.getByName(newCfg.radiusHostName());
314 } else {
315 address = newCfg.radiusIp();
316 }
317
318 configuredAaaServerAddress = address.getHostAddress();
319 } catch (UnknownHostException uhe) {
320 log.warn("Unable to resolve host {}", newCfg.radiusHostName());
321 }
322 }
323
324 private void checkReceivedPacketForValidValidator(RADIUS radiusPacket) {
325 if (!radiusPacket.checkMessageAuthenticator(radiusSecret)) {
326 aaaStatisticsManager.getAaaStats().increaseInvalidValidatorsRx();
327 }
328 }
329 public void checkForPacketFromUnknownServer(String hostAddress) {
330 if (!hostAddress.equals(configuredAaaServerAddress)) {
331 aaaStatisticsManager.getAaaStats().incrementUnknownServerRx();
332 }
333 }
334
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100335 /**
336 * Send RADIUS packet to the RADIUS server.
337 *
338 * @param radiusPacket RADIUS packet to be sent to server.
339 * @param inPkt Incoming EAPOL packet
340 */
341 protected void sendRadiusPacket(RADIUS radiusPacket, InboundPacket inPkt) {
kartikey dubeye1545422019-05-22 12:53:45 +0000342 outPacketSet.add(radiusPacket.getIdentifier());
343 aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(true);
344 aaaStatisticsManager.getAaaStats().increaseAccessRequestsTx();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100345 impl.sendRadiusPacket(radiusPacket, inPkt);
346 }
Ray Milkey967776a2015-10-07 14:37:17 -0700347
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100348 /**
349 * Handles RADIUS packets.
350 *
351 * @param radiusPacket RADIUS packet coming from the RADIUS server.
352 * @throws StateMachineException if an illegal state transition is triggered
Jonathan Hart4731dd92018-05-02 17:30:05 -0700353 * @throws DeserializationException if packet deserialization fails
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100354 */
Jonathan Hart4731dd92018-05-02 17:30:05 -0700355 public void handleRadiusPacket(RADIUS radiusPacket)
356 throws StateMachineException, DeserializationException {
Saurav Das987441a2018-09-18 16:33:47 -0700357 if (log.isTraceEnabled()) {
358 log.trace("Received RADIUS packet {}", radiusPacket);
359 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100360 StateMachine stateMachine = StateMachine.lookupStateMachineById(radiusPacket.getIdentifier());
361 if (stateMachine == null) {
Saurav Das987441a2018-09-18 16:33:47 -0700362 log.error("Invalid packet identifier {}, could not find corresponding "
363 + "state machine ... exiting", radiusPacket.getIdentifier());
kartikey dubeye1545422019-05-22 12:53:45 +0000364 aaaStatisticsManager.getAaaStats().incrementNumberOfSessionsExpired();
365 aaaStatisticsManager.getAaaStats().countDroppedResponsesRx();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100366 return;
Ray Milkey967776a2015-10-07 14:37:17 -0700367 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100368 EAP eapPayload;
369 Ethernet eth;
kartikey dubeye1545422019-05-22 12:53:45 +0000370 checkReceivedPacketForValidValidator(radiusPacket);
371 if (outPacketSet.contains(radiusPacket.getIdentifier())) {
372 aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(false);
373 outPacketSet.remove(new Byte(radiusPacket.getIdentifier()));
374 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100375 switch (radiusPacket.getCode()) {
376 case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400377 log.debug("RADIUS packet: RADIUS_CODE_ACCESS_CHALLENGE");
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100378 RADIUSAttribute radiusAttrState = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE);
379 byte[] challengeState = null;
380 if (radiusAttrState != null) {
381 challengeState = radiusAttrState.getValue();
382 }
383 eapPayload = radiusPacket.decapsulateMessage();
384 stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState);
385 eth = buildEapolResponse(stateMachine.supplicantAddress(),
386 MacAddress.valueOf(nasMacAddress),
387 stateMachine.vlanId(),
388 EAPOL.EAPOL_PACKET,
389 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400390 log.debug("Send EAP challenge response to supplicant {}", stateMachine.supplicantAddress().toString());
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100391 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint());
kartikey dubeye1545422019-05-22 12:53:45 +0000392 aaaStatisticsManager.getAaaStats().increaseChallengeResponsesRx();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100393 break;
394 case RADIUS.RADIUS_CODE_ACCESS_ACCEPT:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400395 log.debug("RADIUS packet: RADIUS_CODE_ACCESS_ACCEPT");
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100396 //send an EAPOL - Success to the supplicant.
397 byte[] eapMessageSuccess =
398 radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue();
Jonathan Hart4731dd92018-05-02 17:30:05 -0700399 eapPayload = EAP.deserializer().deserialize(
400 eapMessageSuccess, 0, eapMessageSuccess.length);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100401 eth = buildEapolResponse(stateMachine.supplicantAddress(),
402 MacAddress.valueOf(nasMacAddress),
403 stateMachine.vlanId(),
404 EAPOL.EAPOL_PACKET,
405 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400406 log.info("Send EAP success message to supplicant {}", stateMachine.supplicantAddress().toString());
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100407 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint());
408
409 stateMachine.authorizeAccess();
kartikey dubeye1545422019-05-22 12:53:45 +0000410 aaaStatisticsManager.getAaaStats().increaseAcceptResponsesRx();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100411 break;
412 case RADIUS.RADIUS_CODE_ACCESS_REJECT:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400413 log.debug("RADIUS packet: RADIUS_CODE_ACCESS_REJECT");
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100414 //send an EAPOL - Failure to the supplicant.
415 byte[] eapMessageFailure;
416 eapPayload = new EAP();
417 RADIUSAttribute radiusAttrEap = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE);
418 if (radiusAttrEap == null) {
419 eapPayload.setCode(EAP.FAILURE);
420 eapPayload.setIdentifier(stateMachine.challengeIdentifier());
421 eapPayload.setLength(EAP.EAP_HDR_LEN_SUC_FAIL);
422 } else {
423 eapMessageFailure = radiusAttrEap.getValue();
Jonathan Hart4731dd92018-05-02 17:30:05 -0700424 eapPayload = EAP.deserializer().deserialize(
425 eapMessageFailure, 0, eapMessageFailure.length);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100426 }
427 eth = buildEapolResponse(stateMachine.supplicantAddress(),
428 MacAddress.valueOf(nasMacAddress),
429 stateMachine.vlanId(),
430 EAPOL.EAPOL_PACKET,
431 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400432 log.warn("Send EAP failure message to supplicant {}", stateMachine.supplicantAddress().toString());
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100433 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint());
434 stateMachine.denyAccess();
kartikey dubeye1545422019-05-22 12:53:45 +0000435 aaaStatisticsManager.getAaaStats().increaseRejectResponsesRx();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100436 break;
437 default:
438 log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode());
kartikey dubeye1545422019-05-22 12:53:45 +0000439 aaaStatisticsManager.getAaaStats().increaseUnknownTypeRx();
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100440 }
kartikey dubeye1545422019-05-22 12:53:45 +0000441 aaaStatisticsManager.getAaaStats().countDroppedResponsesRx();
Aaron Kruglikovd39d99e2015-07-03 13:30:57 -0700442 }
443
Ray Milkey967776a2015-10-07 14:37:17 -0700444 /**
445 * Send the ethernet packet to the supplicant.
446 *
447 * @param ethernetPkt the ethernet packet
448 * @param connectPoint the connect point to send out
449 */
450 private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint) {
451 TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
452 OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(),
453 treatment, ByteBuffer.wrap(ethernetPkt.serialize()));
Saurav Das987441a2018-09-18 16:33:47 -0700454 if (log.isTraceEnabled()) {
455 EAPOL eap = ((EAPOL) ethernetPkt.getPayload());
456 log.trace("Sending eapol payload {} enclosed in {} to supplicant at {}",
457 eap, ethernetPkt, connectPoint);
458 }
Ray Milkey967776a2015-10-07 14:37:17 -0700459 packetService.emit(packet);
460 }
461
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400462 @Override
463 public String toString() {
464 return ToStringBuilder.reflectionToString(this);
465 }
466
Ari Saha89831742015-06-26 10:31:48 -0700467 // our handler defined as a private inner class
468
469 /**
470 * Packet processor responsible for forwarding packets along their paths.
471 */
472 private class ReactivePacketProcessor implements PacketProcessor {
473 @Override
474 public void process(PacketContext context) {
475
476 // Extract the original Ethernet frame from the packet information
477 InboundPacket pkt = context.inPacket();
478 Ethernet ethPkt = pkt.parsed();
479 if (ethPkt == null) {
480 return;
481 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100482
Ray Milkeyf51eba22015-09-25 10:24:23 -0700483 try {
484 // identify if incoming packet comes from supplicant (EAP) or RADIUS
485 switch (EthType.EtherType.lookup(ethPkt.getEtherType())) {
486 case EAPOL:
487 handleSupplicantPacket(context.inPacket());
488 break;
Ray Milkeyf51eba22015-09-25 10:24:23 -0700489 default:
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100490 // any other packets let the specific implementation handle
491 impl.handlePacketFromServer(context);
Ray Milkeyf51eba22015-09-25 10:24:23 -0700492 }
Ray Milkey967776a2015-10-07 14:37:17 -0700493 } catch (StateMachineException e) {
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100494 log.warn("Unable to process packet:", e);
Ari Saha89831742015-06-26 10:31:48 -0700495 }
496 }
497
Ray Milkey9eb293f2015-09-30 15:09:17 -0700498 /**
499 * Creates and initializes common fields of a RADIUS packet.
500 *
Ray Milkey967776a2015-10-07 14:37:17 -0700501 * @param stateMachine state machine for the request
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700502 * @param eapPacket EAP packet
Ray Milkey9eb293f2015-09-30 15:09:17 -0700503 * @return RADIUS packet
504 */
Ray Milkey967776a2015-10-07 14:37:17 -0700505 private RADIUS getRadiusPayload(StateMachine stateMachine, byte identifier, EAP eapPacket) {
Ray Milkey9eb293f2015-09-30 15:09:17 -0700506 RADIUS radiusPayload =
507 new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST,
508 eapPacket.getIdentifier());
Ray Milkey967776a2015-10-07 14:37:17 -0700509
510 // set Request Authenticator in StateMachine
511 stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode());
512
Ray Milkey9eb293f2015-09-30 15:09:17 -0700513 radiusPayload.setIdentifier(identifier);
514 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME,
Ray Milkey967776a2015-10-07 14:37:17 -0700515 stateMachine.username());
Ray Milkey9eb293f2015-09-30 15:09:17 -0700516
517 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP,
Jonathan Hart092dfb22015-11-16 23:05:21 -0800518 AaaManager.this.nasIpAddress.getAddress());
Ray Milkey9eb293f2015-09-30 15:09:17 -0700519
520 radiusPayload.encapsulateMessage(eapPacket);
Ray Milkey9eb293f2015-09-30 15:09:17 -0700521
522 return radiusPayload;
523 }
Ari Saha89831742015-06-26 10:31:48 -0700524
525 /**
Jonathan Harta46dddf2015-06-30 15:31:20 -0700526 * Handles PAE packets (supplicant).
527 *
528 * @param inPacket Ethernet packet coming from the supplicant
Ari Saha89831742015-06-26 10:31:48 -0700529 */
Ray Milkeyf51eba22015-09-25 10:24:23 -0700530 private void handleSupplicantPacket(InboundPacket inPacket) throws StateMachineException {
Jonathan Harta46dddf2015-06-30 15:31:20 -0700531 Ethernet ethPkt = inPacket.parsed();
Ari Saha89831742015-06-26 10:31:48 -0700532 // Where does it come from?
Jonathan Hart092dfb22015-11-16 23:05:21 -0800533 MacAddress srcMac = ethPkt.getSourceMAC();
Ari Saha89831742015-06-26 10:31:48 -0700534
Jonathan Harta46dddf2015-06-30 15:31:20 -0700535 DeviceId deviceId = inPacket.receivedFrom().deviceId();
536 PortNumber portNumber = inPacket.receivedFrom().port();
Ari Saha89831742015-06-26 10:31:48 -0700537 String sessionId = deviceId.toString() + portNumber.toString();
Saurav Das987441a2018-09-18 16:33:47 -0700538 EAPOL eapol = (EAPOL) ethPkt.getPayload();
539 if (log.isTraceEnabled()) {
540 log.trace("Received EAPOL packet {} in enclosing packet {} from "
541 + "dev/port: {}/{}", eapol, ethPkt, deviceId,
542 portNumber);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100543 }
Jonathan Harta46dddf2015-06-30 15:31:20 -0700544
Saurav Das987441a2018-09-18 16:33:47 -0700545 StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(sessionId);
546 if (stateMachine == null) {
547 log.debug("Creating new state machine for sessionId: {} for "
548 + "dev/port: {}/{}", sessionId, deviceId, portNumber);
549 stateMachine = new StateMachine(sessionId);
550 } else {
551 log.debug("Using existing state-machine for sessionId: {}", sessionId);
552 }
553
Ari Saha89831742015-06-26 10:31:48 -0700554 switch (eapol.getEapolType()) {
555 case EAPOL.EAPOL_START:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400556 log.debug("EAP packet: EAPOL_START");
Ray Milkeyf51eba22015-09-25 10:24:23 -0700557 stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom());
Jonathan Hart5db44532018-07-12 18:13:54 -0700558 stateMachine.start();
Ari Saha89831742015-06-26 10:31:48 -0700559
Ray Milkeyf51eba22015-09-25 10:24:23 -0700560 //send an EAP Request/Identify to the supplicant
561 EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100562 if (ethPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) {
563 stateMachine.setPriorityCode(ethPkt.getPriorityCode());
564 }
Jonathan Hart092dfb22015-11-16 23:05:21 -0800565 Ethernet eth = buildEapolResponse(srcMac, MacAddress.valueOf(nasMacAddress),
Ray Milkeyf51eba22015-09-25 10:24:23 -0700566 ethPkt.getVlanID(), EAPOL.EAPOL_PACKET,
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100567 eapPayload, stateMachine.priorityCode());
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400568
Jonathan Hart092dfb22015-11-16 23:05:21 -0800569 stateMachine.setSupplicantAddress(srcMac);
Ray Milkeyf51eba22015-09-25 10:24:23 -0700570 stateMachine.setVlanId(ethPkt.getVlanID());
Ari Saha89831742015-06-26 10:31:48 -0700571
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400572 log.debug("Getting EAP identity from supplicant {}", stateMachine.supplicantAddress().toString());
Ray Milkey967776a2015-10-07 14:37:17 -0700573 sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint());
Ari Saha89831742015-06-26 10:31:48 -0700574
575 break;
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800576 case EAPOL.EAPOL_LOGOFF:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400577 log.debug("EAP packet: EAPOL_LOGOFF");
Ray Milkeyb34b4962016-01-04 10:24:43 -0800578 if (stateMachine.state() == StateMachine.STATE_AUTHORIZED) {
579 stateMachine.logoff();
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800580 }
581
582 break;
Ari Saha89831742015-06-26 10:31:48 -0700583 case EAPOL.EAPOL_PACKET:
Ray Milkeyf51eba22015-09-25 10:24:23 -0700584 RADIUS radiusPayload;
Ray Milkey9eb293f2015-09-30 15:09:17 -0700585 // check if this is a Response/Identify or a Response/TLS
Ari Saha89831742015-06-26 10:31:48 -0700586 EAP eapPacket = (EAP) eapol.getPayload();
587
588 byte dataType = eapPacket.getDataType();
589 switch (dataType) {
Ari Saha89831742015-06-26 10:31:48 -0700590
Ray Milkey9eb293f2015-09-30 15:09:17 -0700591 case EAP.ATTR_IDENTITY:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400592 log.debug("EAP packet: EAPOL_PACKET ATTR_IDENTITY");
Ray Milkey9eb293f2015-09-30 15:09:17 -0700593 // request id access to RADIUS
594 stateMachine.setUsername(eapPacket.getData());
Ari Saha89831742015-06-26 10:31:48 -0700595
Ray Milkey967776a2015-10-07 14:37:17 -0700596 radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100597 radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket);
Jonathan Hart092dfb22015-11-16 23:05:21 -0800598 radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret);
Ari Saha89831742015-06-26 10:31:48 -0700599
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100600 sendRadiusPacket(radiusPayload, inPacket);
Ray Milkeyf51eba22015-09-25 10:24:23 -0700601
Ray Milkey9eb293f2015-09-30 15:09:17 -0700602 // change the state to "PENDING"
kartikey dubeye1545422019-05-22 12:53:45 +0000603 if (stateMachine.state() == StateMachine.STATE_PENDING) {
604 aaaStatisticsManager.getAaaStats().increaseRequestReTx();
605 }
Ray Milkey9eb293f2015-09-30 15:09:17 -0700606 stateMachine.requestAccess();
607 break;
Ari Saha89831742015-06-26 10:31:48 -0700608 case EAP.ATTR_MD5:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400609 log.debug("EAP packet: EAPOL_PACKET ATTR_MD5");
Ray Milkey9eb293f2015-09-30 15:09:17 -0700610 // verify if the EAP identifier corresponds to the
611 // challenge identifier from the client state
612 // machine.
Ray Milkeyf61a24e2015-09-24 16:34:02 -0700613 if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) {
Ari Saha89831742015-06-26 10:31:48 -0700614 //send the RADIUS challenge response
Ray Milkey967776a2015-10-07 14:37:17 -0700615 radiusPayload =
616 getRadiusPayload(stateMachine,
617 stateMachine.identifier(),
618 eapPacket);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100619 radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket);
Ari Saha89831742015-06-26 10:31:48 -0700620
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800621 if (stateMachine.challengeState() != null) {
622 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
623 stateMachine.challengeState());
624 }
Jonathan Hart092dfb22015-11-16 23:05:21 -0800625 radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100626 sendRadiusPacket(radiusPayload, inPacket);
Ari Saha89831742015-06-26 10:31:48 -0700627 }
628 break;
629 case EAP.ATTR_TLS:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400630 log.debug("EAP packet: EAPOL_PACKET ATTR_TLS");
Ray Milkey9eb293f2015-09-30 15:09:17 -0700631 // request id access to RADIUS
Ray Milkey967776a2015-10-07 14:37:17 -0700632 radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100633 radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket);
Ari Saha89831742015-06-26 10:31:48 -0700634
Qianqian Hub55a1ac2015-12-23 20:44:48 +0800635 if (stateMachine.challengeState() != null) {
636 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
637 stateMachine.challengeState());
638 }
Ray Milkeyf51eba22015-09-25 10:24:23 -0700639 stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode());
Ari Saha89831742015-06-26 10:31:48 -0700640
Jonathan Hart092dfb22015-11-16 23:05:21 -0800641 radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100642 sendRadiusPacket(radiusPayload, inPacket);
Ray Milkey5493b512015-10-21 12:13:49 -0700643
Ray Milkeyf3790b82015-10-21 16:28:08 -0700644 if (stateMachine.state() != StateMachine.STATE_PENDING) {
645 stateMachine.requestAccess();
646 }
Ray Milkeyf51eba22015-09-25 10:24:23 -0700647
Ari Saha89831742015-06-26 10:31:48 -0700648 break;
649 default:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400650 log.warn("Unknown EAP packet type");
Ari Saha89831742015-06-26 10:31:48 -0700651 return;
652 }
653 break;
654 default:
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400655 log.debug("Skipping EAPOL message {}", eapol.getEapolType());
Ari Saha89831742015-06-26 10:31:48 -0700656 }
657 }
Ray Milkey967776a2015-10-07 14:37:17 -0700658 }
659
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100660 /**
Jonathan Hart5db44532018-07-12 18:13:54 -0700661 * Delegate allowing the StateMachine to notify us of events.
662 */
663 private class InternalStateMachineDelegate implements StateMachineDelegate {
664
665 @Override
666 public void notify(AuthenticationEvent authenticationEvent) {
667 log.info("Auth event {} for {}",
668 authenticationEvent.type(), authenticationEvent.subject());
669 post(authenticationEvent);
670 }
671 }
672
673 /**
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100674 * Configuration Listener, handles change in configuration.
675 */
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700676 private class InternalConfigListener implements NetworkConfigListener {
677
678 /**
Ray Milkeyc9e8dcc2015-12-30 10:31:32 -0800679 * Reconfigures the AAA application according to the
680 * configuration parameters passed.
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700681 *
682 * @param cfg configuration object
683 */
Jonathan Hart092dfb22015-11-16 23:05:21 -0800684 private void reconfigureNetwork(AaaConfig cfg) {
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400685 log.info("Reconfiguring AaaConfig from config: {}", cfg);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100686
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700687 if (cfg == null) {
Jonathan Hart092dfb22015-11-16 23:05:21 -0800688 newCfg = new AaaConfig();
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700689 } else {
690 newCfg = cfg;
691 }
692 if (newCfg.nasIp() != null) {
693 nasIpAddress = newCfg.nasIp();
694 }
695 if (newCfg.radiusIp() != null) {
696 radiusIpAddress = newCfg.radiusIp();
697 }
698 if (newCfg.radiusMac() != null) {
699 radiusMacAddress = newCfg.radiusMac();
700 }
701 if (newCfg.nasMac() != null) {
702 nasMacAddress = newCfg.nasMac();
703 }
704 if (newCfg.radiusSecret() != null) {
705 radiusSecret = newCfg.radiusSecret();
706 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100707
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530708 boolean reconfigureCustomizer = false;
709 if (customizer == null || !customizer.equals(newCfg.radiusPktCustomizer())) {
710 customizer = newCfg.radiusPktCustomizer();
711 configurePacketCustomizer();
712 reconfigureCustomizer = true;
713 }
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100714
Deepa Vaddireddye0e10722017-09-27 05:00:10 +0530715 if (radiusConnectionType == null
716 || reconfigureCustomizer
717 || !radiusConnectionType.equals(newCfg.radiusConnectionType())) {
718 radiusConnectionType = newCfg.radiusConnectionType();
719 if (impl != null) {
720 impl.withdrawIntercepts();
721 impl.clearLocalState();
722 }
723 configureRadiusCommunication();
724 impl.initializeLocalState(newCfg);
725 impl.requestIntercepts();
726 } else if (impl != null) {
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100727 impl.clearLocalState();
728 impl.initializeLocalState(newCfg);
Ray Milkey5d99bd12015-10-06 15:41:30 -0700729 }
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700730 }
731
732 @Override
733 public void event(NetworkConfigEvent event) {
734
735 if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
736 event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) &&
Jonathan Hart092dfb22015-11-16 23:05:21 -0800737 event.configClass().equals(AaaConfig.class)) {
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700738
Jonathan Hart092dfb22015-11-16 23:05:21 -0800739 AaaConfig cfg = netCfgService.getConfig(appId, AaaConfig.class);
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700740 reconfigureNetwork(cfg);
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100741
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400742 log.info("Reconfigured: {}", cfg.toString());
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700743 }
744 }
745 }
Amit Ghoshf739be52017-09-21 15:49:37 +0100746
747 private class InternalDeviceListener implements DeviceListener {
748 @Override
749 public void event(DeviceEvent event) {
750
751 switch (event.type()) {
752 case PORT_REMOVED:
753 DeviceId devId = event.subject().id();
754 PortNumber portNumber = event.port().number();
755 String sessionId = devId.toString() + portNumber.toString();
756
757 Map<String, StateMachine> sessionIdMap = StateMachine.sessionIdMap();
758 StateMachine removed = sessionIdMap.remove(sessionId);
759 if (removed != null) {
760 StateMachine.deleteStateMachineMapping(removed);
761 }
762
763 break;
764 default:
765 return;
766 }
767 }
768 }
kartikey dubeye1545422019-05-22 12:53:45 +0000769 private class AuthenticationStatisticsEventPublisher implements Runnable {
770 private final Logger log = getLogger(getClass());
771 public void run() {
772 log.info("Notifying AuthenticationStatisticsEvent");
773 aaaStatisticsManager.calculatePacketRoundtripTime();
774 log.debug("AcceptResponsesRx---" + aaaStatisticsManager.getAaaStats().getAcceptResponsesRx());
775 log.debug("AccessRequestsTx---" + aaaStatisticsManager.getAaaStats().getAccessRequestsTx());
776 log.debug("ChallengeResponsesRx---" + aaaStatisticsManager.getAaaStats().getChallengeResponsesRx());
777 log.debug("DroppedResponsesRx---" + aaaStatisticsManager.getAaaStats().getDroppedResponsesRx());
778 log.debug("InvalidValidatorsRx---" + aaaStatisticsManager.getAaaStats().getInvalidValidatorsRx());
779 log.debug("MalformedResponsesRx---" + aaaStatisticsManager.getAaaStats().getMalformedResponsesRx());
780 log.debug("PendingRequests---" + aaaStatisticsManager.getAaaStats().getPendingRequests());
781 log.debug("RejectResponsesRx---" + aaaStatisticsManager.getAaaStats().getRejectResponsesRx());
782 log.debug("RequestReTx---" + aaaStatisticsManager.getAaaStats().getRequestReTx());
783 log.debug("RequestRttMilis---" + aaaStatisticsManager.getAaaStats().getRequestRttMilis());
784 log.debug("UnknownServerRx---" + aaaStatisticsManager.getAaaStats().getUnknownServerRx());
785 log.debug("UnknownTypeRx---" + aaaStatisticsManager.getAaaStats().getUnknownTypeRx());
786 aaaStatisticsManager.getStatsDelegate().
787 notify(new AuthenticationStatisticsEvent(AuthenticationStatisticsEvent.Type.STATS_UPDATE,
788 aaaStatisticsManager.getAaaStats()));
789 }
790 }
Ari Saha89831742015-06-26 10:31:48 -0700791}