-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
301 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,5 @@ gradle-app.setting | |
.idea/ | ||
out/ | ||
|
||
|
||
### Specific to application | ||
src/main/resources/version.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
application.version=1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
rootProject.name = 'simulator' | ||
rootProject.name = 'ssbgp-simulator' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io | ||
|
||
import bgp.BGPRoute | ||
import simulation.NodeDataSet | ||
import java.io.File | ||
import java.io.IOException | ||
|
||
/** | ||
* Created on 02-10-2017. | ||
* | ||
* @author David Fialho | ||
* | ||
* IMPORTANT: This Reporter only works for BGP routes!! | ||
*/ | ||
class NodeDataReporter(private val outputFile: File): Reporter<NodeDataSet> { | ||
|
||
/** | ||
* Flag to indicate if the headers were already printed. | ||
* Helps to ensure the headers are printed only once despite the report() method being called multiple times. | ||
*/ | ||
private var wereHeadersPrinted = false | ||
|
||
/** | ||
* Stores the simulation number, Incremented each time the report() method is called. | ||
*/ | ||
private var simulation = 1 | ||
|
||
/** | ||
* Reports a data set. | ||
*/ | ||
@Throws(IOException::class) | ||
override fun report(data: NodeDataSet) { | ||
|
||
CSVPrinter(outputFile).use { | ||
|
||
if (!wereHeadersPrinted) { | ||
it.printRecord( | ||
"Simulation", | ||
"Node", | ||
"Local Preference", | ||
"Next-hop", | ||
"Path Length", | ||
"Termination Time" | ||
) | ||
|
||
wereHeadersPrinted = true | ||
} | ||
|
||
for ((nodeID, selectedRoute) in data.selectedRoutes) { | ||
|
||
selectedRoute as BGPRoute | ||
|
||
it.printRecord( | ||
simulation, | ||
nodeID, | ||
selectedRoute.localPref, | ||
selectedRoute.asPath.nextHop()?.id, | ||
selectedRoute.asPath.size, | ||
data.terminationTimes[nodeID] | ||
) | ||
} | ||
|
||
simulation++ | ||
} | ||
} | ||
|
||
/** | ||
* Resets the reporter to its initial state. | ||
*/ | ||
override fun reset() { | ||
wereHeadersPrinted = false | ||
simulation = 1 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package simulation | ||
|
||
import bgp.notifications.BGPNotifier | ||
import bgp.notifications.ExportListener | ||
import bgp.notifications.ExportNotification | ||
import core.simulator.notifications.* | ||
import io.NodeDataReporter | ||
import java.io.File | ||
import java.io.IOException | ||
|
||
/** | ||
* Created on 01-10-2017. | ||
* | ||
* @author David Fialho | ||
* | ||
* The node data collector collects data relative to each individual node in the topology. | ||
*/ | ||
class NodeDataCollector(private val reporter: NodeDataReporter) : | ||
DataCollector, StartListener, EndListener, ExportListener { | ||
|
||
/** | ||
* Creates a Basic Reporter that will output results to the specified output file. | ||
*/ | ||
constructor(outputFile: File) : this(NodeDataReporter(outputFile)) | ||
|
||
private val data = NodeDataSet() | ||
|
||
/** | ||
* Adds the collector as a listener for notifications the collector needs to listen to collect data. | ||
*/ | ||
override fun register() { | ||
BasicNotifier.addStartListener(this) | ||
BasicNotifier.addEndListener(this) | ||
BGPNotifier.addExportListener(this) | ||
} | ||
|
||
/** | ||
* Removes the collector from all notifiers | ||
*/ | ||
override fun unregister() { | ||
BasicNotifier.removeStartListener(this) | ||
BasicNotifier.removeEndListener(this) | ||
BGPNotifier.removeExportListener(this) | ||
} | ||
|
||
/** | ||
* Processes the data after all raw data has been collected. It should be called after an execution. | ||
*/ | ||
override fun processData() { | ||
// nothing to do here | ||
} | ||
|
||
/** | ||
* Reports the currently collected data. | ||
* | ||
* @throws IOException If an I/O error occurs | ||
*/ | ||
@Throws(IOException::class) | ||
override fun report() { | ||
reporter.report(data) | ||
} | ||
|
||
/** | ||
* Clears all collected data. | ||
*/ | ||
override fun clear() { | ||
data.clear() | ||
} | ||
|
||
/** | ||
* Invoked to notify the listener of a new start notification. | ||
*/ | ||
override fun notify(notification: StartNotification) { | ||
// Ensure that all nodes start with a termination time of 0. This also ensures | ||
// that all nodes are included in the terminationTimes map Why is this necessary? | ||
// It may occur the some nodes never export a route. If that is the case, then | ||
// these nodes would not be included in the terminationTimes map. | ||
for (node in notification.topology.nodes) | ||
data.terminationTimes[node.id] = 0 | ||
} | ||
|
||
/** | ||
* Invoked to notify the listener of a new export notification. | ||
*/ | ||
override fun notify(notification: ExportNotification) { | ||
// Update termination time of the node that exported a new route | ||
data.terminationTimes[notification.node.id] = notification.time | ||
} | ||
|
||
/** | ||
* Invoked to notify the listener of a new end notification. | ||
*/ | ||
override fun notify(notification: EndNotification) { | ||
for (node in notification.topology.nodes) | ||
data.selectedRoutes[node.id] = node.protocol.selectedRoute | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package simulation | ||
|
||
import core.routing.NodeID | ||
import core.routing.Route | ||
import core.simulator.Time | ||
|
||
/** | ||
* Created on 02-10-2017. | ||
* | ||
* @author David Fialho | ||
*/ | ||
class NodeDataSet : DataSet { | ||
|
||
/** | ||
* Data stored for each node. | ||
*/ | ||
data class NodeData(var selectedRoute: Route, var terminationTime: Time = 0) | ||
|
||
val terminationTimes: MutableMap<NodeID, Time> = HashMap() | ||
val selectedRoutes: MutableMap<NodeID, Route> = HashMap() | ||
|
||
/** | ||
* Clears all data from the data set. | ||
*/ | ||
override fun clear() { | ||
terminationTimes.clear() | ||
selectedRoutes.clear() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.