FiveGTopologyView.java 18.8 KB
Newer Older
Björn Richerzhagen's avatar
Björn Richerzhagen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
 *
 * This file is part of PeerfactSim.KOM.
 * 
 * PeerfactSim.KOM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * PeerfactSim.KOM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with PeerfactSim.KOM.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package de.tud.kom.p2psim.impl.topology.views;

23
import java.util.Arrays;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import de.tud.kom.p2psim.api.common.HostProperties;
import de.tud.kom.p2psim.api.linklayer.mac.Link;
import de.tud.kom.p2psim.api.linklayer.mac.MacAddress;
import de.tud.kom.p2psim.api.linklayer.mac.MacLayer;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.FiveGTopologyView.CellLink;
import de.tud.kom.p2psim.impl.topology.views.fiveg.FiveGTopologyDatabase;
39
import de.tud.kom.p2psim.impl.topology.views.fiveg.FiveGTopologyDatabase.Entry;
40
41
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
42
import de.tudarmstadt.maki.simonstrator.api.Host;
43
import de.tudarmstadt.maki.simonstrator.api.Time;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
44
import de.tudarmstadt.maki.simonstrator.api.component.sensor.handover.HandoverSensor;
45
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;

/**
 * This topology view offers a topology for mobile apps - mobile clients
 * maintain one to one connections to one or multiple cloud servers or cloudlet
 * instances. This view abstracts from real antennas in that the actual range of
 * an antenna etc. is just modeled as a property of the link between mobile
 * client and the endpoint (cloud/cloudlet) based on a client's position. This
 * way, measurements such as the ones by Kaup et al. can be easily incorporated.
 * 
 * TODO add a property to enable usage of access points (lower latency, higher
 * BW at certain client positions around the configured positions of APs)
 * <code><Properties canUseAccessPoints="true" /></code>. NO, just make this
 * configurable via the topology view properties (e.g., a percentage of nodes
 * can use such APs) and THEN set the corresponding host property --> if overlay
 * code wants to access this information, we might need to add
 * {@link HostProperties} to the Simonstrator API.
 * 
 * TODO add distinction for cloudlets and cloud (assuming that cloudlets exhibit
 * lower latency), ideally with yet another (TM) host property on the base
 * station side: <code><Properties isCloudlet="true" /></code>. NO, again just
 * use the groupID of a host as a config setting for this view: e.g., all
 * specified groupIDs are Backend hosts vs. direct cloudlets.
 * 
 * FIXME OR: just base this configuration options on the group-ID in the host
 * builder?
 * 
 * @author Bjoern Richerzhagen
 * @version 1.0, Nov 4, 2015
 */
public class FiveGTopologyView extends AbstractTopologyView<CellLink> {

	private Set<MacAddress> cloudlets = new LinkedHashSet<>();

	private Set<MacAddress> clouds = new LinkedHashSet<>();

	private Set<MacAddress> mobileClients = new LinkedHashSet<>();

Björn Richerzhagen's avatar
Björn Richerzhagen committed
84
85
86
87
88
89
	/**
	 * A subset of mobileClients -> contains all clients that may use access
	 * points.
	 */
	private Set<MacAddress> mobileClientsUsingAccessPoints = new LinkedHashSet<>();

Björn Richerzhagen's avatar
Björn Richerzhagen committed
90
91
92
93
94
95
	private List<MacAddress> mobileClientsList = new LinkedList<>();

	private List<MacAddress> cloudsAndCloudletsList = new LinkedList<>();

	private FiveGTopologyDatabase database = null;

Björn Richerzhagen's avatar
Björn Richerzhagen committed
96
97
	private FiveGTopologyDatabase databaseAccessPoints = null;

Björn Richerzhagen's avatar
Björn Richerzhagen committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
	/**
	 * Configuration setting: all group IDs of nodes that act as cloudlets
	 * (e.g., act as basestations with a lower delay, whatever that means w.r.t.
	 * the specified model)
	 */
	private Set<String> groupIDsCloudlet = new LinkedHashSet<>();

