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 | */ |
alshabib | 6d52745 | 2016-06-01 18:00:47 -0700 | [diff] [blame] | 16 | package org.opencord.aaa; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 17 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Reference; |
| 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 23 | |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 24 | import org.onlab.packet.EAP; |
| 25 | import org.onlab.packet.EAPOL; |
| 26 | import org.onlab.packet.EthType; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 27 | import org.onlab.packet.Ethernet; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 28 | import org.onlab.packet.MacAddress; |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 29 | import org.onlab.packet.RADIUS; |
| 30 | import org.onlab.packet.RADIUSAttribute; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 31 | import org.onlab.packet.VlanId; |
| 32 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 33 | import org.onosproject.core.ApplicationId; |
| 34 | import org.onosproject.core.CoreService; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 35 | import org.onosproject.mastership.MastershipService; |
| 36 | import org.onosproject.net.AnnotationKeys; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 37 | import org.onosproject.net.ConnectPoint; |
| 38 | import org.onosproject.net.DeviceId; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 39 | import org.onosproject.net.PortNumber; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 40 | import org.onosproject.net.config.ConfigFactory; |
| 41 | import org.onosproject.net.config.NetworkConfigEvent; |
| 42 | import org.onosproject.net.config.NetworkConfigListener; |
| 43 | import org.onosproject.net.config.NetworkConfigRegistry; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame^] | 44 | import org.onosproject.net.device.DeviceEvent; |
| 45 | import org.onosproject.net.device.DeviceListener; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 46 | import org.onosproject.net.device.DeviceService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 47 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 48 | import org.onosproject.net.flow.TrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 49 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 50 | import org.onosproject.net.packet.InboundPacket; |
| 51 | import org.onosproject.net.packet.OutboundPacket; |
| 52 | import org.onosproject.net.packet.PacketContext; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 53 | import org.onosproject.net.packet.PacketProcessor; |
| 54 | import org.onosproject.net.packet.PacketService; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 55 | |
| 56 | import org.opencord.olt.AccessDeviceService; |
| 57 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 58 | import org.opencord.sadis.SubscriberAndDeviceInformationService; |
| 59 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 60 | import org.slf4j.Logger; |
| 61 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 62 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 63 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 64 | import static org.slf4j.LoggerFactory.getLogger; |
| 65 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 66 | import java.net.InetAddress; |
| 67 | import java.nio.ByteBuffer; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame^] | 68 | import java.util.Map; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 69 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 70 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 71 | * AAA application for ONOS. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 72 | */ |
| 73 | @Component(immediate = true) |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 74 | public class AaaManager { |
Charles Chan | df7ff86 | 2017-01-20 11:22:05 -0800 | [diff] [blame] | 75 | private static final String APP_NAME = "org.opencord.aaa"; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 76 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 77 | // for verbose output |
| 78 | private final Logger log = getLogger(getClass()); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 79 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 80 | // a list of our dependencies : |
| 81 | // to register with ONOS as an application - described next |
| 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 83 | protected CoreService coreService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 84 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 85 | // to receive Packet-in events that we'll respond to |
| 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 87 | protected PacketService packetService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 88 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 89 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 90 | protected NetworkConfigRegistry netCfgService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 91 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 93 | protected DeviceService deviceService; |
| 94 | |
| 95 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 96 | protected SubscriberAndDeviceInformationService subsService; |
| 97 | |
| 98 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 99 | protected MastershipService mastershipService; |
| 100 | |
| 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 102 | protected AccessDeviceService accessDeviceService; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 103 | |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame^] | 104 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 105 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 106 | // NAS IP address |
| 107 | protected InetAddress nasIpAddress; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 108 | |
| 109 | // self MAC address |
| 110 | protected static String nasMacAddress; |
| 111 | |
| 112 | // Parsed RADIUS server addresses |
| 113 | protected InetAddress radiusIpAddress; |
| 114 | |
| 115 | // MAC address of RADIUS server or net hop router |
| 116 | protected String radiusMacAddress; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 117 | |
| 118 | // RADIUS server secret |
| 119 | protected String radiusSecret; |
| 120 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 121 | // NAS Identifier |
| 122 | protected String nasId; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 123 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 124 | // bindings |
| 125 | protected CustomizationInfo customInfo; |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 126 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 127 | // our application-specific event handler |
| 128 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 129 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 130 | // our unique identifier |
| 131 | private ApplicationId appId; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 132 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 133 | // Setup specific customization/attributes on the RADIUS packets |
| 134 | PacketCustomizer pktCustomizer; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 135 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 136 | // packet customizer to use |
| 137 | private String customizer; |
| 138 | |
| 139 | // Type of connection to use to communicate with Radius server, options are |
| 140 | // "socket" or "packet_out" |
| 141 | private String radiusConnectionType; |
| 142 | |
| 143 | // Object for the spcific type of communication with the RADIUS |
| 144 | // server, socket based or packet_out based |
| 145 | RadiusCommunicator impl = null; |
| 146 | |
| 147 | // latest configuration |
| 148 | AaaConfig newCfg; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 149 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 150 | // Configuration properties factory |
| 151 | private final ConfigFactory factory = |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 152 | new ConfigFactory<ApplicationId, AaaConfig>(APP_SUBJECT_FACTORY, |
| 153 | AaaConfig.class, |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 154 | "AAA") { |
| 155 | @Override |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 156 | public AaaConfig createConfig() { |
| 157 | return new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 158 | } |
| 159 | }; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 160 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 161 | // Listener for config changes |
| 162 | private final InternalConfigListener cfgListener = new InternalConfigListener(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 163 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 164 | /** |
| 165 | * Builds an EAPOL packet based on the given parameters. |
| 166 | * |
| 167 | * @param dstMac destination MAC address |
| 168 | * @param srcMac source MAC address |
| 169 | * @param vlan vlan identifier |
| 170 | * @param eapolType EAPOL type |
| 171 | * @param eap EAP payload |
| 172 | * @return Ethernet frame |
| 173 | */ |
| 174 | private static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac, |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 175 | short vlan, byte eapolType, EAP eap, byte priorityCode) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 176 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 177 | Ethernet eth = new Ethernet(); |
| 178 | eth.setDestinationMACAddress(dstMac.toBytes()); |
| 179 | eth.setSourceMACAddress(srcMac.toBytes()); |
| 180 | eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); |
| 181 | if (vlan != Ethernet.VLAN_UNTAGGED) { |
| 182 | eth.setVlanID(vlan); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 183 | eth.setPriorityCode(priorityCode); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 184 | } |
| 185 | //eapol header |
| 186 | EAPOL eapol = new EAPOL(); |
| 187 | eapol.setEapolType(eapolType); |
| 188 | eapol.setPacketLength(eap.getLength()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 189 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 190 | //eap part |
| 191 | eapol.setPayload(eap); |
| 192 | |
| 193 | eth.setPayload(eapol); |
| 194 | eth.setPad(true); |
| 195 | return eth; |
| 196 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 197 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 198 | @Activate |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 199 | public void activate() { |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 200 | netCfgService.registerConfigFactory(factory); |
Charles Chan | df7ff86 | 2017-01-20 11:22:05 -0800 | [diff] [blame] | 201 | appId = coreService.registerApplication(APP_NAME); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 202 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 203 | cfgListener.reconfigureNetwork(netCfgService.getConfig(appId, AaaConfig.class)); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 204 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 205 | // register our event handler |
Brian O'Connor | d9c7da0 | 2015-07-29 17:49:24 -0700 | [diff] [blame] | 206 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 207 | |
| 208 | customInfo = new CustomizationInfo(subsService, deviceService); |
| 209 | |
| 210 | switch (customizer.toLowerCase()) { |
| 211 | case "sample": |
| 212 | pktCustomizer = new SamplePacketCustomizer(customInfo); |
| 213 | log.info("Created SamplePacketCustomizer"); |
| 214 | break; |
| 215 | default: |
| 216 | pktCustomizer = new PacketCustomizer(customInfo); |
| 217 | log.info("Created default PacketCustomizer"); |
| 218 | break; |
| 219 | } |
| 220 | |
| 221 | if (radiusConnectionType.toLowerCase().equals("socket")) { |
| 222 | impl = new SocketBasedRadiusCommunicator(appId, packetService, this); |
| 223 | } else { |
| 224 | impl = new PortBasedRadiusCommunicator(appId, packetService, mastershipService, |
| 225 | deviceService, subsService, pktCustomizer, this); |
| 226 | } |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 227 | |
| 228 | StateMachine.initializeMaps(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 229 | StateMachine.setAccessDeviceService(accessDeviceService); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 230 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 231 | impl.initializeLocalState(newCfg); |
alshabib | 27afc1d | 2016-12-23 00:33:58 -0800 | [diff] [blame] | 232 | netCfgService.addListener(cfgListener); |
| 233 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 234 | impl.requestIntercepts(); |
| 235 | |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame^] | 236 | deviceService.addListener(deviceListener); |
| 237 | |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 238 | log.info("Started"); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | @Deactivate |
| 242 | public void deactivate() { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 243 | impl.withdrawIntercepts(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 244 | // de-register and null our handler |
| 245 | packetService.removeProcessor(processor); |
| 246 | processor = null; |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 247 | StateMachine.destroyMaps(); |
Deepa Vaddireddy | b9c24c6 | 2017-09-21 13:45:30 +0530 | [diff] [blame] | 248 | netCfgService.removeListener(cfgListener); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 249 | impl.deactivate(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame^] | 250 | deviceService.removeListener(deviceListener); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 251 | |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 252 | log.info("Stopped"); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 255 | /** |
| 256 | * Send RADIUS packet to the RADIUS server. |
| 257 | * |
| 258 | * @param radiusPacket RADIUS packet to be sent to server. |
| 259 | * @param inPkt Incoming EAPOL packet |
| 260 | */ |
| 261 | protected void sendRadiusPacket(RADIUS radiusPacket, InboundPacket inPkt) { |
| 262 | impl.sendRadiusPacket(radiusPacket, inPkt); |
| 263 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 264 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 265 | /** |
| 266 | * Handles RADIUS packets. |
| 267 | * |
| 268 | * @param radiusPacket RADIUS packet coming from the RADIUS server. |
| 269 | * @throws StateMachineException if an illegal state transition is triggered |
| 270 | */ |
| 271 | public void handleRadiusPacket(RADIUS radiusPacket) throws StateMachineException { |
| 272 | StateMachine stateMachine = StateMachine.lookupStateMachineById(radiusPacket.getIdentifier()); |
| 273 | if (stateMachine == null) { |
| 274 | log.error("Invalid session identifier {}, exiting...", radiusPacket.getIdentifier()); |
| 275 | return; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 276 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 277 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 278 | EAP eapPayload; |
| 279 | Ethernet eth; |
Aaron Kruglikov | d39d99e | 2015-07-03 13:30:57 -0700 | [diff] [blame] | 280 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 281 | switch (radiusPacket.getCode()) { |
| 282 | case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE: |
| 283 | RADIUSAttribute radiusAttrState = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE); |
| 284 | byte[] challengeState = null; |
| 285 | if (radiusAttrState != null) { |
| 286 | challengeState = radiusAttrState.getValue(); |
| 287 | } |
| 288 | eapPayload = radiusPacket.decapsulateMessage(); |
| 289 | stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState); |
| 290 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 291 | MacAddress.valueOf(nasMacAddress), |
| 292 | stateMachine.vlanId(), |
| 293 | EAPOL.EAPOL_PACKET, |
| 294 | eapPayload, stateMachine.priorityCode()); |
| 295 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); |
| 296 | break; |
| 297 | case RADIUS.RADIUS_CODE_ACCESS_ACCEPT: |
| 298 | //send an EAPOL - Success to the supplicant. |
| 299 | byte[] eapMessageSuccess = |
| 300 | radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue(); |
| 301 | eapPayload = new EAP(); |
| 302 | eapPayload = (EAP) eapPayload.deserialize(eapMessageSuccess, 0, eapMessageSuccess.length); |
| 303 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 304 | MacAddress.valueOf(nasMacAddress), |
| 305 | stateMachine.vlanId(), |
| 306 | EAPOL.EAPOL_PACKET, |
| 307 | eapPayload, stateMachine.priorityCode()); |
| 308 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); |
| 309 | |
| 310 | stateMachine.authorizeAccess(); |
| 311 | |
| 312 | break; |
| 313 | case RADIUS.RADIUS_CODE_ACCESS_REJECT: |
| 314 | //send an EAPOL - Failure to the supplicant. |
| 315 | byte[] eapMessageFailure; |
| 316 | eapPayload = new EAP(); |
| 317 | RADIUSAttribute radiusAttrEap = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE); |
| 318 | if (radiusAttrEap == null) { |
| 319 | eapPayload.setCode(EAP.FAILURE); |
| 320 | eapPayload.setIdentifier(stateMachine.challengeIdentifier()); |
| 321 | eapPayload.setLength(EAP.EAP_HDR_LEN_SUC_FAIL); |
| 322 | } else { |
| 323 | eapMessageFailure = radiusAttrEap.getValue(); |
| 324 | eapPayload = (EAP) eapPayload.deserialize(eapMessageFailure, 0, eapMessageFailure.length); |
| 325 | } |
| 326 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 327 | MacAddress.valueOf(nasMacAddress), |
| 328 | stateMachine.vlanId(), |
| 329 | EAPOL.EAPOL_PACKET, |
| 330 | eapPayload, stateMachine.priorityCode()); |
| 331 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); |
| 332 | stateMachine.denyAccess(); |
| 333 | |
| 334 | break; |
| 335 | default: |
| 336 | log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode()); |
| 337 | } |
Aaron Kruglikov | d39d99e | 2015-07-03 13:30:57 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 340 | /** |
| 341 | * Send the ethernet packet to the supplicant. |
| 342 | * |
| 343 | * @param ethernetPkt the ethernet packet |
| 344 | * @param connectPoint the connect point to send out |
| 345 | */ |
| 346 | private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint) { |
| 347 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build(); |
| 348 | OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(), |
| 349 | treatment, ByteBuffer.wrap(ethernetPkt.serialize())); |
| 350 | packetService.emit(packet); |
| 351 | } |
| 352 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 353 | // our handler defined as a private inner class |
| 354 | |
| 355 | /** |
| 356 | * Packet processor responsible for forwarding packets along their paths. |
| 357 | */ |
| 358 | private class ReactivePacketProcessor implements PacketProcessor { |
| 359 | @Override |
| 360 | public void process(PacketContext context) { |
| 361 | |
| 362 | // Extract the original Ethernet frame from the packet information |
| 363 | InboundPacket pkt = context.inPacket(); |
| 364 | Ethernet ethPkt = pkt.parsed(); |
| 365 | if (ethPkt == null) { |
| 366 | return; |
| 367 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 368 | |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 369 | try { |
| 370 | // identify if incoming packet comes from supplicant (EAP) or RADIUS |
| 371 | switch (EthType.EtherType.lookup(ethPkt.getEtherType())) { |
| 372 | case EAPOL: |
| 373 | handleSupplicantPacket(context.inPacket()); |
| 374 | break; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 375 | default: |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 376 | // any other packets let the specific implementation handle |
| 377 | impl.handlePacketFromServer(context); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 378 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 379 | } catch (StateMachineException e) { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 380 | log.warn("Unable to process packet:", e); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 384 | /** |
| 385 | * Creates and initializes common fields of a RADIUS packet. |
| 386 | * |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 387 | * @param stateMachine state machine for the request |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 388 | * @param eapPacket EAP packet |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 389 | * @return RADIUS packet |
| 390 | */ |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 391 | private RADIUS getRadiusPayload(StateMachine stateMachine, byte identifier, EAP eapPacket) { |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 392 | RADIUS radiusPayload = |
| 393 | new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, |
| 394 | eapPacket.getIdentifier()); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 395 | |
| 396 | // set Request Authenticator in StateMachine |
| 397 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
| 398 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 399 | radiusPayload.setIdentifier(identifier); |
| 400 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 401 | stateMachine.username()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 402 | |
| 403 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 404 | AaaManager.this.nasIpAddress.getAddress()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 405 | |
| 406 | radiusPayload.encapsulateMessage(eapPacket); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 407 | |
| 408 | return radiusPayload; |
| 409 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 410 | |
| 411 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 412 | * Handles PAE packets (supplicant). |
| 413 | * |
| 414 | * @param inPacket Ethernet packet coming from the supplicant |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 415 | */ |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 416 | private void handleSupplicantPacket(InboundPacket inPacket) throws StateMachineException { |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 417 | Ethernet ethPkt = inPacket.parsed(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 418 | // Where does it come from? |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 419 | MacAddress srcMac = ethPkt.getSourceMAC(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 420 | |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 421 | DeviceId deviceId = inPacket.receivedFrom().deviceId(); |
| 422 | PortNumber portNumber = inPacket.receivedFrom().port(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 423 | String sessionId = deviceId.toString() + portNumber.toString(); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 424 | StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(sessionId); |
| 425 | if (stateMachine == null) { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 426 | if (deviceService != null) { |
| 427 | String nasPortId = deviceService.getPort(inPacket.receivedFrom()). |
| 428 | annotations().value(AnnotationKeys.PORT_NAME); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 429 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 430 | SubscriberAndDeviceInformation subscriber = |
| 431 | subsService.get(nasPortId); |
| 432 | if (subscriber != null) { |
| 433 | stateMachine = new StateMachine(sessionId, subscriber.cTag()); |
Amit Ghosh | cf39d97 | 2017-08-16 08:15:20 +0100 | [diff] [blame] | 434 | } else { |
| 435 | log.error("Could not create new state machine for {}", nasPortId); |
| 436 | return; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 437 | } |
| 438 | } else { |
| 439 | stateMachine = new StateMachine(sessionId, VlanId.vlanId((short) 0)); |
| 440 | } |
| 441 | } |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 442 | |
| 443 | EAPOL eapol = (EAPOL) ethPkt.getPayload(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 444 | |
| 445 | switch (eapol.getEapolType()) { |
| 446 | case EAPOL.EAPOL_START: |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 447 | stateMachine.start(); |
| 448 | stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 449 | |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 450 | //send an EAP Request/Identify to the supplicant |
| 451 | EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 452 | if (ethPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) { |
| 453 | stateMachine.setPriorityCode(ethPkt.getPriorityCode()); |
| 454 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 455 | Ethernet eth = buildEapolResponse(srcMac, MacAddress.valueOf(nasMacAddress), |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 456 | ethPkt.getVlanID(), EAPOL.EAPOL_PACKET, |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 457 | eapPayload, stateMachine.priorityCode()); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 458 | stateMachine.setSupplicantAddress(srcMac); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 459 | stateMachine.setVlanId(ethPkt.getVlanID()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 460 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 461 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 462 | |
| 463 | break; |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 464 | case EAPOL.EAPOL_LOGOFF: |
Ray Milkey | b34b496 | 2016-01-04 10:24:43 -0800 | [diff] [blame] | 465 | if (stateMachine.state() == StateMachine.STATE_AUTHORIZED) { |
| 466 | stateMachine.logoff(); |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 470 | case EAPOL.EAPOL_PACKET: |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 471 | RADIUS radiusPayload; |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 472 | // check if this is a Response/Identify or a Response/TLS |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 473 | EAP eapPacket = (EAP) eapol.getPayload(); |
| 474 | |
| 475 | byte dataType = eapPacket.getDataType(); |
| 476 | switch (dataType) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 477 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 478 | case EAP.ATTR_IDENTITY: |
| 479 | // request id access to RADIUS |
| 480 | stateMachine.setUsername(eapPacket.getData()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 481 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 482 | radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 483 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 484 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 485 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 486 | sendRadiusPacket(radiusPayload, inPacket); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 487 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 488 | // change the state to "PENDING" |
| 489 | stateMachine.requestAccess(); |
| 490 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 491 | case EAP.ATTR_MD5: |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 492 | // verify if the EAP identifier corresponds to the |
| 493 | // challenge identifier from the client state |
| 494 | // machine. |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 495 | if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 496 | //send the RADIUS challenge response |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 497 | radiusPayload = |
| 498 | getRadiusPayload(stateMachine, |
| 499 | stateMachine.identifier(), |
| 500 | eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 501 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 502 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 503 | if (stateMachine.challengeState() != null) { |
| 504 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 505 | stateMachine.challengeState()); |
| 506 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 507 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 508 | sendRadiusPacket(radiusPayload, inPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 509 | } |
| 510 | break; |
| 511 | case EAP.ATTR_TLS: |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 512 | // request id access to RADIUS |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 513 | radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 514 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 515 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 516 | if (stateMachine.challengeState() != null) { |
| 517 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 518 | stateMachine.challengeState()); |
| 519 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 520 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 521 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 522 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 523 | sendRadiusPacket(radiusPayload, inPacket); |
Ray Milkey | 5493b51 | 2015-10-21 12:13:49 -0700 | [diff] [blame] | 524 | |
Ray Milkey | f3790b8 | 2015-10-21 16:28:08 -0700 | [diff] [blame] | 525 | if (stateMachine.state() != StateMachine.STATE_PENDING) { |
| 526 | stateMachine.requestAccess(); |
| 527 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 528 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 529 | break; |
| 530 | default: |
| 531 | return; |
| 532 | } |
| 533 | break; |
| 534 | default: |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 535 | log.trace("Skipping EAPOL message {}", eapol.getEapolType()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 536 | } |
| 537 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 540 | /** |
| 541 | * Configuration Listener, handles change in configuration. |
| 542 | */ |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 543 | private class InternalConfigListener implements NetworkConfigListener { |
| 544 | |
| 545 | /** |
Ray Milkey | c9e8dcc | 2015-12-30 10:31:32 -0800 | [diff] [blame] | 546 | * Reconfigures the AAA application according to the |
| 547 | * configuration parameters passed. |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 548 | * |
| 549 | * @param cfg configuration object |
| 550 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 551 | private void reconfigureNetwork(AaaConfig cfg) { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 552 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 553 | if (cfg == null) { |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 554 | newCfg = new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 555 | } else { |
| 556 | newCfg = cfg; |
| 557 | } |
| 558 | if (newCfg.nasIp() != null) { |
| 559 | nasIpAddress = newCfg.nasIp(); |
| 560 | } |
| 561 | if (newCfg.radiusIp() != null) { |
| 562 | radiusIpAddress = newCfg.radiusIp(); |
| 563 | } |
| 564 | if (newCfg.radiusMac() != null) { |
| 565 | radiusMacAddress = newCfg.radiusMac(); |
| 566 | } |
| 567 | if (newCfg.nasMac() != null) { |
| 568 | nasMacAddress = newCfg.nasMac(); |
| 569 | } |
| 570 | if (newCfg.radiusSecret() != null) { |
| 571 | radiusSecret = newCfg.radiusSecret(); |
| 572 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 573 | |
| 574 | radiusConnectionType = newCfg.radiusConnectionType(); |
| 575 | customizer = newCfg.radiusPktCustomizer(); |
| 576 | |
| 577 | if (impl != null) { |
| 578 | impl.clearLocalState(); |
| 579 | impl.initializeLocalState(newCfg); |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 580 | } |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | @Override |
| 584 | public void event(NetworkConfigEvent event) { |
| 585 | |
| 586 | if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || |
| 587 | event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) && |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 588 | event.configClass().equals(AaaConfig.class)) { |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 589 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 590 | AaaConfig cfg = netCfgService.getConfig(appId, AaaConfig.class); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 591 | reconfigureNetwork(cfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 592 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 593 | log.info("Reconfigured"); |
| 594 | } |
| 595 | } |
| 596 | } |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame^] | 597 | |
| 598 | private class InternalDeviceListener implements DeviceListener { |
| 599 | @Override |
| 600 | public void event(DeviceEvent event) { |
| 601 | |
| 602 | switch (event.type()) { |
| 603 | case PORT_REMOVED: |
| 604 | DeviceId devId = event.subject().id(); |
| 605 | PortNumber portNumber = event.port().number(); |
| 606 | String sessionId = devId.toString() + portNumber.toString(); |
| 607 | |
| 608 | Map<String, StateMachine> sessionIdMap = StateMachine.sessionIdMap(); |
| 609 | StateMachine removed = sessionIdMap.remove(sessionId); |
| 610 | if (removed != null) { |
| 611 | StateMachine.deleteStateMachineMapping(removed); |
| 612 | } |
| 613 | |
| 614 | break; |
| 615 | default: |
| 616 | return; |
| 617 | } |
| 618 | } |
| 619 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 620 | } |