Skip to content

Commit

Permalink
Pass nsaId to PCE in path computation request
Browse files Browse the repository at this point in the history
  • Loading branch information
erikrozendaal committed Dec 8, 2016
1 parent 5bd712f commit 8a0ff0e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
33 changes: 22 additions & 11 deletions app/nl/surfnet/safnari/PceMessage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ sealed trait PceMessage {
def correlationId: CorrelationId
}
sealed trait PceRequest extends PceMessage
case class PathComputationRequest(correlationId: CorrelationId, replyTo: URI, startTime: Option[Instant], endTime: Option[Instant], serviceType: ServiceType, algorithm: PathComputationAlgorithm, connectionTrace: List[ConnectionType]) extends PceRequest
case class PathComputationRequest(
correlationId: CorrelationId,
nsaId: Option[String],
replyTo: URI,
startTime: Option[Instant],
endTime: Option[Instant],
serviceType: ServiceType,
algorithm: PathComputationAlgorithm,
connectionTrace: List[ConnectionType]
) extends PceRequest

sealed trait PathComputationAlgorithm { def name: String }
object PathComputationAlgorithm {
Expand Down Expand Up @@ -221,6 +230,7 @@ object PceMessage {

implicit val PceRequestFormat: Format[PceRequest] = (
(__ \ "correlationId").format[CorrelationId] and
(__ \ "nsaId").formatNullable[String] and
(__ \ "replyTo" \ "url").format[URI] and
(__ \ "replyTo" \ "mediaType").format[String] and
(__ \ "algorithm").format[PathComputationAlgorithm] and
Expand All @@ -229,19 +239,20 @@ object PceMessage {
(__ \ "constraints").format[Seq[String]] and
ServiceTypeFormat and
(__ \ "trace").format[Seq[ConnectionType]])
.apply((correlationId, replyTo, mediaType, algorithm, start, end, constraints, serviceType, connectionTrace) => {
PathComputationRequest(correlationId, replyTo, start.map(_.toInstant), end.map(_.toInstant), serviceType, algorithm, connectionTrace.toList)
.apply((correlationId, nsaId, replyTo, mediaType, algorithm, start, end, constraints, serviceType, connectionTrace) => {
PathComputationRequest(correlationId, nsaId, replyTo, start.map(_.toInstant), end.map(_.toInstant), serviceType, algorithm, connectionTrace.toList)
}, {
case PathComputationRequest(correlationId, replyTo, start, end, serviceType, algorithm, connectionTrace) =>
(correlationId,
replyTo,
case request: PathComputationRequest =>
( request.correlationId,
request.nsaId,
request.replyTo,
"application/json",
algorithm,
start.map(_.toXMLGregorianCalendar()),
end.map(_.toXMLGregorianCalendar()),
request.algorithm,
request.startTime.map(_.toXMLGregorianCalendar()),
request.endTime.map(_.toXMLGregorianCalendar()),
Nil,
serviceType,
connectionTrace)
request.serviceType,
request.connectionTrace)
})

implicit val PceAcknowledgementWrites: Writes[PceAcknowledgement] = Writes {
Expand Down
1 change: 1 addition & 0 deletions app/nl/surfnet/safnari/ReservationStateMachine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ class ReservationStateMachine(
val criteria = nextStateData.criteria.requested.get
Seq(ToPce(PathComputationRequest(
newCorrelationId(),
Some(aggregatorNsa),
pceReplyUri,
criteria.schedule.flatMap(_.startTime.toOption(None)),
criteria.schedule.flatMap(_.endTime.toOption(None)),
Expand Down
1 change: 1 addition & 0 deletions test/nl/surfnet/safnari/ConnectionEntitySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ConnectionEntitySpec extends helpers.ConnectionEntitySpecification {

messages must contain(ToPce(PathComputationRequest(
correlationId = CorrelationId(0, 3),
nsaId = Some(AggregatorNsa),
replyTo = PceReplyToUri,
startTime = Schedule.startTime.toOption(None),
endTime = Schedule.endTime.toOption(None),
Expand Down
7 changes: 4 additions & 3 deletions test/nl/surfnet/safnari/PceMessageSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object PceMessageSpec {

val correlationId = helpers.Specification.newCorrelationId

val pathComputationRequest = PathComputationRequest(correlationId, URI.create("http://localhost/pce/reply"), None, None, ServiceType(ServiceTypeUrl, ServiceBaseType), PathComputationAlgorithm.Chain, Nil)
val pathComputationRequest = PathComputationRequest(correlationId, Some("NSA-ID"), URI.create("http://localhost/pce/reply"), None, None, ServiceType(ServiceTypeUrl, ServiceBaseType), PathComputationAlgorithm.Chain, Nil)

val providerEndPoint = ProviderEndPoint("provider-nsa", URI.create("http://localhost/pce/reply"))
val computedSegment = ComputedSegment(providerEndPoint, ServiceType(ServiceTypeUrl, ServiceBaseType))
Expand All @@ -45,11 +45,12 @@ class PceMessageSpec extends helpers.Specification {
import nl.surfnet.safnari.PceMessage._

"serialize request with p2pServiceBaseType to json" in {
val request = PathComputationRequest(correlationId, URI.create("http://localhost/pce/reply"), None, None, ServiceType(ServiceTypeUrl, ServiceBaseType), PathComputationAlgorithm.Chain, Nil)
val request = PathComputationRequest(correlationId, Some("NSA-ID"), URI.create("http://localhost/pce/reply"), None, None, ServiceType(ServiceTypeUrl, ServiceBaseType), PathComputationAlgorithm.Chain, Nil)

val json = Json.toJson(request)

json \ "correlationId" must beEqualTo(JsString(correlationId.toString))
json \ "nsaId" must beEqualTo(JsString("NSA-ID"))
json \ "replyTo" \ "url" must beEqualTo(JsString("http://localhost/pce/reply"))
json \ "algorithm" must beEqualTo(JsString("CHAIN"))
(json \ "p.p2ps" apply 0) \ "capacity" must beEqualTo(JsNumber(100))
Expand All @@ -61,7 +62,7 @@ class PceMessageSpec extends helpers.Specification {
val first = new ConnectionType().withIndex(0).withValue("firstnsa")
val second = new ConnectionType().withIndex(1).withValue("secondnsa")
val connectionTrace = List(first, second)
val request = PathComputationRequest(correlationId, URI.create("http://localhost/pce/reply"), None, None, ServiceType(ServiceTypeUrl, ServiceBaseType), PathComputationAlgorithm.Chain, connectionTrace)
val request = PathComputationRequest(correlationId, Some("NSA-ID"), URI.create("http://localhost/pce/reply"), None, None, ServiceType(ServiceTypeUrl, ServiceBaseType), PathComputationAlgorithm.Chain, connectionTrace)

val json = Json.toJson(request)
(json \ "trace" apply 0) \ "index" must beEqualTo(JsNumber(first.getIndex))
Expand Down

0 comments on commit 8a0ff0e

Please sign in to comment.