	/**
	 * Configuration setting: all group IDs that act as cloud (e.g., backend
	 * servers). Here, the full latency of a connection from a mobile client to
	 * a network sever somewhere in the Internet is assumed (e.g., as measured
	 * by Android end user devices)
	 */
	private Set<String> groupIDsCloud = new LinkedHashSet<>();

Björn Richerzhagen's avatar
Björn Richerzhagen committed
113
114
115
116
117
118
119
	/**
	 * Configuration setting: all group IDs that act as clients but have access
	 * to access points.
	 */
	private Set<String> groupIDsAccessPointUsage = new LinkedHashSet<>();

	private List<HandoverSensor5G> handoverSensors = new LinkedList<>();
120
121
	
	private List<CellLink> links = new LinkedList<>();
Björn Richerzhagen's avatar
Björn Richerzhagen committed
122

Björn Richerzhagen's avatar
Björn Richerzhagen committed
123
124
125
126
127
128
	/**
	 * 
	 * @param phy
	 */
	public FiveGTopologyView(PhyType phy) {
		super(phy, true);
129
		setHasRealLinkLayer(false);
130
131
132
133
134
135
136
137
		/*
		 * AP state is only set, after components moved. In scenarios without
		 * active movement, this will never happen. Therefore, we trigger the
		 * respective event ONCE at the start of the simulation
		 */
		Event.scheduleImmediately(new EventHandler() {
			@Override
			public void eventOccurred(Object content, int type) {
138
				checkAPAssociations();
139
140
			}
		}, null, 0);
Björn Richerzhagen's avatar
Björn Richerzhagen committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
	}

	@XMLConfigurableConstructor({ "phy" })
	public FiveGTopologyView(String phy) {
		// UMTS is reset with custom type next.
		this(PhyType.UMTS);
		setPhy(phy);
	}

	@Override
	public Link getBestNextLink(MacAddress source, MacAddress lastHop,
			MacAddress currentHop, MacAddress destination) {
		return getLinkBetween(source, destination);
	}

	@Override
	public void changedWaypointModel(WaypointModel model) {
		// I don't care, I love it.
	}

	@Override
	public void changedObstacleModel(ObstacleModel model) {
		// I don't care, I love it.
	}

	@Override
	protected void addedMac(MacLayer mac) {
		String groupId = mac.getHost().getProperties().getGroupID();
		if (groupIDsCloud.contains(groupId)) {
			clouds.add(mac.getMacAddress());
			cloudsAndCloudletsList.add(mac.getMacAddress());
		} else if (groupIDsCloudlet.contains(groupId)) {
			cloudlets.add(mac.getMacAddress());
			cloudsAndCloudletsList.add(mac.getMacAddress());
		} else {
			mobileClients.add(mac.getMacAddress());
			mobileClientsList.add(mac.getMacAddress());
Björn Richerzhagen's avatar
Björn Richerzhagen committed
178
179
180
181
182
183
184
185
186

			if (groupIDsAccessPointUsage.contains(groupId)) {
				assert databaseAccessPoints != null : "An AP Database is needed if AP-Functionality is desired.";
				mobileClientsUsingAccessPoints.add(mac.getMacAddress());
				HandoverSensor5G hs = new HandoverSensor5G(mac.getHost(),
						mac.getMacAddress());
				mac.getHost().registerComponent(hs);
				handoverSensors.add(hs);
			}
Björn Richerzhagen's avatar
Björn Richerzhagen committed
187
188
189
190
191
192
193
194
195
196
		}
	}

