Skip to content

Commit

Permalink
Release 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
David Fialho committed Sep 28, 2017
2 parents bf3f290 + 274f1c6 commit 1b1f1d2
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 15 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
group 'ssbgp'
version '1.1.1'
version '1.2'

buildscript {
ext.kotlin_version = '1.1.4-3'
ext.kotlin_version = '1.1.50'
ext.dokka_version = '0.9.15'
ext.junit_version = '1.0.0-M4'
ext.junit5_version = '5.0.0-M4'
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/bgp/BGP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ abstract class BaseBGP(val mrai: Time, routingTable: RoutingTable<BGPRoute>): Pr
*/
val routingTable = RouteSelector.wrap(routingTable, ::bgpRouteCompare)

/**
* The route selected by the protocol.
*/
override val selectedRoute: BGPRoute
get() = routingTable.getSelectedRoute()

var mraiTimer = Timer.disabled()
protected set

Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/core/routing/Protocol.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ interface Protocol<R: Route> {
*/
val inNeighbors: Collection<Neighbor<R>>

/**
* The route selected by the protocol.
*/
val selectedRoute: R

/**
* Adds a new in-neighbor for the protocol to consider.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/core/simulator/Engine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object Engine {
event.processIt()
}

BasicNotifier.notifyEnd(EndNotification())
BasicNotifier.notifyEnd(EndNotification(topology))

return terminatedBeforeThreshold
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package core.simulator.notifications

import core.routing.Topology


/**
* Created on 25-07-2017.
*
* @author David Fialho
*/
class EndNotification : Notification()
data class EndNotification(val topology: Topology<*>) : Notification()
8 changes: 4 additions & 4 deletions src/main/kotlin/io/BasicReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package io

import simulation.BasicDataSet
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.io.Writer


/**
Expand Down Expand Up @@ -45,7 +43,8 @@ class BasicReporter(private val outputFile: File): Reporter<BasicDataSet> {
"Termination Time (Avg.)",
"Message Count",
"Detection Count",
"Terminated"
"Terminated",
"Disconnected Count"
)

wereHeadersPrinted = true
Expand All @@ -58,7 +57,8 @@ class BasicReporter(private val outputFile: File): Reporter<BasicDataSet> {
data.avgTerminationTime,
data.messageCount,
data.detectionCount,
if (data.terminated) "Yes" else "No"
if (data.terminated) "Yes" else "No",
data.disconnectedCount
)

simulation++
Expand Down
19 changes: 16 additions & 3 deletions src/main/kotlin/simulation/BasicDataCollector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ import java.io.IOException
*
* @param reporter the reporter used to report the final data.
*/
class BasicDataCollector(private val reporter: BasicReporter): DataCollector,
class BasicDataCollector(private val reporter: BasicReporter) : DataCollector,
StartListener,
MessageSentListener,
ExportListener,
DetectListener,
ThresholdReachedListener {
ThresholdReachedListener,
EndListener {

/**
* Creates a Basic Reporter that will output results to the specified output file.
*/
constructor(outputFile: File): this(BasicReporter(outputFile))
constructor(outputFile: File) : this(BasicReporter(outputFile))

/**
* Stores the final data to be reported.
Expand Down Expand Up @@ -57,6 +58,7 @@ class BasicDataCollector(private val reporter: BasicReporter): DataCollector,
BGPNotifier.addExportListener(this)
BGPNotifier.addDetectListener(this)
BasicNotifier.addThresholdReachedListener(this)
BasicNotifier.addEndListener(this)
}

/**
Expand All @@ -68,6 +70,7 @@ class BasicDataCollector(private val reporter: BasicReporter): DataCollector,
BGPNotifier.removeExportListener(this)
BGPNotifier.removeDetectListener(this)
BasicNotifier.removeThresholdReachedListener(this)
BasicNotifier.removeEndListener(this)
}

/**
Expand Down Expand Up @@ -138,5 +141,15 @@ class BasicDataCollector(private val reporter: BasicReporter): DataCollector,
data.terminated = false
}

/**
* Invoked to notify the listener of a new end notification.
*/
override fun notify(notification: EndNotification) {

data.disconnectedCount = notification.topology.nodes
.filterNot { it.protocol.selectedRoute.isValid() }
.count()
}

// endregion
}
5 changes: 4 additions & 1 deletion src/main/kotlin/simulation/BasicDataSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ import core.simulator.Time
* @property avgTerminationTime the average of the termination times of all nodes
* @property detectionCount the number of detections recorded during the simulation.
* @property terminated flag indicating if the simulation terminated or not
* @property disconnectedCount number of nodes left without a route when the simulation ended.
*/
data class BasicDataSet(
var delaySeed: Long = 0L,
var messageCount: Int = 0,
var totalTerminationTime: Time = 0,
var avgTerminationTime: Double = 0.0,
var detectionCount: Int = 0,
var terminated: Boolean = true
var terminated: Boolean = true,
var disconnectedCount: Int = 0

): DataSet {

Expand All @@ -36,5 +38,6 @@ data class BasicDataSet(
avgTerminationTime = 0.0
detectionCount = 0
terminated = true
disconnectedCount = 0
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package bgp.policies.interdomain

import bgp.bgpRouteCompare
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.*
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.context
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.hamcrest.Matchers.`is` as Is


Expand Down Expand Up @@ -51,6 +51,22 @@ object InterdomainCompareRoutesTests: Spek({
}
}

on("comparing a customer route and a peer* route") {

it("returns peer* route has higher preference") {
assertThat(bgpRouteCompare(peerstarRoute(), customerRoute()),
Is(greaterThan(0)))
}
}

on("comparing a peer+ route and a peer* route") {

it("returns peer+ route has higher preference") {
assertThat(bgpRouteCompare(peerplusRoute(), peerstarRoute()),
Is(greaterThan(0)))
}
}

on("comparing a customer route with 0 sibling hops with customer route with 1 sibling hop") {

it("returns route with 0 sibling hops has higher preference") {
Expand Down
3 changes: 3 additions & 0 deletions src/test/kotlin/testing/Fakes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ object FakeProtocol: Protocol<Route> {
override val inNeighbors: Collection<Neighbor<Route>>
get() = TODO("not implemented yet")

override val selectedRoute: Route
get() = TODO("not implemented yet")

override fun addInNeighbor(neighbor: Neighbor<Route>) {
TODO("not implemented yet")
}
Expand Down

0 comments on commit 1b1f1d2

Please sign in to comment.