' Project      : NASA UTM
' Author       : Joseph Rios, joseph.l.rios@nasa.gov
' First version: 31 Aug 2017

@startuml
!include ../utm_fims_arch_seq_style.puml

participant "USS A" as A
participant "USS B" as B
participant "USS C" as C

title USS Negotiation for Strategic Deconfliction, Mark II\n\
VERSION_STAMP


box "LUN"
    participant A
    participant B
    participant C
end box

par POST new Operation to each USS in LUN
    B->A: New operation POST to \operations
    activate A
    A-->B: Ack via HTTP 200
    deactivate A
else
    B->C: New operation POST to \operations
    activate C
    C-->B: Ack via HTTP 200
    deactivate C
end

A->A: Plan operation,\nnotice intersection\nwith existing USS B\noperation.

A->B: New operation POST to \operations
activate B
B-->A: Ack via HTTP 200
deactivate B

par both USSs send NegotiationMessage
   A->B: POST NegotiationMessage\nINTERSECTING_OPERATION_NOTIFICATION\n to \\negotiations
   activate B
   B-->A: Ack via HTTP 200
   deactivate B
else
   B->B: Recognize intersection\n of operations
   B->A: POST NegotiationMessage\nINTERSECTING_OPERATION_NOTIFICATION\n to \\negotiations
   activate A
   A-->B:  Ack via HTTP 200
   deactivate A
end ' notify all in LUN


par both USSs determine who makes first change
   A->A: Determine primary\nand secondary\noperations
else
   B->B: Determine primary\nand secondary\noperations
end ' notify all in LUN

note over B,A

    Assume A is mutually found to be primary operation
    so B has to make first change.

endnote

B->A: POST NegotiationMessage\nREPLAN_BEGINNING_AS_SECONDARY_OPERATION\n to \\negotiations
activate A
A-->B: Ack via HTTP 200
deactivate A

B->B: Calculate new plan\nthat minimizes intersection\nensuring operator acceptance

B->A: Updated operation POST to \operations
activate A
A-->B: Ack via HTTP 200
deactivate A

note over B,A

    At this point, both operations again check for
    intersection. The negotiation continues until
    the documented stopping criteria.

endnote

@enduml