	@Override
	protected void updateOutdatedLink(CellLink link) {
		if (link.isInvalidLink()) {
			// cloud <-> cloud or client <-> client link
			return;
		}
		PositionVector pos = getCachedPosition(link.getMobileClient());
Björn Richerzhagen's avatar
Björn Richerzhagen committed
197

Björn Richerzhagen's avatar
Björn Richerzhagen committed
198
		int segId = database.getSegmentID(pos.getX(), pos.getY());
Björn Richerzhagen's avatar
Björn Richerzhagen committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
		int apSegId = -1;
		if (link.supportsAccessPoints()) {
			/*
			 * Check, if an AP-segment is available
			 */
			apSegId = databaseAccessPoints.getSegmentID(pos.getX(), pos.getY());
			if (link.getSegmentId() != segId
					|| link.getApSegmentId() != apSegId) {
				// Update
				link.setLinkData(database.getEntryFor(segId, link.isCloudlet()),
						databaseAccessPoints.getEntryFor(apSegId,
								link.isCloudlet()));
			}
		} else if (link.getSegmentId() != segId) {
			link.setLinkData(database.getEntryFor(segId, link.isCloudlet()),
					null);
		}
	}
217

218
	/**
219
220
221
222
	 * Check, if a node moved into a new segment. If so, we need to update the
	 * HandoverSensor to trigger the listeners. We only need to check nodes that
	 * are included in the list of ap-enabled nodes (i.e., they already have a
	 * HandoverSensor-instance).
223
224
	 */
	protected void checkAPAssociations() {
Björn Richerzhagen's avatar
Björn Richerzhagen committed
225
226
227
228
229
230
231
232
233
234
		for (HandoverSensor5G sensor : handoverSensors) {
			PositionVector pos = getCachedPosition(sensor.macAddr);
			int segId = databaseAccessPoints.getSegmentID(pos.getX(),
					pos.getY());
			if (segId != sensor.apSegmentId) {
				sensor.apSegmentId = segId;
				// Connected to AP, if segment is provided in the DB
				sensor.setConnectedToAccessPoint(
						databaseAccessPoints.getEntryFor(segId, false) != null);
			}
Björn Richerzhagen's avatar
Björn Richerzhagen committed
235
		}
236

237
238
239
240
241
242
		/*
		 * FIXME the not-so-elegant approach of updating all max-BWs
		 */
		for (MacAddress mobileClient : mobileClientsList) {
			updateMaxMacBandwidth(mobileClient);
		}
243
	}
244

245
	long lastMovementTimestamp = 0;
246

247
	@Override
248
	public void onLocationChanged(Host host, Location location) {
249
		super.onLocationChanged(host, location);		
250
251
		if (lastMovementTimestamp != Time.getCurrentTime()) {
			lastMovementTimestamp = Time.getCurrentTime();
252
253
254
255
			// Force re-assignment to cells.
			for (CellLink cellLink : links) {
				cellLink.setOutdated(true);
			}
256
257
			checkAPAssociations();
		}
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
	}

	/**
	 * FIXME this is currently needed to keep the max upload bandwidth reported
	 * by MOBILE-mac (UMTS) consistent with the bandwidth of the given cell. It
	 * always reports the BW that can be achieved when sending via MOBILE to the
	 * cloud (NOT to cloudlets).
	 * 
	 * @param macAddr
	 */
	private void updateMaxMacBandwidth(MacAddress macAddr) {
		// FIXME workaround for MAC bandwidth updates.
		// Sets the initial max upload BW to the cloud (not to cloudlets!)
		MacLayer mac = getMac(macAddr);
		PositionVector pos = mac.getHost().getTopologyComponent()
				.getRealPosition();
		int segId = database.getSegmentID(pos.getX(), pos.getY());
		Entry usedEntry = database.getEntryFor(segId, false);
		if (mobileClientsUsingAccessPoints.contains(macAddr)) {
			int apSegId = databaseAccessPoints.getSegmentID(pos.getX(),
					pos.getY());
			Entry apEntry = databaseAccessPoints.getEntryFor(apSegId, false);
			usedEntry = (apEntry != null ? apEntry : usedEntry);
		}
		mac.getMaxBandwidth().setUpBW(usedEntry.getBandwidth(true));
		mac.getMaxBandwidth().setDownBW(usedEntry.getBandwidth(false));
Björn Richerzhagen's avatar
Björn Richerzhagen committed
284
285
286
	}

