Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 4e33be2 | 2017-08-03 22:45:46 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -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; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 17 | |
pier | 99c6d1d | 2020-02-13 14:39:55 +0100 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 19 | import org.onlab.packet.BasePacket; |
| 20 | import org.onlab.packet.EAP; |
| 21 | import org.onlab.packet.EAPOL; |
| 22 | import org.onlab.packet.EthType; |
| 23 | import org.onlab.packet.Ethernet; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 24 | import org.onlab.packet.Ip4Address; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 25 | import org.onlab.packet.MacAddress; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 26 | import org.onlab.packet.VlanId; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 27 | import org.onosproject.cfg.ComponentConfigService; |
| 28 | import org.onosproject.cfg.ConfigProperty; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 29 | import org.onosproject.net.Annotations; |
| 30 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 31 | import org.onosproject.net.ConnectPoint; |
Sonal Kasliwal | 7eef29f | 2020-02-12 12:23:22 +0000 | [diff] [blame] | 32 | import org.onosproject.net.DeviceId; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 33 | import org.onosproject.net.Element; |
| 34 | import org.onosproject.net.Port; |
| 35 | import org.onosproject.net.PortNumber; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 36 | import org.onosproject.net.packet.DefaultInboundPacket; |
| 37 | import org.onosproject.net.packet.DefaultPacketContext; |
| 38 | import org.onosproject.net.packet.InboundPacket; |
| 39 | import org.onosproject.net.packet.OutboundPacket; |
| 40 | import org.onosproject.net.packet.PacketContext; |
| 41 | import org.onosproject.net.packet.PacketProcessor; |
| 42 | import org.onosproject.net.packet.PacketServiceAdapter; |
| 43 | |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 44 | import org.opencord.sadis.BandwidthProfileInformation; |
| 45 | import org.opencord.sadis.BaseInformationService; |
| 46 | import org.opencord.sadis.SadisService; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 47 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
pier | 99c6d1d | 2020-02-13 14:39:55 +0100 | [diff] [blame] | 48 | import org.opencord.sadis.UniTagInformation; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 49 | import org.osgi.framework.Bundle; |
| 50 | import org.osgi.framework.BundleContext; |
| 51 | import org.osgi.framework.ServiceReference; |
| 52 | import org.osgi.service.component.ComponentContext; |
| 53 | import org.osgi.service.component.ComponentInstance; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 54 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 55 | import java.nio.ByteBuffer; |
| 56 | import java.security.MessageDigest; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 57 | import java.util.Dictionary; |
| 58 | import java.util.Hashtable; |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 59 | import java.util.LinkedList; |
| 60 | import java.util.List; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 61 | import java.util.Set; |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 62 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 63 | import static org.hamcrest.Matchers.instanceOf; |
| 64 | import static org.hamcrest.Matchers.is; |
| 65 | import static org.hamcrest.Matchers.notNullValue; |
| 66 | import static org.junit.Assert.assertThat; |
| 67 | import static org.junit.Assert.fail; |
| 68 | import static org.onosproject.net.NetTestTools.connectPoint; |
| 69 | |
| 70 | /** |
| 71 | * Common methods for AAA app testing. |
| 72 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 73 | public class AaaTestBase { |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 74 | |
| 75 | MacAddress clientMac = MacAddress.valueOf("1a:1a:1a:1a:1a:1a"); |
| 76 | MacAddress serverMac = MacAddress.valueOf("2a:2a:2a:2a:2a:2a"); |
| 77 | |
| 78 | // Our session id will be the device ID ("of:1") with the port ("1") concatenated |
| 79 | static final String SESSION_ID = "of:11"; |
Sonal Kasliwal | 7eef29f | 2020-02-12 12:23:22 +0000 | [diff] [blame] | 80 | // Device configuration |
| 81 | static final DeviceId DEVICE_ID = DeviceId.deviceId("of:1"); |
| 82 | // Source ip address of a device. |
| 83 | static final Ip4Address SOURCE_IP = Ip4Address.valueOf("10.177.125.4"); |
| 84 | // Port number |
| 85 | static final PortNumber PORT_A = PortNumber.portNumber(1); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 86 | List<BasePacket> savedPackets = new LinkedList<>(); |
| 87 | PacketProcessor packetProcessor; |
| 88 | |
| 89 | /** |
| 90 | * Saves the given packet onto the saved packets list. |
| 91 | * |
| 92 | * @param packet packet to save |
| 93 | */ |
| 94 | void savePacket(BasePacket packet) { |
| 95 | savedPackets.add(packet); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Keeps a reference to the PacketProcessor and saves the OutboundPackets. |
| 100 | */ |
| 101 | class MockPacketService extends PacketServiceAdapter { |
| 102 | |
| 103 | @Override |
| 104 | public void addProcessor(PacketProcessor processor, int priority) { |
| 105 | packetProcessor = processor; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public void emit(OutboundPacket packet) { |
| 110 | try { |
| 111 | Ethernet eth = Ethernet.deserializer().deserialize(packet.data().array(), |
| 112 | 0, packet.data().array().length); |
| 113 | savePacket(eth); |
| 114 | } catch (Exception e) { |
| 115 | fail(e.getMessage()); |
| 116 | } |
| 117 | } |
| 118 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 119 | class MockComponentContext implements ComponentContext { |
| 120 | |
| 121 | @Override |
| 122 | public Dictionary<String, Object> getProperties() { |
| 123 | Dictionary<String, Object> cfgDict = new Hashtable<String, Object>(); |
| 124 | cfgDict.put("statisticsGenerationEvent", 20); |
| 125 | return cfgDict; |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public Object locateService(String name) { |
| 130 | // TODO Auto-generated method stub |
| 131 | return null; |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public Object locateService(String name, ServiceReference reference) { |
| 136 | // TODO Auto-generated method stub |
| 137 | return null; |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public Object[] locateServices(String name) { |
| 142 | // TODO Auto-generated method stub |
| 143 | return null; |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public BundleContext getBundleContext() { |
| 148 | // TODO Auto-generated method stub |
| 149 | return null; |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public Bundle getUsingBundle() { |
| 154 | // TODO Auto-generated method stub |
| 155 | return null; |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public ComponentInstance getComponentInstance() { |
| 160 | // TODO Auto-generated method stub |
| 161 | return null; |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public void enableComponent(String name) { |
| 166 | // TODO Auto-generated method stub |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void disableComponent(String name) { |
| 171 | // TODO Auto-generated method stub |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public ServiceReference getServiceReference() { |
| 176 | // TODO Auto-generated method stub |
| 177 | return null; |
| 178 | } |
| 179 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 180 | |
| 181 | /** |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 182 | * Mocks the DeviceService. |
| 183 | */ |
| 184 | final class TestDeviceService extends DeviceServiceAdapter { |
| 185 | @Override |
| 186 | public Port getPort(ConnectPoint cp) { |
| 187 | return new MockPort(); |
| 188 | } |
| 189 | } |
| 190 | private class MockPort implements Port { |
| 191 | |
| 192 | @Override |
| 193 | public boolean isEnabled() { |
| 194 | return true; |
| 195 | } |
| 196 | public long portSpeed() { |
| 197 | return 1000; |
| 198 | } |
| 199 | public Element element() { |
| 200 | return null; |
| 201 | } |
| 202 | public PortNumber number() { |
| 203 | return null; |
| 204 | } |
| 205 | public Annotations annotations() { |
| 206 | return new MockAnnotations(); |
| 207 | } |
| 208 | public Type type() { |
| 209 | return Port.Type.FIBER; |
| 210 | } |
| 211 | |
| 212 | private class MockAnnotations implements Annotations { |
| 213 | |
| 214 | @Override |
| 215 | public String value(String val) { |
| 216 | return "PON 1/1"; |
| 217 | } |
| 218 | public Set<String> keys() { |
| 219 | return null; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | private class MockSubscriberAndDeviceInformation extends SubscriberAndDeviceInformation { |
| 225 | |
pier | 99c6d1d | 2020-02-13 14:39:55 +0100 | [diff] [blame] | 226 | MockSubscriberAndDeviceInformation(String id, VlanId uniTagMatch, VlanId ctag, |
| 227 | VlanId stag, int dsPonPrio, int upPonPrio, |
| 228 | int techProfileId, String dsBpId, String usBpId, |
| 229 | String nasPortId, String circuitId, MacAddress hardId, |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 230 | Ip4Address ipAddress) { |
pier | 99c6d1d | 2020-02-13 14:39:55 +0100 | [diff] [blame] | 231 | // Builds UniTagInformation |
| 232 | UniTagInformation.Builder tagInfoBuilder = new UniTagInformation.Builder(); |
| 233 | UniTagInformation uniTagInfo = tagInfoBuilder.setUniTagMatch(uniTagMatch) |
| 234 | .setPonCTag(ctag) |
| 235 | .setPonSTag(stag) |
| 236 | .setDsPonCTagPriority(dsPonPrio) |
| 237 | .setUsPonSTagPriority(upPonPrio) |
| 238 | .setTechnologyProfileId(techProfileId) |
| 239 | .setDownstreamBandwidthProfile(dsBpId) |
| 240 | .setUpstreamBandwidthProfile(usBpId) |
| 241 | .build(); |
| 242 | |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 243 | this.setHardwareIdentifier(hardId); |
| 244 | this.setId(id); |
| 245 | this.setIPAddress(ipAddress); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 246 | this.setNasPortId(nasPortId); |
| 247 | this.setCircuitId(circuitId); |
pier | 99c6d1d | 2020-02-13 14:39:55 +0100 | [diff] [blame] | 248 | this.setUniTagList(Lists.newArrayList(uniTagInfo)); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 252 | final class MockSadisService implements SadisService { |
| 253 | |
| 254 | @Override |
| 255 | public BaseInformationService<SubscriberAndDeviceInformation> getSubscriberInfoService() { |
| 256 | return new MockSubService(); |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public BaseInformationService<BandwidthProfileInformation> getBandwidthProfileService() { |
| 261 | return null; |
| 262 | } |
| 263 | } |
| 264 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 265 | final class MockCfgService implements ComponentConfigService { |
| 266 | @Override |
| 267 | public Set<String> getComponentNames() { |
| 268 | // TODO Auto-generated method stub |
| 269 | return null; |
| 270 | } |
| 271 | |
| 272 | @Override |
| 273 | public void registerProperties(Class<?> componentClass) { |
| 274 | // TODO Auto-generated method stub |
| 275 | } |
| 276 | |
| 277 | @Override |
| 278 | public void unregisterProperties(Class<?> componentClass, boolean clear) { |
| 279 | // TODO Auto-generated method stub |
| 280 | } |
| 281 | |
| 282 | @Override |
| 283 | public Set<ConfigProperty> getProperties(String componentName) { |
| 284 | return null; |
| 285 | } |
| 286 | |
| 287 | @Override |
| 288 | public void setProperty(String componentName, String name, String value) { |
| 289 | // TODO Auto-generated method stub |
| 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void preSetProperty(String componentName, String name, String value) { |
| 294 | // TODO Auto-generated method stub |
| 295 | } |
| 296 | |
| 297 | @Override |
| 298 | public void preSetProperty(String componentName, String name, String value, boolean override) { |
| 299 | // TODO Auto-generated method stub |
| 300 | } |
| 301 | |
| 302 | @Override |
| 303 | public void unsetProperty(String componentName, String name) { |
| 304 | // TODO Auto-generated method stub |
| 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public ConfigProperty getProperty(String componentName, String attribute) { |
| 309 | return null; |
| 310 | } |
| 311 | |
| 312 | } |
| 313 | |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 314 | final class MockSubService implements BaseInformationService<SubscriberAndDeviceInformation> { |
pier | 99c6d1d | 2020-02-13 14:39:55 +0100 | [diff] [blame] | 315 | private final VlanId uniTagMatch = VlanId.vlanId((short) 35); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 316 | private final VlanId clientCtag = VlanId.vlanId((short) 999); |
| 317 | private final VlanId clientStag = VlanId.vlanId((short) 111); |
pier | 99c6d1d | 2020-02-13 14:39:55 +0100 | [diff] [blame] | 318 | private final int dsPrio = 0; |
| 319 | private final int usPrio = 0; |
| 320 | private final int techProfileId = 64; |
| 321 | private final String usBpId = "HSIA-US"; |
| 322 | private final String dsBpId = "HSIA-DS"; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 323 | private final String clientNasPortId = "PON 1/1"; |
| 324 | private final String clientCircuitId = "CIR-PON 1/1"; |
| 325 | |
pier | 99c6d1d | 2020-02-13 14:39:55 +0100 | [diff] [blame] | 326 | |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 327 | MockSubscriberAndDeviceInformation sub = |
pier | 99c6d1d | 2020-02-13 14:39:55 +0100 | [diff] [blame] | 328 | new MockSubscriberAndDeviceInformation(clientNasPortId, uniTagMatch, clientCtag, |
| 329 | clientStag, dsPrio, usPrio, |
| 330 | techProfileId, dsBpId, usBpId, |
| 331 | clientNasPortId, clientCircuitId, null, |
| 332 | null); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 333 | @Override |
| 334 | public SubscriberAndDeviceInformation get(String id) { |
| 335 | |
| 336 | return sub; |
| 337 | |
| 338 | } |
| 339 | |
| 340 | @Override |
| 341 | public void invalidateAll() {} |
| 342 | public void invalidateId(String id) {} |
| 343 | public SubscriberAndDeviceInformation getfromCache(String id) { |
| 344 | return null; |
| 345 | } |
| 346 | } |
| 347 | /** |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 348 | * Mocks the DefaultPacketContext. |
| 349 | */ |
| 350 | final class TestPacketContext extends DefaultPacketContext { |
| 351 | |
Shubham Sharma | 1ad1663 | 2019-11-26 11:09:21 +0000 | [diff] [blame] | 352 | TestPacketContext(long time, InboundPacket inPkt, |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 353 | OutboundPacket outPkt, boolean block) { |
| 354 | super(time, inPkt, outPkt, block); |
| 355 | } |
| 356 | |
| 357 | @Override |
| 358 | public void send() { |
| 359 | // We don't send anything out. |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Sends an Ethernet packet to the process method of the Packet Processor. |
| 365 | * |
| 366 | * @param reply Ethernet packet |
| 367 | */ |
| 368 | void sendPacket(Ethernet reply) { |
| 369 | final ByteBuffer byteBuffer = ByteBuffer.wrap(reply.serialize()); |
| 370 | InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), |
| 371 | reply, |
| 372 | byteBuffer); |
| 373 | |
| 374 | PacketContext context = new TestPacketContext(127L, inPacket, null, false); |
| 375 | packetProcessor.process(context); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Constructs an Ethernet packet containing identification payload. |
| 380 | * |
| 381 | * @return Ethernet packet |
| 382 | */ |
| 383 | Ethernet constructSupplicantIdentifyPacket(StateMachine stateMachine, |
| 384 | byte type, |
| 385 | byte id, |
| 386 | Ethernet radiusChallenge) |
| 387 | throws Exception { |
| 388 | Ethernet eth = new Ethernet(); |
| 389 | eth.setDestinationMACAddress(clientMac.toBytes()); |
| 390 | eth.setSourceMACAddress(serverMac.toBytes()); |
| 391 | eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); |
| 392 | eth.setVlanID((short) 2); |
| 393 | |
| 394 | String username = "testuser"; |
| 395 | byte[] data = username.getBytes(); |
| 396 | |
| 397 | |
| 398 | if (type == EAP.ATTR_MD5) { |
| 399 | String password = "testpassword"; |
| 400 | EAPOL eapol = (EAPOL) radiusChallenge.getPayload(); |
| 401 | EAP eap = (EAP) eapol.getPayload(); |
| 402 | |
| 403 | byte[] identifier = new byte[password.length() + eap.getData().length]; |
| 404 | |
| 405 | identifier[0] = stateMachine.challengeIdentifier(); |
| 406 | System.arraycopy(password.getBytes(), 0, identifier, 1, password.length()); |
| 407 | System.arraycopy(eap.getData(), 1, identifier, 1 + password.length(), 16); |
| 408 | |
| 409 | MessageDigest md = MessageDigest.getInstance("MD5"); |
| 410 | byte[] hash = md.digest(identifier); |
| 411 | data = new byte[17]; |
| 412 | data[0] = (byte) 16; |
| 413 | System.arraycopy(hash, 0, data, 1, 16); |
| 414 | } |
| 415 | EAP eap = new EAP(EAP.RESPONSE, (byte) 1, type, |
| 416 | data); |
| 417 | eap.setIdentifier(id); |
| 418 | |
| 419 | // eapol header |
| 420 | EAPOL eapol = new EAPOL(); |
| 421 | eapol.setEapolType(EAPOL.EAPOL_PACKET); |
| 422 | eapol.setPacketLength(eap.getLength()); |
| 423 | |
| 424 | // eap part |
| 425 | eapol.setPayload(eap); |
| 426 | |
| 427 | eth.setPayload(eapol); |
| 428 | eth.setPad(true); |
| 429 | return eth; |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Constructs an Ethernet packet containing a EAPOL_START Payload. |
| 434 | * |
| 435 | * @return Ethernet packet |
| 436 | */ |
| 437 | Ethernet constructSupplicantStartPacket() { |
| 438 | Ethernet eth = new Ethernet(); |
| 439 | eth.setDestinationMACAddress(clientMac.toBytes()); |
| 440 | eth.setSourceMACAddress(serverMac.toBytes()); |
| 441 | eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); |
| 442 | eth.setVlanID((short) 2); |
| 443 | |
Shubham Sharma | 048cc26 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 444 | EAP eap = new EAP(EAPOL.EAPOL_START, (byte) 3, EAPOL.EAPOL_START, null); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 445 | |
| 446 | // eapol header |
| 447 | EAPOL eapol = new EAPOL(); |
| 448 | eapol.setEapolType(EAPOL.EAPOL_START); |
| 449 | eapol.setPacketLength(eap.getLength()); |
| 450 | |
| 451 | // eap part |
| 452 | eapol.setPayload(eap); |
| 453 | |
| 454 | eth.setPayload(eapol); |
| 455 | eth.setPad(true); |
| 456 | return eth; |
| 457 | } |
| 458 | |
| 459 | /** |
Shubham Sharma | 001ae11 | 2020-01-28 10:04:01 +0000 | [diff] [blame] | 460 | * Constructs an Ethernet packet containing a EAPOL_ASF Payload. |
| 461 | * |
| 462 | * @return Ethernet packet |
| 463 | */ |
| 464 | Ethernet constructSupplicantAsfPacket() { |
| 465 | Ethernet eth = new Ethernet(); |
| 466 | eth.setDestinationMACAddress(clientMac.toBytes()); |
| 467 | eth.setSourceMACAddress(serverMac.toBytes()); |
| 468 | eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); |
| 469 | eth.setVlanID((short) 2); |
| 470 | |
| 471 | EAP eap = new EAP(EAPOL.EAPOL_START, (byte) 3, EAPOL.EAPOL_START, null); |
| 472 | |
| 473 | // eapol header |
| 474 | EAPOL eapol = new EAPOL(); |
| 475 | eapol.setEapolType(EAPOL.EAPOL_ASF); |
| 476 | eapol.setPacketLength(eap.getLength()); |
| 477 | |
| 478 | // eap part |
| 479 | eapol.setPayload(eap); |
| 480 | |
| 481 | eth.setPayload(eapol); |
| 482 | eth.setPad(true); |
| 483 | return eth; |
| 484 | } |
| 485 | |
| 486 | /** |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 487 | * Checks the contents of a RADIUS packet being sent to the RADIUS server. |
| 488 | * |
| 489 | * @param radiusPacket packet to check |
| 490 | * @param code expected code |
| 491 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 492 | void checkRadiusPacket(AaaManager aaaManager, Ethernet radiusPacket, byte code) { |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 493 | |
| 494 | assertThat(radiusPacket.getSourceMAC(), |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 495 | is(MacAddress.valueOf(aaaManager.nasMacAddress))); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 496 | assertThat(radiusPacket.getDestinationMAC(), is(serverMac)); |
| 497 | |
| 498 | assertThat(radiusPacket.getPayload(), instanceOf(EAPOL.class)); |
| 499 | EAPOL eapol = (EAPOL) radiusPacket.getPayload(); |
| 500 | assertThat(eapol, notNullValue()); |
| 501 | |
| 502 | assertThat(eapol.getEapolType(), is(EAPOL.EAPOL_PACKET)); |
| 503 | assertThat(eapol.getPayload(), instanceOf(EAP.class)); |
| 504 | EAP eap = (EAP) eapol.getPayload(); |
| 505 | assertThat(eap, notNullValue()); |
| 506 | |
| 507 | assertThat(eap.getCode(), is(code)); |
| 508 | } |
Shubham Sharma | c7aa620 | 2019-12-12 10:19:10 +0000 | [diff] [blame] | 509 | |
| 510 | /** |
| 511 | * Constructs an Ethernet packet containing a EAPOL_LOGOFF Payload. |
| 512 | * |
| 513 | * @return Ethernet packet |
| 514 | */ |
| 515 | Ethernet constructSupplicantLogoffPacket() { |
| 516 | Ethernet eth = new Ethernet(); |
| 517 | eth.setDestinationMACAddress(clientMac.toBytes()); |
| 518 | eth.setSourceMACAddress(serverMac.toBytes()); |
| 519 | eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); |
| 520 | eth.setVlanID((short) 2); |
| 521 | |
| 522 | EAP eap = new EAP(EAPOL.EAPOL_LOGOFF, (byte) 2, EAPOL.EAPOL_LOGOFF, null); |
| 523 | |
| 524 | // eapol header |
| 525 | EAPOL eapol = new EAPOL(); |
| 526 | eapol.setEapolType(EAPOL.EAPOL_LOGOFF); |
| 527 | eapol.setPacketLength(eap.getLength()); |
| 528 | |
| 529 | // eap part |
| 530 | eapol.setPayload(eap); |
| 531 | |
| 532 | eth.setPayload(eapol); |
| 533 | eth.setPad(true); |
| 534 | return eth; |
| 535 | } |
| 536 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 537 | } |