Skip to content

Commit

Permalink
Release 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
David Fialho committed Sep 11, 2017
2 parents 7965f14 + bd84b51 commit bf3f290
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'ssbgp'
version '1.1'
version '1.1.1'

buildscript {
ext.kotlin_version = '1.1.4-3'
Expand Down
45 changes: 29 additions & 16 deletions src/main/kotlin/bgp/policies/interdomain/InterdomainExtenders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,81 @@ import core.routing.Node
* @author David Fialho
*/

const val LOCAL_PREF_PEERPLUS: Int = 400000
const val LOCAL_PREF_PEERPLUS: Int = 500000
const val LOCAL_PREF_PEERSTAR: Int = 400000
const val LOCAL_PREF_CUSTOMER: Int = 300000
const val LOCAL_PREF_PEER: Int = 200000
const val LOCAL_PREF_PROVIDER: Int = 100000

object CustomerExtender : Extender<BGPRoute> {
object CustomerExtender: Extender<BGPRoute> {

override fun extend(route: BGPRoute, sender: Node<BGPRoute>): BGPRoute {

return when {
route.localPref <= LOCAL_PREF_PEER -> BGPRoute.invalid()
else -> customerRoute(asPath = route.asPath.append(sender))
route.localPref <= LOCAL_PREF_PEER || route.localPref == LOCAL_PREF_PEERSTAR -> BGPRoute.invalid()
else -> customerRoute(asPath = route.asPath.append(sender))
}
}

}

object PeerExtender : Extender<BGPRoute> {
object PeerExtender: Extender<BGPRoute> {

override fun extend(route: BGPRoute, sender: Node<BGPRoute>): BGPRoute {

return when {
route.localPref <= LOCAL_PREF_PEER -> BGPRoute.invalid()
else -> peerRoute(asPath = route.asPath.append(sender))
route.localPref <= LOCAL_PREF_PEER || route.localPref == LOCAL_PREF_PEERSTAR -> BGPRoute.invalid()
else -> peerRoute(asPath = route.asPath.append(sender))
}
}

}

object ProviderExtender : Extender<BGPRoute> {
object ProviderExtender: Extender<BGPRoute> {

override fun extend(route: BGPRoute, sender: Node<BGPRoute>): BGPRoute {

return when {
!route.isValid() -> BGPRoute.invalid()
else -> providerRoute(asPath = route.asPath.append(sender))
else -> providerRoute(asPath = route.asPath.append(sender))
}
}

}

object PeerplusExtender : Extender<BGPRoute> {
object PeerplusExtender: Extender<BGPRoute> {

override fun extend(route: BGPRoute, sender: Node<BGPRoute>): BGPRoute {

return when {
route.localPref <= LOCAL_PREF_PEER -> BGPRoute.invalid()
else -> peerplusRoute(asPath = route.asPath.append(sender))
route.localPref <= LOCAL_PREF_PEER || route.localPref == LOCAL_PREF_PEERSTAR -> BGPRoute.invalid()
else -> peerplusRoute(asPath = route.asPath.append(sender))
}
}

}

object SiblingExtender : Extender<BGPRoute> {
object PeerstarExtender: Extender<BGPRoute> {

override fun extend(route: BGPRoute, sender: Node<BGPRoute>): BGPRoute {

return when {
!route.isValid() -> BGPRoute.invalid()
route.localPref <= LOCAL_PREF_PEER || route.localPref == LOCAL_PREF_PEERSTAR -> BGPRoute.invalid()
else -> peerstarRoute(asPath = route.asPath.append(sender))
}
}

}

object SiblingExtender: Extender<BGPRoute> {

override fun extend(route: BGPRoute, sender: Node<BGPRoute>): BGPRoute {

return when {
!route.isValid() -> BGPRoute.invalid()
route === BGPRoute.self() -> customerRoute(siblingHops = 1, asPath = route.asPath.append(sender))
else -> BGPRoute.with(localPref = route.localPref - 1,
asPath = route.asPath.append(sender))
else -> BGPRoute.with(localPref = route.localPref - 1,
asPath = route.asPath.append(sender))
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/bgp/policies/interdomain/Routes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import core.routing.emptyPath
fun peerplusRoute(siblingHops: Int = 0, asPath: Path = emptyPath())
= BGPRoute.with(localPref = LOCAL_PREF_PEERPLUS - siblingHops, asPath = asPath)

/**
* Returns a peer* route.
*/
fun peerstarRoute(siblingHops: Int = 0, asPath: Path = emptyPath())
= BGPRoute.with(localPref = LOCAL_PREF_PEERSTAR - siblingHops, asPath = asPath)

/**
* Returns a customer route.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/io/ExtenderParseFunctions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import core.routing.Extender
* Parses an Interdomain Extender. The supported labels are:
*
* R+ - parsed as a PeerplusExtender
* R* - parsed as a PeerstarExtender
* C - parsed as a CustomerExtender
* R - parsed as a PeerExtender
* P - parsed as a ProviderExtender
Expand All @@ -33,12 +34,13 @@ fun parseInterdomainExtender(label: String, lineNumber: Int): Extender<BGPRoute>

return when (label.toLowerCase()) {
"r+" -> PeerplusExtender
"r*" -> PeerstarExtender
"c" -> CustomerExtender
"r" -> PeerExtender
"p" -> ProviderExtender
"s" -> SiblingExtender
else -> throw ParseException("Extender label `$label` was not recognized: " +
"must be either R+, C, R, P, or S", lineNumber)
"must be either R+, R*, C, R, P, or S", lineNumber)
}
}

Expand Down
117 changes: 117 additions & 0 deletions src/test/kotlin/bgp/SSBGP2WithInterdomainRoutingTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package bgp

import bgp.policies.interdomain.customerRoute
import bgp.policies.interdomain.peerplusRoute
import core.simulator.Engine
import org.hamcrest.MatcherAssert.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import testing.*
import testing.bgp.pathOf
import org.hamcrest.Matchers.`is` as Is

/**
* Created on 01-09-2017
*
* @author David Fialho
*/
object SSBGP2WithInterdomainRoutingTests: Spek({


given("topology with cycle with all R+ links except one R* link") {

val topology = bgpTopology {
node { 0 deploying SSBGP2() }
node { 1 deploying SSBGP2() }
node { 2 deploying SSBGP2() }
node { 3 deploying SSBGP2() }

customerLink { 1 to 0 }
customerLink { 2 to 0 }
customerLink { 3 to 0 }
peerplusLink { 1 to 2 }
peerplusLink { 2 to 3 }
peerstarLink { 3 to 1 }
}

afterEachTest {
Engine.scheduler.reset()
topology.reset()
}

val node = topology.nodes.sortedBy { it.id }
val protocol = node.map { it.protocol as SSBGP2 }

on("simulating with node 0 as the destination") {

val terminated = Engine.simulate(topology, node[0], threshold = 1000)

it("terminates") {
assertThat(terminated, Is(true))
}

it("finishes with node 1 selecting peer+ route via 2") {
assertThat(protocol[1].routingTable.getSelectedRoute(),
Is(peerplusRoute(0, pathOf(0, 3, 2))))
}

it("finishes with node 2 selecting peer+ route via 3") {
assertThat(protocol[2].routingTable.getSelectedRoute(),
Is(peerplusRoute(0, pathOf(0, 3))))
}

it("finishes with node 3 selecting customer route via 0") {
assertThat(protocol[3].routingTable.getSelectedRoute(),
Is(customerRoute(0, pathOf(0))))
}

it("finishes with link from 1 to 2 enabled") {
assertThat(protocol[1].routingTable.table.isEnabled(node[2]), Is(true))
}

it("finishes with link from 2 to 3 enabled") {
assertThat(protocol[2].routingTable.table.isEnabled(node[3]), Is(true))
}

it("finishes with link from 3 to 1 disabled") {
assertThat(protocol[3].routingTable.table.isEnabled(node[1]), Is(false))
}
}
}

given("topology with cycle with all R* links") {

val topology = bgpTopology {
node { 0 deploying SSBGP2() }
node { 1 deploying SSBGP2() }
node { 2 deploying SSBGP2() }
node { 3 deploying SSBGP2() }

customerLink { 1 to 0 }
customerLink { 2 to 0 }
customerLink { 3 to 0 }
peerstarLink { 1 to 2 }
peerstarLink { 2 to 3 }
peerstarLink { 3 to 1 }
}

afterEachTest {
Engine.scheduler.reset()
topology.reset()
}

val node = topology.nodes.sortedBy { it.id }

on("simulating with node 0 as the destination") {

val terminated = Engine.simulate(topology, node[0], threshold = 1000)

it("does NOT terminate") {
assertThat(terminated, Is(false))
}
}
}

})
Loading

0 comments on commit bf3f290

Please sign in to comment.