	@Override
287
	protected CellLink createLink(MacAddress source, MacAddress destination) {
Björn Richerzhagen's avatar
Björn Richerzhagen committed
288
289
290
291
292
293
294
295
296
		boolean sourceIsClient = mobileClients.contains(source);
		boolean destinationIsClient = mobileClients.contains(destination);
		if (sourceIsClient == destinationIsClient) {
			// both client or both not client -> not connected
			return new CellLink(source, destination);
		}
		MacAddress mobileClient = sourceIsClient ? source : destination;
		CellLink link = new CellLink(source, destination, true,
				getPhyType().getDefaultMTU(), mobileClient,
297
				cloudlets.contains(sourceIsClient ? destination : source),
Björn Richerzhagen's avatar
Björn Richerzhagen committed
298
				mobileClientsUsingAccessPoints.contains(mobileClient));
299
		links.add(link);
Björn Richerzhagen's avatar
Björn Richerzhagen committed
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
		updateOutdatedLink(link);
		return link;
	}

	@Override
	protected List<MacAddress> updateNeighborhood(MacAddress source) {
		if (cloudlets.contains(source) || clouds.contains(source)) {
			return mobileClientsList;
		} else {
			assert mobileClients.contains(source);
			// Is a client, has all clouds and cloudlets as neighbors
			return cloudsAndCloudletsList;
		}
	}

315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
	/**
	 * Access to the {@link FiveGTopologyDatabase} that takes care of the
	 * UMTS-links in the 5G-TopoView.
	 * 
	 * @return
	 */
	public FiveGTopologyDatabase getUMTSTopologyDatabase() {
		return database;
	}

	/**
	 * Access to the {@link FiveGTopologyDatabase} used to determine Wi-Fi AP
	 * connectivity in the 5G TopoView.
	 * 
	 * @return
	 */
	public FiveGTopologyDatabase getAccessPointTopologyDatabase() {
		return databaseAccessPoints;
	}

Björn Richerzhagen's avatar
Björn Richerzhagen committed
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
	/*
	 * Configuration options
	 */

	/**
	 * GroupIDs (as specified in the host builder section) that should act as
	 * clouds (e.g., full measured latency and bandwidth is applied)
	 * 
	 * @param cloudGroupIDs
	 */
	@SuppressWarnings("unchecked")
	public void setCloudGroups(String[] cloudGroupIDs) {
		this.groupIDsCloud = new LinkedHashSet<>(Arrays.asList(cloudGroupIDs));
	}

	/**
	 * GroupIDs that act as cloudlets (e.g., lower latency, higher BW) - models
	 * regional computations facilities.
	 * 
	 * @param cloudletGroups
	 */
	@SuppressWarnings("unchecked")
	public void setCloudletGroups(String[] cloudletGroups) {
		this.groupIDsCloudlet = new LinkedHashSet<>(
				Arrays.asList(cloudletGroups));
	}

Björn Richerzhagen's avatar
Björn Richerzhagen committed
362
363
364
	/**
	 * GroupIDs that act as clients and have access to access points.
	 * 
Clemens Krug's avatar
Clemens Krug committed
365
	 * @param accessPointGroups
Björn Richerzhagen's avatar
Björn Richerzhagen committed
366
367
368
369
370
371
372
	 */
	@SuppressWarnings("unchecked")
	public void setAccessPointGroups(String[] accessPointGroups) {
		this.groupIDsAccessPointUsage = new LinkedHashSet<>(
				Arrays.asList(accessPointGroups));
	}

Björn Richerzhagen's avatar
Björn Richerzhagen committed
373
374
375
376
377
378
379
380
381
382
383
	/**
	 * Set the measurement database providing link quality data for clients
	 * based on their position.
	 * 
	 * @param database
	 */
	public void setDatabase(FiveGTopologyDatabase database) {
		assert this.database == null;
		this.database = database;
	}

Björn Richerzhagen's avatar
Björn Richerzhagen committed
384
385
386
387
388
389
390
391
392
393
	/**
	 * Another layer of a database, this time for access points.
	 * 
	 * @param accessPoints
	 */
	public void setAccessPoints(FiveGTopologyDatabase accessPoints) {
		assert this.databaseAccessPoints == null;
		this.databaseAccessPoints = accessPoints;
	}

Björn Richerzhagen's avatar
Björn Richerzhagen committed
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
	/**
	 * A custom link object supporting dynamic updates of the properties without
	 * relying on a movement model notification - the client's position is used
	 * to determine the link performance.
	 * 
	 * @author Bjoern Richerzhagen
	 * @version 1.0, Nov 4, 2015
	 */
	public class CellLink extends DefaultLink {

