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