		/**
		 * Address of the mobile client
		 */
		private final MacAddress mobileClient;

		private FiveGTopologyDatabase.Entry linkData;

Björn Richerzhagen's avatar
Björn Richerzhagen committed
411
412
		private FiveGTopologyDatabase.Entry apLinkData;

Björn Richerzhagen's avatar
Björn Richerzhagen committed
413
414
		private final boolean isUpload;

Björn Richerzhagen's avatar
Björn Richerzhagen committed
415
416
		private final boolean supportsAccessPoints;

Björn Richerzhagen's avatar
Björn Richerzhagen committed
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
		private final boolean isCloudlet;

		private final boolean isInvalidLink;

		/**
		 * An unconnected link
		 * 
		 * @param source
		 * @param destination
		 */
		public CellLink(MacAddress source, MacAddress destination) {
			super(source, destination, false, -1, -1, -1, -1);
			this.mobileClient = null;
			this.isUpload = false;
			this.isCloudlet = false;
			this.isInvalidLink = true;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
433
			this.supportsAccessPoints = false;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
434
435
436
437
		}

		public CellLink(MacAddress source, MacAddress destination,
				boolean isConnected, int mtu, MacAddress mobileClient,
Björn Richerzhagen's avatar
Björn Richerzhagen committed
438
				boolean isCloudlet, boolean supportsAccessPoints) {
Björn Richerzhagen's avatar
Björn Richerzhagen committed
439
440
441
442
443
444
445
446
447
448
			super(source, destination, isConnected, -1, -1, -1, mtu);
			this.mobileClient = mobileClient;
			this.isCloudlet = isCloudlet;
			if (mobileClient.equals(source)) {
				isUpload = true;
			} else {
				assert mobileClient.equals(destination);
				isUpload = false;
			}
			this.isInvalidLink = false;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
449
			this.supportsAccessPoints = supportsAccessPoints;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
450
451
452
453
454
455
		}

		public boolean isInvalidLink() {
			return isInvalidLink;
		}

Björn Richerzhagen's avatar
Björn Richerzhagen committed
456
457
458
459
		public boolean supportsAccessPoints() {
			return supportsAccessPoints;
		}

Björn Richerzhagen's avatar
Björn Richerzhagen committed
460
461
462
463
		public int getSegmentId() {
			return linkData == null ? -1 : linkData.getSegmentID();
		}

Björn Richerzhagen's avatar
Björn Richerzhagen committed
464
465
466
467
468
469
470
		public int getApSegmentId() {
			assert supportsAccessPoints;
			return apLinkData == null ? -1 : apLinkData.getSegmentID();
		}

		public void setLinkData(FiveGTopologyDatabase.Entry linkData,
				FiveGTopologyDatabase.Entry apLinkData) {
471

472
473
474
475
476
477
478
479
480
481
482
483
			// Initialization
			if (this.linkData == null && this.apLinkData == null) {
				this.linkData = linkData;
				this.apLinkData = apLinkData;
				if (apLinkData != null) {
					apLinkData.onHostEntersSegment(mobileClient);
				} else {
					linkData.onHostEntersSegment(mobileClient);
				}
				// For the first update on link creation.
				return;
			}
484

485
			// Update
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
			if (apLinkData != null) {
				assert supportsAccessPoints;
				if (this.apLinkData != null) {
					// was in AP, moves into AP
					this.apLinkData.onHostLeavesSegment(mobileClient);
					apLinkData.onHostEntersSegment(mobileClient);
				} else {
					// was NOT in AP, moves into AP
					this.linkData.onHostLeavesSegment(mobileClient);
					apLinkData.onHostEntersSegment(mobileClient);
				}
			} else {
				if (this.apLinkData != null) {
					// was in AP, moves OUT OF AP
					this.apLinkData.onHostLeavesSegment(mobileClient);
					linkData.onHostEntersSegment(mobileClient);
				} else {
					// was NOT in AP, moves into NON-AP segment
					this.linkData.onHostLeavesSegment(mobileClient);
					linkData.onHostEntersSegment(mobileClient);
				}
			}
508

Björn Richerzhagen's avatar
Björn Richerzhagen committed
509
			this.linkData = linkData;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
510
511
512
			assert (apLinkData != null && supportsAccessPoints)
					|| apLinkData == null;
			this.apLinkData = apLinkData;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
513
514
515
516
517
518
519
520
521
522
		}

		public MacAddress getMobileClient() {
			return mobileClient;
		}

		public boolean isCloudlet() {
			return isCloudlet;
		}

523
524
525
526
		public boolean isUpload() {
			return isUpload;
		}

Björn Richerzhagen's avatar
Björn Richerzhagen committed
527
528
		@Override
		public long getBandwidth(boolean isBroadcast) {
Björn Richerzhagen's avatar
Björn Richerzhagen committed
529
530
			assert (apLinkData != null && supportsAccessPoints)
					|| apLinkData == null;
531
			long tmp = apLinkData != null ? apLinkData.getBandwidth(isUpload)
Björn Richerzhagen's avatar
Björn Richerzhagen committed
532
					: linkData.getBandwidth(isUpload);
533
			return tmp;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
534
535
536
537
		}

		@Override
		public double getDropProbability() {
Björn Richerzhagen's avatar
Björn Richerzhagen committed
538
539
540
541
			assert (apLinkData != null && supportsAccessPoints)
					|| apLinkData == null;
			return apLinkData != null ? apLinkData.getDropProbability(isUpload)
					: linkData.getDropProbability(isUpload);
Björn Richerzhagen's avatar
Björn Richerzhagen committed
542
543
544
545
		}

		@Override
		public long getLatency() {
Björn Richerzhagen's avatar
Björn Richerzhagen committed
546
547
548
549
550
551
			assert (apLinkData != null && supportsAccessPoints)
					|| apLinkData == null;
			return apLinkData != null ? apLinkData.getLatency(isUpload)
					: linkData.getLatency(isUpload);
		}

Clemens Krug's avatar
Clemens Krug committed
552
		@Override
553
		public boolean isConnected() {
554
555
556
557
558
559
			if (apLinkData != null) {
				return apLinkData.isAvailable();
			}
			if (linkData != null) {
				return linkData.isAvailable();
			}
Clemens Krug's avatar
Clemens Krug committed
560
561
562
			return false;
		}

Björn Richerzhagen's avatar
Björn Richerzhagen committed
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
	}

	/**
	 * Implementation of a {@link HandoverSensor} within the 5G topo-view.
	 * 
	 * @author Bjoern Richerzhagen
	 * @version 1.0, Nov 20, 2015
	 */
	public class HandoverSensor5G implements HandoverSensor {

		private List<HandoverListener> listeners = new LinkedList<>();

		private boolean isConnectedToAccessPoint;

		public int apSegmentId = -1;

		public final MacAddress macAddr;

		private Host host;

		public HandoverSensor5G(Host host, MacAddress macAddr) {
			this.host = host;
			this.macAddr = macAddr;
		}

		@Override
		public boolean isConnectedToAccessPoint() {
			return isConnectedToAccessPoint;
		}

		public void setConnectedToAccessPoint(
				boolean isConnectedToAccessPoint) {
			if (this.isConnectedToAccessPoint != isConnectedToAccessPoint) {
				this.isConnectedToAccessPoint = isConnectedToAccessPoint;
				for (HandoverListener listener : listeners) {
					listener.onHandover(isConnectedToAccessPoint);
				}
			}
		}

		@Override
		public void addHandoverListener(HandoverListener listener) {
			listeners.add(listener);
		}

		@Override
		public boolean removeHandoverListener(
				HandoverListener listenerToRemove) {
			return listeners.remove(listenerToRemove);
		}

		@Override
		public void initialize() {
			// not needed
		}

		@Override
		public void shutdown() {
			// not needed
		}

		@Override
		public Host getHost() {
			return host;
Björn Richerzhagen's avatar
Björn Richerzhagen committed
627
628
629
630
		}

	}

Marc Schiller's avatar
Marc Schiller committed
631
}